1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.pluto.portalImpl.om.servlet.impl;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.Locale;
27 import java.util.Vector;
28
29 import javax.servlet.ServletContext;
30
31 import org.apache.pluto.om.common.Description;
32 import org.apache.pluto.om.common.DescriptionSet;
33 import org.apache.pluto.om.common.DisplayName;
34 import org.apache.pluto.om.common.DisplayNameSet;
35 import org.apache.pluto.om.common.ObjectID;
36 import org.apache.pluto.om.common.ParameterSet;
37 import org.apache.pluto.om.common.SecurityRoleSet;
38 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
39 import org.apache.pluto.om.servlet.ServletDefinitionList;
40 import org.apache.pluto.om.servlet.WebApplicationDefinition;
41 import org.apache.pluto.portalImpl.om.common.Support;
42 import org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl;
43 import org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl;
44 import org.apache.pluto.portalImpl.services.log.Log;
45 import org.apache.pluto.util.StringUtils;
46
47 public class WebApplicationDefinitionImpl
48 implements WebApplicationDefinition, java.io.Serializable, Support {
49
50
51
52 public String icon;
53 public String distributable;
54 public String sessionConfig;
55 public String mimeMapping;
56 public String welcomeFileList;
57 public String errorPage;
58 public String taglib;
59 public String resourceRef;
60 public String loginConfig;
61 public String securityRole;
62 public String envEntry;
63 public String ejbRef;
64 private Collection castorMimeMappings = new ArrayList();
65
66 private Collection securityConstraints = new ArrayList();
67
68
69 private String contextPath;
70 private DescriptionSet descriptions = new org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl();
71 private DisplayNameSet displayNames = new org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl();
72 private String id = "";
73 private ParameterSet initParams = new org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl();
74 private ObjectID objectId;
75 private Collection servletMappings = new ArrayList();
76 private ServletDefinitionList servlets = new ServletDefinitionListImpl();
77 private SecurityRoleSet securityRoles = new org.apache.pluto.portalImpl.om.common.impl.SecurityRoleSetImpl();
78
79
80
81 private TagDefinitionSet taglibs = new TagDefinitionSet();
82 private ResourceRefSet castorResourceRef = new ResourceRefSet();
83
84
85
86
87 public ObjectID getId() {
88 if (objectId==null) {
89 objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(id);
90 }
91 return objectId;
92 }
93
94
95
96
97 public DisplayName getDisplayName(Locale locale) {
98 return displayNames.get(locale);
99 }
100
101 public Description getDescription(Locale locale)
102 {
103 return descriptions.get(locale);
104 }
105
106 public ParameterSet getInitParameterSet()
107 {
108 return initParams;
109 }
110
111 public ServletDefinitionList getServletDefinitionList()
112 {
113 return servlets;
114 }
115
116 public ServletContext getServletContext(ServletContext servletContext)
117 {
118 if (Log.isDebugEnabled()) {
119 Log.debug("Looking up ServletContext for path "+contextPath);
120 }
121 return servletContext.getContext(contextPath);
122 }
123
124 public String getContextRoot() {
125
126 return contextPath;
127 }
128
129
130
131 public void postBuild(Object parameter) throws Exception
132 {
133
134 }
135
136 public void postLoad(Object parameter) throws Exception
137 {
138 Vector structure = (Vector)parameter;
139 PortletApplicationDefinition portletApplication = (PortletApplicationDefinition)structure.get(0);
140
141 ((Support)portletApplication).postLoad(this);
142
143 ((Support)servlets).postLoad(this);
144
145 ((Support)descriptions).postLoad(parameter);
146 ((Support)displayNames).postLoad(parameter);
147
148 }
149
150 public void postStore(Object parameter) throws Exception
151 {
152 ((Support)servlets).postStore(this);
153 }
154
155 public void preBuild(Object parameter) throws Exception
156 {
157 Vector structure = (Vector)parameter;
158 PortletApplicationDefinition portletApplication = (PortletApplicationDefinition)structure.get(0);
159 String contextString = (String)structure.get(1);
160
161 setContextRoot(contextString);
162
163 HashMap servletMap = new HashMap(1);
164 Vector structure2 = new Vector();
165 structure2.add(this);
166 structure2.add(servletMappings);
167 structure2.add(servletMap);
168
169 ((Support)servlets).preBuild(structure2);
170
171 Vector structure3 = new Vector();
172 structure3.add(contextString);
173 structure3.add(this);
174 structure3.add(servletMap);
175 ((Support)portletApplication).preBuild(structure3);
176 }
177
178 public void preStore(Object parameter) throws Exception
179 {
180 Vector structure = (Vector)parameter;
181 PortletApplicationDefinition portletApplication = (PortletApplicationDefinition)structure.get(0);
182
183 ((Support)portletApplication).preStore(null);
184
185 ((Support)servlets).preStore(this);
186 }
187
188
189
190 public String getCastorId() {
191 if (id.length() > 0) {
192 return getId().toString();
193 } else {
194 return null;
195 }
196 }
197
198 public Collection getCastorInitParams()
199 {
200 return(org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams;
201 }
202
203 public Collection getCastorServlets()
204 {
205 return(ServletDefinitionListImpl)servlets;
206 }
207
208 public Collection getCastorDisplayNames()
209 {
210 return(DisplayNameSetImpl)displayNames;
211 }
212
213 public Collection getCastorDescriptions()
214 {
215 return(DescriptionSetImpl)descriptions;
216 }
217
218 public SecurityRoleSet getSecurityRoles()
219 {
220 return securityRoles;
221 }
222
223 public Collection getServletMappings()
224 {
225 return servletMappings;
226 }
227 public void setCastorId(String id) {
228 setId(id);
229 }
230
231 protected void setContextRoot(String contextPath)
232 {
233
234 if (contextPath != null && contextPath.endsWith(".war"))
235 {
236 contextPath = contextPath.substring(0, contextPath.length()-4);
237 }
238 this.contextPath = contextPath;
239 }
240
241 public void setDescriptions(DescriptionSet descriptions)
242 {
243 this.descriptions = descriptions;
244 }
245
246 public void setDisplayNames(DisplayNameSet displayNames)
247 {
248 this.displayNames = displayNames;
249 }
250
251 public void setCastorDescriptions(DescriptionSet castorDescriptions)
252 {
253 this.descriptions = castorDescriptions;
254 }
255
256 public void setCastorDisplayNames(DisplayNameSet castorDisplayNames)
257 {
258 this.displayNames = castorDisplayNames;
259 }
260
261 public void setId(String id)
262 {
263 this.id = id;
264 objectId = null;
265 }
266
267
268
269 public String toString()
270 {
271 return toString(0);
272 }
273
274 public String toString(int indent)
275 {
276 StringBuffer buffer = new StringBuffer(50);
277 StringUtils.newLine(buffer,indent);
278 buffer.append(getClass().toString()); buffer.append(":");
279 StringUtils.newLine(buffer,indent);
280 buffer.append("{");
281 StringUtils.newLine(buffer,indent);
282 buffer.append("id='"); buffer.append(id); buffer.append("'");
283
284 StringUtils.newLine(buffer,indent);
285 buffer.append(((DisplayNameSetImpl)displayNames).toString(indent));
286
287 StringUtils.newLine(buffer,indent);
288 buffer.append(((DescriptionSetImpl)descriptions).toString(indent));
289
290 StringUtils.newLine(buffer,indent);
291 buffer.append(((org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams).toString(indent));
292
293 StringUtils.newLine(buffer,indent);
294 buffer.append(((ServletDefinitionListImpl)servlets).toString(indent));
295
296 Iterator iterator = servletMappings.iterator();
297 if (iterator.hasNext()) {
298 StringUtils.newLine(buffer,indent);
299 buffer.append("ServletMappings:");
300 }
301 while (iterator.hasNext()) {
302 buffer.append(((ServletMappingImpl)iterator.next()).toString(indent+2));
303 }
304
305 StringUtils.newLine(buffer,indent);
306 buffer.append("contextPath='"); buffer.append(contextPath); buffer.append("'");
307 StringUtils.newLine(buffer,indent);
308 buffer.append("}");
309 return buffer.toString();
310 }
311
312
313
314 /***
315 * @return Custom tag definitions configured in the webapp.
316 */
317 public TagDefinitionSet getTagDefinitionSet()
318 {
319 return taglibs;
320 }
321
322 public Collection getCastorTagDefinitions() {
323 return taglibs;
324 }
325
326 public void setCastorTagDefinitions(TagDefinitionSet taglibs)
327 {
328 this.taglibs = taglibs;
329 }
330
331 public ResourceRefSet getCastorResourceRefSet() {
332 return castorResourceRef;
333 }
334
335 public void setCastorResourceRefSet(ResourceRefSet resourceRefs) {
336 castorResourceRef = resourceRefs;
337 }
338
339
340 /***
341 * @return Returns the castorMimeMappings.
342 */
343 public Collection getCastorMimeMappings()
344 {
345 return castorMimeMappings;
346 }
347
348 public Collection getSecurityConstraints() {
349 return securityConstraints;
350 }
351
352 /***
353 * @param castorMimeMappings The castorMimeMappings to set.
354 */
355 public void setCastorMimeMappings(Collection castorMimeMappings)
356 {
357 this.castorMimeMappings = castorMimeMappings;
358 }
359
360 public void setSecurityConstraints(Collection securityConstraints) {
361 this.securityConstraints = securityConstraints;
362 }
363 }