Get Jasper to use same web.xml (including merging if appropriate) as Catalina by...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 30 Dec 2009 16:04:23 +0000 (16:04 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 30 Dec 2009 16:04:23 +0000 (16:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@894659 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/compiler/TldLocationsCache.java
java/org/apache/jasper/xmlparser/ParserUtils.java

index 97c94d4..4a6488e 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.jasper.compiler;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -237,50 +238,67 @@ public class TldLocationsCache {
      * This is not kept in sync with o.a.c.startup.TldConfig as the Jasper only
      * needs the URI to TLD mappings from scan web.xml whereas TldConfig needs
      * to scan the actual TLD files.
+     * 
+     * Search order is:
+     * - web.xml scanned by Tomcat and placed in context attribute
+     * - location specified by ALT_DD_ATTR
+     * - /WEB-INF/web.xml
      */    
     private void tldScanWebXml() throws Exception {
 
         InputStream is = null;
+        String systemId = null;
 
         try {
-            // Acquire input stream to web application deployment descriptor
-            String altDDName = (String)ctxt.getAttribute(
-                                                    Constants.ALT_DD_ATTR);
-            URL uri = null;
-            if (altDDName != null) {
-                try {
-                    uri = new URL(FILE_PROTOCOL+altDDName.replace('\\', '/'));
-                } catch (MalformedURLException e) {
-                    if (log.isWarnEnabled()) {
+            // Is a web.xml provided as context attribute?
+            String webXml = (String) ctxt.getAttribute(
+                    org.apache.tomcat.util.scan.Constants.MERGED_WEB_XML);
+            if (webXml != null) {
+                is = new ByteArrayInputStream(webXml.getBytes());
+                systemId = org.apache.tomcat.util.scan.Constants.MERGED_WEB_XML;
+            }
+            
+            // If not available as context attribute, look for an alternative
+            // location
+            if (is == null) {
+                // Acquire input stream to web application deployment descriptor
+                String altDDName = (String)ctxt.getAttribute(
+                                                        Constants.ALT_DD_ATTR);
+                if (altDDName != null) {
+                    try {
+                        URL uri =
+                            new URL(FILE_PROTOCOL+altDDName.replace('\\', '/'));
+                        is = uri.openStream();
+                        systemId = uri.toExternalForm();
+                    } catch (MalformedURLException e) {
                         log.warn(Localizer.getMessage(
-                                            "jsp.error.internal.filenotfound",
-                                            altDDName));
+                                "jsp.error.internal.filenotfound",
+                                altDDName));
                     }
                 }
-            } else {
-                uri = ctxt.getResource(WEB_XML);
-                if (uri == null && log.isWarnEnabled()) {
+            }
+            
+            // Finally, try the default /WEB-INF/web.xml
+            if (is == null) {
+                URL uri = ctxt.getResource(WEB_XML);
+                if (uri == null) {
                     log.warn(Localizer.getMessage(
-                                            "jsp.error.internal.filenotfound",
-                                            WEB_XML));
+                            "jsp.error.internal.filenotfound", WEB_XML));
+                } else {
+                    is = uri.openStream();
+                    systemId = uri.toExternalForm();
                 }
             }
 
-            if (uri == null) {
+            if (is == null) {
                 return;
             }
-            is = uri.openStream();
             InputSource ip = new InputSource(is);
-            ip.setSystemId(uri.toExternalForm()); 
+            ip.setSystemId(systemId); 
 
             // Parse the web application deployment descriptor
             TreeNode webtld = null;
-            // altDDName is the absolute path of the DD
-            if (altDDName != null) {
-                webtld = new ParserUtils().parseXMLDocument(altDDName, ip);
-            } else {
-                webtld = new ParserUtils().parseXMLDocument(WEB_XML, ip);
-            }
+            webtld = new ParserUtils().parseXMLDocument(systemId, ip);
 
             // Allow taglib to be an element of the root or jsp-config (JSP2.0)
             TreeNode jspConfig = webtld.findChild("jsp-config");
index 661ae5a..5b15587 100644 (file)
@@ -73,13 +73,13 @@ public class ParserUtils {
      * Parse the specified XML document, and return a <code>TreeNode</code>
      * that corresponds to the root node of the document tree.
      *
-     * @param uri URI of the XML document being parsed
+     * @param location Location (eg URI) of the XML document being parsed
      * @param is Input source containing the deployment descriptor
      *
      * @exception JasperException if an input/output error occurs
      * @exception JasperException if a parsing error occurs
      */
-    public TreeNode parseXMLDocument(String uri, InputSource is)
+    public TreeNode parseXMLDocument(String location, InputSource is)
         throws JasperException {
 
         Document document = null;
@@ -96,20 +96,20 @@ public class ParserUtils {
             document = builder.parse(is);
        } catch (ParserConfigurationException ex) {
             throw new JasperException
-                (Localizer.getMessage("jsp.error.parse.xml", uri), ex);
+                (Localizer.getMessage("jsp.error.parse.xml", location), ex);
        } catch (SAXParseException ex) {
             throw new JasperException
                 (Localizer.getMessage("jsp.error.parse.xml.line",
-                                     uri,
+                                     location,
                                      Integer.toString(ex.getLineNumber()),
                                      Integer.toString(ex.getColumnNumber())),
                 ex);
        } catch (SAXException sx) {
             throw new JasperException
-                (Localizer.getMessage("jsp.error.parse.xml", uri), sx);
+                (Localizer.getMessage("jsp.error.parse.xml", location), sx);
         } catch (IOException io) {
             throw new JasperException
-                (Localizer.getMessage("jsp.error.parse.xml", uri), io);
+                (Localizer.getMessage("jsp.error.parse.xml", location), io);
        }
 
         // Convert the resulting document to a graph of TreeNodes