001: /*
002: * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/WebRuleSet.java,v 1.1 2001/10/17 00:44:02 craigmcc Exp $
003: * $Revision: 1.1 $
004: * $Date: 2001/10/17 00:44:02 $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
011: * reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions
015: * are met:
016: *
017: * 1. Redistributions of source code must retain the above copyright
018: * notice, this list of conditions and the following disclaimer.
019: *
020: * 2. Redistributions in binary form must reproduce the above copyright
021: * notice, this list of conditions and the following disclaimer in
022: * the documentation and/or other materials provided with the
023: * distribution.
024: *
025: * 3. The end-user documentation included with the redistribution, if
026: * any, must include the following acknowlegement:
027: * "This product includes software developed by the
028: * Apache Software Foundation (http://www.apache.org/)."
029: * Alternately, this acknowlegement may appear in the software itself,
030: * if and wherever such third-party acknowlegements normally appear.
031: *
032: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
033: * Foundation" must not be used to endorse or promote products derived
034: * from this software without prior written permission. For written
035: * permission, please contact apache@apache.org.
036: *
037: * 5. Products derived from this software may not be called "Apache"
038: * nor may "Apache" appear in their names without prior written
039: * permission of the Apache Group.
040: *
041: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
042: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
043: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
044: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
045: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
046: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
047: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
048: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
049: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
050: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
051: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
052: * SUCH DAMAGE.
053: * ====================================================================
054: *
055: * This software consists of voluntary contributions made by many
056: * individuals on behalf of the Apache Software Foundation. For more
057: * information on the Apache Software Foundation, please see
058: * <http://www.apache.org/>.
059: *
060: */
061:
062: package org.apache.catalina.startup;
063:
064: import java.lang.reflect.Method;
065: import org.apache.catalina.Context;
066: import org.apache.catalina.Wrapper;
067: import org.apache.catalina.deploy.SecurityConstraint;
068: import org.apache.commons.digester.Digester;
069: import org.apache.commons.digester.Rule;
070: import org.apache.commons.digester.RuleSetBase;
071: import org.xml.sax.Attributes;
072:
073: /**
074: * <p><strong>RuleSet</strong> for processing the contents of a web application
075: * deployment descriptor (<code>/WEB-INF/web.xml</code>) resource.</p>
076: *
077: * @author Craig R. McClanahan
078: * @version $Revision: 1.1 $ $Date: 2001/10/17 00:44:02 $
079: */
080:
081: public class WebRuleSet extends RuleSetBase {
082:
083: // ----------------------------------------------------- Instance Variables
084:
085: /**
086: * The matching pattern prefix to use for recognizing our elements.
087: */
088: protected String prefix = null;
089:
090: // ------------------------------------------------------------ Constructor
091:
092: /**
093: * Construct an instance of this <code>RuleSet</code> with the default
094: * matching pattern prefix.
095: */
096: public WebRuleSet() {
097:
098: this ("");
099:
100: }
101:
102: /**
103: * Construct an instance of this <code>RuleSet</code> with the specified
104: * matching pattern prefix.
105: *
106: * @param prefix Prefix for matching pattern rules (including the
107: * trailing slash character)
108: */
109: public WebRuleSet(String prefix) {
110:
111: super ();
112: this .namespaceURI = null;
113: this .prefix = prefix;
114:
115: }
116:
117: // --------------------------------------------------------- Public Methods
118:
119: /**
120: * <p>Add the set of Rule instances defined in this RuleSet to the
121: * specified <code>Digester</code> instance, associating them with
122: * our namespace URI (if any). This method should only be called
123: * by a Digester instance.</p>
124: *
125: * @param digester Digester instance to which the new Rule instances
126: * should be added.
127: */
128: public void addRuleInstances(Digester digester) {
129:
130: digester.addRule(prefix + "web-app", new SetPublicIdRule(
131: digester, "setPublicId"));
132:
133: digester.addCallMethod(prefix + "web-app/context-param",
134: "addParameter", 2);
135: digester.addCallParam(prefix
136: + "web-app/context-param/param-name", 0);
137: digester.addCallParam(prefix
138: + "web-app/context-param/param-value", 1);
139:
140: digester.addCallMethod(prefix + "web-app/display-name",
141: "setDisplayName", 0);
142:
143: digester.addRule(prefix + "web-app/distributable",
144: new SetDistributableRule(digester));
145:
146: digester.addObjectCreate(prefix + "web-app/ejb-local-ref",
147: "org.apache.catalina.deploy.ContextLocalEjb");
148: digester.addSetNext(prefix + "web-app/ejb-local-ref",
149: "addLocalEjb",
150: "org.apache.catalina.deploy.ContextLocalEjb");
151:
152: digester.addCallMethod(prefix
153: + "web-app/ejb-local-ref/description",
154: "setDescription", 0);
155: digester.addCallMethod(prefix
156: + "web-app/ejb-local-ref/ejb-link", "setLink", 0);
157: digester.addCallMethod(prefix
158: + "web-app/ejb-local-ref/ejb-ref-name", "setName", 0);
159: digester.addCallMethod(prefix
160: + "web-app/ejb-local-ref/ejb-ref-type", "setType", 0);
161: digester.addCallMethod(prefix + "web-app/ejb-local-ref/local",
162: "setLocal", 0);
163: digester.addCallMethod(prefix
164: + "web-app/ejb-local-ref/local-home", "setHome", 0);
165:
166: digester.addObjectCreate(prefix + "web-app/ejb-ref",
167: "org.apache.catalina.deploy.ContextEjb");
168: digester.addSetNext(prefix + "web-app/ejb-ref", "addEjb",
169: "org.apache.catalina.deploy.ContextEjb");
170:
171: digester.addCallMethod(prefix + "web-app/ejb-ref/description",
172: "setDescription", 0);
173: digester.addCallMethod(prefix + "web-app/ejb-ref/ejb-link",
174: "setLink", 0);
175: digester.addCallMethod(prefix + "web-app/ejb-ref/ejb-ref-name",
176: "setName", 0);
177: digester.addCallMethod(prefix + "web-app/ejb-ref/ejb-ref-type",
178: "setType", 0);
179: digester.addCallMethod(prefix + "web-app/ejb-ref/home",
180: "setHome", 0);
181: digester.addCallMethod(prefix + "web-app/ejb-ref/remote",
182: "setRemote", 0);
183:
184: digester.addObjectCreate(prefix + "web-app/env-entry",
185: "org.apache.catalina.deploy.ContextEnvironment");
186: digester.addSetNext(prefix + "web-app/env-entry",
187: "addEnvironment",
188: "org.apache.catalina.deploy.ContextEnvironment");
189:
190: digester.addCallMethod(
191: prefix + "web-app/env-entry/description",
192: "setDescription", 0);
193: digester.addCallMethod(prefix
194: + "web-app/env-entry/env-entry-name", "setName", 0);
195: digester.addCallMethod(prefix
196: + "web-app/env-entry/env-entry-type", "setType", 0);
197: digester.addCallMethod(prefix
198: + "web-app/env-entry/env-entry-value", "setValue", 0);
199:
200: digester.addObjectCreate(prefix + "web-app/error-page",
201: "org.apache.catalina.deploy.ErrorPage");
202: digester.addSetNext(prefix + "web-app/error-page",
203: "addErrorPage", "org.apache.catalina.deploy.ErrorPage");
204:
205: digester.addCallMethod(
206: prefix + "web-app/error-page/error-code",
207: "setErrorCode", 0);
208: digester.addCallMethod(prefix
209: + "web-app/error-page/exception-type",
210: "setExceptionType", 0);
211: digester.addCallMethod(prefix + "web-app/error-page/location",
212: "setLocation", 0);
213:
214: digester.addObjectCreate(prefix + "web-app/filter",
215: "org.apache.catalina.deploy.FilterDef");
216: digester.addSetNext(prefix + "web-app/filter", "addFilterDef",
217: "org.apache.catalina.deploy.FilterDef");
218:
219: digester.addCallMethod(prefix + "web-app/filter/description",
220: "setDescription", 0);
221: digester.addCallMethod(prefix + "web-app/filter/display-name",
222: "setDisplayName", 0);
223: digester.addCallMethod(prefix + "web-app/filter/filter-class",
224: "setFilterClass", 0);
225: digester.addCallMethod(prefix + "web-app/filter/filter-name",
226: "setFilterName", 0);
227: digester.addCallMethod(prefix + "web-app/filter/large-icon",
228: "setLargeIcon", 0);
229: digester.addCallMethod(prefix + "web-app/filter/small-icon",
230: "setSmallIcon", 0);
231:
232: digester.addCallMethod(prefix + "web-app/filter/init-param",
233: "addInitParameter", 2);
234: digester.addCallParam(prefix
235: + "web-app/filter/init-param/param-name", 0);
236: digester.addCallParam(prefix
237: + "web-app/filter/init-param/param-value", 1);
238:
239: digester.addObjectCreate(prefix + "web-app/filter-mapping",
240: "org.apache.catalina.deploy.FilterMap");
241: digester.addSetNext(prefix + "web-app/filter-mapping",
242: "addFilterMap", "org.apache.catalina.deploy.FilterMap");
243:
244: digester.addCallMethod(prefix
245: + "web-app/filter-mapping/filter-name",
246: "setFilterName", 0);
247: digester.addCallMethod(prefix
248: + "web-app/filter-mapping/servlet-name",
249: "setServletName", 0);
250: digester.addCallMethod(prefix
251: + "web-app/filter-mapping/url-pattern",
252: "setURLPattern", 0);
253:
254: digester.addCallMethod(prefix
255: + "web-app/listener/listener-class",
256: "addApplicationListener", 0);
257:
258: digester.addObjectCreate(prefix + "web-app/login-config",
259: "org.apache.catalina.deploy.LoginConfig");
260: digester.addSetNext(prefix + "web-app/login-config",
261: "setLoginConfig",
262: "org.apache.catalina.deploy.LoginConfig");
263:
264: digester.addCallMethod(prefix
265: + "web-app/login-config/auth-method", "setAuthMethod",
266: 0);
267: digester.addCallMethod(prefix
268: + "web-app/login-config/realm-name", "setRealmName", 0);
269: digester
270: .addCallMethod(
271: prefix
272: + "web-app/login-config/form-login-config/form-error-page",
273: "setErrorPage", 0);
274: digester
275: .addCallMethod(
276: prefix
277: + "web-app/login-config/form-login-config/form-login-page",
278: "setLoginPage", 0);
279:
280: digester.addCallMethod(prefix + "web-app/mime-mapping",
281: "addMimeMapping", 2);
282: digester.addCallParam(
283: prefix + "web-app/mime-mapping/extension", 0);
284: digester.addCallParam(
285: prefix + "web-app/mime-mapping/mime-type", 1);
286:
287: digester.addCallMethod(prefix + "web-app/resource-env-ref",
288: "addResourceEnvRef", 2);
289: digester.addCallParam(prefix
290: + "web-app/resource-env-ref/resource-env-ref-name", 0);
291: digester.addCallParam(prefix
292: + "web-app/resource-env-ref/resource-env-ref-type", 1);
293:
294: digester.addObjectCreate(prefix + "web-app/resource-ref",
295: "org.apache.catalina.deploy.ContextResource");
296: digester.addSetNext(prefix + "web-app/resource-ref",
297: "addResource",
298: "org.apache.catalina.deploy.ContextResource");
299:
300: digester.addCallMethod(prefix
301: + "web-app/resource-ref/description", "setDescription",
302: 0);
303: digester.addCallMethod(
304: prefix + "web-app/resource-ref/res-auth", "setAuth", 0);
305: digester.addCallMethod(prefix
306: + "web-app/resource-ref/res-ref-name", "setName", 0);
307: digester.addCallMethod(prefix
308: + "web-app/resource-ref/res-sharing-scope", "setScope",
309: 0);
310: digester.addCallMethod(
311: prefix + "web-app/resource-ref/res-type", "setType", 0);
312:
313: digester.addObjectCreate(
314: prefix + "web-app/security-constraint",
315: "org.apache.catalina.deploy.SecurityConstraint");
316: digester.addSetNext(prefix + "web-app/security-constraint",
317: "addConstraint",
318: "org.apache.catalina.deploy.SecurityConstraint");
319:
320: digester.addRule(prefix
321: + "web-app/security-constraint/auth-constraint",
322: new SetAuthConstraintRule(digester));
323: digester
324: .addCallMethod(
325: prefix
326: + "web-app/security-constraint/auth-constraint/role-name",
327: "addAuthRole", 0);
328: digester.addCallMethod(prefix
329: + "web-app/security-constraint/display-name",
330: "setDisplayName", 0);
331: digester
332: .addCallMethod(
333: prefix
334: + "web-app/security-constraint/user-data-constraint/transport-guarantee",
335: "setUserConstraint", 0);
336:
337: digester
338: .addObjectCreate(
339: prefix
340: + "web-app/security-constraint/web-resource-collection",
341: "org.apache.catalina.deploy.SecurityCollection");
342: digester
343: .addSetNext(
344: prefix
345: + "web-app/security-constraint/web-resource-collection",
346: "addCollection",
347: "org.apache.catalina.deploy.SecurityCollection");
348: digester
349: .addCallMethod(
350: prefix
351: + "web-app/security-constraint/web-resource-collection/http-method",
352: "addMethod", 0);
353: digester
354: .addCallMethod(
355: prefix
356: + "web-app/security-constraint/web-resource-collection/url-pattern",
357: "addPattern", 0);
358: digester
359: .addCallMethod(
360: prefix
361: + "web-app/security-constraint/web-resource-collection/web-resource-name",
362: "setName", 0);
363:
364: digester.addCallMethod(prefix
365: + "web-app/security-role/role-name", "addSecurityRole",
366: 0);
367:
368: digester.addRule(prefix + "web-app/servlet",
369: new WrapperCreateRule(digester));
370: digester.addSetNext(prefix + "web-app/servlet", "addChild",
371: "org.apache.catalina.Container");
372:
373: digester.addCallMethod(prefix + "web-app/servlet/init-param",
374: "addInitParameter", 2);
375: digester.addCallParam(prefix
376: + "web-app/servlet/init-param/param-name", 0);
377: digester.addCallParam(prefix
378: + "web-app/servlet/init-param/param-value", 1);
379:
380: digester.addCallMethod(prefix + "web-app/servlet/jsp-file",
381: "setJspFile", 0);
382: digester.addCallMethod(prefix
383: + "web-app/servlet/load-on-startup",
384: "setLoadOnStartupString", 0);
385: digester.addCallMethod(prefix
386: + "web-app/servlet/run-as/role-name", "setRunAs", 0);
387:
388: digester.addCallMethod(prefix
389: + "web-app/servlet/security-role-ref",
390: "addSecurityReference", 2);
391: digester.addCallParam(prefix
392: + "web-app/servlet/security-role-ref/role-link", 1);
393: digester.addCallParam(prefix
394: + "web-app/servlet/security-role-ref/role-name", 0);
395:
396: digester.addCallMethod(
397: prefix + "web-app/servlet/servlet-class",
398: "setServletClass", 0);
399: digester.addCallMethod(prefix + "web-app/servlet/servlet-name",
400: "setName", 0);
401:
402: digester.addCallMethod(prefix + "web-app/servlet-mapping",
403: "addServletMapping", 2);
404: digester.addCallParam(prefix
405: + "web-app/servlet-mapping/servlet-name", 1);
406: digester.addCallParam(prefix
407: + "web-app/servlet-mapping/url-pattern", 0);
408:
409: digester.addCallMethod(prefix
410: + "web-app/session-config/session-timeout",
411: "setSessionTimeout", 1, new Class[] { Integer.TYPE });
412: digester.addCallParam(prefix
413: + "web-app/session-config/session-timeout", 0);
414:
415: digester.addCallMethod(prefix + "web-app/taglib", "addTaglib",
416: 2);
417: digester.addCallParam(
418: prefix + "web-app/taglib/taglib-location", 1);
419: digester.addCallParam(prefix + "web-app/taglib/taglib-uri", 0);
420:
421: digester.addCallMethod(prefix
422: + "web-app/welcome-file-list/welcome-file",
423: "addWelcomeFile", 0);
424:
425: }
426:
427: }
428:
429: // ----------------------------------------------------------- Private Classes
430:
431: /**
432: * A Rule that calls the <code>setAuthConstraint(true)</code> method of
433: * the top item on the stack, which must be of type
434: * <code>org.apache.catalina.deploy.SecurityConstraint</code>.
435: */
436:
437: final class SetAuthConstraintRule extends Rule {
438:
439: public SetAuthConstraintRule(Digester digester) {
440: super (digester);
441: }
442:
443: public void begin(Attributes attributes) throws Exception {
444: SecurityConstraint securityConstraint = (SecurityConstraint) digester
445: .peek();
446: securityConstraint.setAuthConstraint(true);
447: if (digester.getDebug() > 0)
448: digester
449: .log("Calling SecurityConstraint.setAuthConstraint(true)");
450: }
451:
452: }
453:
454: /**
455: * Class that calls <code>setDistributable(true)</code> for the top object
456: * on the stack, which must be a <code>org.apache.catalina.Context</code>.
457: */
458:
459: final class SetDistributableRule extends Rule {
460:
461: public SetDistributableRule(Digester digester) {
462: super (digester);
463: }
464:
465: public void begin(Attributes attributes) throws Exception {
466: Context context = (Context) digester.peek();
467: context.setDistributable(true);
468: if (digester.getDebug() > 0)
469: digester.log(context.getClass().getName()
470: + ".setDistributable( true)");
471: }
472:
473: }
474:
475: /**
476: * Class that calls a property setter for the top object on the stack,
477: * passing the public ID of the entity we are currently processing.
478: */
479:
480: final class SetPublicIdRule extends Rule {
481:
482: public SetPublicIdRule(Digester digester, String method) {
483: super (digester);
484: this .method = method;
485: }
486:
487: private String method = null;
488:
489: public void begin(Attributes attributes) throws Exception {
490:
491: Context context = (Context) digester
492: .peek(digester.getCount() - 1);
493: Object top = digester.peek();
494: Class paramClasses[] = new Class[1];
495: paramClasses[0] = "String".getClass();
496: String paramValues[] = new String[1];
497: paramValues[0] = digester.getPublicId();
498:
499: Method m = null;
500: try {
501: m = top.getClass().getMethod(method, paramClasses);
502: } catch (NoSuchMethodException e) {
503: digester.log("Can't find method " + method + " in " + top
504: + " CLASS " + top.getClass());
505: return;
506: }
507:
508: m.invoke(top, paramValues);
509: if (digester.getDebug() >= 1)
510: digester.log("" + top.getClass().getName() + "." + method
511: + "(" + paramValues[0] + ")");
512:
513: }
514:
515: }
516:
517: /**
518: * A Rule that calls the factory method on the specified Context to
519: * create the object that is to be added to the stack.
520: */
521:
522: final class WrapperCreateRule extends Rule {
523:
524: public WrapperCreateRule(Digester digester) {
525: super (digester);
526: }
527:
528: public void begin(Attributes attributes) throws Exception {
529: Context context = (Context) digester
530: .peek(digester.getCount() - 1);
531: Wrapper wrapper = context.createWrapper();
532: digester.push(wrapper);
533: if (digester.getDebug() > 0)
534: digester.log("new " + wrapper.getClass().getName());
535: }
536:
537: public void end() throws Exception {
538: Wrapper wrapper = (Wrapper) digester.pop();
539: if (digester.getDebug() > 0)
540: digester.log("pop " + wrapper.getClass().getName());
541: }
542:
543: }
|