tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup Constants.java ContextConfig.java
Date Wed, 04 Oct 2000 02:26:38 GMT
craigmcc    00/10/03 19:26:35

  Modified:    .        NEW_SPECS.txt
               catalina/src/share/org/apache/catalina/startup
                        Constants.java ContextConfig.java
  Added:       catalina/src/conf tld_11.dtd tld_12.dtd
  Log:
  Scan the tag library descriptors of all custom tag libraries that can be
  found in each web application, and register any application events
  listener classes that are found.
  
  This change requires Catalina to be able to process TLDs in addition to
  deployment descriptors.  Therefore, the DTDs for the tag library
  descriptor for JSP version 1.1 (official) and 1.2 (unofficial) are being
  checked in so that TLDs can be validated as they are processed.
  
  Revision  Changes    Path
  1.4       +2 -2      jakarta-tomcat-4.0/NEW_SPECS.txt
  
  Index: NEW_SPECS.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/NEW_SPECS.txt,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NEW_SPECS.txt	2000/10/01 03:10:14	1.3
  +++ NEW_SPECS.txt	2000/10/04 02:26:25	1.4
  @@ -3,7 +3,7 @@
   		New Spec Features Implementation
   		================================
   
  -$Id: NEW_SPECS.txt,v 1.3 2000/10/01 03:10:14 craigmcc Exp $
  +$Id: NEW_SPECS.txt,v 1.4 2000/10/04 02:26:25 craigmcc Exp $
   
   
   Introduction
  @@ -130,7 +130,7 @@
   (for example), where there is no need to buffer or post-process the data
   rendered for each row.
   
  -Custom Tag Libraries Can Declare Application Listeners [Rare]
  +Custom Tag Libraries Can Declare Application Listeners [Medium]
   -------------------------------------------------------------
   A custom tag library can optionally declare a listener for application events,
   using the new servlet 2.3 capability.
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/conf/tld_11.dtd
  
  Index: tld_11.dtd
  ===================================================================
  <!--
  
     This is the DTD defining the JavaServer Pages 1.1 Tag Library
     descriptor (.tld) (XML) file format/syntax.
  
     A Tag Library is a JAR file containing a valid instance of a Tag Library
     Descriptor (taglib.tld) file in the META-INF subdirectory, along with the
     appropriate implementing classes, and other resources required to
     implement the tags defined therein.
  
    -->
  
  <!NOTATION JSPTAGLIB.1_1 PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN">
  
  <!--
  
  	The taglib tag is the document root, it defines:
  
  	tlibversion	the version of the tag library implementation
  	jspversion	the version of JSP the tag library depends upon
  
  	shortname	a simple default short name that could be used by
  			a JSP authoring tool to create names with a mnemonic
  			value; for example, the it may be used as the prefered
  			prefix value in taglib directives
  	uri		a uri uniquely identifying this taglib
  	info		a simple string describing the "use" of this taglib,
  			should be user discernable
  	
    -->
  
  <!ELEMENT taglib (tlibversion, jspversion?, shortname, uri?, info?, tag+) >
  	<!ATTLIST taglib id	    ID    #IMPLIED
  	 xmlns CDATA #FIXED    "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"
  	>
  
  <!--
  
  	Describes this version (number) of the taglibrary (dewey decimal)
  
  	#PCDATA ::= [0-9]*{ "."[0-9] }0..3
    -->
  
  <!ELEMENT tlibversion (#PCDATA) >
  
  <!--
  
  	Describes the JSP version (number) this taglibrary requires in order to function (dewey
decimal)
  
  	The default is 1.1
  
  	#PCDATA ::= [0-9]*{ "."[0-9] }0..3
  
    -->
  
  <!ELEMENT jspversion  (#PCDATA) >
  
  <!--
  	Defines a short (default) shortname to be used for tags and variable names used/created
by this tag library.
  	Do not use white space, and do not start with digits or underscore.
  
  	#PCDATA ::= NMTOKEN
    -->
  
  <!ELEMENT shortname      (#PCDATA) >
  
  <!--
  
  	Defines a public URI that uniquely identifies this version of the taglibrary
  	Leave it empty if it does not apply.
    -->
  
  <!ELEMENT uri	 (#PCDATA) >
  
  <!--
  
  	Defines an arbitrary text string descirbing the tag library
    -->
  
  <!ELEMENT info	(#PCDATA) >
  
  <!--
  
  	The tag defines a unique tag in this tag library, defining:
  	
  	- the unique tag/element name
  	- the subclass of javax.servlet.jsp.tagext.Tag implementation class
  	- an optional subclass of javax.servlet.jsp.tagext.TagExtraInfo
  	- the body content type (hint)
  	- optional tag-specific information
  	- any attributes
  	
    -->
  
  <!ELEMENT tag (name, tagclass, teiclass?, bodycontent?, info?, attribute*) >
  	<!ATTLIST tag id ID #IMPLIED >
  
  <!--
  
  	Defines the subclass of javax.serlvet.jsp.tagext.Tag that implements
  	the request time semantics for this tag. (required)
  
  	#PCDATA ::= fully qualified Java class name
    -->
  
  <!ELEMENT tagclass (#PCDATA) >
  
  <!--
  
  	Defines the subclass of javax.servlet.jsp.tagext.TagExtraInfo for
  	this tag. (optional)
  
  	The default is javax.servlet.jsp.tagext.TagExtraInfo
  
  	#PCDATA ::= fully qualified Java class name
    -->
  
  <!ELEMENT teiclass (#PCDATA) >
  
  <!--
  	Provides a hint as to the content of the body of this tag. Primarily
  	intended for use by page composition tools.
  
  	There are currently three values specified:
  
  	tagdependent	The body of the tag is interpreted by the tag 
  			implementation itself, and is most likely in a
  			different "langage", e.g embedded SQL statements.
  
  	JSP		The body of the tag contains nested JSP syntax
  	
  	empty		The body must be empty
  
  	The default (if not defined) is JSP
  
  	#PCDATA ::=  tagdependent | JSP | empty
  
    -->
  
  <!ELEMENT bodycontent (#PCDATA) >
  
  <!--
  
  	The attribute tag defines an attribute for the nesting tag
  
  	An attribute definition is composed of:
  	
  	- the attributes name (required)
  	- if the attribute is required or optional (optional)
  	- if the attributes value may be dynamically calculated at runtime
  	  by a scriptlet expression (optional)
  
    -->
  
  <!ELEMENT attribute (name, required? , rtexprvalue?) >
  	<!ATTLIST attribute     id     ID       #IMPLIED>
  
  <!--
  
  	Defines the canonical name of a tag or attribute being defined
  
  	#PCDATA ::= NMTOKEN
    -->
  
  <!ELEMENT name	(#PCDATA) >
  
  <!--
  
  	Defines if the nesting attribute is required or optional.
  
  	#PCDATA ::= true | false | yes | no
  
  	If not present then the default is "false", i.e the attribute is optional
    -->
  
  <!ELEMENT required    (#PCDATA) >
  
  <!--
  
  	Defines if the nesting attribute can have scriptlet expressions as
  	a value, i.e the value of the attribute may be dynamically calculated
  	at request time, as opposed to a static value determined at translation
  	time.
  
  	#PCDATA ::= true | false | yes | no
  
  	If not present then the default is "false", i.e the attribute has a static value
    -->
  
  <!ELEMENT rtexprvalue (#PCDATA) >
  
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/conf/tld_12.dtd
  
  Index: tld_12.dtd
  ===================================================================
  <!-- TEMPORARY DTD FOR THE JSP 1.2 TAG LIBRARY DESCRIPTOR.
       THIS WILL BE REPLACED BY THE OFFICIAL ONE WHEN IT IT
       POSTED.  -->
  
  <!--
  
     This is the DTD defining the JavaServer Pages 1.2 Tag Library
     descriptor (.tld) (XML) file format/syntax.
  
     A Tag Library is a JAR file containing a valid instance of a Tag Library
     Descriptor (taglib.tld) file in the META-INF subdirectory, along with the
     appropriate implementing classes, and other resources required to
     implement the tags defined therein.
  
    -->
  
  <!NOTATION WEB-JSPTAGLIB.1_2 PUBLIC
            "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN">
  
  <!--
  
  	The taglib tag is the document root, it defines:
  
  	tlibversion	the version of the tag library implementation
  
  	jspversion	the version of JSP the tag library depends upon
  
  	shortname	a simple default short name that could be used by
  			a JSP authoring tool to create names with a mnemonic
  			value; for example, the it may be used as the prefered
  			prefix value in taglib directives
  	uri		a uri uniquely identifying this taglib
  
          display-name    the display-name element contains a short name that
                          is intended to be displayed by tools
  
          small-icon      optional small-icon that can be used by tools
  
          large-icon      optional large-icon that can be used by tools
  
  	info		a simple string describing the "use" of this taglib,
  			should be user discernable
  	
          validatorclass  optional TagLibraryValidator class
  
          listener        optional event listener specification
  
    -->
  
  <!ELEMENT taglib (tlibversion, jspversion?, shortname, uri?,
                    display-name?, small-icon?, large-icon?, info?,
                    validatorclass?, listener*, tag+) >
  	<!ATTLIST taglib id	    ID    #IMPLIED
  	 xmlns CDATA #FIXED    "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd"
  	>
  
  <!--
  
  	Describes this version (number) of the taglibrary (dewey decimal)
  
  	#PCDATA ::= [0-9]*{ "."[0-9] }0..3
    -->
  
  <!ELEMENT tlibversion (#PCDATA) >
  
  <!--
  
  	Describes the JSP version (number) this taglibrary requires in order to function (dewey
decimal)
  
  	The default is 1.2
  
  	#PCDATA ::= [0-9]*{ "."[0-9] }0..3
  
    -->
  
  <!ELEMENT jspversion  (#PCDATA) >
  
  <!--
  	Defines a short (default) shortname to be used for tags and variable names used/created
by this tag library.
  	Do not use white space, and do not start with digits or underscore.
  
  	#PCDATA ::= NMTOKEN
    -->
  
  <!ELEMENT shortname      (#PCDATA) >
  
  <!--
  
  	Defines a public URI that uniquely identifies this version of the
          tag library.  It is recommended that the URI identifying a tag library
          is actually a URL to the tag library descriptor for this specific
          version of the tag library.
    -->
  
  <!ELEMENT uri	 (#PCDATA) >
  
  <!--
  
  	Defines an arbitrary text string descirbing the tag library
    -->
  
  <!ELEMENT info	(#PCDATA) >
  
  <!--
  
          Defines an optional TagLibraryValidator class that can be used to
          validate the conformance of a JSP page to using this tag library.
  -->
  
  <!ELEMENT validatorClass (#PCDATA) >
  
  <!--
  
          Defines an optional event listener object to be instantiated and
          registered automatically.
  -->
  
  <!ELEMENT listener (listener-class) >
  
  <!--
  
          The listener-class element declares a class in the application that
          must be registered as a web application listener bean.  See the
          Servlet 2.3 specification for details.
  -->
  
  <!ELEMENT listener-class (#PCDATA) >
  
  
  <!--
  
  	The tag defines a unique tag in this tag library.  It has one
          attribute, id.
  
          The tag element may have several subelements defining:
  
          name              The unique action name
  
          tagclass          The tag handler class implementing
                            javax.servlet.jsp.tagext.Tag
  
          teiclass          An optional subclass of
                            javax.servlet.jsp.tagext.TagExtraInfo
  
          bodycontent       The body content type
  
          display-name      A short name that is intended to be displayed
                            by tools
  
          small-icon        Optional small-icon that can be used by tools
  
          large-icon        Optional large-icon that can be used by tools
  
          info              Optional tag-specific information
  
          variable          Optional scripting variable information
  
          attribute         All attributes of this action
  -->
  
  <!ELEMENT tag (name, tagclass, teiclass?, bodycontent?, display-name?,
                 small-icon?, large-icon?, info?, variable*, attribute*) >
  	<!ATTLIST tag id ID #IMPLIED >
  
  <!--
  
  	Defines the subclass of javax.serlvet.jsp.tagext.Tag that implements
  	the request time semantics for this tag. (required)
  
  	#PCDATA ::= fully qualified Java class name
    -->
  
  <!ELEMENT tagclass (#PCDATA) >
  
  <!--
  
  	Defines the subclass of javax.servlet.jsp.tagext.TagExtraInfo for
  	this tag. (optional)
  
  	The default is javax.servlet.jsp.tagext.TagExtraInfo
  
  	#PCDATA ::= fully qualified Java class name
    -->
  
  <!ELEMENT teiclass (#PCDATA) >
  
  <!--
  	Provides a hint as to the content of the body of this tag. Primarily
  	intended for use by page composition tools.
  
  	There are currently three values specified:
  
  	tagdependent	The body of the tag is interpreted by the tag 
  			implementation itself, and is most likely in a
  			different "langage", e.g embedded SQL statements.
  
  	JSP		The body of the tag contains nested JSP syntax
  	
  	empty		The body must be empty
  
  	The default (if not defined) is JSP
  
  	#PCDATA ::=  tagdependent | JSP | empty
  
    -->
  
  <!ELEMENT bodycontent (#PCDATA) >
  
  <!--
  
          The display-name element contains a short name that is intended
          to be displayed by tools.
  -->
  
  <!ELEMENT display-name (#PCDATA) >
  
  
  <!--
  
          The large-icon element contains the name of a file containing a large
          (32 x 32) icon image.  The file name is a relative path within the
          tag library.  The image must be either in the JPEG or GIF format, and
          the file name must end with the suffix ".jpg" or ".gif" respectively.
          The icon can be used by tools.
  -->
  
  <!ELEMENT large-icon (#PCDATA) >
  
  <!--
  
          The small-icon element contains the name of a file containing a large
          (32 x 32) icon image.  The file name is a relative path within the
          tag library.  The image must be either in the JPEG or GIF format, and
          the file name must end with the suffix ".jpg" or ".gif" respectively.
          The icon can be used by tools.
  -->
  
  <!ELEMENT small-icon (#PCDATA) >
  
  <!--
  
          The variable tag provides information on the scripting variables
          defined by this tag.  It is a (translation time) error for a tag
          that has one or more variable subelements to have a TagExtraInfo
          class that returns a non-null object.
  
          The subelements of variable are of the form:
  
          name-given               The variable name as a constant
  
          name-from-attribute      The name of an attribute whose (translation
                                   time) value will give the name of the
                                   variable.  One of name-given or
                                   name-from-attribute is required.
  
          class                    Name of the class of the variable.
                                   java.lang.String is default.
  
          declare                  Whether the variable is declared or not.
                                   True is the default.
  
          scope                    The scope of the scripting varaible
                                   defined.  NESTED is default.
  -->
  
  <!ELEMENT variable ( (name-given | name-from-attribute), class?,
                      declare?, scope?) >
  
  <!--
  
          The name for the scripting variable.  One of name-given or
          name-from-attribute is required.
  -->
  
  <!ELEMENT name-given (#PCDATA) >
  
  <!--
  
          The name of an attribute whose (translation-time) value will give
          the name of the variable.  One of name-given or name-from-attribute
          is required.
  -->
  
  <!ELEMENT name-from-attribute (#PCDATA) >
  
  <!--
  
          The optional name of the class for the scripting variable.  The
          default is java.lang.String.
  -->
  
  <!ELEMENT class (#PCDATA) >
  
  <!--
  
          Whether the scripting variable is to be defined or not.  See
          TagExtraInfo for details.  This element is optional and "true"
          is the default.
  -->
  
  <!ELEMENT declare (#PCDATA) >
  
  <!--
  
          The scope of the scripting variable.  See TagExtraInfo for details.
          The element is optional and "NESTED" is the default.  Other legal
          values are "AT_BEGIN" and "AT_END".
  -->
  
  <!ELEMENT scope (#PCDATA) >
  
  <!--
  
  	The attribute tag defines an attribute for the nesting tag
  
  	An attribute definition is composed of:
  	
  	- the attributes name (required)
  	- if the attribute is required or optional (optional)
  	- if the attributes value may be dynamically calculated at runtime
  	  by a scriptlet expression (optional)
          - the type of the attributes value (optional)
  
    -->
  
  <!ELEMENT attribute (name, required? , rtexprvalue?, type?) >
  	<!ATTLIST attribute     id     ID       #IMPLIED>
  
  <!--
  
  	Defines the canonical name of a tag or attribute being defined
  
  	#PCDATA ::= NMTOKEN
    -->
  
  <!ELEMENT name	(#PCDATA) >
  
  <!--
  
  	Defines if the nesting attribute is required or optional.
  
  	#PCDATA ::= true | false | yes | no
  
  	If not present then the default is "false", i.e the attribute is optional
    -->
  
  <!ELEMENT required    (#PCDATA) >
  
  <!--
  
  	Defines if the nesting attribute can have scriptlet expressions as
  	a value, i.e the value of the attribute may be dynamically calculated
  	at request time, as opposed to a static value determined at translation
  	time.
  
  	#PCDATA ::= true | false | yes | no
  
  	If not present then the default is "false", i.e the attribute has a static value
    -->
  
  <!ELEMENT rtexprvalue (#PCDATA) >
  
  <!--
  
          Defines the Java type of the attributes value.  For static values
          (those determined at translation time) the type is always
          java.lang.String.
  -->
  
  <!ELEMENT type (#PCDATA) >
  
  
  
  
  1.3       +14 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Constants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Constants.java	2000/08/19 20:36:49	1.2
  +++ Constants.java	2000/10/04 02:26:30	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Constants.java,v
1.2 2000/08/19 20:36:49 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/08/19 20:36:49 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Constants.java,v
1.3 2000/10/04 02:26:30 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/10/04 02:26:30 $
    *
    * ====================================================================
    *
  @@ -69,7 +69,7 @@
    * String constants for the startup package.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/08/19 20:36:49 $
  + * @version $Revision: 1.3 $ $Date: 2000/10/04 02:26:30 $
    */
   
   public final class Constants {
  @@ -78,6 +78,16 @@
   
       public static final String ApplicationWebXml = "/WEB-INF/web.xml";
       public static final String DefaultWebXml = "conf/web.xml";
  +
  +    public static final String TldDtdPublicId_11 =
  +        "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN";
  +    public static final String TldDtdResourcePath_11 =
  +        "conf/tld_11.dtd";
  +
  +    public static final String TldDtdPublicId_12 =
  +        "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN";
  +    public static final String TldDtdResourcePath_12 =
  +        "conf/tld_12.dtd";
   
       public static final String WebDtdPublicId_22 =
   	"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN";
  
  
  
  1.20      +194 -8    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java
  
  Index: ContextConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ContextConfig.java	2000/10/03 21:30:42	1.19
  +++ ContextConfig.java	2000/10/04 02:26:33	1.20
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
1.19 2000/10/03 21:30:42 craigmcc Exp $
  - * $Revision: 1.19 $
  - * $Date: 2000/10/03 21:30:42 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
1.20 2000/10/04 02:26:33 craigmcc Exp $
  + * $Revision: 1.20 $
  + * $Date: 2000/10/04 02:26:33 $
    *
    * ====================================================================
    *
  @@ -71,11 +71,15 @@
   import java.io.InputStream;
   import java.io.IOException;
   import java.lang.reflect.InvocationTargetException;
  +import java.net.JarURLConnection;
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.util.ArrayList;
   import java.util.MissingResourceException;
   import java.util.ResourceBundle;
   import java.util.Stack;
  +import java.util.jar.JarEntry;
  +import java.util.jar.JarFile;
   import javax.servlet.ServletContextEvent;
   import javax.servlet.ServletContextListener;
   import org.apache.catalina.Authenticator;
  @@ -111,7 +115,7 @@
    * of that Context, and the associated defined servlets.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.19 $ $Date: 2000/10/03 21:30:42 $
  + * @version $Revision: 1.20 $ $Date: 2000/10/04 02:26:33 $
    */
   
   public final class ContextConfig
  @@ -374,10 +378,37 @@
   
   
       /**
  +     * Create and return an XmlMapper configured to process a tag library
  +     * descriptor, looking for additional listener classes to be registered.
  +     */
  +    private XmlMapper createTldMapper() {
  +
  +        XmlMapper mapper = new XmlMapper();
  +        if (debug > 0)
  +            mapper.setDebug(3);
  +        mapper.setValidating(true);
  +	File resourceFile = new File(System.getProperty("catalina.home"),
  +				     Constants.TldDtdResourcePath_11);
  +	mapper.registerDTDFile(Constants.TldDtdPublicId_11,
  +			       resourceFile.toString());
  +	resourceFile = new File(System.getProperty("catalina.home"),
  +				Constants.TldDtdResourcePath_12);
  +	mapper.registerDTDFile(Constants.TldDtdPublicId_12,
  +			       resourceFile.toString());
  +
  +	mapper.addRule("taglib/listener/listener-class",
  +		       mapper.methodSetter("addApplicationListener", 0));
  +
  +        return (mapper);
  +
  +    }
  +
  +
  +    /**
        * Create and return an XmlMapper configured to process the web application
        * deployment descriptor (web.xml).
        */
  -    private XmlMapper createMapper() {
  +    private XmlMapper createWebMapper() {
   
   	XmlMapper mapper = new XmlMapper();
   	if (debug > 0)
  @@ -884,9 +915,6 @@
   	    log(sm.getString("contextConfig.start"));
           ok = true;
   
  -	// Configure a mapper to read a web application deployment descriptor
  -	XmlMapper mapper = createMapper();
  -
   	// Add missing Loader component if necessary
   	if (context.getLoader() == null) {
   	    if (debug > 0)
  @@ -913,9 +941,14 @@
   	loaderConfig();
   
   	// Process the default and application web.xml files
  +	XmlMapper mapper = createWebMapper();
   	defaultConfig(mapper);
   	applicationConfig(mapper);
   
  +        // Scan tag library descriptor files for additional listener classes
  +        if (ok)
  +            tldConfig();
  +
           // Configure a certificates exposer valve, if required
           if (ok)
               certificatesConfig();
  @@ -973,7 +1006,160 @@
       }
   
   
  +    /**
  +     * Scan the tag library descriptors of all tag libraries we can find, and
  +     * register any application descriptor classes that are found there.
  +     */
  +    private void tldConfig() {
  +
  +        // Acquire an XmlMapper to use for parsing
  +        XmlMapper mapper = createTldMapper();
  +
  +        // First, scan tag libraries declared in our deployment descriptor
  +        if (debug >= 1)
  +            log("Scanning web.xml tag libraries");
  +        ArrayList resourcePaths = new ArrayList(); // Already processed TLDs
  +        String taglibs[] = context.findTaglibs();
  +        for (int i = 0; i < taglibs.length; i++) {
  +
  +            // Calculate the resource path of the next tag library to check
  +            String resourcePath = context.findTaglib(taglibs[i]);
  +            if (!resourcePath.startsWith("/"))
  +                resourcePath = "/WEB-INF/web.xml/../" + resourcePath;
  +            if (debug >= 2)
  +                log("  URI='" + taglibs[i] + "', ResourcePath='" +
  +                    resourcePath + "'");
  +            if (resourcePaths.contains(resourcePath)) {
  +                if (debug >= 2)
  +                    log("    Already processed");
  +                continue;
  +            }
  +            resourcePaths.add(resourcePath);
  +
  +            // Process either a JAR file or a TLD at this location
  +            if (!tldConfigJar(resourcePath, mapper))
  +                tldConfigTld(resourcePath, mapper);
  +
  +        }
  +
  +        // Second, scan tag libraries defined in JAR files
  +        // FIXME - Yet another dependence on files
  +        if (debug >= 1)
  +            log("Scanning library JAR files");
  +	Resources resources = context.getResources();
  +        URL libURL = null;
  +        try {
  +            libURL = resources.getResource("/WEB-INF/lib");
  +        } catch (MalformedURLException e) {
  +            ;
  +        }
  +
  +	if ((libURL != null) && "file".equals(libURL.getProtocol())) {
  +	    File libFile = new File(libURL.getFile());
  +	    if (libFile.exists() && libFile.canRead() &&
  +	        libFile.isDirectory()) {
  +		String filenames[] = libFile.list();
  +		for (int i = 0; i < filenames.length; i++) {
  +		    if (!filenames[i].endsWith(".jar"))
  +		        continue;
  +                    String resourcePath = "/WEB-INF/lib/" + filenames[i];
  +                    if (debug >= 2)
  +                        log("  Trying '" + resourcePath + "'");
  +                    tldConfigJar("/WEB-INF/lib/" + filenames[i], mapper);
  +		}
  +	    }
  +	}
  +
  +    }
  +
  +
  +    /**
  +     * Process a TLD (if there is one) in the JAR file (if there is one) at
  +     * the specified resource path.  Return <code>true</code> if we actually
  +     * found and processed such a TLD, or <code>false</code> otherwise.
  +     *
  +     * @param resourcePath Context-relative resource path
  +     * @param mapper XmlMapper to use for parsing
  +     */
  +    private boolean tldConfigJar(String resourcePath, XmlMapper mapper) {
  +
  +        JarFile jarFile = null;
  +        InputStream stream = null;
  +        try {
  +            URL url = context.getServletContext().getResource(resourcePath);
  +            if (url == null)
  +                return (false);
  +            url = new URL("jar:" + url.toString() + "!/");
  +            JarURLConnection conn =
  +                (JarURLConnection) url.openConnection();
  +            jarFile = conn.getJarFile();
  +            JarEntry jarEntry = jarFile.getJarEntry("META-INF/taglib.tld");
  +            if (jarEntry == null)
  +                return (false);
  +            stream = jarFile.getInputStream(jarEntry);
  +            mapper.readXml(stream, context);
  +            stream.close();
  +            return (true);
  +        } catch (Exception e) {
  +            if (debug >= 2)
  +                log("    tldConfigJar(" + resourcePath + "): " + e);
  +            if (stream != null) {
  +                try {
  +                    stream.close();
  +                } catch (Throwable t) {
  +                    ;
  +                }
  +            }
  +            if (jarFile != null) {
  +                try {
  +                    jarFile.close();
  +                } catch (Throwable t) {
  +                    ;
  +                }
  +            }
  +            return (false);
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Process a TLD (if there is one) at the specified resource path.
  +     * Return <code>true</code> if we actually found and processed such
  +     * a TLD, or <code>false</code> otherwise.
  +     *
  +     * @param resourcePath Context-relative resource path
  +     * @param mapper XmlMapper to use for parsing
  +     */
  +    private boolean tldConfigTld(String resourcePath, XmlMapper mapper) {
  +
  +        InputStream stream = null;
  +        try {
  +            stream =
  +                context.getServletContext().getResourceAsStream(resourcePath);
  +            if (stream == null)
  +                return (false);
  +            mapper.readXml(stream, context);
  +            stream.close();
  +            return (true);            
  +        } catch (Exception e) {
  +            if (debug >= 2)
  +                log("    tldConfigTld(" + resourcePath + "): " + e);
  +            if (stream != null) {
  +                try {
  +                    stream.close();
  +                } catch (Throwable t) {
  +                    ;
  +                }
  +            }
  +            return (false);
  +        }
  +
  +    }
  +
  +
   }
  +
   
   
   // ----------------------------------------------------------- Private Classes
  
  
  

Mime
View raw message