Fix an problem highlighted by the JSP 2.1 TCK. Only provide merged 3.0+ web.xml for...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 30 Dec 2009 21:50:33 +0000 (21:50 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 30 Dec 2009 21:50:33 +0000 (21:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@894718 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/startup/ContextConfig.java
java/org/apache/catalina/startup/WebRuleSet.java
java/org/apache/catalina/startup/WebXml.java

index 17edb9c..4a4ed9a 100644 (file)
@@ -1190,7 +1190,13 @@ public class ContextConfig
         InputSource contextWebXml = getContextWebXmlSource();
         parseWebXml(contextWebXml, webXml, false);
         
-        if (!webXml.isMetadataComplete()) {
+        // Assuming 0 is safe for what is required in this case
+        double webXmlVersion = 0;
+        if (webXml.getVersion() != null) {
+            webXmlVersion = Double.parseDouble(webXml.getVersion());
+        }
+        
+        if (webXmlVersion >= 3 && !webXml.isMetadataComplete()) {
             // Process /WEB-INF/classes for annotations
             URL webinfClasses;
             try {
@@ -1219,19 +1225,21 @@ public class ContextConfig
 
             // Apply merged web.xml to Context
             webXml.configureContext(context);
+            
+            // Make the merged web.xml available to other components,
+            // specifically Jasper, to save those components from having to
+            // re-generate it.
+            String mergedWebXml = webXml.toXml();
+            context.getServletContext().setAttribute(
+                   org.apache.tomcat.util.scan.Constants.MERGED_WEB_XML,
+                    mergedWebXml);
+            if (context.getLogEffectiveWebXml()) {
+                log.info("web.xml:\n" + mergedWebXml);
+            }
         } else {
-            // Apply merged web.xml to Context
+            // Apply unmerged web.xml to Context
             webXml.configureContext(context);
-        }
-        // Make the merged web.xml available to other components, specifically
-        // Jasper, to save those components from having to re-generate it.
-        String mergedWebXml = webXml.toXml();
-        context.getServletContext().setAttribute(
-               org.apache.tomcat.util.scan.Constants.MERGED_WEB_XML,
-                mergedWebXml);
-        if (context.getLogEffectiveWebXml()) {
-            log.info("web.xml:\n" + mergedWebXml);
-        }
+        }        
     }
 
     
index 55fc3b2..dea67e4 100644 (file)
@@ -160,6 +160,8 @@ public class WebRuleSet extends RuleSetBase {
                          new SetPublicIdRule("setPublicId"));
         digester.addRule(fullPrefix,
                          new IgnoreAnnotationsRule());
+        digester.addRule(fullPrefix,
+                new VersionRule());
 
         if (fragment) {
             // web-fragment.xml
@@ -1007,6 +1009,33 @@ final class IgnoreAnnotationsRule extends Rule {
 }
 
 /**
+ * A Rule that records the spec version of the web.xml being parsed
+ * 
+ */
+
+final class VersionRule extends Rule {
+
+    public VersionRule() {
+        // NO-OP
+    }
+
+    @Override
+    public void begin(String namespace, String name, Attributes attributes)
+        throws Exception {
+        WebXml webxml = (WebXml) digester.peek(digester.getCount() - 1);
+        webxml.setVersion(attributes.getValue("version"));
+        
+        if (digester.getLogger().isDebugEnabled()) {
+            digester.getLogger().debug
+                (webxml.getClass().getName() + ".setVersion( " +
+                        webxml.getVersion() + ")");
+        }
+    }
+
+}
+
+
+/**
  * A rule that logs a warning if absolute ordering is configured.
  */
 final class AbsoluteOrderingRule extends Rule {
index fd0cc27..2ce6f2a 100644 (file)
@@ -505,7 +505,14 @@ public class WebXml {
         sb.append("\"http://www.w3.org/2001/XMLSchema-instance\"\n");
         sb.append("         xsi:schemaLocation=");
         sb.append("\"http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\"\n");
-        sb.append("         version=\"3.0\"\n");
+        sb.append("         version=\"");
+        if (version != null) {
+            sb.append(version);
+        } else {
+            // Should be non-null but in case it isn't assume 3.0
+            sb.append("3.0");
+        }
+        sb.append("\"\n");
         sb.append("         metadata-complete=\"true\">\n\n");
 
         appendElement(sb, INDENT2, "display-name", displayName);