001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.pluto.om;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.HashMap;
022: import java.util.Locale;
023: import java.util.Vector;
024:
025: import javax.servlet.ServletContext;
026:
027: import org.apache.pluto.om.common.Description;
028: import org.apache.pluto.om.common.DescriptionSet;
029: import org.apache.pluto.om.common.DisplayName;
030: import org.apache.pluto.om.common.DisplayNameSet;
031: import org.apache.pluto.om.common.ObjectID;
032: import org.apache.pluto.om.common.ParameterSet;
033: import org.apache.pluto.om.common.SecurityRoleSet;
034: import org.apache.pluto.om.portlet.PortletApplicationDefinition;
035: import org.apache.pluto.om.servlet.ServletDefinitionList;
036: import org.apache.pluto.om.servlet.WebApplicationDefinition;
037: import org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl;
038: import org.apache.cocoon.portal.pluto.om.common.ParameterSetImpl;
039: import org.apache.cocoon.portal.pluto.om.common.ResourceRefSet;
040: import org.apache.cocoon.portal.pluto.om.common.SecurityRoleSetImpl;
041: import org.apache.cocoon.portal.pluto.om.common.Support;
042: import org.apache.cocoon.portal.pluto.om.common.DescriptionSetImpl;
043: import org.apache.cocoon.portal.pluto.om.common.DisplayNameSetImpl;
044: import org.apache.cocoon.portal.pluto.om.common.TagDefinitionSet;
045:
046: /**
047: *
048: *
049: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
050: *
051: * @version CVS $Id: WebApplicationDefinitionImpl.java 433543 2006-08-22 06:22:54Z crossley $
052: */
053: public class WebApplicationDefinitionImpl implements
054: WebApplicationDefinition, Support {
055:
056: // <not used variables - only for castor>
057: public String icon;
058: public String distributable;
059: public String sessionConfig;
060: public String mimeMapping;
061: public String welcomeFileList;
062: public String errorPage;
063: public String taglib;
064: public String resourceRef;
065: public String loginConfig;
066: public String securityRole;
067: public String envEntry;
068: public String ejbRef;
069: private Collection castorMimeMappings = new ArrayList();
070: // </not used variables - only for castor>
071: private Collection securityConstraints = new ArrayList();
072:
073: private String contextPath;
074: private DescriptionSet descriptions = new DescriptionSetImpl();
075: private DisplayNameSet displayNames = new DisplayNameSetImpl();
076: private String id = "";
077: private ParameterSet initParams = new ParameterSetImpl();
078: /** The object id */
079: private ObjectID objectId;
080: private Collection servletMappings = new ArrayList();
081: private ServletDefinitionList servlets = new ServletDefinitionListImpl();
082: private SecurityRoleSet securityRoles = new SecurityRoleSetImpl();
083:
084: // modified by YCLI: START :: to handle multiple taglib tags and resource-ref tag
085: // private TagDefinition castorTagDefinition = new TagDefinition();
086: private TagDefinitionSet taglibs = new TagDefinitionSet();
087: private ResourceRefSet castorResourceRef = new ResourceRefSet();
088:
089: // modified by YCLI: END
090:
091: // WebApplicationDefinition implementation.
092:
093: public ObjectID getId() {
094: if (this .objectId == null) {
095: this .objectId = ObjectIDImpl.createFromString(id);
096: }
097: return this .objectId;
098: }
099:
100: /* (non-Javadoc)
101: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getDisplayName(Locale)
102: */
103: public DisplayName getDisplayName(Locale locale) {
104: return displayNames.get(locale);
105: }
106:
107: /* (non-Javadoc)
108: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getDescription(java.util.Locale)
109: */
110: public Description getDescription(Locale locale) {
111: return descriptions.get(locale);
112: }
113:
114: /* (non-Javadoc)
115: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getInitParameterSet()
116: */
117: public ParameterSet getInitParameterSet() {
118: return initParams;
119: }
120:
121: /* (non-Javadoc)
122: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getServletDefinitionList()
123: */
124: public ServletDefinitionList getServletDefinitionList() {
125: return servlets;
126: }
127:
128: /* (non-Javadoc)
129: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getServletContext(javax.servlet.ServletContext)
130: */
131: public ServletContext getServletContext(
132: ServletContext servletContext) {
133: return servletContext.getContext(contextPath);
134: }
135:
136: /* (non-Javadoc)
137: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getContextRoot()
138: */
139: public String getContextRoot() {
140: return contextPath;
141: }
142:
143: /* (non-Javadoc)
144: * @see org.apache.cocoon.portal.pluto.om.common.Support#postBuild(java.lang.Object)
145: */
146: public void postBuild(Object parameter) throws Exception {
147: // not needed in this implementation
148: }
149:
150: /* (non-Javadoc)
151: * @see org.apache.cocoon.portal.pluto.om.common.Support#postLoad(java.lang.Object)
152: */
153: public void postLoad(Object parameter) throws Exception {
154: Vector structure = (Vector) parameter;
155: PortletApplicationDefinition portletApplication = (PortletApplicationDefinition) structure
156: .get(0);
157:
158: ((Support) portletApplication).postLoad(this );
159:
160: ((Support) servlets).postLoad(this );
161:
162: ((Support) descriptions).postLoad(parameter);
163: ((Support) displayNames).postLoad(parameter);
164:
165: }
166:
167: /* (non-Javadoc)
168: * @see org.apache.cocoon.portal.pluto.om.common.Support#postStore(java.lang.Object)
169: */
170: public void postStore(Object parameter) throws Exception {
171: ((Support) servlets).postStore(this );
172: }
173:
174: /* (non-Javadoc)
175: * @see org.apache.cocoon.portal.pluto.om.common.Support#preBuild(java.lang.Object)
176: */
177: public void preBuild(Object parameter) throws Exception {
178: Vector structure = (Vector) parameter;
179: PortletApplicationDefinition portletApplication = (PortletApplicationDefinition) structure
180: .get(0);
181: String contextString = (String) structure.get(1);
182:
183: setContextRoot(contextString);
184:
185: HashMap servletMap = new HashMap(1);
186: Vector structure2 = new Vector();
187: structure2.add(this );
188: structure2.add(servletMappings);
189: structure2.add(servletMap);
190:
191: ((Support) servlets).preBuild(structure2);
192:
193: Vector structure3 = new Vector();
194: structure3.add(contextString);
195: structure3.add(this );
196: structure3.add(servletMap);
197: ((Support) portletApplication).preBuild(structure3);
198: }
199:
200: /* (non-Javadoc)
201: * @see org.apache.cocoon.portal.pluto.om.common.Support#preStore(java.lang.Object)
202: */
203: public void preStore(Object parameter) throws Exception {
204: Vector structure = (Vector) parameter;
205: PortletApplicationDefinition portletApplication = (PortletApplicationDefinition) structure
206: .get(0);
207:
208: ((Support) portletApplication).preStore(null);
209:
210: ((Support) servlets).preStore(this );
211: }
212:
213: // additional methods.
214:
215: public String getCastorId() {
216: if (id.length() > 0) {
217: return getId().toString();
218: }
219: return null;
220: }
221:
222: public Collection getCastorInitParams() {
223: return (ParameterSetImpl) initParams;
224: }
225:
226: public Collection getCastorServlets() {
227: return (ServletDefinitionListImpl) servlets;
228: }
229:
230: public Collection getCastorDisplayNames() {
231: return (DisplayNameSetImpl) displayNames;
232: }
233:
234: public Collection getCastorDescriptions() {
235: return (DescriptionSetImpl) descriptions;
236: }
237:
238: public SecurityRoleSet getSecurityRoles() {
239: return securityRoles;
240: }
241:
242: public Collection getServletMappings() {
243: return servletMappings;
244: }
245:
246: public void setCastorId(String id) {
247: setId(id);
248: }
249:
250: protected void setContextRoot(String contextPath) {
251: // Test for IBM WebSphere
252: if (contextPath != null && contextPath.endsWith(".war")) {
253: contextPath = contextPath.substring(0,
254: contextPath.length() - 4);
255: }
256: this .contextPath = contextPath;
257: }
258:
259: public void setDescriptions(DescriptionSet descriptions) {
260: this .descriptions = descriptions;
261: }
262:
263: public void setDisplayNames(DisplayNameSet displayNames) {
264: this .displayNames = displayNames;
265: }
266:
267: public void setCastorDescriptions(DescriptionSet castorDescriptions) {
268: this .descriptions = castorDescriptions;
269: }
270:
271: public void setCastorDisplayNames(DisplayNameSet castorDisplayNames) {
272: this .displayNames = castorDisplayNames;
273: }
274:
275: public void setId(String id) {
276: this .id = id;
277: objectId = null;
278: }
279:
280: // modified by YCLI: START :: handling multiple taglib tags and resource-ref tag
281:
282: /**
283: * @return Custom tag definitions configured in the webapp.
284: */
285: public TagDefinitionSet getTagDefinitionSet() {
286: return taglibs;
287: }
288:
289: public Collection getCastorTagDefinitions() {
290: return taglibs;
291: }
292:
293: public void setCastorTagDefinitions(TagDefinitionSet taglibs) {
294: this .taglibs = taglibs;
295: }
296:
297: public ResourceRefSet getCastorResourceRefSet() {
298: return castorResourceRef;
299: }
300:
301: public void setCastorResourceRefSet(ResourceRefSet resourceRefs) {
302: castorResourceRef = resourceRefs;
303: }
304:
305: // modified by YCLI: END
306:
307: /**
308: * @return Returns the castorMimeMappings.
309: */
310: public Collection getCastorMimeMappings() {
311: return castorMimeMappings;
312: }
313:
314: public Collection getSecurityConstraints() {
315: return securityConstraints;
316: }
317:
318: /**
319: * @param castorMimeMappings The castorMimeMappings to set.
320: */
321: public void setCastorMimeMappings(Collection castorMimeMappings) {
322: this .castorMimeMappings = castorMimeMappings;
323: }
324:
325: public void setSecurityConstraints(Collection securityConstraints) {
326: this.securityConstraints = securityConstraints;
327: }
328: }
|