001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util.bridges.jsp;
022:
023: import com.liferay.portal.kernel.portlet.LiferayRenderRequest;
024: import com.liferay.portal.kernel.util.GetterUtil;
025:
026: import java.io.IOException;
027:
028: import javax.portlet.ActionRequest;
029: import javax.portlet.ActionResponse;
030: import javax.portlet.GenericPortlet;
031: import javax.portlet.PortletException;
032: import javax.portlet.PortletRequestDispatcher;
033: import javax.portlet.RenderRequest;
034: import javax.portlet.RenderResponse;
035:
036: import org.apache.commons.logging.Log;
037: import org.apache.commons.logging.LogFactory;
038:
039: /**
040: * <a href="JSPPortlet.java.html"><b><i>View Source</i></b></a>
041: *
042: * @author Brian Wing Shun Chan
043: *
044: */
045: public class JSPPortlet extends GenericPortlet {
046:
047: public void init() throws PortletException {
048: editJSP = getInitParameter("edit-jsp");
049: helpJSP = getInitParameter("help-jsp");
050: viewJSP = getInitParameter("view-jsp");
051:
052: clearRequestParameters = GetterUtil
053: .getBoolean(getInitParameter("clear-request-parameters"));
054: }
055:
056: public void doDispatch(RenderRequest req, RenderResponse res)
057: throws IOException, PortletException {
058:
059: String jspPage = req.getParameter("jspPage");
060:
061: if (jspPage != null) {
062: include(jspPage, req, res);
063: } else {
064: super .doDispatch(req, res);
065: }
066: }
067:
068: public void doEdit(RenderRequest req, RenderResponse res)
069: throws IOException, PortletException {
070:
071: if (req.getPreferences() == null) {
072: super .doEdit(req, res);
073: } else {
074: include(editJSP, req, res);
075: }
076: }
077:
078: public void doHelp(RenderRequest req, RenderResponse res)
079: throws IOException, PortletException {
080:
081: include(helpJSP, req, res);
082: }
083:
084: public void doView(RenderRequest req, RenderResponse res)
085: throws IOException, PortletException {
086:
087: include(viewJSP, req, res);
088: }
089:
090: public void processAction(ActionRequest req, ActionResponse res)
091: throws IOException, PortletException {
092: }
093:
094: protected void include(String path, RenderRequest req,
095: RenderResponse res) throws IOException, PortletException {
096:
097: PortletRequestDispatcher prd = getPortletContext()
098: .getRequestDispatcher(path);
099:
100: if (prd == null) {
101: _log.error(path + " is not a valid include");
102: } else {
103: prd.include(req, res);
104: }
105:
106: if (clearRequestParameters) {
107: ((LiferayRenderRequest) req).getRenderParameters().clear();
108: }
109: }
110:
111: protected String editJSP;
112: protected String helpJSP;
113: protected String viewJSP;
114: protected boolean clearRequestParameters;
115:
116: private static Log _log = LogFactory.getLog(JSPPortlet.class);
117:
118: }
|