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 2013/09/16 15:15:31 UTC

svn commit: r1523634 - in /tomcat/trunk/java/org/apache/catalina/webresources: AbstractArchiveResourceSet.java JarResourceSet.java JarWarResourceSet.java

Author: markt
Date: Mon Sep 16 13:15:31 2013
New Revision: 1523634

URL: http://svn.apache.org/r1523634
Log:
Pull up common code

Modified:
    tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
    tomcat/trunk/java/org/apache/catalina/webresources/JarResourceSet.java
    tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java

Modified: tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java?rev=1523634&r1=1523633&r2=1523634&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java Mon Sep 16 13:15:31 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.catalina.webresources;
 
+import java.io.File;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -23,6 +24,8 @@ import java.util.Iterator;
 import java.util.Set;
 import java.util.jar.JarEntry;
 
+import org.apache.catalina.WebResource;
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.util.ResourceSet;
 
 public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
@@ -149,4 +152,64 @@ public abstract class AbstractArchiveRes
 
         return false;
     }
+
+    @Override
+    public final WebResource getResource(String path) {
+        checkPath(path);
+        String webAppMount = getWebAppMount();
+        WebResourceRoot root = getRoot();
+
+        /*
+         * Implementation notes
+         *
+         * The path parameter passed into this method always starts with '/'.
+         *
+         * The path parameter passed into this method may or may not end with a
+         * '/'. JarFile.getEntry() will return a matching directory entry
+         * whether or not the name ends in a '/'. However, if the entry is
+         * requested without the '/' subsequent calls to JarEntry.isDirectory()
+         * will return false.
+         *
+         * Paths in JARs never start with '/'. Leading '/' need to be removed
+         * before any JarFile.getEntry() call.
+         */
+
+        // If the JAR has been mounted below the web application root, return
+        // an empty resource for requests outside of the mount point.
+
+        if (path.startsWith(webAppMount)) {
+            String pathInJar = getInternalPath() + path.substring(
+                    webAppMount.length(), path.length());
+            // Always strip off the leading '/' to get the JAR path
+            if (pathInJar.charAt(0) == '/') {
+                pathInJar = pathInJar.substring(1);
+            }
+            if (pathInJar.equals("")) {
+                // Special case
+                return new JarResourceRoot(root, new File(getBase()),
+                        pathInJar, path);
+            } else {
+                JarEntry jarEntry = null;
+                if (!(pathInJar.charAt(pathInJar.length() - 1) == '/')) {
+                    jarEntry = jarFileEntries.get(pathInJar + '/');
+                    if (jarEntry != null) {
+                        path = path + '/';
+                    }
+                }
+                if (jarEntry == null) {
+                    jarEntry = jarFileEntries.get(pathInJar);
+                }
+                if (jarEntry == null) {
+                    return new EmptyResource(root, path);
+                } else {
+                    return createArchiveResource(jarEntry, path);
+                }
+            }
+        } else {
+            return new EmptyResource(root, path);
+        }
+    }
+
+    protected abstract WebResource createArchiveResource(JarEntry jarEntry,
+            String webAppPath);
 }

Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarResourceSet.java?rev=1523634&r1=1523633&r2=1523634&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarResourceSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarResourceSet.java Mon Sep 16 13:15:31 2013
@@ -32,8 +32,6 @@ import org.apache.catalina.WebResourceRo
  */
 public class JarResourceSet extends AbstractArchiveResourceSet {
 
-    protected String baseUrl;
-
     /**
      * A no argument constructor is required for this to work with the digester.
      */
@@ -74,61 +72,10 @@ public class JarResourceSet extends Abst
     }
 
     @Override
-    public WebResource getResource(String path) {
-        checkPath(path);
-        String webAppMount = getWebAppMount();
-        WebResourceRoot root = getRoot();
-
-        /*
-         * Implementation notes
-         *
-         * The path parameter passed into this method always starts with '/'.
-         *
-         * The path parameter passed into this method may or may not end with a
-         * '/'. JarFile.getEntry() will return a matching directory entry
-         * whether or not the name ends in a '/'. However, if the entry is
-         * requested without the '/' subsequent calls to JarEntry.isDirectory()
-         * will return false.
-         *
-         * Paths in JARs never start with '/'. Leading '/' need to be removed
-         * before any JarFile.getEntry() call.
-         */
-
-        // If the JAR has been mounted below the web application root, return
-        // an empty resource for requests outside of the mount point.
-
-        if (path.startsWith(webAppMount)) {
-            String pathInJar = getInternalPath() + path.substring(
-                    webAppMount.length(), path.length());
-            // Always strip off the leading '/' to get the JAR path
-            if (pathInJar.charAt(0) == '/') {
-                pathInJar = pathInJar.substring(1);
-            }
-            if (pathInJar.equals("")) {
-                // Special case
-                return new JarResourceRoot(root, new File(getBase()),
-                        pathInJar, path);
-            } else {
-                JarEntry jarEntry = null;
-                if (!(pathInJar.charAt(pathInJar.length() - 1) == '/')) {
-                    jarEntry = jarFileEntries.get(pathInJar + '/');
-                    if (jarEntry != null) {
-                        path = path + '/';
-                    }
-                }
-                if (jarEntry == null) {
-                    jarEntry = jarFileEntries.get(pathInJar);
-                }
-                if (jarEntry == null) {
-                    return new EmptyResource(root, path);
-                } else {
-                    return new JarResource(root, getBase(), baseUrl, jarEntry,
-                            getInternalPath(), path);
-                }
-            }
-        } else {
-            return new EmptyResource(root, path);
-        }
+    protected WebResource createArchiveResource(JarEntry jarEntry,
+            String webAppPath) {
+        return new JarResource(getRoot(), getBase(), baseUrl, jarEntry,
+                getInternalPath(), webAppPath);
     }
 
     //-------------------------------------------------------- Lifecycle methods

Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java?rev=1523634&r1=1523633&r2=1523634&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java Mon Sep 16 13:15:31 2013
@@ -75,64 +75,12 @@ public class JarWarResourceSet extends A
     }
 
     @Override
-    public WebResource getResource(String path) {
-        checkPath(path);
-        String webAppMount = getWebAppMount();
-        WebResourceRoot root = getRoot();
-
-        /*
-         * Implementation notes
-         *
-         * The path parameter passed into this method always starts with '/'.
-         *
-         * The path parameter passed into this method may or may not end with a
-         * '/'. JarFile.getEntry() will return a matching directory entry
-         * whether or not the name ends in a '/'. However, if the entry is
-         * requested without the '/' subsequent calls to JarEntry.isDirectory()
-         * will return false.
-         *
-         * Paths in JARs never start with '/'. Leading '/' need to be removed
-         * before any JarFile.getEntry() call.
-         */
-
-        // If the JAR has been mounted below the web application root, return
-        // an empty resource for requests outside of the mount point.
-
-        if (path.startsWith(webAppMount)) {
-            String pathInJar = getInternalPath() + path.substring(
-                    webAppMount.length(), path.length());
-            // Always strip off the leading '/' to get the JAR path
-            if (pathInJar.charAt(0) == '/') {
-                pathInJar = pathInJar.substring(1);
-            }
-            if (pathInJar.equals("")) {
-                // Special case
-                return new JarResourceRoot(root, new File(getBase()),
-                        pathInJar, path);
-            } else {
-                JarEntry jarEntry = null;
-                if (!(pathInJar.charAt(pathInJar.length() - 1) == '/')) {
-                    jarEntry = jarFileEntries.get(pathInJar + '/');
-                    if (jarEntry != null) {
-                        path = path + '/';
-                    }
-                }
-                if (jarEntry == null) {
-                    jarEntry = jarFileEntries.get(pathInJar);
-                }
-                if (jarEntry == null) {
-                    return new EmptyResource(root, path);
-                } else {
-                    return new JarWarResource(root, getBase(), baseUrl, jarEntry,
-                            archivePath, getInternalPath(), path);
-                }
-            }
-        } else {
-            return new EmptyResource(root, path);
-        }
+    protected WebResource createArchiveResource(JarEntry jarEntry,
+            String webAppPath) {
+        return new JarWarResource(getRoot(), getBase(), baseUrl, jarEntry,
+                archivePath, getInternalPath(), webAppPath);
     }
 
-
     //-------------------------------------------------------- Lifecycle methods
     @Override
     protected void initInternal() throws LifecycleException {



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