[jboss-cvs] JBossAS SVN: r93980 - in projects/demos/microcontainer/trunk: vfs/src/main/java/org/jboss/demos/bootstrap/vfs and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 24 06:23:42 EDT 2009


Author: alesj
Date: 2009-09-24 06:23:42 -0400 (Thu, 24 Sep 2009)
New Revision: 93980

Added:
   projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipFileHandlerPlugin.java
Modified:
   projects/demos/microcontainer/trunk/pom.xml
   projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/VFSMain.java
   projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContext.java
   projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java
Log:
Use JBVFS-124, allowing to handle .gzip files from FileHandler.

Modified: projects/demos/microcontainer/trunk/pom.xml
===================================================================
--- projects/demos/microcontainer/trunk/pom.xml	2009-09-24 10:12:16 UTC (rev 93979)
+++ projects/demos/microcontainer/trunk/pom.xml	2009-09-24 10:23:42 UTC (rev 93980)
@@ -37,7 +37,7 @@
   
   <properties>
     <version.jboss.jbossas>5.1.0.GA</version.jboss.jbossas>
-    <version.jboss.vfs>2.1.3.SP1</version.jboss.vfs>
+    <version.jboss.vfs>2.1.4-SNAPSHOT</version.jboss.vfs>
     <version.jboss.man>2.1.0.GA</version.jboss.man>
     <version.jboss.mdr>2.0.2.GA</version.jboss.mdr>
     <version.jboss.microcontainer>2.0.9.GA</version.jboss.microcontainer>

Modified: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/VFSMain.java
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/VFSMain.java	2009-09-24 10:12:16 UTC (rev 93979)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/VFSMain.java	2009-09-24 10:23:42 UTC (rev 93980)
@@ -23,10 +23,9 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.FileNotFoundException;
-import java.net.URL;
 
 import org.jboss.demos.vfs.gzip.GZipVFSContextFactory;
 import org.jboss.virtual.VFS;
@@ -56,13 +55,12 @@
                demosHome = "/projects/demos";
          }
 
-         File test = new File(demosHome + "/vfs/src/main/resources/compressed.gzip");
-         if (test.exists() == false)
-            throw new FileNotFoundException(test.getAbsolutePath());
+         File resources = new File(demosHome + "/vfs/src/main/resources");
+         if (resources.exists() == false)
+            throw new FileNotFoundException(resources.getAbsolutePath());
 
-         String urlString = test.toURI().toURL().toExternalForm();
-         URL url = new URL("gzip" + urlString.substring("file".length()));
-         VirtualFile file = VFS.getRoot(url);
+         VirtualFile root = VFS.getRoot(resources.toURL());
+         VirtualFile file = root.getChild("compressed.gzip");
 
          System.out.println();
          InputStream is = file.openStream();

Copied: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipFileHandlerPlugin.java (from rev 93964, projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java)
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipFileHandlerPlugin.java	                        (rev 0)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipFileHandlerPlugin.java	2009-09-24 10:23:42 UTC (rev 93980)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.demos.vfs.gzip;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+
+import org.jboss.virtual.plugins.context.file.FileSystemContext;
+import org.jboss.virtual.spi.FileHandlerPlugin;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * GZIP virtual file handler pluing.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class GZipFileHandlerPlugin implements FileHandlerPlugin
+{
+   private FileFilter filter = new DefaultFileFilter();
+
+   public int getRelativeOrder()
+   {
+      return Integer.MAX_VALUE - 10;
+   }
+
+   public VirtualFileHandler createHandler(VFSContext context, VirtualFileHandler parent, File file) throws IOException
+   {
+      FileSystemContext fsContext = FileSystemContext.class.cast(context);
+      boolean doHandleFile = fsContext.exists(file) && filter.accept(file);
+      return doHandleFile ? new GZipVirtualFileHandler(context, parent, file) : null;
+   }
+
+   /**
+    * Set file filter.
+    *
+    * @param filter the file filter
+    */
+   public void setFilter(FileFilter filter)
+   {
+      this.filter = filter;
+   }
+
+   private class DefaultFileFilter implements FileFilter
+   {
+      public boolean accept(File pathname)
+      {
+         return pathname.getName().endsWith(".gzip");
+      }
+   }
+}
\ No newline at end of file

Modified: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContext.java
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContext.java	2009-09-24 10:12:16 UTC (rev 93979)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContext.java	2009-09-24 10:23:42 UTC (rev 93980)
@@ -59,8 +59,15 @@
          {
             URI rootURI = getRootURI();
             String urlString = rootURI.toURL().toExternalForm();
-            URL url = new URL("file" + urlString.substring(urlString.indexOf(":/")));
-            file = new File(VFSUtils.toURI(url));
+            if (urlString.startsWith("file") == false)
+            {
+               URL url = new URL("file" + urlString.substring(urlString.indexOf(":/")));
+               file = new File(VFSUtils.toURI(url));
+            }
+            else
+            {
+               file = new File(rootURI);
+            }
          }
          catch (Exception e)
          {

Modified: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java	2009-09-24 10:12:16 UTC (rev 93979)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java	2009-09-24 10:23:42 UTC (rev 93980)
@@ -49,7 +49,7 @@
    {
       super(context, parent, file.getName());
       this.file = file;
-      setVfsUrl(context.getRootURI().toURL());
+      setVfsUrl(file.toURL());
    }
 
    public URI toURI() throws URISyntaxException




More information about the jboss-cvs-commits mailing list