[Jboss-cvs] JBossAS SVN: r56707 - in projects/microcontainer/trunk/container/src/main/org/jboss/virtual: . plugins/context/file

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 11 00:50:45 EDT 2006


Author: scott.stark at jboss.org
Date: 2006-09-11 00:50:43 -0400 (Mon, 11 Sep 2006)
New Revision: 56707

Modified:
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFSUtils.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/LinkHandler.java
Log:
Move the link parsing to FileSystemContext so that the link properties can be parsed before the creation of the LinkHandler

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFSUtils.java	2006-09-11 02:28:54 UTC (rev 56706)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFSUtils.java	2006-09-11 04:50:43 UTC (rev 56707)
@@ -50,7 +50,11 @@
 {
    /** The log */
    private static final Logger log = Logger.getLogger(VFSUtils.class);
+   /** */
    public static final String VFS_LINK_PREFIX = ".vfslink";
+   /** */
+   public static final String VFS_LINK_NAME = "vfs.link.name";
+   public static final String VFS_LINK_TARGET = "vfs.link.target";
 
    /**
     * Get the paths string for a collection of virtual files
@@ -247,13 +251,13 @@
    }
 
    /**
-    * Does a vf name match the VFS link prefix
+    * Does a vf name contain the VFS link prefix
     * @param name - the name portion of a virtual file
     * @return true if the name starts with VFS_LINK_PREFIX, false otherwise
     */
    public static boolean isLink(String name)
    {
-      boolean isLink = name.startsWith(VFS_LINK_PREFIX);
+      boolean isLink = name.indexOf(VFS_LINK_PREFIX) >= 0;
       return isLink;
    }
 
@@ -266,12 +270,12 @@
     * @return a list of the links read from the stream
     * @throws IOException on failure to read/parse the stream
     */
-   public static List<LinkInfo> readLinkInfo(InputStream is, String name)
+   public static List<LinkInfo> readLinkInfo(InputStream is, String name, Properties props)
       throws IOException, URISyntaxException
    {
       ArrayList<LinkInfo> info = new ArrayList<LinkInfo>();
       if( name.endsWith(".properties") )
-         parseLinkProperties(is, info);
+         parseLinkProperties(is, info, props);
       else
          throw new UnsupportedEncodingException("Unknown link format: "+name);
       return info;
@@ -285,17 +289,16 @@
     * @throws IOException
     * @throws URISyntaxException 
     */
-   public static void parseLinkProperties(InputStream is, List<LinkInfo> info)
+   public static void parseLinkProperties(InputStream is, List<LinkInfo> info, Properties props)
       throws IOException, URISyntaxException
    {
-      Properties props = new Properties();
       props.load(is);
       // Iterate over the property tuples
       for(int n = 0; ; n ++)
       {
-         String nameKey = "link.name." + n;
+         String nameKey = VFS_LINK_NAME + "." + n;
          String name = props.getProperty(nameKey);
-         String uriKey = "link.uri." + n;
+         String uriKey = VFS_LINK_TARGET + "." + n;
          String uri = props.getProperty(uriKey);
          // End when the value is null since a link may not have a name
          if (uri == null)

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java	2006-09-11 02:28:54 UTC (rev 56706)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java	2006-09-11 04:50:43 UTC (rev 56707)
@@ -22,16 +22,20 @@
 package org.jboss.virtual.plugins.context.file;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.List;
+import java.util.Properties;
 
 import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.plugins.context.AbstractVFSContext;
 import org.jboss.virtual.plugins.context.jar.JarHandler;
 import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.jboss.virtual.spi.LinkInfo;
 import org.jboss.virtual.spi.VirtualFileHandler;
 
 /**
@@ -183,7 +187,8 @@
     * @throws IOException for any error accessing the file system
     * @throws IllegalArgumentException for a null file
     */
-   public VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, File file, URI uri) throws IOException
+   public VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, File file, URI uri)
+      throws IOException
    {
       if (file == null)
          throw new IllegalArgumentException("Null file");
@@ -192,7 +197,33 @@
 
       VirtualFileHandler handler;
       if( VFSUtils.isLink(file.getName()) )
-         handler = new LinkHandler(this, parent, file, uri);
+      {
+         Properties props = new Properties();
+         FileInputStream fis = new FileInputStream(file);
+         try
+         {
+            List<LinkInfo> links = VFSUtils.readLinkInfo(fis, file.getName(), props);
+            String name = props.getProperty(VFSUtils.VFS_LINK_NAME, "link");
+            handler = new LinkHandler(this, parent, uri, name, links);            
+         }
+         catch(URISyntaxException e)
+         {
+            IOException ex = new IOException("Failed to parse link URIs");
+            ex.initCause(e);
+            throw ex;
+         }
+         finally
+         {
+            try
+            {
+               fis.close();
+            }
+            catch(IOException e)
+            {
+               log.debug("Exception closing file input stream: " + fis, e);
+            }
+         }
+      }
       else
          handler = new FileHandler(this, parent, file, uri);
       return handler;

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/LinkHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/LinkHandler.java	2006-09-11 02:28:54 UTC (rev 56706)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/LinkHandler.java	2006-09-11 04:50:43 UTC (rev 56707)
@@ -21,16 +21,14 @@
 */
 package org.jboss.virtual.plugins.context.file;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 
 import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.plugins.context.AbstractURLHandler;
 import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
 import org.jboss.virtual.spi.LinkInfo;
 import org.jboss.virtual.spi.VFSContext;
@@ -44,7 +42,7 @@
  * @author Scott.Stark at jboss.org
  * @version $Revision: 1.1 $
  */
-public class LinkHandler extends FileHandler
+public class LinkHandler extends AbstractURLHandler
    implements StructuredVirtualFileHandler
 {
    private static final long serialVersionUID = 1;
@@ -63,33 +61,12 @@
     * @throws IOException for an error accessing the file system
     * @throws IllegalArgumentException for a null context, url
     */
-   public LinkHandler(FileSystemContext context, VirtualFileHandler parent, File file, URI uri)
+   public LinkHandler(FileSystemContext context, VirtualFileHandler parent, URI uri, String name,
+         List<LinkInfo> links)
       throws IOException
    {
-      super(context, parent, file, uri);
-      // Read the link info from the file
-      FileInputStream fis = new FileInputStream(file);
-      try
-      {
-          links = VFSUtils.readLinkInfo(fis, file.getName());
-      }
-      catch (URISyntaxException e)
-      {
-         IOException ex = new IOException();
-         ex.initCause(e);
-         throw ex;
-      }
-      finally
-      {
-         try
-         {
-            fis.close();
-         }
-         catch(IOException e)
-         {
-            log.warn("Exception closing file input stream: " + fis, e);
-         }
-      }
+      super(context, parent, uri.toURL(), name);
+      this.links = links;
    }
 
    @Override
@@ -98,7 +75,6 @@
       return false;
    }
 
-   @Override
    public boolean isDirectory()
    {
       return true;
@@ -110,7 +86,6 @@
       return false;
    }
 
-   @Override
    public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
    {
       List<VirtualFileHandler> result = new ArrayList<VirtualFileHandler>();
@@ -141,7 +116,10 @@
       return result;
    }
 
-   @Override
+   public VirtualFileHandler findChild(String path) throws IOException
+   {
+      return structuredFindChild(path);
+   }
    public VirtualFileHandler createChildHandler(String name) throws IOException
    {
       VirtualFileHandler handler = linkTargets.get(name);




More information about the jboss-cvs-commits mailing list