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.jetspeed.util.descriptor;
018:
019: import java.io.Reader;
020:
021: import org.apache.commons.digester.Digester;
022: import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
023: import org.apache.jetspeed.om.servlet.impl.SecurityRoleImpl;
024: import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
025: import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
026: import org.apache.jetspeed.util.JetspeedLocale;
027:
028: /**
029: * Utilities for manipulating the web.xml deployment descriptor
030: *
031: * @author <a href="mailto:ate@douma.nu">Ate Douma </a>*
032: * @version $Id: WebDescriptorUtilities.java,v 1.2 2004/05/12 22:25:04 taylor
033: * Exp $
034: */
035: public class WebApplicationDescriptor {
036:
037: protected Reader webXmlReader;
038: protected String contextRoot;
039:
040: public WebApplicationDescriptor(Reader webXmlReader,
041: String contextRoot) {
042: if (webXmlReader == null) {
043: throw new IllegalArgumentException(
044: "webXmlReader cannot be null");
045: }
046: this .webXmlReader = webXmlReader;
047: this .contextRoot = contextRoot;
048: }
049:
050: /**
051: * Load a web.xml file into a Web Application tree
052: *
053: * @param pathWebXML
054: * The path to the web.xml file
055: * @param contexRoot
056: * The context root of the web application
057: * @param locale
058: * The locale of the display name of the web application
059: * @param displayName
060: * The display name of the web application
061: * @return The Java object tree representing web.xml
062: */
063: public MutableWebApplication createWebApplication()
064: throws PortletApplicationException {
065: try {
066:
067: // TODO move config to digester-rules.xml. Example:
068: // http://www.onjava.com/pub/a/onjava/2002/10/23/digester.html?page=3
069: Digester digester = new Digester();
070: digester.setClassLoader(this .getClass().getClassLoader());
071: digester.setValidating(false);
072:
073: digester
074: .register(
075: "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
076: WebApplicationDescriptor.class.getResource(
077: "web-app_2_2.dtd").toString());
078: digester
079: .register(
080: "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
081: WebApplicationDescriptor.class.getResource(
082: "web-app_2_3.dtd").toString());
083:
084: digester.addObjectCreate("web-app",
085: WebApplicationDefinitionImpl.class);
086:
087: digester.addObjectCreate("web-app/security-role",
088: SecurityRoleImpl.class);
089: digester.addBeanPropertySetter(
090: "web-app/security-role/description", "description");
091: digester.addBeanPropertySetter(
092: "web-app/security-role/role-name", "roleName");
093: digester.addSetNext("web-app/security-role",
094: "addSecurityRole");
095:
096: WebApplicationDefinitionImpl wd = (WebApplicationDefinitionImpl) digester
097: .parse(webXmlReader);
098:
099: wd.setContextRoot(contextRoot);
100: //wd.addDescription(locale, displayName);
101: wd.addDescription(JetspeedLocale.getDefaultLocale(),
102: contextRoot);
103: return wd;
104:
105: } catch (Throwable t) {
106: String msg = "Could not digester web.xml." + t.toString();
107: throw new PortletApplicationException(msg, t);
108: }
109: }
110:
111: }
|