Commits

rgielen  committed aecf3e5

WW-3121:
Extend JBoss URL detection to vfsmemory:

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1992e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 9dac970

Comments (0)

Files changed (2)

File core/src/main/java/com/opensymphony/xwork2/util/URLUtil.java

      * Prefix for Jar files in JBoss Virtual File System
      */
     public static final String JBOSS5_VFSZIP = "vfszip";
+    public static final String JBOSS5_VFSMEMORY = "vfsmemory";
 
     private static final Pattern JAR_PATTERN = Pattern.compile("^(jar:|wsjar:|zip:|vfsfile:|code-source:)?(file:)?(.*?)(\\!/|.jar/)(.*)");
     private static final int JAR_FILE_PATH = 3;
         Matcher jarMatcher = JAR_PATTERN.matcher(fileName);
         try {
             if (isJBoss5Url(url)){
-                return new URL("file", null, fileName.substring(JBOSS5_VFSZIP.length() + 1));
+                return new URL("file", null, fileName.substring(fileName.indexOf(":") + 1));
             } else  if (jarMatcher.matches()) {
                 String path = jarMatcher.group(JAR_FILE_PATH);
                 return new URL("file", "", path);
      * @return
      */
     public static boolean isJBoss5Url(URL fileUrl) {
-        return JBOSS5_VFSZIP.equals(fileUrl.getProtocol());
+        final String protocol = fileUrl.getProtocol();
+        return JBOSS5_VFSZIP.equals(protocol) || JBOSS5_VFSMEMORY.equals(fileUrl.getProtocol());
     }
 
 }

File core/src/test/java/com/opensymphony/xwork2/util/URLUtilTest.java

         assertEquals("file:/c:/somefile.war/somelibrary.jar", outputURL.toExternalForm());
     }
 
+    public void testJBossFile() throws MalformedURLException {
+        URL url = new URL("vfszip:/c:/somefile.jar!/");
+        URL outputURL = URLUtil.normalizeToFileProtocol(url);
+
+        assertNotNull(outputURL);
+        assertEquals("file:/c:/somefile.jar", outputURL.toExternalForm());
+
+        url = new URL("vfszip:/c:/somefile.jar!/somestuf/bla/bla");
+        outputURL = URLUtil.normalizeToFileProtocol(url);
+        assertEquals("file:/c:/somefile.jar", outputURL.toExternalForm());
+
+        url = new URL("vfsmemory:c:/somefile.jar!/somestuf/bla/bla");
+        outputURL = URLUtil.normalizeToFileProtocol(url);
+        assertEquals("file:c:/somefile.jar", outputURL.toExternalForm());
+
+        url = new URL("vfsmemory:/c:/somefile.war/somelibrary.jar");
+        outputURL = URLUtil.normalizeToFileProtocol(url);
+        assertEquals("file:/c:/somefile.war/somelibrary.jar", outputURL.toExternalForm());
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
 
         assertTrue(URLUtil.isJBoss5Url(new URL("vfszip:/c:/somewar.war/somelibrary.jar")));
         assertFalse(URLUtil.isJBoss5Url(new URL("vfsfile:/c:/somewar.war/somelibrary.jar")));
         assertFalse(URLUtil.isJBoss5Url(new URL("jar:file:/c:/somelibrary.jar")));
+        assertTrue(URLUtil.isJBoss5Url(new URL("vfsmemory:/c:/somewar.war/somelibrary.jar")));
     }
 }