jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r604166 - in /jackrabbit/trunk/jackrabbit-jcr-commons/src: main/java/org/apache/jackrabbit/util/ISO9075.java test/java/org/apache/jackrabbit/util/ISO9075Test.java
Date Fri, 14 Dec 2007 11:15:47 GMT
Author: mreutegg
Date: Fri Dec 14 03:15:45 2007
New Revision: 604166

URL: http://svn.apache.org/viewvc?rev=604166&view=rev
Log:
JCR-1258: Add path encoding to ISO9075

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java?rev=604166&r1=604165&r2=604166&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java
Fri Dec 14 03:15:45 2007
@@ -107,6 +107,36 @@
     }
 
     /**
+     * Encodes <code>path</code> as specified in ISO 9075. Please note that
+     * the character '<code>[</code>' is not encoded but rather interpreted as
+     * the start of an index in a path segment.
+     *
+     * @param path the <code>String</code> to encode.
+     * @return the encoded <code>String</code>.
+     */
+    public static String encodePath(String path) {
+        String[] names = Text.explode(path, '/', true);
+        StringBuffer encoded = new StringBuffer(path.length());
+        for (int i = 0; i < names.length; i++) {
+            // detect index
+            String index = null;
+            int idx = names[i].indexOf('[');
+            if (idx != -1) {
+                index = names[i].substring(idx);
+                names[i] = names[i].substring(0, idx);
+            }
+            encoded.append(encode(names[i]));
+            if (index != null) {
+                encoded.append(index);
+            }
+            if (i < names.length - 1) {
+                encoded.append('/');
+            }
+        }
+        return encoded.toString();
+    }
+
+    /**
      * Decodes the <code>name</code>.
      * @param name the <code>QName</code> to decode.
      * @return the decoded <code>QName</code>.

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java?rev=604166&r1=604165&r2=604166&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java
Fri Dec 14 03:15:45 2007
@@ -52,6 +52,16 @@
                 "StringWith_x005c_inside", ISO9075.encode("StringWith\\inside"));
     }
 
+    public void testPath() {
+        assertEquals("foo/bar", ISO9075.encodePath("foo/bar"));
+        assertEquals("/foo/bar", ISO9075.encodePath("/foo/bar"));
+        assertEquals("/foo/bar/", ISO9075.encodePath("/foo/bar/"));
+        assertEquals("/foo/bar[3]", ISO9075.encodePath("/foo/bar[3]"));
+        assertEquals("home/My_x0020_Documents", ISO9075.encodePath("home/My Documents"));
+        assertEquals("year/_x0032_007", ISO9075.encodePath("year/2007"));
+        assertEquals("year/_x0032_007[2]", ISO9075.encodePath("year/2007[2]"));
+    }
+
     /**
      * This is a disabled brute force test. It tests permutations of characters:
      * <code>' ', '_', 'x', '0', '2', 'a', 'b', '{'</code>, encodes and decodes



Mime
View raw message