--- /dev/null
+/**
+ * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.liferay.ext.util.bridges.mvc;
+
+import com.liferay.portal.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+import com.liferay.portal.kernel.portlet.LiferayPortlet;
+import com.liferay.portal.kernel.util.GetterUtil;
+import com.liferay.portal.util.PortalUtil;
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+
+public class MVCPortlet extends LiferayPortlet {
+
+ public void init() {
+ aboutJSP = getInitParameter("about-jsp");
+ configJSP = getInitParameter("config-jsp");
+ editJSP = getInitParameter("edit-jsp");
+ editDefaultsJSP = getInitParameter("edit-defaults-jsp");
+ editGuestJSP = getInitParameter("edit-guest-jsp");
+ helpJSP = getInitParameter("help-jsp");
+ previewJSP = getInitParameter("preview-jsp");
+ printJSP = getInitParameter("print-jsp");
+ viewJSP = getInitParameter("view-jsp");
+
+ clearRequestParameters = GetterUtil.getBoolean(
+ getInitParameter("clear-request-parameters"));
+ copyRequestParameters = GetterUtil.getBoolean(
+ getInitParameter("copy-request-parameters"));
+ }
+
+ public void doAbout(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(aboutJSP, renderRequest, renderResponse);
+ }
+
+ public void doConfig(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(configJSP, renderRequest, renderResponse);
+ }
+
+ public void doEdit(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ if (renderRequest.getPreferences() == null) {
+ super.doEdit(renderRequest, renderResponse);
+ }
+ else {
+ include(editJSP, renderRequest, renderResponse);
+ }
+ }
+
+ public void doEditDefaults(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ if (renderRequest.getPreferences() == null) {
+ super.doEdit(renderRequest, renderResponse);
+ }
+ else {
+ include(editDefaultsJSP, renderRequest, renderResponse);
+ }
+ }
+
+ public void doEditGuest(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ if (renderRequest.getPreferences() == null) {
+ super.doEdit(renderRequest, renderResponse);
+ }
+ else {
+ include(editGuestJSP, renderRequest, renderResponse);
+ }
+ }
+
+ public void doHelp(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(helpJSP, renderRequest, renderResponse);
+ }
+
+ public void doPreview(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(previewJSP, renderRequest, renderResponse);
+ }
+
+ public void doPrint(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(printJSP, renderRequest, renderResponse);
+ }
+
+ public void doView(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(viewJSP, renderRequest, renderResponse);
+ }
+
+ public void processAction(
+ ActionRequest actionRequest, ActionResponse actionResponse)
+ throws IOException, PortletException {
+
+ super.processAction(actionRequest, actionResponse);
+
+ if (copyRequestParameters) {
+ PortalUtil.copyRequestParameters(actionRequest, actionResponse);
+ }
+ }
+
+ public void serveResource(
+ ResourceRequest resourceRequest, ResourceResponse resourceResponse)
+ throws IOException, PortletException {
+
+ String jspPage = resourceRequest.getParameter("jspPage");
+
+ if (jspPage != null) {
+ include(
+ jspPage, resourceRequest, resourceResponse,
+ PortletRequest.RESOURCE_PHASE);
+ }
+ else {
+ super.serveResource(resourceRequest, resourceResponse);
+ }
+ }
+
+ protected void doDispatch(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ String jspPage = renderRequest.getParameter("jspPage");
+
+ if (jspPage != null) {
+ include(jspPage, renderRequest, renderResponse);
+ }
+ else {
+ super.doDispatch(renderRequest, renderResponse);
+ }
+ }
+
+ protected void include(
+ String path, PortletRequest portletRequest,
+ PortletResponse portletResponse)
+ throws IOException, PortletException {
+
+ include(
+ path, portletRequest, portletResponse, PortletRequest.RENDER_PHASE);
+ }
+
+ protected void include(
+ String path, PortletRequest portletRequest,
+ PortletResponse portletResponse, String lifecycle)
+ throws IOException, PortletException {
+
+ PortletRequestDispatcher portletRequestDispatcher =
+ getPortletContext().getRequestDispatcher(path);
+
+ if (portletRequestDispatcher == null) {
+ _log.error(path + " is not a valid include");
+ }
+ else {
+ portletRequestDispatcher.include(portletRequest, portletResponse);
+ }
+
+ if (clearRequestParameters) {
+ if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
+ portletResponse.setProperty("clear-request-parameters", "true");
+ }
+ }
+ }
+
+ protected String aboutJSP;
+ protected String configJSP;
+ protected String editJSP;
+ protected String editDefaultsJSP;
+ protected String editGuestJSP;
+ protected String helpJSP;
+ protected String previewJSP;
+ protected String printJSP;
+ protected String viewJSP;
+ protected boolean clearRequestParameters;
+ protected boolean copyRequestParameters;
+
+ private static Log _log = LogFactoryUtil.getLog(MVCPortlet.class);
+
+}
\ No newline at end of file