KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > apache > jk > BaseApacheHandler


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

17 package org.apache.geronimo.console.apache.jk;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23 import javax.portlet.ActionResponse;
24 import javax.portlet.PortletRequest;
25 import javax.portlet.PortletSession;
26 import org.apache.geronimo.console.MultiPageAbstractHandler;
27 import org.apache.geronimo.console.MultiPageModel;
28 import org.apache.geronimo.console.util.PortletManager;
29 import org.apache.geronimo.kernel.repository.Artifact;
30 import org.apache.geronimo.gbean.AbstractName;
31
32 /**
33  * The base class for all handlers for this portlet
34  *
35  * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
36  */

37 public abstract class BaseApacheHandler extends MultiPageAbstractHandler {
38     protected static final String JavaDoc INDEX_MODE = "index";
39     protected static final String JavaDoc BASIC_CONFIG_MODE = "basic";
40     protected static final String JavaDoc AJP_MODE = "ajp";
41     protected static final String JavaDoc WEB_APP_MODE = "webapp";
42     protected static final String JavaDoc RESULTS_MODE = "results";
43
44     protected BaseApacheHandler(String JavaDoc mode, String JavaDoc viewName) {
45         super(mode, viewName);
46     }
47
48     public final static class WebAppData implements Serializable JavaDoc {
49         private String JavaDoc parentConfigId;
50         private String JavaDoc childName;
51         private String JavaDoc moduleBeanName;
52         private boolean enabled;
53         private String JavaDoc dynamicPattern;
54         private boolean serveStaticContent;
55         private String JavaDoc contextRoot;
56         private String JavaDoc webAppDir;
57
58         public WebAppData(Artifact parentConfigId, String JavaDoc childName, AbstractName moduleBeanName, boolean enabled, String JavaDoc dynamicPattern, boolean serveStaticContent) {
59             this.parentConfigId = parentConfigId.toString();
60             this.enabled = enabled;
61             this.dynamicPattern = dynamicPattern;
62             this.serveStaticContent = serveStaticContent;
63             this.moduleBeanName = moduleBeanName == null ? null : moduleBeanName.toString();
64             this.childName = childName;
65         }
66
67         public WebAppData(PortletRequest request, String JavaDoc prefix) {
68             parentConfigId = request.getParameter(prefix+"configId");
69             childName = request.getParameter(prefix+"childName");
70             moduleBeanName = request.getParameter(prefix+"moduleBeanName");
71             dynamicPattern = request.getParameter(prefix+"dynamicPattern");
72             String JavaDoc test = request.getParameter(prefix+"enabled");
73             enabled = test != null && !test.equals("") && !test.equals("false");
74             test = request.getParameter(prefix+"serveStaticContent");
75             serveStaticContent = test != null && !test.equals("") && !test.equals("false");
76             contextRoot = request.getParameter(prefix+"contextRoot");
77             webAppDir = request.getParameter(prefix+"webAppDir");
78         }
79
80         public void save(ActionResponse response, String JavaDoc prefix) {
81             response.setRenderParameter(prefix+"configId", parentConfigId);
82             response.setRenderParameter(prefix+"moduleBeanName", moduleBeanName);
83             response.setRenderParameter(prefix+"dynamicPattern", dynamicPattern);
84             response.setRenderParameter(prefix+"enabled", Boolean.toString(enabled));
85             response.setRenderParameter(prefix+"serveStaticContent", Boolean.toString(serveStaticContent));
86             if(!isEmpty(contextRoot)) response.setRenderParameter(prefix+"contextRoot", contextRoot);
87             if(!isEmpty(webAppDir)) response.setRenderParameter(prefix+"webAppDir", webAppDir);
88             if(!isEmpty(childName)) response.setRenderParameter(prefix+"childName", childName);
89         }
90
91         public boolean isEnabled() {
92             return enabled;
93         }
94
95         public void setEnabled(boolean enabled) {
96             this.enabled = enabled;
97         }
98
99         public String JavaDoc getParentConfigId() {
100             return parentConfigId;
101         }
102
103         public void setParentConfigId(String JavaDoc parentConfigId) {
104             this.parentConfigId = parentConfigId;
105         }
106
107         public String JavaDoc getDynamicPattern() {
108             return dynamicPattern;
109         }
110
111         public void setDynamicPattern(String JavaDoc dynamicPattern) {
112             this.dynamicPattern = dynamicPattern;
113         }
114
115         public boolean isServeStaticContent() {
116             return serveStaticContent;
117         }
118
119         public void setServeStaticContent(boolean serveStaticContent) {
120             this.serveStaticContent = serveStaticContent;
121         }
122
123         public String JavaDoc getContextRoot() {
124             return contextRoot;
125         }
126
127         public void setContextRoot(String JavaDoc contextRoot) {
128             this.contextRoot = contextRoot;
129         }
130
131         public String JavaDoc getWebAppDir() {
132             return webAppDir;
133         }
134
135         public void setWebAppDir(String JavaDoc webAppDir) {
136             this.webAppDir = webAppDir;
137         }
138
139         public String JavaDoc getChildName() {
140             return childName;
141         }
142
143         public String JavaDoc getModuleBeanName() {
144             return moduleBeanName;
145         }
146
147         public String JavaDoc getName() {
148             return isEmpty(childName) ? parentConfigId : childName;
149         }
150
151         public boolean isRunning() {
152             return webAppDir != null;
153         }
154     }
155
156     public final static class ApacheModel implements MultiPageModel {
157         public final static String JavaDoc WEB_APP_SESSION_KEY = "console.apache.jk.WebApps";
158         private String JavaDoc os;
159         private Integer JavaDoc addAjpPort;
160         private String JavaDoc logFilePath;
161         private String JavaDoc workersPath;
162         private List JavaDoc webApps = new ArrayList JavaDoc();
163
164         public ApacheModel(PortletRequest request) {
165             Map JavaDoc map = request.getParameterMap();
166             os = request.getParameter("os");
167             logFilePath = request.getParameter("logFilePath");
168             if(logFilePath == null) {
169                 logFilePath = PortletManager.getCurrentServer(request).getServerInfo().resolve("var/log/apache_mod_jk.log").getPath();
170             }
171             workersPath = request.getParameter("workersPath");
172             if(workersPath == null) {
173                 workersPath = PortletManager.getCurrentServer(request).getServerInfo().resolve("var/config/workers.properties").getPath();
174             }
175             String JavaDoc ajp = request.getParameter("addAjpPort");
176             if(!isEmpty(ajp)) addAjpPort = new Integer JavaDoc(ajp);
177             int index = 0;
178             boolean found = false;
179             while(true) {
180                 String JavaDoc key = "webapp."+(index++)+".";
181                 if(!map.containsKey(key+"configId")) {
182                     break;
183                 }
184                 found = true;
185                 WebAppData data = new WebAppData(request, key);
186                 webApps.add(data);
187             }
188             if(!found) {
189                 List JavaDoc list = (List JavaDoc) request.getPortletSession(true).getAttribute(WEB_APP_SESSION_KEY);
190                 if(list != null) {
191                     webApps = list;
192                 }
193             }
194         }
195
196         public void save(ActionResponse response, PortletSession session) {
197             if(!isEmpty(os)) response.setRenderParameter("os", os);
198             if(!isEmpty(logFilePath)) response.setRenderParameter("logFilePath", logFilePath);
199             if(!isEmpty(workersPath)) response.setRenderParameter("workersPath", workersPath);
200             if(addAjpPort != null) response.setRenderParameter("addAjpPort", addAjpPort.toString());
201             if(webApps.size() > 0) {
202                 session.setAttribute(WEB_APP_SESSION_KEY, webApps);
203             }
204         }
205
206         public String JavaDoc getOs() {
207             return os;
208         }
209
210         public void setOs(String JavaDoc os) {
211             this.os = os;
212         }
213
214         public Integer JavaDoc getAddAjpPort() {
215             return addAjpPort;
216         }
217
218         public void setAddAjpPort(Integer JavaDoc addAjpPort) {
219             this.addAjpPort = addAjpPort;
220         }
221
222         public String JavaDoc getLogFilePath() {
223             return logFilePath;
224         }
225
226         public void setLogFilePath(String JavaDoc logFilePath) {
227             this.logFilePath = logFilePath;
228         }
229
230         public String JavaDoc getWorkersPath() {
231             return workersPath;
232         }
233
234         public void setWorkersPath(String JavaDoc workersPath) {
235             this.workersPath = workersPath;
236         }
237
238         public List JavaDoc getWebApps() {
239             return webApps;
240         }
241
242         public void setWebApps(List JavaDoc webApps) {
243             this.webApps = webApps;
244         }
245     }
246 }
247
Popular Tags