You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2010/02/01 21:06:01 UTC

svn commit: r905397 - in /geronimo/server/trunk/plugins: jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/ tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/

Author: gawor
Date: Mon Feb  1 20:06:00 2010
New Revision: 905397

URL: http://svn.apache.org/viewvc?rev=905397&view=rev
Log:
GERONIMO-4989: Support ServletContext.getResourcePaths() in Jetty. Also, minor improvements in Tomcats implementation of the same

Added:
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/BundlePathResource.java   (with props)
Modified:
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java

Added: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/BundlePathResource.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/BundlePathResource.java?rev=905397&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/BundlePathResource.java (added)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/BundlePathResource.java Mon Feb  1 20:06:00 2010
@@ -0,0 +1,119 @@
+/**
+ *  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.geronimo.jetty8.handler;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.eclipse.jetty.util.resource.Resource;
+
+public class BundlePathResource extends Resource {
+
+    private String name;
+    private String[] resources;
+    
+    public BundlePathResource(String name, Enumeration<String> paths) {
+        this.name = name;
+        String baseName = removeSlash(name);
+        List<String> list = new ArrayList<String>();
+        while(paths.hasMoreElements()) {
+            String path = getRelativeName(baseName, paths.nextElement());
+            list.add(path);            
+        }
+        this.resources = list.toArray(new String [list.size()]);
+    }
+    
+    private static String removeSlash(String name) {
+        return name.startsWith("/") ? name.substring(1): name;        
+    }
+    
+    private static String getRelativeName(String base, String name) {
+        if (base != null && name.startsWith(base)) {
+            return name.substring(base.length());
+        } else {
+            return name;
+        }
+    }
+    
+    public boolean exists() {
+        return true;
+    }
+    
+    public boolean isDirectory() {
+        return true;
+    }
+    
+    public long lastModified() {
+        return -1;
+    }
+
+    public long length() {
+        return -1;
+    }
+    
+    public String[] list() {
+        return resources;
+    }
+        
+    public String getName() {
+        return name;
+    }
+    
+    public void release() {
+    }
+       
+    public InputStream getInputStream() throws IOException {
+        return new ByteArrayInputStream(new byte[] {});
+    }
+
+    public URL getURL() {
+        return null;
+    }
+
+    public File getFile() throws IOException {
+        return null;
+    }
+    
+    public OutputStream getOutputStream() throws IOException, SecurityException {
+        throw new IOException( "Output not supported");
+    }
+
+    public boolean delete() throws SecurityException {  
+        throw new SecurityException( "Delete not supported");
+    }
+
+    public boolean renameTo(Resource dest) throws SecurityException {    
+        throw new SecurityException( "RenameTo not supported");
+    }
+    
+    public Resource addPath(String arg0) throws IOException, MalformedURLException {
+        return null;
+    }
+    
+    public boolean isContainedIn(Resource arg0) throws MalformedURLException {
+        return false;
+    }
+    
+}

Propchange: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/BundlePathResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/BundlePathResource.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/BundlePathResource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java?rev=905397&r1=905396&r2=905397&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java (original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java Mon Feb  1 20:06:00 2010
@@ -23,6 +23,7 @@
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Enumeration;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -127,11 +128,19 @@
         if (modulePath != null) {
             uriInContext = modulePath + uriInContext;
         }
-        URL url = integrationContext.getBundle().getEntry(uriInContext);
-        if (url == null) {
-            return null;
+        if (uriInContext.endsWith("/")) {
+            Enumeration<String> paths = integrationContext.getBundle().getEntryPaths(uriInContext);
+            if (paths == null) {
+                return null;
+            }
+            return new BundlePathResource(uriInContext, paths);
+        } else {
+            URL url = integrationContext.getBundle().getEntry(uriInContext);
+            if (url == null) {
+                return null;
+            }
+            return new BasicURLResource(url);
         }
-        return new BasicURLResource(url);
     }
 
     private static class BasicURLResource extends URLResource {

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java?rev=905397&r1=905396&r2=905397&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java Mon Feb  1 20:06:00 2010
@@ -1482,6 +1482,14 @@
         }
     }
     
+    private static String removeSlash(String name) {
+        if (name.endsWith("/")) {
+            return name.substring(0, name.length() - 1);
+        } else {
+            return name;
+        }
+    }
+    
     private static class NameClassPairEnumeration implements NamingEnumeration<NameClassPair> {
         
         private String basePath;
@@ -1511,7 +1519,7 @@
             String name = (String) entries.nextElement();
             String relativeName = getRelativeName(name);
             if (name.endsWith("/")) {
-                return new Binding(relativeName, DirContext.class.getName());
+                return new Binding(removeSlash(relativeName), DirContext.class.getName());
             } else {
                 return new Binding(relativeName, String.class.getName());
             }
@@ -1557,7 +1565,7 @@
             String name = (String) entries.nextElement();
             String relativeName = getRelativeName(name);
             if (name.endsWith("/")) {
-                return new Binding(relativeName, new BundleDirContext(bundle, name));
+                return new Binding(removeSlash(relativeName), new BundleDirContext(bundle, name));
             } else {
                 return new Binding(relativeName, relativeName);
             }