Author: markt
Date: Mon Sep 16 13:18:00 2013
New Revision: 1523637

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

Modified:
    
tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResource.java
    tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java
    tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java

Modified: 
tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResource.java?rev=1523637&r1=1523636&r2=1523637&view=diff
==============================================================================
--- 
tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResource.java 
(original)
+++ 
tomcat/trunk/java/org/apache/catalina/webresources/AbstractArchiveResource.java 
Mon Sep 16 13:18:00 2013
@@ -18,6 +18,8 @@ package org.apache.catalina.webresources
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
@@ -25,13 +27,46 @@ import org.apache.catalina.WebResourceRo
 
 public abstract class AbstractArchiveResource extends AbstractResource {
 
-    protected final JarEntry resource;
-    protected String name;
+    private final String base;
+    private final String baseUrl;
+    private final JarEntry resource;
+    private final String name;
 
     protected AbstractArchiveResource(WebResourceRoot root, String webAppPath,
-            JarEntry jarEntry) {
+            String base, String baseUrl, JarEntry jarEntry,
+            String internalPath) {
         super(root, webAppPath);
+        this.base = base;
+        this.baseUrl = baseUrl;
         this.resource = jarEntry;
+
+        String resourceName = resource.getName();
+        if (resourceName.charAt(resourceName.length() - 1) == '/') {
+            resourceName = resourceName.substring(0, resourceName.length() - 
1);
+        }
+        if (internalPath.length() > 0 && resourceName.equals(
+                internalPath.subSequence(1, internalPath.length()))) {
+            name = "";
+        } else {
+            int index = resourceName.lastIndexOf('/');
+            if (index == -1) {
+                name = resourceName;
+            } else {
+                name = resourceName.substring(index + 1);
+            }
+        }
+    }
+
+    public String getBase() {
+        return base;
+    }
+
+    public String getBaseUrl() {
+        return baseUrl;
+    }
+
+    public JarEntry getResource() {
+        return resource;
     }
 
     @Override
@@ -89,6 +124,19 @@ public abstract class AbstractArchiveRes
         return resource.getTime();
     }
 
+    @Override
+    public URL getURL() {
+        try {
+            return new URL(baseUrl + "!/" + resource.getName());
+        } catch (MalformedURLException e) {
+            if (getLog().isDebugEnabled()) {
+                getLog().debug(sm.getString("fileResource.getUrlFail",
+                        resource.getName(), baseUrl), e);
+            }
+            return null;
+        }
+    }
+
 
     protected static class JarInputStreamWrapper extends InputStream {
 

Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java?rev=1523637&r1=1523636&r2=1523637&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java Mon Sep 
16 13:18:00 2013
@@ -18,8 +18,6 @@ package org.apache.catalina.webresources
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
@@ -35,55 +33,21 @@ public class JarResource extends Abstrac
 
     private static final Log log = LogFactory.getLog(JarResource.class);
 
-    private final String base;
-    private final String baseUrl;
-
     public JarResource(WebResourceRoot root, String webAppPath, String base,
             String baseUrl, JarEntry jarEntry, String internalPath) {
-        super(root, webAppPath, jarEntry);
-        this.base = base;
-        this.baseUrl = "jar:" + baseUrl;
-
-        String resourceName = resource.getName();
-        if (resourceName.charAt(resourceName.length() - 1) == '/') {
-            resourceName = resourceName.substring(0, resourceName.length() - 
1);
-        }
-        if (internalPath.length() > 0 && resourceName.equals(
-                internalPath.subSequence(1, internalPath.length()))) {
-            name = "";
-        } else {
-            int index = resourceName.lastIndexOf('/');
-            if (index == -1) {
-                name = resourceName;
-            } else {
-                name = resourceName.substring(index + 1);
-            }
-        }
+        super(root, webAppPath, base, "jar:" + baseUrl, jarEntry, 
internalPath);
     }
 
     @Override
     public InputStream getInputStream() {
         try {
-            JarFile jarFile = new JarFile(base);
-            InputStream is = jarFile.getInputStream(resource);
+            JarFile jarFile = new JarFile(getBase());
+            InputStream is = jarFile.getInputStream(getResource());
             return new JarInputStreamWrapper(jarFile, is);
         } catch (IOException e) {
             if (log.isDebugEnabled()) {
                 log.debug(sm.getString("fileResource.getInputStreamFail",
-                        resource.getName(), baseUrl), e);
-            }
-            return null;
-        }
-    }
-
-    @Override
-    public URL getURL() {
-        try {
-            return new URL(baseUrl + "!/" + resource.getName());
-        } catch (MalformedURLException e) {
-            if (log.isDebugEnabled()) {
-                log.debug(sm.getString("fileResource.getUrlFail",
-                        resource.getName(), baseUrl), e);
+                        getResource().getName(), getBaseUrl()), e);
             }
             return null;
         }

Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java?rev=1523637&r1=1523636&r2=1523637&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java Mon 
Sep 16 13:18:00 2013
@@ -18,8 +18,6 @@ package org.apache.catalina.webresources
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
@@ -36,46 +34,27 @@ public class JarWarResource extends Abst
 
     private static final Log log = LogFactory.getLog(JarResource.class);
 
-    private final String base;
-    private final String baseUrl;
     private final String archivePath;
 
     public JarWarResource(WebResourceRoot root, String webAppPath, String base,
             String baseUrl, JarEntry jarEntry, String archivePath,
             String internalPath) {
-        super(root, webAppPath, jarEntry);
-        this.base = base;
+        super(root, webAppPath, base, "jar:war:" + baseUrl + "^/" + 
archivePath,
+                jarEntry, internalPath);
         this.archivePath = archivePath;
-        this.baseUrl = "jar:war:" + baseUrl + "^/" + archivePath;
-
-        String resourceName = resource.getName();
-        if (resourceName.charAt(resourceName.length() - 1) == '/') {
-            resourceName = resourceName.substring(0, resourceName.length() - 
1);
-        }
-        if (internalPath.length() > 0 && resourceName.equals(
-                internalPath.subSequence(1, internalPath.length()))) {
-            name = "";
-        } else {
-            int index = resourceName.lastIndexOf('/');
-            if (index == -1) {
-                name = resourceName;
-            } else {
-                name = resourceName.substring(index + 1);
-            }
-        }
     }
 
     @Override
     public InputStream getInputStream() {
         try {
-            JarFile warFile = new JarFile(base);
+            JarFile warFile = new JarFile(getBase());
             JarEntry jarFileInWar = warFile.getJarEntry(archivePath);
             InputStream isInWar = warFile.getInputStream(jarFileInWar);
 
             JarInputStream jarIs = new JarInputStream(isInWar);
             JarEntry entry = jarIs.getNextJarEntry();
             while (entry != null &&
-                    !entry.getName().equals(resource.getName())) {
+                    !entry.getName().equals(getResource().getName())) {
                 entry = jarIs.getNextJarEntry();
             }
 
@@ -97,20 +76,7 @@ public class JarWarResource extends Abst
         } catch (IOException e) {
             if (log.isDebugEnabled()) {
                 log.debug(sm.getString("fileResource.getInputStreamFail",
-                        resource.getName(), baseUrl), e);
-            }
-            return null;
-        }
-    }
-
-    @Override
-    public URL getURL() {
-        try {
-            return new URL(baseUrl + "!/" + resource.getName());
-        } catch (MalformedURLException e) {
-            if (log.isDebugEnabled()) {
-                log.debug(sm.getString("fileResource.getUrlFail",
-                        resource.getName(), baseUrl), e);
+                        getResource().getName(), getBaseUrl()), e);
             }
             return null;
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to