[jboss-cvs] JBossAS SVN: r90754 - in projects/vfs/branches/dml-zip-rework: src/main/java/org/jboss/virtual and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 1 22:01:40 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-07-01 22:01:39 -0400 (Wed, 01 Jul 2009)
New Revision: 90754

Added:
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/file/
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/file/Handler.java
Removed:
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/AbstractVFSHandler.java
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/vfs/
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/vfsfile/
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/vfsjar/
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/vfsmemory/
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/vfszip/
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/zip/
Modified:
   projects/vfs/branches/dml-zip-rework/pom.xml
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
Log:
URL stuff

Modified: projects/vfs/branches/dml-zip-rework/pom.xml
===================================================================
--- projects/vfs/branches/dml-zip-rework/pom.xml	2009-07-02 01:28:49 UTC (rev 90753)
+++ projects/vfs/branches/dml-zip-rework/pom.xml	2009-07-02 02:01:39 UTC (rev 90754)
@@ -32,7 +32,7 @@
     <version.jboss.jzipfile>1.0.0.CR1</version.jboss.jzipfile>
     <version.jboss.truezip>6.6</version.jboss.truezip>
     <version.jboss.common.core>2.2.13.GA</version.jboss.common.core>
-    <version.jboss.logging>2.0.5.GA</version.jboss.logging>
+    <version.jboss.logging>2.1.0.GA</version.jboss.logging>
     <version.jboss.test>1.1.0.GA</version.jboss.test>
     <version.junit>4.4</version.junit>
   </properties>

Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java	2009-07-02 01:28:49 UTC (rev 90753)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java	2009-07-02 02:01:39 UTC (rev 90754)
@@ -23,8 +23,6 @@
 
 import java.io.IOException;
 import java.io.Closeable;
-import java.net.URI;
-import java.net.URL;
 import java.util.List;
 import java.util.Collections;
 import java.util.Map;
@@ -51,18 +49,33 @@
 
    private final ConcurrentNavigableMap<List<String>, Mount> activeMounts = new ConcurrentSkipListMap<List<String>, Mount>(LongestMatchComparator.<String, List<String>>create());
    private final VirtualFile rootVirtualFile;
+   private static VFS instance = new VFS();
 
    static
    {
       init();
    }
 
+   /**
+    * Get the "global" instance.
+    *
+    * @return the VFS instance
+    */
+   public static VFS getInstance()
+   {
+      return instance;
+   }
+
+   /**
+    * Create a new instance.
+    */
    public VFS()
    {
       // By default, there's a root mount which points to the "real" FS
       final List<String> emptyList = Collections.<String>emptyList();
       activeMounts.put(emptyList, new Mount(RealFileSystem.ROOT_INSTANCE, emptyList));
-      rootVirtualFile = new VirtualFile(this, Collections.<String>emptyList(), "");
+      //noinspection ThisEscapedInObjectConstruction
+      rootVirtualFile = new VirtualFile(this, emptyList, "");
    }
 
    /**
@@ -105,6 +118,7 @@
       if (activeMounts.putIfAbsent(realMountPoint, mount) == null) {
          throw new IOException("Filsystem already mounted at mount point \"" + mountPoint + "\"");
       }
+      log.debugf("Created mount %s for %s on %s at mount point '%s'", mount, fileSystem, this, mountPoint);
       return mount;
    }
 
@@ -116,7 +130,7 @@
     * @throws IOException for any problem accessing the VFS
     * @throws IllegalArgumentException if the path is null
     */
-   public VirtualFile getChild(String path) throws IOException
+   public VirtualFile getChild(String path)
    {
       if (path == null)
          throw new IllegalArgumentException("Null path");
@@ -245,7 +259,9 @@
 
       public void close() throws IOException
       {
-         activeMounts.remove(realMountPoint, this);
+         if (activeMounts.remove(realMountPoint, this)) {
+            log.debugf("Unmounted %s for %s on %s", this, fileSystem, this);
+         }
       }
 
       FileSystem getFileSystem()

Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java	2009-07-02 01:28:49 UTC (rev 90753)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java	2009-07-02 02:01:39 UTC (rev 90754)
@@ -23,11 +23,15 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.File;
+import java.io.FilePermission;
 import java.net.URL;
 import java.net.URLConnection;
+import java.security.Permission;
 
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
+import sun.net.www.ParseUtil;
 
 /**
  * Implements basic URLConnection for a VirtualFile
@@ -39,36 +43,28 @@
 public class VirtualFileURLConnection extends URLConnection
 {
    protected VirtualFile file;
-   protected URL vfsurl;
-   protected String relativePath;
 
-   public VirtualFileURLConnection(URL url, URL vfsurl, String relativePath)
+   public VirtualFileURLConnection(URL url) throws IOException
    {
       super(url);
-      this.vfsurl = vfsurl;
-      this.relativePath = relativePath;
+      file = VFS.getInstance().getChild(url.getPath());
    }
 
-   public VirtualFileURLConnection(URL url, VirtualFile file)
-   {
-      super(url);
-      this.file = file;
-   }
-
    public void connect() throws IOException
    {
    }
 
    public VirtualFile getContent() throws IOException
    {
-      return getVirtualFile();
+      return file;
    }
 
    public int getContentLength()
    {
       try
       {
-         return (int)getVirtualFile().getSize();
+         final long size = file.getSize();
+         return size > (long)Integer.MAX_VALUE ? -1 : (int)size;
       }
       catch (IOException e)
       {
@@ -80,7 +76,7 @@
    {
       try
       {
-         return getVirtualFile().getLastModified();
+         return file.getLastModified();
       }
       catch (IOException e)
       {
@@ -90,33 +86,16 @@
 
    public InputStream getInputStream() throws IOException
    {
-      return getVirtualFile().openStream();
+      return file.openStream();
    }
 
-   @SuppressWarnings("deprecation")
-   protected static VirtualFile resolveCachedVirtualFile(URL vfsurl, String relativePath) throws IOException
-   {
-      return resolveVirtualFile(vfsurl, relativePath);
+   public Permission getPermission() throws IOException {
+      String decodedPath = ParseUtil.decode(url.getPath());
+      if (File.separatorChar == '/') {
+         return new FilePermission(decodedPath, "read");
+      } else {
+         return new FilePermission(
+               decodedPath.replace('/',File.separatorChar), "read");
+      }
    }
-
-   @SuppressWarnings("deprecation")
-   protected static VirtualFile resolveVirtualFile(URL vfsurl, String relativePath) throws IOException
-   {
-      VirtualFile file = VFS.getRoot(vfsurl);
-      return file.findChild(relativePath);
-   }
-
-   /**
-    * Get the virtual file.
-    *
-    * @return the underlying virtual file
-    * @throws IOException for any error
-    */
-   protected synchronized VirtualFile getVirtualFile() throws IOException
-   {
-      if (file == null)
-         file = resolveVirtualFile(vfsurl, relativePath);
-      
-      return file;
-   }
 }

Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java	2009-07-02 01:28:49 UTC (rev 90753)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java	2009-07-02 02:01:39 UTC (rev 90754)
@@ -221,9 +221,8 @@
     *
     * @param path the path
     * @return simple path, containing no . or .. paths
-    * @throws IOException if reverse path goes over the top path
     */
-   public static String applySpecialPaths(String path) throws IOException
+   public static String applySpecialPaths(String path) throws IllegalArgumentException
    {
       List<String> tokens = getTokens(path);
       if (tokens == null)
@@ -242,7 +241,7 @@
             tokens.set(i++, token);
 
          if (i < 0)
-            throw new IOException("Using reverse path on top path: " + path);
+            throw new IllegalArgumentException(".. on root path");
       }
       return getRemainingPath(tokens, 0, i);
    }
@@ -252,9 +251,9 @@
     *
     * @param pathTokens the path tokens
     * @return the simple path tokens
-    * @throws IOException if reverse path goes over the top path
+    * @throws IllegalArgumentException if reverse path goes over the top path
     */
-   public static List<String> applySpecialPaths(List<String> pathTokens) throws IOException
+   public static List<String> applySpecialPaths(List<String> pathTokens) throws IllegalArgumentException
    {
       final ArrayList<String> newTokens = new ArrayList<String>();
       for (String pathToken : pathTokens)
@@ -262,7 +261,13 @@
          if (isCurrentToken(pathToken))
             continue;
          else if (isReverseToken(pathToken))
-            newTokens.remove(newTokens.size() - 1);
+         {
+            final int size = newTokens.size();
+            if (size == 0) {
+               throw new IllegalArgumentException(".. on root path");
+            }
+            newTokens.remove(size - 1);
+         }
          else
             newTokens.add(pathToken);
       }

Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/AbstractVFSHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/AbstractVFSHandler.java	2009-07-02 01:28:49 UTC (rev 90753)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/AbstractVFSHandler.java	2009-07-02 02:01:39 UTC (rev 90754)
@@ -1,112 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.protocol;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLDecoder;
-import java.net.URLStreamHandler;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
-
-/**
- * VFS's file URL handler.
- *
- * @author <a href="bill at jboss.com">Bill Burke</a>
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public abstract class AbstractVFSHandler extends URLStreamHandler
-{
-   private static Map<Class, Integer> lengths = new WeakHashMap<Class, Integer>();
-
-   /**
-    * Get protocol name length.
-    * e.g. vfsfile - 7, vfszip - 6, ...
-    *
-    * @return protocol name lenght
-    */
-   protected int getProtocolNameLength()
-   {
-      Class<?> clazz = getClass();
-      Integer length = lengths.get(clazz);
-      if (length == null)
-      {
-         Package pck = clazz.getPackage();
-         String pckName = pck.getName();
-         int p = pckName.lastIndexOf('.');
-         length = pckName.substring(p + 1).length();
-         lengths.put(clazz, length);
-      }
-      return length;
-   }
-
-   protected URLConnection openConnection(URL url) throws IOException
-   {
-      VFSRegistry registry = VFSRegistry.getInstance();
-      VirtualFile vf = registry.getFile(url);
-      if (vf != null)
-         return new VirtualFileURLConnection(url, vf);
-
-      String file = URLDecoder.decode(url.toExternalForm(), "UTF-8").substring(getProtocolNameLength() + 1); // strip out vfs protocol + :
-      URL vfsurl = null;
-      String relative;
-      String queryStr = url.getQuery();
-      if (queryStr != null)
-         file = file.substring(0, file.lastIndexOf('?'));
-
-      File fp = new File(file);
-      if (fp.exists())
-      {
-         vfsurl = fp.getParentFile().toURI().toURL();
-         relative = fp.getName();
-      }
-      else
-      {
-         File curr = fp;
-         relative = fp.getName();
-         while ((curr = curr.getParentFile()) != null)
-         {
-            if (curr.exists())
-            {
-               vfsurl = curr.toURI().toURL();
-               break;
-            }
-            else
-            {
-               relative = curr.getName() + "/" + relative;
-            }
-         }
-      }
-
-      if (vfsurl == null)
-         throw new IOException("VFS file does not exist: " + url);
-      if (queryStr != null)
-         vfsurl = new URL(vfsurl + "?" + queryStr);
-      
-      return new VirtualFileURLConnection(url, vfsurl, relative);
-   }
-}
\ No newline at end of file

Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/file/Handler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/file/Handler.java	                        (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/protocol/file/Handler.java	2009-07-02 02:01:39 UTC (rev 90754)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.virtual.protocol.file;
+
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+
+import java.net.URLStreamHandler;
+import java.net.URLConnection;
+import java.net.URL;
+import java.net.Proxy;
+import java.io.IOException;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * The VFS URL stream handler.
+ */
+public final class Handler extends URLStreamHandler
+{
+   private static final Set<String> locals;
+
+   static {
+      Set<String> set = new HashSet<String>();
+      set.add(null);
+      set.add("");
+      set.add("~");
+      set.add("localhost");
+      locals = set;
+   }
+
+   protected URLConnection openConnection(URL u) throws IOException
+   {
+      if (locals.contains(toLower(u.getHost())))
+      {
+         // the URL is a valid local URL
+         return new VirtualFileURLConnection(u);
+      }
+
+      throw new IOException("Remote host access not supported for URLs of type \"" + u.getProtocol() + "\"");
+   }
+
+   protected URLConnection openConnection(URL u, Proxy p) throws IOException
+   {
+      return openConnection(u);
+   }
+
+   @Override
+   protected boolean hostsEqual(URL url1, URL url2)
+   {
+      return locals.contains(toLower(url1.getHost())) && locals.contains(toLower(url2.getHost())) || super.hostsEqual(url1, url2);
+   }
+
+   private static String toLower(String str) {
+      return str == null ? null : str.toLowerCase();
+   }
+}




More information about the jboss-cvs-commits mailing list