1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.pluto.portlet.admin.controller;
17
18 import java.io.IOException;
19 import java.util.Enumeration;
20 import java.util.Properties;
21
22 import javax.portlet.GenericPortlet;
23 import javax.portlet.PortletConfig;
24 import javax.portlet.PortletContext;
25 import javax.portlet.PortletException;
26 import javax.portlet.PortletRequest;
27 import javax.portlet.PortletRequestDispatcher;
28 import javax.portlet.RenderRequest;
29 import javax.portlet.RenderResponse;
30
31 import org.apache.pluto.portlet.admin.PlutoAdminConstants;
32 import org.apache.pluto.portlet.admin.util.PlutoAdminContext;
33
34 /***
35 * Base class to all portlets.
36 *
37 * @author Craig Doremus
38 *
39 */
40 public class ControllerPortlet extends GenericPortlet {
41
42 protected String _incView = "/view.jsp";
43 protected String _incEdit = "/edit.jsp";
44 protected String _incHelp = "/help.jsp";
45 protected Properties _properties = null;
46 protected PortletContext _ctx = null;
47
48
49
50
51 protected void doEdit(RenderRequest request, RenderResponse response)
52 throws PortletException, IOException {
53 response.setContentType("text/html");
54
55 PortletRequestDispatcher rd = _ctx.getRequestDispatcher(_incEdit);
56 rd.include(request, response);
57 }
58
59
60
61 protected void doView(RenderRequest request, RenderResponse response)
62 throws PortletException, IOException {
63 response.setContentType("text/html");
64
65 PortletRequestDispatcher rd = _ctx.getRequestDispatcher(_incView);
66 rd.include(request, response);
67 }
68
69
70
71
72 protected void doHelp(RenderRequest request, RenderResponse response)
73 throws PortletException, IOException {
74 response.setContentType("text/html");
75
76 PortletRequestDispatcher rd = _ctx.getRequestDispatcher(_incHelp);
77 rd.include(request, response);
78 }
79
80
81
82
83
84 public void init() throws PortletException {
85 super.init();
86
87 try {
88 _ctx = getPortletContext();
89 PortletConfig config = getPortletConfig();
90 String tmp = config.getInitParameter("view_include");
91 if (tmp != null) {
92 _incView = tmp;
93 }
94 log("View include: " + _incView);
95 tmp = config.getInitParameter("edit_include");
96 if (tmp != null) {
97 _incEdit = tmp;
98 }
99 log("Edit include: " + _incEdit);
100 tmp = config.getInitParameter("help_include");
101 if (tmp != null) {
102 _incHelp = tmp;
103 }
104 log("Help include: " + _incHelp);
105
106
107 _properties = PlutoAdminContext.getProperties();
108
109
110
111
112 String plutoPath = _ctx.getRealPath("");
113
114 PlutoAdminContext.parseDeploymentPaths(plutoPath);
115 } catch (Throwable e) {
116 log("Error thrown in ControllerPortlet.init()", e);
117 }
118
119
120 }
121
122
123
124
125
126
127
128
129
130
131 protected void log(String msg) {
132 _ctx.log(msg);
133
134 }
135
136 protected void log(String msg, Throwable e) {
137 _ctx.log(msg, e);
138
139 }
140
141 protected String getPageRegistryFileName() {
142 String fileName = _properties.getProperty("pageregistry-file");
143 return fileName;
144 }
145
146 protected String getPageRegistryFilePath() {
147 return getDataDirPath() + PlutoAdminConstants.FS + getPageRegistryFileName();
148 }
149
150 protected String getPortletRegistryFileName() {
151 String fileName = _properties.getProperty("portletregistry-file");
152 return fileName;
153 }
154
155 protected String getPortletRegistryFilePath() {
156 return getDataDirPath() + PlutoAdminConstants.FS + getPortletRegistryFileName();
157 }
158
159 protected String getDataDirPath() {
160 String path = null;
161
162
163
164
165 String plutoHome = PlutoAdminContext.getInstance().getPlutoHome();
166
167
168
169 String dataDirRelPath = _properties.getProperty("data-dir-relative-path");
170 path = plutoHome + PlutoAdminConstants.FS + dataDirRelPath;
171 return path;
172 }
173
174
175 protected void printParams(PortletRequest request) {
176 log("Parameter names/values");
177 Enumeration penum = request.getParameterNames();
178 while (penum.hasMoreElements()) {
179 String pname = (String) penum.nextElement();
180 String[] pvals = request.getParameterValues(pname);
181 for (int i = 0; i < pvals.length; i++) {
182 String val = pvals[i];
183 log("Parameter: " + pname + "==" + val);
184 }
185 }
186 }
187 }