From jboss-osgi-commits at lists.jboss.org Thu Mar 4 17:38:18 2010
Content-Type: multipart/mixed; boundary="===============3223376563447588463=="
MIME-Version: 1.0
From: jboss-osgi-commits at lists.jboss.org
To: jboss-osgi-commits at lists.jboss.org
Subject: [jboss-osgi-commits] JBoss-OSGI SVN: r101912 - in
projects/jboss-osgi/projects/vfs/trunk/vfs30:
src/main/java/org/jboss/osgi/vfs30 and 1 other directory.
Date: Thu, 04 Mar 2010 17:38:17 -0500
Message-ID: <201003042238.o24McHKr013623@svn01.web.mwc.hst.phx2.redhat.com>
--===============3223376563447588463==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: thomas.diesler(a)jboss.com
Date: 2010-03-04 17:38:17 -0500 (Thu, 04 Mar 2010)
New Revision: 101912
Added:
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osg=
i/vfs30/VFSEntryPathsEnumeration.java
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osg=
i/vfs30/VFSFindEntriesEnumeration.java
Modified:
projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osg=
i/vfs30/VirtualFileAdaptor30.java
Log:
Implement getEntryPaths, findEntries
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml 2010-03-04 22:19:1=
1 UTC (rev 101911)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml 2010-03-04 22:38:1=
7 UTC (rev 101912)
@@ -30,7 +30,7 @@
=
- 3.0.0.CR2
+ 3.0.0.CR3
=
Added: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss=
/osgi/vfs30/VFSEntryPathsEnumeration.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/os=
gi/vfs30/VFSEntryPathsEnumeration.java (rev 0)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/os=
gi/vfs30/VFSEntryPathsEnumeration.java 2010-03-04 22:38:17 UTC (rev 101912)
@@ -0,0 +1,92 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.osgi.vfs30;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * An enumeration of VFS entry paths.
+ * =
+ * @author Adrian Brock
+ * @author thomas.diesler(a)jboss.com
+ * @version $Revision: 1.1 $
+ */
+class VFSEntryPathsEnumeration implements Enumeration
+{
+ /** The paths */
+ private Iterator paths;
+
+ /**
+ * Create a new VFSEntryPathsEnumeration.
+ * =
+ * @param root the root file
+ * @param file the file to enumerate
+ * @throws IOException for any error
+ */
+ public VFSEntryPathsEnumeration(VirtualFile root, VirtualFile file) thr=
ows IOException
+ {
+ if (root =3D=3D null)
+ throw new IllegalArgumentException("Null root");
+ if (file =3D=3D null)
+ throw new IllegalArgumentException("Null file");
+
+ String rootPath =3D root.getPathName();
+ ArrayList paths =3D new ArrayList();
+ paths.add(fixPath(rootPath, file));
+
+ List children =3D file.getChildrenRecursively();
+ for (VirtualFile child : children)
+ paths.add(fixPath(rootPath, child));
+
+ this.paths =3D paths.iterator();
+ }
+
+ public boolean hasMoreElements()
+ {
+ return paths.hasNext();
+ }
+
+ public String nextElement()
+ {
+ return paths.next();
+ }
+
+ private String fixPath(String rootPath, VirtualFile file)
+ {
+ String result =3D file.getPathName();
+
+ int length =3D rootPath.length();
+ if (length !=3D 0)
+ result =3D result.substring(length);
+
+ if (file.isDirectory() && result.endsWith("/") =3D=3D false)
+ result +=3D "/";
+
+ return result;
+ }
+}
Added: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss=
/osgi/vfs30/VFSFindEntriesEnumeration.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/os=
gi/vfs30/VFSFindEntriesEnumeration.java (rev 0)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/os=
gi/vfs30/VFSFindEntriesEnumeration.java 2010-03-04 22:38:17 UTC (rev 101912)
@@ -0,0 +1,134 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.osgi.vfs30;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.VirtualFileVisitor;
+import org.jboss.vfs.VisitorAttributes;
+import org.jboss.vfs.util.MatchAllVirtualFileFilter;
+
+
+/**
+ * An enumeration of VFS entries.
+ * =
+ * @author Adrian Brock
+ * @author thomas.diesler(a)jboss.com
+ * @version $Revision: 1.1 $
+ */
+class VFSFindEntriesEnumeration implements Enumeration
+{
+ /** The paths */
+ private Iterator paths;
+
+ /**
+ * Create a new VFSFindEntriesEnumeration.
+ * =
+ * @param root the root file
+ * @param file the file to enumerate
+ * @param filePattern the file pattern
+ * @param recurse whether to recurse
+ * @throws IOException for any error
+ */
+ public VFSFindEntriesEnumeration(VirtualFile root, VirtualFile file, St=
ring filePattern, boolean recurse) throws IOException
+ {
+ if (root =3D=3D null)
+ throw new IllegalArgumentException("Null root");
+ if (file =3D=3D null)
+ throw new IllegalArgumentException("Null file");
+
+ String rootPath =3D root.getPathName();
+ VisitorAttributes attributes =3D new VisitorAttributes();
+ attributes.setIncludeRoot(false);
+ attributes.setLeavesOnly(true);
+ if (recurse)
+ attributes.setRecurseFilter(MatchAllVirtualFileFilter.INSTANCE);
+ =
+ VisitorImpl visitor =3D new VisitorImpl(rootPath, filePattern, attri=
butes);
+ file.visit(visitor);
+ =
+ this.paths =3D visitor.paths.iterator();
+ }
+
+ public boolean hasMoreElements()
+ {
+ return paths.hasNext();
+ }
+
+ public URL nextElement()
+ {
+ return paths.next();
+ }
+ =
+ static class VisitorImpl implements VirtualFileVisitor
+ {
+ ArrayList paths =3D new ArrayList();
+
+ Pattern filter;
+ String rootPath;
+ VisitorAttributes attributes;
+ =
+ VisitorImpl(String rootPath, String filter, VisitorAttributes attrib=
utes)
+ {
+ this.rootPath =3D rootPath;
+ this.filter =3D convertToPattern(filter);
+ this.attributes =3D attributes;
+ }
+
+ public VisitorAttributes getAttributes()
+ {
+ return attributes;
+ }
+
+ public void visit(VirtualFile virtualFile)
+ {
+ // See if the filter matches
+ Matcher matcher =3D filter.matcher(virtualFile.getName());
+ if (matcher.find() =3D=3D false)
+ return;
+ =
+ try
+ {
+ paths.add(virtualFile.toURL());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error visiting " + virtualFile, e);
+ }
+ }
+ =
+ // Convert file pattern (RFC 1960-based Filter) into a RegEx pattern
+ private static Pattern convertToPattern(String filePattern)
+ {
+ filePattern =3D filePattern.replace("*", ".*");
+ return Pattern.compile("^" + filePattern + "$");
+ }
+
+ }
+}
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jb=
oss/osgi/vfs30/VirtualFileAdaptor30.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/os=
gi/vfs30/VirtualFileAdaptor30.java 2010-03-04 22:19:11 UTC (rev 101911)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/os=
gi/vfs30/VirtualFileAdaptor30.java 2010-03-04 22:38:17 UTC (rev 101912)
@@ -77,7 +77,7 @@
public VirtualFile getChild(String path) throws IOException
{
org.jboss.vfs.VirtualFile child =3D delegate.getChild(path);
- if (child =3D=3D null)
+ if (child.exists() =3D=3D false)
return null;
=
return new VirtualFileAdaptor30(child);
@@ -94,12 +94,35 @@
=
public Enumeration findEntries(String path, String pattern, boolea=
n recurse) throws IOException
{
- throw new IllegalArgumentException("not implemented");
+ if (path =3D=3D null)
+ throw new IllegalArgumentException("Null path");
+ =
+ if (pattern =3D=3D null)
+ pattern =3D "*";
+
+ if (path.startsWith("/"))
+ path =3D path.substring(1);
+
+ org.jboss.vfs.VirtualFile child =3D delegate.getChild(path);
+ if (child.exists() =3D=3D false)
+ return null;
+ =
+ return new VFSFindEntriesEnumeration(delegate, child, pattern, recur=
se);
}
=
- public Enumeration getEntryPaths(String path)
+ public Enumeration getEntryPaths(String path) throws IOException
{
- throw new IllegalArgumentException("not implemented");
+ if (path =3D=3D null)
+ throw new IllegalArgumentException("Null path");
+ =
+ if (path.startsWith("/"))
+ path =3D path.substring(1);
+ =
+ org.jboss.vfs.VirtualFile child =3D delegate.getChild(path);
+ if (child.exists() =3D=3D false)
+ return null;
+ =
+ return new VFSEntryPathsEnumeration(delegate, child);
}
=
public InputStream openStream() throws IOException
--===============3223376563447588463==--