You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by lu...@apache.org on 2003/04/24 23:13:11 UTC

cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup ContextConfig.java

luehe       2003/04/24 14:13:11

  Modified:    catalina/src/share/org/apache/catalina/startup
                        ContextConfig.java
  Log:
  Removed duplicate TLD listener scanning code that has been factored out into TldConfig.java
  
  Revision  Changes    Path
  1.23      +1 -335    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ContextConfig.java
  
  Index: ContextConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ContextConfig.java	20 Mar 2003 23:33:44 -0000	1.22
  +++ ContextConfig.java	24 Apr 2003 21:13:11 -0000	1.23
  @@ -170,12 +170,6 @@
       private static final StringManager sm =
           StringManager.getManager(Constants.Package);
   
  -    /**
  -     * The <code>Digester</code> we will use to process tag library
  -     * descriptor files.
  -     */
  -    private static Digester tldDigester = null;
  -
   
       /**
        * The <code>Digester</code> we will use to process web application
  @@ -526,47 +520,6 @@
           }
   
       }
  -
  -
  -    /**
  -     * Create (if necessary) and return a Digester configured to process a tag
  -     * library descriptor, looking for additional listener classes to be
  -     * registered.
  -     */
  -    private static Digester createTldDigester() {
  -
  -        URL url = null;
  -        Digester tldDigester = new Digester();
  -        tldDigester.setNamespaceAware(xmlNamespaceAware);
  -        tldDigester.setValidating(xmlValidation);
  -        
  -        if (tldDigester.getFactory().getClass().getName().indexOf("xerces")!=-1) {
  -            tldDigester = patchXerces(tldDigester);
  -        }
  -        // Set the schemaLocation
  -        url = ContextConfig.class.getResource(Constants.TldSchemaResourcePath_20);
  -        SchemaResolver tldEntityResolver = new SchemaResolver(url.toString(), 
  -                                                              tldDigester);
  -        if( xmlValidation ) {
  -            tldDigester.setSchema(url.toString());
  -        }
  -        
  -        url = ContextConfig.class.getResource(Constants.TldDtdResourcePath_11);
  -        tldEntityResolver.register(Constants.TldDtdPublicId_11,
  -                                   url.toString());
  -        
  -        url = ContextConfig.class.getResource(Constants.TldDtdResourcePath_12);
  -        tldEntityResolver.register(Constants.TldDtdPublicId_12,
  -                                   url.toString());
  -        
  -        tldEntityResolver = registerLocalSchema(tldEntityResolver);
  -        
  -        tldDigester.setEntityResolver(tldEntityResolver);
  -        tldDigester.addRuleSet(new TldRuleSet());
  -        return (tldDigester);
  -
  -    }
  -
       
       private static Digester patchXerces(Digester digester){
           // This feature is needed for backward compatibility with old DDs
  @@ -835,17 +788,6 @@
               validateSecurityRoles();
           }
   
  -        // Scan tag library descriptor files for additional listener classes
  -        if (ok) {
  -            try {
  -                tldScan();
  -            } catch (Exception e) {
  -                log.error(e.getMessage(), e);
  -                ok = false;
  -            }
  -        }
  -
  -
           // Configure a certificates exposer valve, if required
           if (ok)
               certificatesConfig();
  @@ -1042,282 +984,6 @@
           ok = true;
   
       }
  -
  -    /**
  -     * Scan for and configure all tag library descriptors found in this
  -     * web application.
  -     *
  -     * @exception Exception if a fatal input/output or parsing error occurs
  -     */
  -    private void tldScan() throws Exception {
  -        long t1=System.currentTimeMillis();
  -
  -        // Acquire this list of TLD resource paths to be processed
  -        Set resourcePaths = tldScanResourcePaths();
  -
  -        // Scan each accumulated resource paths for TLDs to be processed
  -        Iterator paths = resourcePaths.iterator();
  -        while (paths.hasNext()) {
  -            String path = (String) paths.next();
  -            if (path.endsWith(".jar")) {
  -                tldScanJar(path);
  -            } else {
  -                tldScanTld(path);
  -            }
  -        }
  -        long t2=System.currentTimeMillis();
  -        if( context instanceof StandardContext ) {
  -            ((StandardContext)context).setTldScanTime(t2-t1);
  -        }
  -
  -    }
  -
  -
  -    /**
  -     * Scan the JAR file at the specified resource path for TLDs in the
  -     * <code>META-INF</code> subdirectory, and scan them for application
  -     * event listeners that need to be registered.
  -     *
  -     * @param resourcePath Resource path of the JAR file to scan
  -     *
  -     * @exception Exception if an exception occurs while scanning this JAR
  -     */
  -    private void tldScanJar(String resourcePath) throws Exception {
  -
  -        if (log.isDebugEnabled()) {
  -            log.debug(" Scanning JAR at resource path '" + resourcePath + "'");
  -        }
  -
  -        JarFile jarFile = null;
  -        String name = null;
  -        InputStream inputStream = null;
  -        try {
  -            URL url = context.getServletContext().getResource(resourcePath);
  -            if (url == null) {
  -                throw new IllegalArgumentException
  -                    (sm.getString("contextConfig.tldResourcePath",
  -                                  resourcePath));
  -            }
  -            url = new URL("jar:" + url.toString() + "!/");
  -            JarURLConnection conn =
  -                (JarURLConnection) url.openConnection();
  -            conn.setUseCaches(false);
  -            jarFile = conn.getJarFile();
  -            Enumeration entries = jarFile.entries();
  -            while (entries.hasMoreElements()) {
  -                JarEntry entry = (JarEntry) entries.nextElement();
  -                name = entry.getName();
  -                if (!name.startsWith("META-INF/")) {
  -                    continue;
  -                }
  -                if (!name.endsWith(".tld")) {
  -                    continue;
  -                }
  -                if (log.isTraceEnabled()) {
  -                    log.trace("  Processing TLD at '" + name + "'");
  -                }
  -                inputStream = jarFile.getInputStream(entry);
  -                tldScanStream(inputStream);
  -                inputStream.close();
  -                inputStream = null;
  -                name = null;
  -            }
  -            // FIXME - Closing the JAR file messes up the class loader???
  -            //            jarFile.close();
  -        } catch (Exception e) {
  -            // XXX Why do we wrap it ? The signature is 'throws Exception'
  -            if (name == null) {
  -                throw new ServletException
  -                    (sm.getString("contextConfig.tldJarException",
  -                                  resourcePath, context.getPath()), e);
  -            } else {
  -                throw new ServletException
  -                    (sm.getString("contextConfig.tldEntryException",
  -                                  name, resourcePath, context.getPath()), e);
  -            }
  -        } finally {
  -            if (inputStream != null) {
  -                try {
  -                    inputStream.close();
  -                } catch (Throwable t) {
  -                    ;
  -                }
  -                inputStream = null;
  -            }
  -            if (jarFile != null) {
  -            // FIXME - Closing the JAR file messes up the class loader???
  -            //                try {
  -            //                    jarFile.close();
  -            //                } catch (Throwable t) {
  -            //                    ;
  -            //                }
  -                jarFile = null;
  -            }
  -        }
  -
  -    }
  -
  -
  -    /**
  -     * Scan the TLD contents in the specified input stream, and register
  -     * any application event listeners found there.  <b>NOTE</b> - It is
  -     * the responsibility of the caller to close the InputStream after this
  -     * method returns.
  -     *
  -     * @param resourceStream InputStream containing a tag library descriptor
  -     *
  -     * @exception Exception if an exception occurs while scanning this TLD
  -     */
  -    private void tldScanStream(InputStream resourceStream)
  -        throws Exception {
  -
  -        if (tldDigester == null){
  -            tldDigester = createTldDigester();
  -        }
  -        
  -        synchronized (tldDigester) {
  -            tldDigester.clear();
  -            tldDigester.push(context);
  -            tldDigester.parse(resourceStream);
  -        }
  -
  -    }
  -
  -
  -    /**
  -     * Scan the TLD contents at the specified resource path, and register
  -     * any application event listeners found there.
  -     *
  -     * @param resourcePath Resource path being scanned
  -     *
  -     * @exception Exception if an exception occurs while scanning this TLD
  -     */
  -    private void tldScanTld(String resourcePath) throws Exception {
  -
  -        if (log.isDebugEnabled()) {
  -            log.debug(" Scanning TLD at resource path '" + resourcePath + "'");
  -        }
  -
  -        InputStream inputStream = null;
  -        try {
  -            inputStream =
  -                context.getServletContext().getResourceAsStream(resourcePath);
  -            if (inputStream == null) {
  -                throw new IllegalArgumentException
  -                    (sm.getString("contextConfig.tldResourcePath",
  -                                  resourcePath));
  -            }
  -            tldScanStream(inputStream);
  -            inputStream.close();
  -            inputStream = null;
  -        } catch (Exception e) {
  -             throw new ServletException
  -                 (sm.getString("contextConfig.tldFileException", resourcePath, context.getPath()),
  -                  e);
  -        } finally {
  -            if (inputStream != null) {
  -                try {
  -                    inputStream.close();
  -                } catch (Throwable t) {
  -                    ;
  -                }
  -                inputStream = null;
  -            }
  -        }
  -
  -    }
  -
  -
  -    /**
  -     * Accumulate and return a Set of resource paths to be analyzed for
  -     * tag library descriptors.  Each element of the returned set will be
  -     * the context-relative path to either a tag library descriptor file,
  -     * or to a JAR file that may contain tag library descriptors in its
  -     * <code>META-INF</code> subdirectory.
  -     *
  -     * @exception IOException if an input/output error occurs while
  -     *  accumulating the list of resource paths
  -     */
  -    private Set tldScanResourcePaths() throws IOException {
  -        if (log.isDebugEnabled()) {
  -            log.debug(" Accumulating TLD resource paths");
  -        }
  -        Set resourcePaths = new HashSet();
  -
  -        // Accumulate resource paths explicitly listed in the web application
  -        // deployment descriptor
  -        if (log.isTraceEnabled()) {
  -            log.trace("  Scanning <taglib> elements in web.xml");
  -        }
  -        String taglibs[] = context.findTaglibs();
  -        for (int i = 0; i < taglibs.length; i++) {
  -            String resourcePath = context.findTaglib(taglibs[i]);
  -            // FIXME - Servlet 2.4 DTD implies that the location MUST be
  -            // a context-relative path starting with '/'?
  -            if (!resourcePath.startsWith("/")) {
  -                resourcePath = "/WEB-INF/" + resourcePath;
  -            }
  -            if (log.isTraceEnabled()) {
  -                log.trace("   Adding path '" + resourcePath +
  -                    "' for URI '" + taglibs[i] + "'");
  -            }
  -            resourcePaths.add(resourcePath);
  -        }
  -
  -        // Scan TLDs in the /WEB-INF subdirectory of the web application
  -        if (log.isTraceEnabled()) {
  -            log.trace("  Scanning TLDs in /WEB-INF subdirectory");
  -        }
  -        DirContext resources = context.getResources();
  -        if( resources!=null ) {
  -            try {
  -                NamingEnumeration items = resources.list("/WEB-INF");
  -                while (items.hasMoreElements()) {
  -                    NameClassPair item = (NameClassPair) items.nextElement();
  -                    String resourcePath = "/WEB-INF/" + item.getName();
  -                    // FIXME - JSP 2.0 is not explicit about whether we should
  -                    // scan subdirectories of /WEB-INF for TLDs also
  -                    if (!resourcePath.endsWith(".tld")) {
  -                        continue;
  -                    }
  -                    if (log.isTraceEnabled()) {
  -                        log.trace("   Adding path '" + resourcePath + "'");
  -                    }
  -                    resourcePaths.add(resourcePath);
  -                }
  -            } catch (NamingException e) {
  -                ; // Silent catch: it's valid that no /WEB-INF directory exists
  -            }
  -        } else {
  -            log.info("No resource " + context + " " + context.getClass());
  -        }
  -
  -        // Scan JARs in the /WEB-INF/lib subdirectory of the web application
  -        if (log.isTraceEnabled()) {
  -            log.trace("  Scanning JARs in /WEB-INF/lib subdirectory");
  -        }
  -        try {
  -            NamingEnumeration items = resources.list("/WEB-INF/lib");
  -            while (items.hasMoreElements()) {
  -                NameClassPair item = (NameClassPair) items.nextElement();
  -                String resourcePath = "/WEB-INF/lib/" + item.getName();
  -                if (!resourcePath.endsWith(".jar")) {
  -                    continue;
  -                }
  -                if (log.isTraceEnabled()) {
  -                    log.trace("   Adding path '" + resourcePath + "'");
  -                }
  -                resourcePaths.add(resourcePath);
  -            }
  -        } catch (NamingException e) {
  -            ; // Silent catch: it's valid that no /WEB-INF/lib directory exists
  -        }
  -
  -        // Return the completed set
  -        return (resourcePaths);
  -
  -    }
  -
   
       /**
        * Validate the usage of security role names in the web application
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org