1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.util.descriptor;
18
19 import java.io.Reader;
20
21 import org.apache.commons.digester.Digester;
22 import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
23 import org.apache.jetspeed.om.servlet.impl.SecurityRoleImpl;
24 import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
25 import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
26 import org.apache.jetspeed.util.JetspeedLocale;
27
28 /***
29 * Utilities for manipulating the web.xml deployment descriptor
30 *
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 taylor
33 * Exp $
34 */
35 public class WebApplicationDescriptor
36 {
37
38 protected Reader webXmlReader;
39 protected String contextRoot;
40 public WebApplicationDescriptor(Reader webXmlReader, String contextRoot )
41 {
42 if(webXmlReader == null)
43 {
44 throw new IllegalArgumentException("webXmlReader cannot be null");
45 }
46 this.webXmlReader = webXmlReader;
47 this.contextRoot = contextRoot;
48 }
49
50
51 /***
52 * Load a web.xml file into a Web Application tree
53 *
54 * @param pathWebXML
55 * The path to the web.xml file
56 * @param contexRoot
57 * The context root of the web application
58 * @param locale
59 * The locale of the display name of the web application
60 * @param displayName
61 * The display name of the web application
62 * @return The Java object tree representing web.xml
63 */
64 public MutableWebApplication createWebApplication() throws PortletApplicationException
65 {
66 try
67 {
68
69
70
71 Digester digester = new Digester();
72 digester.setClassLoader(this.getClass().getClassLoader());
73 digester.setValidating(false);
74
75 digester.register("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", WebApplicationDescriptor.class
76 .getResource("web-app_2_2.dtd").toString());
77 digester.register("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", WebApplicationDescriptor.class
78 .getResource("web-app_2_3.dtd").toString());
79
80 digester.addObjectCreate("web-app", WebApplicationDefinitionImpl.class);
81
82 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");
86
87 WebApplicationDefinitionImpl wd = (WebApplicationDefinitionImpl) digester.parse(webXmlReader);
88
89 wd.setContextRoot(contextRoot);
90
91 wd.addDescription(JetspeedLocale.getDefaultLocale(), contextRoot);
92 return wd;
93
94 }
95 catch (Throwable t)
96 {
97 String msg = "Could not digester web.xml." + t.toString();
98 throw new PortletApplicationException(msg, t);
99 }
100 }
101
102 }