KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portlet > admin > controller > ControllerPortlet


1 /*
2  * Copyright 2003,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.pluto.portlet.admin.controller;
17
18 import java.io.IOException JavaDoc;
19 import java.util.Enumeration JavaDoc;
20 import java.util.Properties JavaDoc;
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 JavaDoc _incView = "/view.jsp";
43     protected String JavaDoc _incEdit = "/edit.jsp";
44     protected String JavaDoc _incHelp = "/help.jsp";
45     protected Properties JavaDoc _properties = null;
46     protected PortletContext _ctx = null;
47
48     /* (non-Javadoc)
49      * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
50      */

51     protected void doEdit(RenderRequest request, RenderResponse response)
52             throws PortletException, IOException JavaDoc {
53         response.setContentType("text/html");
54
55         PortletRequestDispatcher rd = _ctx.getRequestDispatcher(_incEdit);
56         rd.include(request, response);
57     }
58     /* (non-Javadoc)
59      * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
60      */

61     protected void doView(RenderRequest request, RenderResponse response)
62             throws PortletException, IOException JavaDoc {
63         response.setContentType("text/html");
64
65         PortletRequestDispatcher rd = _ctx.getRequestDispatcher(_incView);
66         rd.include(request, response);
67     }
68
69     /* (non-Javadoc)
70      * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
71      */

72     protected void doHelp(RenderRequest request, RenderResponse response)
73             throws PortletException, IOException JavaDoc {
74         response.setContentType("text/html");
75
76         PortletRequestDispatcher rd = _ctx.getRequestDispatcher(_incHelp);
77         rd.include(request, response);
78     }
79
80
81     /* (non-Javadoc)
82      * @see javax.portlet.GenericPortlet#init()
83      */

84     public void init() throws PortletException {
85         super.init();
86         //
87
try {
88             _ctx = getPortletContext();
89             PortletConfig config = getPortletConfig();
90             String JavaDoc 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             //load properties
107
_properties = PlutoAdminContext.getProperties();
108
109             //Configure the paths to the container home dir,
110
// Pluto's dir and the deployment dir. This needs to
111
// be done before any admin portlets are called.
112
String JavaDoc plutoPath = _ctx.getRealPath("");//Path with single slash is also allowed
113
// String plutoPath = null;//for testing
114
PlutoAdminContext.parseDeploymentPaths(plutoPath);
115         } catch (Throwable JavaDoc e) {
116             log("Error thrown in ControllerPortlet.init()", e);
117         }
118
119
120     }
121
122     /* (non-Javadoc)
123      * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
124     public void processAction(ActionRequest request, ActionResponse response)
125             throws PortletException, IOException {
126         // TODO Auto-generated method stub
127         super.processAction(request, response);
128     }
129      */

130
131     protected void log(String JavaDoc msg) {
132         _ctx.log(msg);
133 // System.out.println(msg);
134
}
135
136     protected void log(String JavaDoc msg, Throwable JavaDoc e) {
137         _ctx.log(msg, e);
138 // System.out.println(msg + " Message:" + e.getMessage());
139
}
140
141     protected String JavaDoc getPageRegistryFileName() {
142         String JavaDoc fileName = _properties.getProperty("pageregistry-file");
143         return fileName;
144     }
145
146     protected String JavaDoc getPageRegistryFilePath() {
147         return getDataDirPath() + PlutoAdminConstants.FS + getPageRegistryFileName();
148     }
149
150     protected String JavaDoc getPortletRegistryFileName() {
151         String JavaDoc fileName = _properties.getProperty("portletregistry-file");
152         return fileName;
153     }
154
155     protected String JavaDoc getPortletRegistryFilePath() {
156         return getDataDirPath() + PlutoAdminConstants.FS + getPortletRegistryFileName();
157     }
158
159     protected String JavaDoc getDataDirPath() {
160         String JavaDoc path = null;
161 // String realPath = _ctx.getRealPath("/");
162
// int indTomcatHome = realPath.indexOf( PlutoAdminConstants.FS + "webapps");
163
// String tomcatHome = realPath.substring(0, indTomcatHome);
164

165         String JavaDoc plutoHome = PlutoAdminContext.getInstance().getPlutoHome();
166 // path = tomcatHome + PlutoAdminConstants.FS + "webapps" +
167
// PlutoAdminConstants.FS + _properties.getProperty("pluto-web-context") +
168
// PlutoAdminConstants.FS + dataDirRelPath;
169
String JavaDoc 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 JavaDoc penum = request.getParameterNames();
178         while (penum.hasMoreElements()) {
179             String JavaDoc pname = (String JavaDoc) penum.nextElement();
180             String JavaDoc[] pvals = request.getParameterValues(pname);
181             for (int i = 0; i < pvals.length; i++) {
182                 String JavaDoc val = pvals[i];
183                 log("Parameter: " + pname + "==" + val);
184             }
185         }
186     }
187 }
188
Popular Tags