1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
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:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
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
20   * SOFTWARE.
21   */
22  
23  package com.liferay.util.bridges.jsp;
24  
25  import com.liferay.portal.kernel.portlet.LiferayRenderRequest;
26  import com.liferay.portal.kernel.util.GetterUtil;
27  
28  import java.io.IOException;
29  
30  import javax.portlet.ActionRequest;
31  import javax.portlet.ActionResponse;
32  import javax.portlet.GenericPortlet;
33  import javax.portlet.PortletException;
34  import javax.portlet.PortletRequestDispatcher;
35  import javax.portlet.RenderRequest;
36  import javax.portlet.RenderResponse;
37  
38  import org.apache.commons.logging.Log;
39  import org.apache.commons.logging.LogFactory;
40  
41  /**
42   * <a href="JSPPortlet.java.html"><b><i>View Source</i></b></a>
43   *
44   * @author Brian Wing Shun Chan
45   *
46   */
47  public class JSPPortlet extends GenericPortlet {
48  
49      public void init() throws PortletException {
50          editJSP = getInitParameter("edit-jsp");
51          helpJSP = getInitParameter("help-jsp");
52          viewJSP = getInitParameter("view-jsp");
53  
54          clearRequestParameters = GetterUtil.getBoolean(
55              getInitParameter("clear-request-parameters"));
56      }
57  
58      public void doDispatch(RenderRequest req, RenderResponse res)
59          throws IOException, PortletException {
60  
61          String jspPage = req.getParameter("jspPage");
62  
63          if (jspPage != null) {
64              include(jspPage, req, res);
65          }
66          else {
67              super.doDispatch(req, res);
68          }
69      }
70  
71      public void doEdit(RenderRequest req, RenderResponse res)
72          throws IOException, PortletException {
73  
74          if (req.getPreferences() == null) {
75              super.doEdit(req, res);
76          }
77          else {
78              include(editJSP, req, res);
79          }
80      }
81  
82      public void doHelp(RenderRequest req, RenderResponse res)
83          throws IOException, PortletException {
84  
85          include(helpJSP, req, res);
86      }
87  
88      public void doView(RenderRequest req, RenderResponse res)
89          throws IOException, PortletException {
90  
91          include(viewJSP, req, res);
92      }
93  
94      public void processAction(ActionRequest req, ActionResponse res)
95          throws IOException, PortletException {
96      }
97  
98      protected void include(String path, RenderRequest req, RenderResponse res)
99          throws IOException, PortletException {
100 
101         PortletRequestDispatcher prd =
102             getPortletContext().getRequestDispatcher(path);
103 
104         if (prd == null) {
105             _log.error(path + " is not a valid include");
106         }
107         else {
108             prd.include(req, res);
109         }
110 
111         if (clearRequestParameters) {
112             ((LiferayRenderRequest)req).getRenderParameters().clear();
113         }
114     }
115 
116     protected String editJSP;
117     protected String helpJSP;
118     protected String viewJSP;
119     protected boolean clearRequestParameters;
120 
121     private static Log _log = LogFactory.getLog(JSPPortlet.class);
122 
123 }