001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.portlet.mvc;
018
019import javax.portlet.ActionRequest;
020import javax.portlet.ActionResponse;
021import javax.portlet.PortletException;
022import javax.portlet.RenderRequest;
023import javax.portlet.RenderResponse;
024
025import org.springframework.web.portlet.ModelAndView;
026
027/**
028 * <p>Trivial controller that transforms the PortletMode to a view name.
029 * The advantage here is that the client is not exposed to
030 * the concrete view technology but rather just to the controller URL;
031 * the concrete view will be determined by the ViewResolver.</p>
032 *
033 * <p>Example: PortletMode.VIEW -> "view"</p>
034 *
035 * <p>This controller does not handle action requests.</p>
036 *
037 * @author William G. Thompson, Jr.
038 * @author John A. Lewis
039 * @since 2.0
040 */
041public class PortletModeNameViewController implements Controller {
042
043        @Override
044        public void handleActionRequest(ActionRequest request, ActionResponse response) throws Exception {
045                throw new PortletException("PortletModeNameViewController does not handle action requests");
046        }
047
048        @Override
049        public ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) {
050                return new ModelAndView(request.getPortletMode().toString());
051        }
052
053}