2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 package com.liferay.ext.util.bridges.mvc;
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.portlet.LiferayPortlet;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.util.PortalUtil;
31 import java.io.IOException;
33 import javax.portlet.ActionRequest;
34 import javax.portlet.ActionResponse;
35 import javax.portlet.PortletException;
36 import javax.portlet.PortletRequest;
37 import javax.portlet.PortletRequestDispatcher;
38 import javax.portlet.PortletResponse;
39 import javax.portlet.RenderRequest;
40 import javax.portlet.RenderResponse;
41 import javax.portlet.ResourceRequest;
42 import javax.portlet.ResourceResponse;
44 public class MVCPortlet extends LiferayPortlet {
47 aboutJSP = getInitParameter("about-jsp");
48 configJSP = getInitParameter("config-jsp");
49 editJSP = getInitParameter("edit-jsp");
50 editDefaultsJSP = getInitParameter("edit-defaults-jsp");
51 editGuestJSP = getInitParameter("edit-guest-jsp");
52 helpJSP = getInitParameter("help-jsp");
53 previewJSP = getInitParameter("preview-jsp");
54 printJSP = getInitParameter("print-jsp");
55 viewJSP = getInitParameter("view-jsp");
57 clearRequestParameters = GetterUtil.getBoolean(
58 getInitParameter("clear-request-parameters"));
59 copyRequestParameters = GetterUtil.getBoolean(
60 getInitParameter("copy-request-parameters"));
64 RenderRequest renderRequest, RenderResponse renderResponse)
65 throws IOException, PortletException {
67 include(aboutJSP, renderRequest, renderResponse);
71 RenderRequest renderRequest, RenderResponse renderResponse)
72 throws IOException, PortletException {
74 include(configJSP, renderRequest, renderResponse);
78 RenderRequest renderRequest, RenderResponse renderResponse)
79 throws IOException, PortletException {
81 if (renderRequest.getPreferences() == null) {
82 super.doEdit(renderRequest, renderResponse);
85 include(editJSP, renderRequest, renderResponse);
89 public void doEditDefaults(
90 RenderRequest renderRequest, RenderResponse renderResponse)
91 throws IOException, PortletException {
93 if (renderRequest.getPreferences() == null) {
94 super.doEdit(renderRequest, renderResponse);
97 include(editDefaultsJSP, renderRequest, renderResponse);
101 public void doEditGuest(
102 RenderRequest renderRequest, RenderResponse renderResponse)
103 throws IOException, PortletException {
105 if (renderRequest.getPreferences() == null) {
106 super.doEdit(renderRequest, renderResponse);
109 include(editGuestJSP, renderRequest, renderResponse);
114 RenderRequest renderRequest, RenderResponse renderResponse)
115 throws IOException, PortletException {
117 include(helpJSP, renderRequest, renderResponse);
120 public void doPreview(
121 RenderRequest renderRequest, RenderResponse renderResponse)
122 throws IOException, PortletException {
124 include(previewJSP, renderRequest, renderResponse);
128 RenderRequest renderRequest, RenderResponse renderResponse)
129 throws IOException, PortletException {
131 include(printJSP, renderRequest, renderResponse);
135 RenderRequest renderRequest, RenderResponse renderResponse)
136 throws IOException, PortletException {
138 include(viewJSP, renderRequest, renderResponse);
141 public void processAction(
142 ActionRequest actionRequest, ActionResponse actionResponse)
143 throws IOException, PortletException {
145 super.processAction(actionRequest, actionResponse);
147 if (copyRequestParameters) {
148 PortalUtil.copyRequestParameters(actionRequest, actionResponse);
152 public void serveResource(
153 ResourceRequest resourceRequest, ResourceResponse resourceResponse)
154 throws IOException, PortletException {
156 String jspPage = resourceRequest.getParameter("jspPage");
158 if (jspPage != null) {
160 jspPage, resourceRequest, resourceResponse,
161 PortletRequest.RESOURCE_PHASE);
164 super.serveResource(resourceRequest, resourceResponse);
168 protected void doDispatch(
169 RenderRequest renderRequest, RenderResponse renderResponse)
170 throws IOException, PortletException {
172 String jspPage = renderRequest.getParameter("jspPage");
174 if (jspPage != null) {
175 include(jspPage, renderRequest, renderResponse);
178 super.doDispatch(renderRequest, renderResponse);
182 protected void include(
183 String path, PortletRequest portletRequest,
184 PortletResponse portletResponse)
185 throws IOException, PortletException {
188 path, portletRequest, portletResponse, PortletRequest.RENDER_PHASE);
191 protected void include(
192 String path, PortletRequest portletRequest,
193 PortletResponse portletResponse, String lifecycle)
194 throws IOException, PortletException {
196 PortletRequestDispatcher portletRequestDispatcher =
197 getPortletContext().getRequestDispatcher(path);
199 if (portletRequestDispatcher == null) {
200 _log.error(path + " is not a valid include");
203 portletRequestDispatcher.include(portletRequest, portletResponse);
206 if (clearRequestParameters) {
207 if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
208 portletResponse.setProperty("clear-request-parameters", "true");
213 protected String aboutJSP;
214 protected String configJSP;
215 protected String editJSP;
216 protected String editDefaultsJSP;
217 protected String editGuestJSP;
218 protected String helpJSP;
219 protected String previewJSP;
220 protected String printJSP;
221 protected String viewJSP;
222 protected boolean clearRequestParameters;
223 protected boolean copyRequestParameters;
225 private static Log _log = LogFactoryUtil.getLog(MVCPortlet.class);