[jboss-cvs] JBossAS SVN: r73689 - in projects/vfs/branches/jar-alter-work/src: test/java/org/jboss/test/virtual/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 26 14:00:09 EDT 2008


Author: mstruk
Date: 2008-05-26 14:00:09 -0400 (Mon, 26 May 2008)
New Revision: 73689

Added:
   projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java
Modified:
   projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
   projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
Log:
Merged in changes from trunk 72869:73585

Modified: projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java	2008-05-26 17:33:40 UTC (rev 73688)
+++ projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java	2008-05-26 18:00:09 UTC (rev 73689)
@@ -21,8 +21,9 @@
 */
 package org.jboss.virtual.plugins.vfs.helpers;
 
-import java.util.StringTokenizer;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * PathTokenizer.
@@ -31,6 +32,7 @@
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
+ at SuppressWarnings({"StringEquality"})
 public class PathTokenizer
 {
    /** The reverse path const */
@@ -87,23 +89,60 @@
       if (path == null)
          throw new IllegalArgumentException("Null path");
 
-      StringTokenizer tokenizer = new StringTokenizer(path, "/");
-      int count = tokenizer.countTokens();
-      if (count == 0)
-         return null;
+      char[] chars = path.toCharArray();
+      StringBuilder buffer = new StringBuilder();
+      List<String> list = new ArrayList<String>();
+      String specialToken = null;
 
-      String[] tokens = new String[count];
-      int i = 0;
-      while (tokenizer.hasMoreTokens())
+      for (int index=0; index < chars.length; index++)
       {
-         String token = tokenizer.nextToken();
+         char ch = chars[index];
 
-         if ("".equals(token))
-            throw new IllegalArgumentException("A path element is empty: " + path);
+         if (ch == '/')
+         {
+            if (index > 0)
+            {
+               if (buffer.length() == 0 && specialToken == null)
+                  throw new IllegalArgumentException("A path element is empty: " + path);
 
-         tokens[i++] = token;
+               if (specialToken != null)
+                  list.add(specialToken);
+               else
+                  list.add(buffer.toString());
+
+               // reset
+               buffer.setLength(0);
+               specialToken = null;
+            }
+         }
+         else if (ch == '.')
+         {
+            if (specialToken == null && buffer.length() == 0)
+               specialToken = CURRENT_PATH;
+            else if (specialToken == CURRENT_PATH && buffer.length() == 0)
+               specialToken = REVERSE_PATH;
+            else if (specialToken != null && buffer.length() == 0)
+               throw new IllegalArgumentException("Illegal token in path: " + path);
+            else
+               buffer.append(ch);
+         }
+         else
+         {
+            // token starts with '.' or '..', but also has some path after that
+            if (specialToken != null)
+               throw new IllegalArgumentException("Illegal token in path: " + path);
+
+            buffer.append(ch);
+         }
       }
-      return tokens;
+
+      // add last token
+      if (specialToken != null)
+         list.add(specialToken);
+      else if (buffer.length() > 0)
+         list.add(buffer.toString());
+
+      return list.toArray(new String[list.size()]);
    }
    
    /**
@@ -161,7 +200,7 @@
     */
    public static boolean isCurrentToken(String token)
    {
-      return CURRENT_PATH.equals(token);
+      return CURRENT_PATH == token;
    }
 
    /**
@@ -172,6 +211,6 @@
     */
    public static boolean isReverseToken(String token)
    {
-      return REVERSE_PATH.equals(token);
+      return REVERSE_PATH == token;
    }
 }

Copied: projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java (from rev 73585, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java)
===================================================================
--- projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java	                        (rev 0)
+++ projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java	2008-05-26 18:00:09 UTC (rev 73689)
@@ -0,0 +1,78 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.test.virtual.test;
+
+import java.net.URL;
+
+import junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Test path tokens.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class PathTokensTestCase extends AbstractVFSTest
+{
+   public PathTokensTestCase(String s)
+   {
+      super(s);
+   }
+
+   public static Test suite()
+   {
+      return suite(PathTokensTestCase.class);
+   }
+
+   protected void testPath(String path) throws Throwable
+   {
+      try
+      {
+         URL url = getResource("/vfs");
+         VirtualFile vf = VFS.getRoot(url);
+         vf.getChild(path);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         assertInstanceOf(t, IllegalArgumentException.class, false);
+      }
+   }
+
+   public void testSpecialTokens() throws Throwable
+   {
+      testPath("/.../");
+      testPath(".../");
+      testPath("/...");
+      testPath("...");
+      testPath("/..somemorepath/");
+      testPath("..somemorepath/");
+      testPath("/..somemorepath");
+      testPath("..somemorepath");
+      testPath("path//morepath");
+      testPath("//morepath");
+      // we need 3 '/', since by default we always remove the last one
+      testPath("///"); 
+      testPath("morepath///");
+   }
+}
\ No newline at end of file

Modified: projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java	2008-05-26 17:33:40 UTC (rev 73688)
+++ projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java	2008-05-26 18:00:09 UTC (rev 73689)
@@ -70,8 +70,9 @@
       suite.addTest(AssembledContextTestCase.suite());
       suite.addTest(MemoryTestCase.suite());
       suite.addTest(SundryVFSUnitTestCase.suite());
-      // options / policy
+      // options / policy / path
       suite.addTest(PathQueryTestCase.suite());
+      suite.addTest(PathTokensTestCase.suite());
       // unpack
       suite.addTest(UnpackTestCase.suite());
 




More information about the jboss-cvs-commits mailing list