[portal-commits] JBoss Portal SVN: r13039 - in modules/common/trunk: common and 2 other directories.
portal-commits at lists.jboss.org
portal-commits at lists.jboss.org
Mon Mar 16 18:21:26 EDT 2009
Author: mwringe
Date: 2009-03-16 18:21:26 -0400 (Mon, 16 Mar 2009)
New Revision: 13039
Added:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/vfs/
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/vfs/VFSZipURLNavigationProvider.java
Modified:
modules/common/trunk/build/pom.xml
modules/common/trunk/common/pom.xml
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLNavigator.java
Log:
Add url navigator support for the vfszip protocol.
Modified: modules/common/trunk/build/pom.xml
===================================================================
--- modules/common/trunk/build/pom.xml 2009-03-16 22:17:49 UTC (rev 13038)
+++ modules/common/trunk/build/pom.xml 2009-03-16 22:21:26 UTC (rev 13039)
@@ -22,6 +22,7 @@
<version.apache.commons-httpclient>3.0.1</version.apache.commons-httpclient>
<version.jboss.microcontainer>2.0.2.GA</version.jboss.microcontainer>
<version.jboss.man>2.0.0.GA</version.jboss.man>
+ <version.jboss.vfs>2.1.0.GA</version.jboss.vfs>
<version.cargo>0.8</version.cargo>
<version.junit>3.8.1</version.junit>
<version.ant>1.7.0</version.ant>
@@ -90,6 +91,12 @@
<artifactId>jboss-jmx</artifactId>
<version>${version.jboss-jmx}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ <version>${version.jboss.vfs}</version>
+ </dependency>
<dependency>
<groupId>commons-httpclient</groupId>
Modified: modules/common/trunk/common/pom.xml
===================================================================
--- modules/common/trunk/common/pom.xml 2009-03-16 22:17:49 UTC (rev 13038)
+++ modules/common/trunk/common/pom.xml 2009-03-16 22:21:26 UTC (rev 13039)
@@ -29,6 +29,11 @@
</dependency>
<dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</dependency>
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLNavigator.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLNavigator.java 2009-03-16 22:17:49 UTC (rev 13038)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLNavigator.java 2009-03-16 22:21:26 UTC (rev 13039)
@@ -24,6 +24,7 @@
import org.jboss.portal.common.net.file.FileURLNavigationProvider;
import org.jboss.portal.common.net.jar.JarURLNavigationProvider;
+import org.jboss.portal.common.net.vfs.VFSZipURLNavigationProvider;
import java.io.IOException;
import java.net.URL;
@@ -40,6 +41,8 @@
private static final URLNavigationProvider fileNav = new FileURLNavigationProvider();
private static final URLNavigationProvider jarNav = new JarURLNavigationProvider();
+
+ private static final URLNavigationProvider vfsZipNav = new VFSZipURLNavigationProvider();
private static final URLFilter NULL_FILTER = new URLFilter()
{
@@ -97,6 +100,10 @@
{
return fileNav;
}
+ else if ("vfszip".equals(protocol))
+ {
+ return vfsZipNav;
+ }
else
{
throw new IllegalArgumentException("Not recognized " + protocol);
Added: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/vfs/VFSZipURLNavigationProvider.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/vfs/VFSZipURLNavigationProvider.java (rev 0)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/vfs/VFSZipURLNavigationProvider.java 2009-03-16 22:21:26 UTC (rev 13039)
@@ -0,0 +1,131 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.common.net.vfs;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.log4j.Logger;
+import org.jboss.portal.common.net.URLFilter;
+import org.jboss.portal.common.net.URLNavigationProvider;
+import org.jboss.portal.common.net.URLVisitor;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 7448 $
+ */
+public class VFSZipURLNavigationProvider implements URLNavigationProvider
+{
+
+ /** The logger. */
+ private Logger log = Logger.getLogger(VFSZipURLNavigationProvider.class);
+
+ /** Trace. */
+ private boolean trace = log.isDebugEnabled();
+
+ public void visit(URL url, URLVisitor visitor, URLFilter filter) throws IllegalArgumentException, IOException
+ {
+ if (url == null)
+ {
+ throw new IllegalArgumentException("Null URL not accepted");
+ }
+ if (!"vfszip".equals(url.getProtocol()))
+ {
+ throw new IllegalArgumentException("Only jar URL are accepted, not " + url.getProtocol());
+ }
+ VirtualFileURLConnection conn = (VirtualFileURLConnection) url.openConnection();
+ VirtualFile vFile = conn.getContent();
+
+ visit(vFile, visitor, filter);
+ }
+
+ private void visit(VirtualFile file, URLVisitor visitor, URLFilter filter) throws IOException
+ {
+ if (!file.exists())
+ {
+ throw new FileNotFoundException();
+ }
+ else
+ {
+ String name = file.getName();
+ if (!file.isLeaf())
+ {
+ if (trace)
+ {
+ log.debug("entering directory" + file.getPathName());
+ }
+ try
+ {
+ URL url = file.toURL();
+ boolean visit = filter == null || filter.acceptDir(url);
+ if (visit)
+ {
+ visitor.startDir(url, name);
+ for (VirtualFile child : file.getChildren())
+ {
+ visit(child, visitor, filter);
+ }
+
+ visitor.endDir(file.toURL(), name);
+ if (trace)
+ {
+ log.debug("leaving directory" + file.getPathName());
+ }
+ }
+ }
+ catch (URISyntaxException e)
+ {
+ throw new IOException("Error trying to get Virtual File for " + file.toString() + ". " + e);
+ }
+ }
+ else
+ {
+ try
+ {
+ if (trace)
+ {
+ log.debug("visiting file " + file.getPathName());
+ }
+ URL url = file.toURL();
+ if (filter.acceptFile(url))
+ {
+ visitor.file(url, name);
+ }
+ else if (trace)
+ {
+ log.debug("The file does not respect url format");
+ }
+ }
+ catch (URISyntaxException e)
+ {
+ throw new IOException("Error trying to get Virtual File for " + file.toString() + ". " + e);
+ }
+ }
+ }
+ }
+
+}
More information about the portal-commits
mailing list