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.portlet;
022:
023: import com.liferay.portal.kernel.portlet.LiferayPortlet;
024: import com.liferay.portal.kernel.util.GetterUtil;
025: import com.liferay.portal.kernel.util.Validator;
026: import com.liferay.portal.struts.StrutsUtil;
027: import com.liferay.portal.util.PortalUtil;
028:
029: import java.io.IOException;
030:
031: import javax.portlet.ActionRequest;
032: import javax.portlet.ActionResponse;
033: import javax.portlet.PortletException;
034: import javax.portlet.PortletRequestDispatcher;
035: import javax.portlet.RenderRequest;
036: import javax.portlet.RenderResponse;
037:
038: import org.apache.commons.logging.Log;
039: import org.apache.commons.logging.LogFactory;
040:
041: /**
042: * <a href="JSPPortlet.java.html"><b><i>View Source</i></b></a>
043: *
044: * @author Brian Wing Shun Chan
045: *
046: */
047: public class JSPPortlet extends LiferayPortlet {
048:
049: public void init() throws PortletException {
050: aboutJSP = getInitParameter("about-jsp");
051: configJSP = getInitParameter("config-jsp");
052: editJSP = getInitParameter("edit-jsp");
053: editDefaultsJSP = getInitParameter("edit-defaults-jsp");
054: editGuestJSP = getInitParameter("edit-guest-jsp");
055: helpJSP = getInitParameter("help-jsp");
056: previewJSP = getInitParameter("preview-jsp");
057: printJSP = getInitParameter("print-jsp");
058: viewJSP = getInitParameter("view-jsp");
059:
060: copyRequestParameters = GetterUtil.getBoolean(
061: getInitParameter("copy-request-parameters"), true);
062: }
063:
064: public void processAction(ActionRequest req, ActionResponse res)
065: throws IOException, PortletException {
066:
067: if (copyRequestParameters) {
068: PortalUtil.copyRequestParameters(req, res);
069: }
070: }
071:
072: public void doDispatch(RenderRequest req, RenderResponse res)
073: throws IOException, PortletException {
074:
075: String jspPage = req.getParameter("jsp_page");
076:
077: if (Validator.isNotNull(jspPage)) {
078: include(jspPage, req, res);
079: } else {
080: super .doDispatch(req, res);
081: }
082: }
083:
084: public void doAbout(RenderRequest req, RenderResponse res)
085: throws IOException, PortletException {
086:
087: include(aboutJSP, req, res);
088: }
089:
090: public void doConfig(RenderRequest req, RenderResponse res)
091: throws IOException, PortletException {
092:
093: include(configJSP, req, res);
094: }
095:
096: public void doEdit(RenderRequest req, RenderResponse res)
097: throws IOException, PortletException {
098:
099: if (req.getPreferences() == null) {
100: super .doEdit(req, res);
101: } else {
102: include(editJSP, req, res);
103: }
104: }
105:
106: public void doEditDefaults(RenderRequest req, RenderResponse res)
107: throws IOException, PortletException {
108:
109: if (req.getPreferences() == null) {
110: super .doEdit(req, res);
111: } else {
112: include(editDefaultsJSP, req, res);
113: }
114: }
115:
116: public void doEditGuest(RenderRequest req, RenderResponse res)
117: throws IOException, PortletException {
118:
119: if (req.getPreferences() == null) {
120: super .doEdit(req, res);
121: } else {
122: include(editGuestJSP, req, res);
123: }
124: }
125:
126: public void doHelp(RenderRequest req, RenderResponse res)
127: throws IOException, PortletException {
128:
129: include(helpJSP, req, res);
130: }
131:
132: public void doPreview(RenderRequest req, RenderResponse res)
133: throws IOException, PortletException {
134:
135: include(previewJSP, req, res);
136: }
137:
138: public void doPrint(RenderRequest req, RenderResponse res)
139: throws IOException, PortletException {
140:
141: include(printJSP, req, res);
142: }
143:
144: public void doView(RenderRequest req, RenderResponse res)
145: throws IOException, PortletException {
146:
147: include(viewJSP, req, res);
148: }
149:
150: protected void include(String path, RenderRequest req,
151: RenderResponse res) throws IOException, PortletException {
152:
153: PortletRequestDispatcher prd = getPortletContext()
154: .getRequestDispatcher(StrutsUtil.TEXT_HTML_DIR + path);
155:
156: if (prd == null) {
157: _log.error(path + " is not a valid include");
158: } else {
159: prd.include(req, res);
160: }
161:
162: if (copyRequestParameters) {
163: PortalUtil.clearRequestParameters(req);
164: }
165: }
166:
167: protected String aboutJSP;
168: protected String configJSP;
169: protected String editJSP;
170: protected String editDefaultsJSP;
171: protected String editGuestJSP;
172: protected String helpJSP;
173: protected String previewJSP;
174: protected String printJSP;
175: protected String viewJSP;
176: protected boolean copyRequestParameters;
177:
178: private static Log _log = LogFactory.getLog(JSPPortlet.class);
179:
180: }
|