1
22
23 package com.liferay.portlet;
24
25 import com.liferay.portal.kernel.portlet.LiferayPortlet;
26 import com.liferay.portal.kernel.util.GetterUtil;
27 import com.liferay.portal.kernel.util.Validator;
28 import com.liferay.portal.struts.StrutsUtil;
29 import com.liferay.portal.util.PortalUtil;
30
31 import java.io.IOException;
32
33 import javax.portlet.ActionRequest;
34 import javax.portlet.ActionResponse;
35 import javax.portlet.PortletException;
36 import javax.portlet.PortletRequestDispatcher;
37 import javax.portlet.RenderRequest;
38 import javax.portlet.RenderResponse;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43
49 public class JSPPortlet extends LiferayPortlet {
50
51 public void init() throws PortletException {
52 aboutJSP = getInitParameter("about-jsp");
53 configJSP = getInitParameter("config-jsp");
54 editJSP = getInitParameter("edit-jsp");
55 editDefaultsJSP = getInitParameter("edit-defaults-jsp");
56 editGuestJSP = getInitParameter("edit-guest-jsp");
57 helpJSP = getInitParameter("help-jsp");
58 previewJSP = getInitParameter("preview-jsp");
59 printJSP = getInitParameter("print-jsp");
60 viewJSP = getInitParameter("view-jsp");
61
62 copyRequestParameters = GetterUtil.getBoolean(
63 getInitParameter("copy-request-parameters"), true);
64 }
65
66 public void processAction(ActionRequest req, ActionResponse res)
67 throws IOException, PortletException {
68
69 if (copyRequestParameters) {
70 PortalUtil.copyRequestParameters(req, res);
71 }
72 }
73
74 public void doDispatch(RenderRequest req, RenderResponse res)
75 throws IOException, PortletException {
76
77 String jspPage = req.getParameter("jsp_page");
78
79 if (Validator.isNotNull(jspPage)) {
80 include(jspPage, req, res);
81 }
82 else {
83 super.doDispatch(req, res);
84 }
85 }
86
87 public void doAbout(RenderRequest req, RenderResponse res)
88 throws IOException, PortletException {
89
90 include(aboutJSP, req, res);
91 }
92
93 public void doConfig(RenderRequest req, RenderResponse res)
94 throws IOException, PortletException {
95
96 include(configJSP, req, res);
97 }
98
99 public void doEdit(RenderRequest req, RenderResponse res)
100 throws IOException, PortletException {
101
102 if (req.getPreferences() == null) {
103 super.doEdit(req, res);
104 }
105 else {
106 include(editJSP, req, res);
107 }
108 }
109
110 public void doEditDefaults(RenderRequest req, RenderResponse res)
111 throws IOException, PortletException {
112
113 if (req.getPreferences() == null) {
114 super.doEdit(req, res);
115 }
116 else {
117 include(editDefaultsJSP, req, res);
118 }
119 }
120
121 public void doEditGuest(RenderRequest req, RenderResponse res)
122 throws IOException, PortletException {
123
124 if (req.getPreferences() == null) {
125 super.doEdit(req, res);
126 }
127 else {
128 include(editGuestJSP, req, res);
129 }
130 }
131
132 public void doHelp(RenderRequest req, RenderResponse res)
133 throws IOException, PortletException {
134
135 include(helpJSP, req, res);
136 }
137
138 public void doPreview(RenderRequest req, RenderResponse res)
139 throws IOException, PortletException {
140
141 include(previewJSP, req, res);
142 }
143
144 public void doPrint(RenderRequest req, RenderResponse res)
145 throws IOException, PortletException {
146
147 include(printJSP, req, res);
148 }
149
150 public void doView(RenderRequest req, RenderResponse res)
151 throws IOException, PortletException {
152
153 include(viewJSP, req, res);
154 }
155
156 protected void include(String path, RenderRequest req, RenderResponse res)
157 throws IOException, PortletException {
158
159 PortletRequestDispatcher prd =
160 getPortletContext().getRequestDispatcher(
161 StrutsUtil.TEXT_HTML_DIR + path);
162
163 if (prd == null) {
164 _log.error(path + " is not a valid include");
165 }
166 else {
167 prd.include(req, res);
168 }
169
170 if (copyRequestParameters) {
171 PortalUtil.clearRequestParameters(req);
172 }
173 }
174
175 protected String aboutJSP;
176 protected String configJSP;
177 protected String editJSP;
178 protected String editDefaultsJSP;
179 protected String editGuestJSP;
180 protected String helpJSP;
181 protected String previewJSP;
182 protected String printJSP;
183 protected String viewJSP;
184 protected boolean copyRequestParameters;
185
186 private static Log _log = LogFactory.getLog(JSPPortlet.class);
187
188 }