1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */17packageorg.apache.jetspeed.util.descriptor;
1819import java.io.Reader;
2021import org.apache.commons.digester.Digester;
22import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
23import org.apache.jetspeed.om.servlet.impl.SecurityRoleImpl;
24import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
25import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
26import org.apache.jetspeed.util.JetspeedLocale;
2728/***29 * Utilities for manipulating the web.xml deployment descriptor30 * 31 * @author <a href="mailto:ate@douma.nu">Ate Douma </a>*32 * @version $Id: WebDescriptorUtilities.java,v 1.2 2004/05/12 22:25:04 taylor33 * Exp $34 */35publicclassWebApplicationDescriptor36 {
3738protected Reader webXmlReader;
39protected String contextRoot;
40publicWebApplicationDescriptor(Reader webXmlReader, String contextRoot )
41 {
42if(webXmlReader == null)
43 {
44thrownew IllegalArgumentException("webXmlReader cannot be null");
45 }
46this.webXmlReader = webXmlReader;
47this.contextRoot = contextRoot;
48 }
495051/***52 * Load a web.xml file into a Web Application tree53 * 54 * @param pathWebXML55 * The path to the web.xml file56 * @param contexRoot57 * The context root of the web application58 * @param locale59 * The locale of the display name of the web application60 * @param displayName61 * The display name of the web application62 * @return The Java object tree representing web.xml63 */64public MutableWebApplication createWebApplication() throws PortletApplicationException
65 {
66try67 {
6869// TODO move config to digester-rules.xml. Example:70// http://www.onjava.com/pub/a/onjava/2002/10/23/digester.html?page=371 Digester digester = new Digester();
72 digester.setClassLoader(this.getClass().getClassLoader());
73 digester.setValidating(false);
7475 digester.register("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", WebApplicationDescriptor.class76 .getResource("web-app_2_2.dtd").toString());
77 digester.register("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", WebApplicationDescriptor.class78 .getResource("web-app_2_3.dtd").toString());
7980 digester.addObjectCreate("web-app", WebApplicationDefinitionImpl.class);
8182 digester.addObjectCreate("web-app/security-role", SecurityRoleImpl.class);
83 digester.addBeanPropertySetter("web-app/security-role/description", "description");
84 digester.addBeanPropertySetter("web-app/security-role/role-name", "roleName");
85 digester.addSetNext("web-app/security-role", "addSecurityRole");
8687 WebApplicationDefinitionImpl wd = (WebApplicationDefinitionImpl) digester.parse(webXmlReader);
8889 wd.setContextRoot(contextRoot);
90//wd.addDescription(locale, displayName);91 wd.addDescription(JetspeedLocale.getDefaultLocale(), contextRoot);
92return wd;
9394 }
95catch (Throwable t)
96 {
97 String msg = "Could not digester web.xml." + t.toString();
98thrownewPortletApplicationException(msg, t);
99 }
100 }
101102 }