Author: mwringe
Date: 2007-06-15 15:23:26 -0400 (Fri, 15 Jun 2007)
New Revision: 7448
Modified:
trunk/common/src/main/org/jboss/portal/common/jar/JarEntryInfo.java
trunk/common/src/main/org/jboss/portal/common/net/file/FileURLNavigationProvider.java
trunk/common/src/main/org/jboss/portal/common/net/jar/JarURLNavigationProvider.java
trunk/common/src/main/org/jboss/portal/test/common/net/URLNavigatorTestCase.java
Log:
- modify tests for URLNavigationTestCase.
- Re-add file name based filtering.
- Re-add option to allow visiting jar root.
Modified: trunk/common/src/main/org/jboss/portal/common/jar/JarEntryInfo.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/jar/JarEntryInfo.java 2007-06-15
19:22:59 UTC (rev 7447)
+++ trunk/common/src/main/org/jboss/portal/common/jar/JarEntryInfo.java 2007-06-15
19:23:26 UTC (rev 7448)
@@ -55,6 +55,10 @@
//
String entryName = entry.getName();
ArrayList atoms = new ArrayList();
+
+ //add the root element since this is not actually included in the jar as a entry
+ atoms.add("/");
+
int previous = -1;
while (true)
{
Modified:
trunk/common/src/main/org/jboss/portal/common/net/file/FileURLNavigationProvider.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/net/file/FileURLNavigationProvider.java 2007-06-15
19:22:59 UTC (rev 7447)
+++
trunk/common/src/main/org/jboss/portal/common/net/file/FileURLNavigationProvider.java 2007-06-15
19:23:26 UTC (rev 7448)
@@ -29,6 +29,7 @@
import java.util.Arrays;
import java.net.URL;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
@@ -53,48 +54,55 @@
private void visit(File file, URLVisitor visitor, URLFilter filter) throws
IllegalArgumentException, IOException
{
- String name = file.getName();
- if (file.isDirectory())
+ if (!file.exists())
{
- if (trace)
+ throw new FileNotFoundException();
+ }
+ else
+ {
+ String name = file.getName();
+ if (file.isDirectory())
{
- log.debug("entering directory" + file.getAbsolutePath());
+ if (trace)
+ {
+ log.debug("entering directory" + file.getAbsolutePath());
+ }
+ URL url = file.toURL();
+ boolean visit = filter == null || filter.acceptDir(url);
+ if (visit)
+ {
+ visitor.startDir(url, name);
+ File[] childrenFiles = file.listFiles();
+ Arrays.sort(childrenFiles);
+ for (int i = 0; i < childrenFiles.length; i++)
+ {
+ File childFile = childrenFiles[i];
+ visit(childFile, visitor, filter);
+ }
+ visitor.endDir(file.toURL(), name);
+ if (trace)
+ {
+ log.debug("leaving directory" + file.getAbsolutePath());
+ }
+ }
}
- URL url = file.toURL();
- boolean visit = filter == null || filter.acceptDir(url);
- if (visit)
+ else
{
- visitor.startDir(url, name);
- File[] childrenFiles = file.listFiles();
- Arrays.sort(childrenFiles);
- for (int i = 0; i < childrenFiles.length; i++)
+ if (trace)
{
- File childFile = childrenFiles[i];
- visit(childFile, visitor, filter);
+ log.debug("visiting file " + file.getAbsolutePath());
}
- visitor.endDir(file.toURL(), name);
- if (trace)
+ URL url = file.toURL();
+ File file2 = new File(url.getFile());
+ if (file.equals(file2) && filter.acceptFile(url))
{
- log.debug("leaving directory" + file.getAbsolutePath());
+ visitor.file(url, name);
}
+ else if (trace)
+ {
+ log.debug("The file does not respect url format");
+ }
}
}
- else
- {
- if (trace)
- {
- log.debug("visiting file " + file.getAbsolutePath());
- }
- URL url = file.toURL();
- File file2 = new File(url.getFile());
- if (file.equals(file2))
- {
- visitor.file(url, name);
- }
- else if (trace)
- {
- log.debug("The file does not respect url format");
- }
- }
}
}
Modified:
trunk/common/src/main/org/jboss/portal/common/net/jar/JarURLNavigationProvider.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/net/jar/JarURLNavigationProvider.java 2007-06-15
19:22:59 UTC (rev 7447)
+++
trunk/common/src/main/org/jboss/portal/common/net/jar/JarURLNavigationProvider.java 2007-06-15
19:23:26 UTC (rev 7448)
@@ -25,7 +25,6 @@
import org.jboss.portal.common.net.URLNavigationProvider;
import org.jboss.portal.common.net.URLVisitor;
import org.jboss.portal.common.net.URLFilter;
-import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.common.jar.JarEntryInfo;
import org.jboss.portal.common.jar.JarInfo;
@@ -66,11 +65,25 @@
URL jarURL = conn.getJarFileURL();
JarEntry rootEntry = conn.getJarEntry();
- //
- if (rootEntry == null)
+ // if the URL specifies a directory without a "/" at the end
+ // the entry will be found, except it won't actually exist.
+ // To get around this issue, we need to check if an entry exists
+ // with a "/" at the end.
+ if (rootEntry != null)
{
- throw new NotYetImplemented("The code for exact jar url has not been
implemented");
+ JarEntry testDirEntry = conn.getJarFile().getJarEntry(rootEntry +
"/");
+ if (testDirEntry != null)
+ {
+ rootEntry = testDirEntry;
+ }
}
+ else
+ {
+ // if rootEntry == null then the url points to the root of the jar. The problem
+ // is that the root of the jar doesn't actually exist in the jar.
+ // We need to create a fake jar entry to mimic this behavior
+ rootEntry = new JarEntry("/");
+ }
// Get the root entry
JarEntryInfo rootEntryInfo = new JarEntryInfo(rootEntry);
@@ -89,8 +102,15 @@
// Only consider descendant of the root or root itself
if (entryInfo.equals(rootEntryInfo) || entryInfo.isDescendantOf(rootEntryInfo))
{
+ List relPath;
// The relative path from the root
- List relPath = entryInfo.getNames().subList(rootEntryInfo.size() - 1,
entryInfo.size());
+ if (rootEntryInfo.size() > 1){
+ relPath = entryInfo.getNames().subList(rootEntryInfo.size() - 1,
entryInfo.size());
+ }
+ else
+ {
+ relPath = entryInfo.getNames();
+ }
// Enter intermediate dirs
while (stack.size() < relPath.size() - 1 && enabled)
@@ -145,7 +165,10 @@
String name = (String)relPath.get(relPath.size() - 1);
stack.push(name, false);
URL url = stack.getURL();
- visitor.file(url, name);
+ if (filter.acceptFile(url))
+ {
+ visitor.file(url, name);
+ }
stack.pop();
}
}
@@ -216,22 +239,38 @@
*/
URL getURL() throws MalformedURLException
{
- StringBuffer tmp = new StringBuffer(jarURL.toString()).append("!");
+ StringBuffer tmp = new StringBuffer(jarURL.toString()).append("!/");
for (int i = 0; i < root.size() - 1; i++)
{
String name = root.getName(i);
- tmp.append("/").append(name);
+ if (!tmp.toString().endsWith("/"))
+ {
+ tmp.append("/");
+ }
+ // we don't want to add an extra '/' if the actual jar root
element
+ if (!name.equals("/"))
+ {
+ tmp.append(name);
+ }
}
for (int i = 0; i < entries.size(); i++)
{
Entry entry = (Entry)entries.get(i);
String name = entry.name;
- tmp.append("/").append(name);
+ if (!tmp.toString().endsWith("/"))
+ {
+ tmp.append("/");
+ }
+ if (!name.equals("/"))
+ {
+ tmp.append(name);
+ }
+
}
Entry entry = peek();
- if (entry.dir)
+ if (entry.dir && !entry.name.equals("/") &&
!(tmp.toString().endsWith("/")))
{
- tmp.append('/');
+ tmp.append('/');
}
return new URL("jar", "", tmp.toString());
}
Modified:
trunk/common/src/main/org/jboss/portal/test/common/net/URLNavigatorTestCase.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/test/common/net/URLNavigatorTestCase.java 2007-06-15
19:22:59 UTC (rev 7447)
+++
trunk/common/src/main/org/jboss/portal/test/common/net/URLNavigatorTestCase.java 2007-06-15
19:23:26 UTC (rev 7448)
@@ -183,7 +183,6 @@
expectedURLs.add("/test-jar/");
expectedURLs.addAll(expectedURLsA1);
expectedURLs.addAll(expectedURLsA3txt);
- //expectedURLs.add("a3.txt");
expectedURLs.add("/test-jar/");
doTest (fileURL, expectedAtoms, expectedURLs, noFilter);
@@ -206,6 +205,7 @@
expectedAtoms.add("</META-INF>");
expectedAtoms.addAll(expectedAtomsA1);
expectedAtoms.addAll(expectedAtomsA3txt);
+ //TODO: should this really be //?
expectedAtoms.add("<//>");
ArrayList expectedURLs = new ArrayList();
@@ -381,12 +381,26 @@
{
//Note no / at the end
URL jarURL = getJarURL("/a1");
+ doTest (jarURL, expectedAtomsA1, expectedURLsA1, noFilter);
+ doTest (jarURL, new ArrayList(), new ArrayList(), fullFilter);
+ doTest (jarURL, removeFiles(expectedAtomsA1), removeFiles(expectedURLsA1),
noFileFilter);
+ // since we pass it a directory, we can't enter the directory
+ doTest (jarURL, new ArrayList(), new ArrayList(),noDirFilter);
+ try
+ {
+ //Note extra / at front
+ jarURL = getJarURL("//a1");
doTest (jarURL, expectedAtomsA1, expectedURLsA1, noFilter);
doTest (jarURL, new ArrayList(), new ArrayList(), fullFilter);
doTest (jarURL, removeFiles(expectedAtomsA1), removeFiles(expectedURLsA1),
noFileFilter);
// since we pass it a directory, we can't enter the directory
doTest (jarURL, new ArrayList(), new ArrayList(),noDirFilter);
+ }
+ catch (FileNotFoundException fnfe)
+ {
+ //expected result
+ }
try
{
@@ -514,6 +528,10 @@
{
fail("URL " + entryURL + " does not end with the suffix "
+ suffix + " at index " + i);
}
+ if (entryURL.getPath().endsWith ("//" + suffix.substring(1)))
+ {
+ fail("URL " + entryURL + " ends with /" + suffix + "
at index " + i);
+ }
}
if (filter != null)