You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/02/03 20:10:48 UTC

svn commit: r906183 - in /tomcat/trunk: java/org/apache/catalina/ java/org/apache/catalina/core/ java/org/apache/catalina/deploy/ test/org/apache/ test/org/apache/catalina/deploy/

Author: markt
Date: Wed Feb  3 19:10:48 2010
New Revision: 906183

URL: http://svn.apache.org/viewvc?rev=906183&view=rev
Log:
Servlet 3.0
Effective major/minor version support

Added:
    tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java   (with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/Context.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java
    tomcat/trunk/test/org/apache/TestAll.java

Modified: tomcat/trunk/java/org/apache/catalina/Context.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Context.java?rev=906183&r1=906182&r2=906183&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Context.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Context.java Wed Feb  3 19:10:48 2010
@@ -1128,5 +1128,33 @@
      * @param path The path to the desired resource
      */
     public String getRealPath(String path);
+    
+    
+    /**
+     * Return the effective major version of the Servlet spec used by this
+     * context.
+     */
+    public int getEffectiveMajorVersion();
+    
+    
+    /**
+     * Set the effective major version of the Servlet spec used by this
+     * context.
+     */
+    public void setEffectiveMajorVersion(int major);
+    
+    
+    /**
+     * Return the effective minor version of the Servlet spec used by this
+     * context.
+     */
+    public int getEffectiveMinorVersion();
+    
+    
+    /**
+     * Set the effective minor version of the Servlet spec used by this
+     * context.
+     */
+    public void setEffectiveMinorVersion(int minor);
 }
 

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=906183&r1=906182&r2=906183&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Wed Feb  3 19:10:48 2010
@@ -1348,15 +1348,13 @@
 
     @Override
     public int getEffectiveMajorVersion() {
-        // TODO SERVLET3
-        return 0;
+        return context.getEffectiveMajorVersion();
     }
 
 
     @Override
     public int getEffectiveMinorVersion() {
-        // TODO SERVLET3
-        return 0;
+        return context.getEffectiveMinorVersion();
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=906183&r1=906182&r2=906183&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Wed Feb  3 19:10:48 2010
@@ -763,8 +763,28 @@
      */
     private boolean logEffectiveWebXml = false;
 
+    private int effectiveMajorVersion = 3;
+    
+    private int effectiveMinorVersion = 0;
+
     // ----------------------------------------------------- Context Properties
 
+    public int getEffectiveMajorVersion() {
+        return effectiveMajorVersion;
+    }
+
+    public void setEffectiveMajorVersion(int effectiveMajorVersion) {
+        this.effectiveMajorVersion = effectiveMajorVersion;
+    }
+
+    public int getEffectiveMinorVersion() {
+        return effectiveMinorVersion;
+    }
+
+    public void setEffectiveMinorVersion(int effectiveMinorVersion) {
+        this.effectiveMinorVersion = effectiveMinorVersion;
+    }
+    
     public void setLogEffectiveWebXml(boolean logEffectiveWebXml) {
         this.logEffectiveWebXml = logEffectiveWebXml;
     }

Modified: tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=906183&r1=906182&r2=906183&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties Wed Feb  3 19:10:48 2010
@@ -38,4 +38,6 @@
 webXml.mergeConflictSessionTimeout=The session timeout was defined inconsistently in multiple fragments with different values including fragment with name [{0}] located at [{1}]
 webXml.mergeConflictSessionTrackingMode=The session tracking modes were defined inconsistently in multiple fragments including fragment with name [{0}] located at [{1}]
 webXml.mergeConflictString=The [{0}] with name [{1}] was defined inconsistently in multiple fragments including fragment with name [{2}] located at [{3}]
-webXml.multipleOther=Multiple others entries in ordering
\ No newline at end of file
+webXml.multipleOther=Multiple others entries in ordering
+webxml.unrecognisedPublicId=The public ID [{0}] did not match any of the known public ID's for web.xml files so the version could not be identified
+webXml.version.nfe=Unable to parse [{0}] from the version string [{1}]. This component of the version string will be ignored. 

Modified: tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java?rev=906183&r1=906182&r2=906183&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java Wed Feb  3 19:10:48 2010
@@ -110,12 +110,85 @@
     // Required attribute of web-app element
     private String version = null;
     public String getVersion() { return version; }
-    public void setVersion(String version) { this.version = version; }
+    /**
+     * Set the version for this web.xml file
+     * @param version   Values of <code>null</code> will be ignored
+     */
+    public void setVersion(String version) {
+        if (version == null) return;
+        
+        this.version = version;
+        // Update major and minor version
+        // Expected format is n.n - allow for any number of digits just in case
+        String major = null;
+        String minor = null;
+        int split = version.indexOf('.');
+        if (split < 0) {
+            // Major only
+            major = version;
+        } else {
+            major = version.substring(0, split);
+            minor = version.substring(split + 1);
+        }
+        if (major == null || major.length() == 0) {
+            majorVersion = 0;
+        } else {
+            try {
+                majorVersion = Integer.parseInt(major);
+            } catch (NumberFormatException nfe) {
+                log.warn(sm.getString("webXml.version.nfe", major, version),
+                        nfe);
+                majorVersion = 0;
+            }
+        }
+        
+        if (minor == null || minor.length() == 0) {
+            minorVersion = 0;
+        } else {
+            try {
+                minorVersion = Integer.parseInt(minor);
+            } catch (NumberFormatException nfe) {
+                log.warn(sm.getString("webXml.version.nfe", minor, version),
+                        nfe);
+                minorVersion = 0;
+            }
+        }
+    }
+
 
     // Optional publicId attribute
     private String publicId = null;
     public String getPublicId() { return publicId; }
-    public void setPublicId(String publicId) { this.publicId = publicId; }
+    public void setPublicId(String publicId) {
+        this.publicId = publicId;
+        // Update major and minor version
+        if (org.apache.catalina.startup.Constants.WebSchemaPublicId_30.
+                equalsIgnoreCase(publicId) ||
+                org.apache.catalina.startup.Constants.WebFragmentSchemaPublicId_30.
+                equalsIgnoreCase(publicId)) {
+            majorVersion = 3;
+            minorVersion = 0;
+        } else if (org.apache.catalina.startup.Constants.WebSchemaPublicId_25.
+                equalsIgnoreCase(publicId)) {
+            majorVersion = 2;
+            minorVersion = 5;
+        } else if (org.apache.catalina.startup.Constants.WebSchemaPublicId_24.
+                equalsIgnoreCase(publicId)) {
+            majorVersion = 2;
+            minorVersion = 4;
+        } else if (org.apache.catalina.startup.Constants.WebDtdPublicId_23.
+                equalsIgnoreCase(publicId)) {
+            majorVersion = 2;
+            minorVersion = 3;
+        } else if (org.apache.catalina.startup.Constants.WebDtdPublicId_22.
+                equalsIgnoreCase(publicId)) {
+            majorVersion = 2;
+            minorVersion = 2;
+        } else {
+            // Unrecognised publicId
+            log.warn(sm.getString("webxml.unrecognisedPublicId", publicId));
+        }
+    }
     
     // Optional metadata-complete attribute
     private boolean metadataComplete = false;
@@ -135,6 +208,13 @@
         }
     }
 
+    // Derived major and minor version attributes
+    // Default to 3.0 until we know otherwise
+    private int majorVersion = 3;
+    private int minorVersion = 0;
+    public int getMajorVersion() { return majorVersion; }
+    public int getMinorVersion() { return minorVersion; }
+    
     // web-app elements
     // TODO: Ignored elements:
     // - description
@@ -1055,6 +1135,9 @@
         context.setPublicId(publicId);
 
         // Everything else in order
+        context.setEffectiveMajorVersion(getMajorVersion());
+        context.setEffectiveMinorVersion(getMinorVersion());
+        
         for (Entry<String, String> entry : contextParams.entrySet()) {
             context.addParameter(entry.getKey(), entry.getValue());
         }

Modified: tomcat/trunk/test/org/apache/TestAll.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/TestAll.java?rev=906183&r1=906182&r2=906183&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/TestAll.java (original)
+++ tomcat/trunk/test/org/apache/TestAll.java Wed Feb  3 19:10:48 2010
@@ -23,7 +23,7 @@
 import org.apache.catalina.connector.TestKeepAliveCount;
 import org.apache.catalina.connector.TestRequest;
 import org.apache.catalina.core.TestStandardContext;
-import org.apache.catalina.deploy.TestWebXml;
+import org.apache.catalina.deploy.TestWebXmlOrdering;
 import org.apache.catalina.ha.session.TestSerializablePrincipal;
 import org.apache.catalina.startup.TestTomcat;
 import org.apache.catalina.startup.TestTomcatSSL;
@@ -51,7 +51,7 @@
         // startup
         suite.addTestSuite(TestTomcat.class);
         suite.addTestSuite(TestTomcatSSL.class);
-        suite.addTestSuite(TestWebXml.class);
+        suite.addTestSuite(TestWebXmlOrdering.class);
         // tribes
         // suite.addTest(TribesTestSuite.suite());
         

Added: tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java?rev=906183&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java (added)
+++ tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java Wed Feb  3 19:10:48 2010
@@ -0,0 +1,83 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.catalina.deploy;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for {@link WebXml}.
+ */
+public class TestWebXml extends TestCase {
+
+    public void testParseVersion() {
+        
+        WebXml webxml = new WebXml();
+        
+        // Defaults
+        assertEquals(3, webxml.getMajorVersion());
+        assertEquals(0, webxml.getMinorVersion());
+        
+        // Both get changed
+        webxml.setVersion("2.5");
+        assertEquals(2, webxml.getMajorVersion());
+        assertEquals(5, webxml.getMinorVersion());
+        
+        // Reset
+        webxml.setVersion("0.0");
+        assertEquals(0, webxml.getMajorVersion());
+        assertEquals(0, webxml.getMinorVersion());
+        
+        // null input should be ignored
+        webxml.setVersion(null);
+        assertEquals(0, webxml.getMajorVersion());
+        assertEquals(0, webxml.getMinorVersion());
+        
+        // major only
+        webxml.setVersion("3");
+        assertEquals(3, webxml.getMajorVersion());
+        assertEquals(0, webxml.getMinorVersion());
+        
+        // no minor digit
+        webxml.setVersion("0.0");   // reset
+        webxml.setVersion("3.");
+        assertEquals(3, webxml.getMajorVersion());
+        assertEquals(0, webxml.getMinorVersion());
+        
+        // minor only
+        webxml.setVersion("0.0");   // reset
+        webxml.setVersion(".5");
+        assertEquals(0, webxml.getMajorVersion());
+        assertEquals(5, webxml.getMinorVersion());
+        
+        // leading & training zeros
+        webxml.setVersion("0.0");   // reset
+        webxml.setVersion("002.500");
+        assertEquals(2, webxml.getMajorVersion());
+        assertEquals(500, webxml.getMinorVersion());
+    }
+    
+    public void testParsePublicIdVersion() {
+        
+        WebXml webxml = new WebXml();
+        
+        webxml.setPublicId(
+                org.apache.catalina.startup.Constants.WebSchemaPublicId_25);
+        assertEquals(2, webxml.getMajorVersion());
+        assertEquals(5, webxml.getMinorVersion());
+    }
+}

Propchange: tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java
------------------------------------------------------------------------------
    svn:eol-style = native



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