Author: markt
Date: Wed Dec 30 21:50:33 2009
New Revision: 894718

URL: http://svn.apache.org/viewvc?rev=894718&view=rev
Log:
Fix an problem highlighted by the JSP 2.1 TCK. Only provide merged 3.0+ web.xml 
for 3.0+ apps.

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
    tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java
    tomcat/trunk/java/org/apache/catalina/startup/WebXml.java

Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=894718&r1=894717&r2=894718&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Wed Dec 30 
21:50:33 2009
@@ -1190,7 +1190,13 @@
         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 @@
 
             // 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);
-        }
+        }        
     }
 
     

Modified: tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java?rev=894718&r1=894717&r2=894718&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java Wed Dec 30 
21:50:33 2009
@@ -160,6 +160,8 @@
                          new SetPublicIdRule("setPublicId"));
         digester.addRule(fullPrefix,
                          new IgnoreAnnotationsRule());
+        digester.addRule(fullPrefix,
+                new VersionRule());
 
         if (fragment) {
             // web-fragment.xml
@@ -1007,6 +1009,33 @@
 }
 
 /**
+ * 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 {

Modified: tomcat/trunk/java/org/apache/catalina/startup/WebXml.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebXml.java?rev=894718&r1=894717&r2=894718&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/WebXml.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/WebXml.java Wed Dec 30 
21:50:33 2009
@@ -505,7 +505,14 @@
         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);



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

Reply via email to