tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1041356 - in /tomcat/trunk: java/org/apache/catalina/util/ContextName.java test/org/apache/catalina/util/TestContextName.java
Date Thu, 02 Dec 2010 12:56:56 GMT
Author: markt
Date: Thu Dec  2 12:56:56 2010
New Revision: 1041356

URL: http://svn.apache.org/viewvc?rev=1041356&view=rev
Log:
HostConfig passed a context name to ContextName(String) - ensure that this is correctly parsed.
ContextName(String) now accepts all variations of Context name.

Modified:
    tomcat/trunk/java/org/apache/catalina/util/ContextName.java
    tomcat/trunk/test/org/apache/catalina/util/TestContextName.java

Modified: tomcat/trunk/java/org/apache/catalina/util/ContextName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/ContextName.java?rev=1041356&r1=1041355&r2=1041356&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/ContextName.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/ContextName.java Thu Dec  2 12:56:56 2010
@@ -33,35 +33,53 @@ public final class ContextName {
     private final String name;
     
     /**
-     * Creates an instance from a base name, directory name, WAR name or
-     * context.xml name.
+     * Creates an instance from a context name, display name, base name,
+     * directory name, WAR name or context.xml name.
      * 
      * @param name  The name to use as the basis for this object
      */
     public ContextName(String name) {
-        // Remove file extension, if any
-        if (name.toLowerCase(Locale.ENGLISH).endsWith(".war") ||
-                name.toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
-            baseName = name.substring(0, name.length() -4);
-        } else {
-            baseName = name;
+        
+        String tmp1 = name;
+        
+        // Convert Context names and display names to base names
+        
+        // Strip off any leading "/"
+        if (tmp1.startsWith("/")) {
+            tmp1 = tmp1.substring(1);
+        }
+        
+        // Replace any remaining /
+        tmp1.replaceAll("/", FWD_SLASH_REPLACEMENT);
+        
+        // Insert the ROOT name if required
+        if (tmp1.startsWith(VERSION_MARKER) || "".equals(tmp1)) {
+            tmp1 = ROOT_NAME + tmp1;
         }
 
-        String tmp;
+        // Remove any file extensions
+        if (tmp1.toLowerCase(Locale.ENGLISH).endsWith(".war") ||
+                tmp1.toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
+            tmp1 = tmp1.substring(0, tmp1.length() -4);
+        }
+
+        baseName = tmp1;
+        
+        String tmp2;
         // Extract version number
         int versionIndex = baseName.indexOf(VERSION_MARKER);
         if (versionIndex > -1) {
             version = baseName.substring(versionIndex + 2);
-            tmp = baseName.substring(0, versionIndex);
+            tmp2 = baseName.substring(0, versionIndex);
         } else {
             version = "";
-            tmp = baseName;
+            tmp2 = baseName;
         }
 
-        if (ROOT_NAME.equals(tmp)) {
+        if (ROOT_NAME.equals(tmp2)) {
             path = "";
         } else {
-            path = "/" + tmp.replaceAll(FWD_SLASH_REPLACEMENT, "/");
+            path = "/" + tmp2.replaceAll(FWD_SLASH_REPLACEMENT, "/");
         }
         
         if (versionIndex > -1) {

Modified: tomcat/trunk/test/org/apache/catalina/util/TestContextName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestContextName.java?rev=1041356&r1=1041355&r2=1041356&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestContextName.java (original)
+++ tomcat/trunk/test/org/apache/catalina/util/TestContextName.java Thu Dec  2 12:56:56 2010
@@ -137,4 +137,41 @@ public class TestContextName extends Tes
         assertEquals("/foo/bar##E", cn16.getDisplayName());
     }
 
+    public void testConstructorStringWithName() {
+        assertEquals("", new ContextName(cn1.getName()).getName());
+        assertEquals("", new ContextName(cn2.getName()).getName());
+        assertEquals("", new ContextName(cn3.getName()).getName());
+        assertEquals("/foo", new ContextName(cn4.getName()).getName());
+        assertEquals("/foo/bar", new ContextName(cn5.getName()).getName());
+        assertEquals("##A", new ContextName(cn6.getName()).getName());
+        assertEquals("##B", new ContextName(cn7.getName()).getName());
+        assertEquals("##C", new ContextName(cn8.getName()).getName());
+        assertEquals("/foo##D", new ContextName(cn9.getName()).getName());
+        assertEquals("/foo/bar##E", new ContextName(cn10.getName()).getName());
+        assertEquals("", new ContextName(cn11.getName()).getName());
+        assertEquals("/foo", new ContextName(cn12.getName()).getName());
+        assertEquals("/foo/bar", new ContextName(cn13.getName()).getName());
+        assertEquals("##A", new ContextName(cn14.getName()).getName());
+        assertEquals("/foo##D", new ContextName(cn15.getName()).getName());
+        assertEquals("/foo/bar##E", new ContextName(cn16.getName()).getName());
+    }
+
+    public void testConstructorStringWithDisplayName() {
+        assertEquals("", new ContextName(cn1.getDisplayName()).getName());
+        assertEquals("", new ContextName(cn2.getDisplayName()).getName());
+        assertEquals("", new ContextName(cn3.getDisplayName()).getName());
+        assertEquals("/foo", new ContextName(cn4.getDisplayName()).getName());
+        assertEquals("/foo/bar", new ContextName(cn5.getDisplayName()).getName());
+        assertEquals("##A", new ContextName(cn6.getDisplayName()).getName());
+        assertEquals("##B", new ContextName(cn7.getDisplayName()).getName());
+        assertEquals("##C", new ContextName(cn8.getDisplayName()).getName());
+        assertEquals("/foo##D", new ContextName(cn9.getDisplayName()).getName());
+        assertEquals("/foo/bar##E", new ContextName(cn10.getDisplayName()).getName());
+        assertEquals("", new ContextName(cn11.getDisplayName()).getName());
+        assertEquals("/foo", new ContextName(cn12.getDisplayName()).getName());
+        assertEquals("/foo/bar", new ContextName(cn13.getDisplayName()).getName());
+        assertEquals("##A", new ContextName(cn14.getDisplayName()).getName());
+        assertEquals("/foo##D", new ContextName(cn15.getDisplayName()).getName());
+        assertEquals("/foo/bar##E", new ContextName(cn16.getDisplayName()).getName());
+    }
 }



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


Mime
View raw message