View Javadoc

1   /*
2    * Copyright 2003,2004 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  /* 
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      // <not used variables - only for castor>
52      public String icon = null;
53      public String distributable = null;
54      public String sessionConfig = null;
55      public String mimeMapping = null;
56      public String welcomeFileList = null;
57      public String errorPage = null;
58      public String taglib = null;
59      public String resourceRef = null;
60      public String securityConstraint = null;
61      public String loginConfig = null;
62      public String securityRole = null;
63      public String envEntry = null;
64      public String ejbRef = null;
65      private Collection castorMimeMappings = new ArrayList();    // </not used variables - only for castor>
66  
67  
68      private String contextPath = null;        
69      private DescriptionSet descriptions = new org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl();
70      private DisplayNameSet displayNames =  new org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl();
71      private String id = "";
72      private ParameterSet initParams = new org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl();
73      private ObjectID objectId = null;
74      private Collection servletMappings = new ArrayList();
75      private ServletDefinitionList servlets = new ServletDefinitionListImpl();
76      private SecurityRoleSet securityRoles = new org.apache.pluto.portalImpl.om.common.impl.SecurityRoleSetImpl();
77  
78      // modified by YCLI: START :: to handle multiple taglib tags and resource-ref tag
79      // private TagDefinition castorTagDefinition = new TagDefinition();
80      private TagDefinitionSet taglibs = new TagDefinitionSet();
81      private ResourceRefSet castorResourceRef = new ResourceRefSet();
82      // modified by YCLI: END
83  
84      // WebApplicationDefinition implementation.
85      
86      public ObjectID getId() {
87          if (objectId==null) {
88              objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(id);
89          }
90          return objectId;
91      }
92  
93      /* (non-Javadoc)
94       * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getDisplayName(Locale)
95       */
96      public DisplayName getDisplayName(Locale locale) {
97          return displayNames.get(locale);
98      }
99  
100     public Description getDescription(Locale locale)
101     {
102         return descriptions.get(locale);
103     }
104 
105     public ParameterSet getInitParameterSet()
106     {
107         return initParams;
108     }
109 
110     public ServletDefinitionList getServletDefinitionList()
111     {
112         return servlets;
113     }
114 
115     public ServletContext getServletContext(ServletContext servletContext)
116     {
117         if (Log.isDebugEnabled()) {
118             Log.debug("Looking up ServletContext for path "+contextPath);
119         }
120         return servletContext.getContext(contextPath);
121     }
122 
123     public String getContextRoot() {
124 
125         return contextPath;
126     }
127 
128     // Support implementation.
129 
130     public void postBuild(Object parameter) throws Exception
131     {
132         // not needed in this implementation
133     }
134 
135     public void postLoad(Object parameter) throws Exception
136     {
137         Vector structure = (Vector)parameter;
138         PortletApplicationDefinition portletApplication = (PortletApplicationDefinition)structure.get(0);
139         String contextString = (String)structure.get(1);
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         String contextString = (String)structure.get(1);
183 
184         ((Support)portletApplication).preStore(null);
185 
186         ((Support)servlets).preStore(this);
187     }
188     
189     // additional methods.
190     
191     public String getCastorId() {                
192         if (id.length() > 0) {
193             return getId().toString();
194         } else {
195             return null;
196         }
197     }
198 
199     public Collection getCastorInitParams()
200     {
201         return(org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams;
202     }
203 
204     public Collection getCastorServlets()
205     {
206         return(ServletDefinitionListImpl)servlets;
207     }
208 
209     public Collection getCastorDisplayNames()
210     {
211         return(DisplayNameSetImpl)displayNames;
212     }
213 
214     public Collection getCastorDescriptions()
215     {
216         return(DescriptionSetImpl)descriptions;
217     }
218 
219     public SecurityRoleSet getSecurityRoles()
220     {
221         return securityRoles;
222     }
223 
224     public Collection getServletMappings()
225     {
226         return servletMappings;
227     }
228     public void setCastorId(String id) {        
229         setId(id);
230     }
231     
232     protected void setContextRoot(String contextPath)
233     {
234         // Test for IBM WebSphere 
235         if (contextPath != null && contextPath.endsWith(".war"))
236         {
237             contextPath = contextPath.substring(0, contextPath.length()-4);
238         }
239         this.contextPath = contextPath;
240     }    
241 
242     public void setDescriptions(DescriptionSet descriptions)
243     {
244         this.descriptions = descriptions;
245     }
246 
247     public void setDisplayNames(DisplayNameSet displayNames)
248     {
249         this.displayNames = displayNames;
250     }
251 
252     public void setCastorDescriptions(DescriptionSet castorDescriptions)
253     {
254         this.descriptions = castorDescriptions;
255     }
256 
257     public void setCastorDisplayNames(DisplayNameSet castorDisplayNames)
258     {
259         this.displayNames = castorDisplayNames;
260     }
261 
262     public void setId(String id)
263     {
264         this.id = id;
265         objectId = null;
266     }
267 
268     // internal methods used for debugging purposes only
269 
270     public String toString()
271     {
272         return toString(0);
273     }
274 
275     public String toString(int indent)
276     {
277         StringBuffer buffer = new StringBuffer(50);
278         StringUtils.newLine(buffer,indent);
279         buffer.append(getClass().toString()); buffer.append(":");
280         StringUtils.newLine(buffer,indent);
281         buffer.append("{");
282         StringUtils.newLine(buffer,indent);
283         buffer.append("id='"); buffer.append(id); buffer.append("'");
284 
285         StringUtils.newLine(buffer,indent);
286         buffer.append(((DisplayNameSetImpl)displayNames).toString(indent));
287 
288         StringUtils.newLine(buffer,indent);
289         buffer.append(((DescriptionSetImpl)descriptions).toString(indent));
290 
291         StringUtils.newLine(buffer,indent);
292         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams).toString(indent));
293 
294         StringUtils.newLine(buffer,indent);
295         buffer.append(((ServletDefinitionListImpl)servlets).toString(indent));
296 
297         Iterator iterator = servletMappings.iterator();
298         if (iterator.hasNext()) {
299             StringUtils.newLine(buffer,indent);
300             buffer.append("ServletMappings:");
301         }
302         while (iterator.hasNext()) {
303             buffer.append(((ServletMappingImpl)iterator.next()).toString(indent+2));
304         }
305 
306         StringUtils.newLine(buffer,indent);
307         buffer.append("contextPath='"); buffer.append(contextPath); buffer.append("'");
308         StringUtils.newLine(buffer,indent);
309         buffer.append("}");
310         return buffer.toString();
311     }
312 
313     // modified by YCLI: START :: handling multiple taglib tags and resource-ref tag
314 
315     /***
316      * @return Custom tag definitions configured in the webapp.
317      */
318     public TagDefinitionSet getTagDefinitionSet()
319     {
320         return taglibs;
321     }
322 
323     public Collection getCastorTagDefinitions() {
324         return (TagDefinitionSet) taglibs;
325     }
326 
327     public void setCastorTagDefinitions(TagDefinitionSet taglibs)
328     {
329         this.taglibs = taglibs;
330     }
331 
332     public ResourceRefSet getCastorResourceRefSet() {
333         return castorResourceRef;
334     }
335 
336     public void setCastorResourceRefSet(ResourceRefSet resourceRefs) {
337         castorResourceRef = resourceRefs;
338     }
339     // modified by YCLI: END
340 
341     /***
342      * @return Returns the castorMimeMappings.
343      */
344     public Collection getCastorMimeMappings() 
345     {
346         return castorMimeMappings;
347     }
348     
349     /***
350      * @param castorMimeMappings The castorMimeMappings to set.
351      */
352     public void setCastorMimeMappings(Collection castorMimeMappings) 
353     {
354         this.castorMimeMappings = castorMimeMappings;
355     }
356 }