jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1151793 - in /jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util: Paths.java Values.java
Date Thu, 28 Jul 2011 11:08:50 GMT
Author: mduerig
Date: Thu Jul 28 11:08:49 2011
New Revision: 1151793

URL: http://svn.apache.org/viewvc?rev=1151793&view=rev
Log:
spi2microkernel (WIP)
- implement ns mapping 

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java?rev=1151793&r1=1151792&r2=1151793&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
Thu Jul 28 11:08:49 2011
@@ -19,6 +19,8 @@
 
 package org.apache.jackrabbit.spi2microkernel.util;
 
+import org.apache.commons.collections.BidiMap;
+import org.apache.commons.collections.bidimap.DualHashBidiMap;
 import org.apache.jackrabbit.mk.util.PathUtils;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
@@ -82,8 +84,16 @@ public final class Paths {
         return '{' + escapeNameSpaceURI(nameSpaceURI) + '}' + name.getLocalName();
     }
 
-    public static String pathToString(String wspName, Path path) throws RepositoryException
{
-        return PathUtils.concat('/' + getWorkspaceName(wspName), translateQPath(path));
+    public static String pathToString(Path absPath) throws RepositoryException {
+        return translateQPath(absPath);
+    }
+
+    public static String pathToString(String wspName, Path absPath) throws RepositoryException
{
+        String wspPath = '/' + getWorkspaceName(wspName);
+
+        return absPath.denotesRoot()
+            ? wspPath
+            : wspPath + translateQPath(absPath);
     }
 
     public static String getWorkspaceName(String name) throws NoSuchWorkspaceException {
@@ -100,17 +110,32 @@ public final class Paths {
 
     //------------------------------------------< private >---
 
+    private static final BidiMap KNOWN_NAME_SPACES = new DualHashBidiMap() {{
+        put("jcr", "http://www.jcp.org/jcr/1.0");
+        put("xs", "http://www.w3.org/2001/XMLSchema");
+        put("nt", "http://www.jcp.org/jcr/nt/1.0");
+        put("mix", "http://www.jcp.org/jcr/mix/1.0");
+        put("sv", "http://www.jcp.org/jcr/sv/1.0");
+        put("xml", "http://www.w3.org/XML/1998/namespace");
+    }};
+
     private static String escapeNameSpaceURI(String nameSpaceURI) {
-        return nameSpaceURI.replace('/', '\\');
+        String prefix = (String) KNOWN_NAME_SPACES.getKey(nameSpaceURI);
+        return prefix == null
+            ? nameSpaceURI.replace('/', '\\')
+            : prefix;
     }
 
     private static String unescapeNameSpaceURI(String nameSpaceURI) {
-        return nameSpaceURI.replace('\\', '/');
+        String nsUri = (String) KNOWN_NAME_SPACES.get(nameSpaceURI);
+        return nsUri == null
+            ? nameSpaceURI.replace('\\', '/')
+            : nsUri;
     }
 
     private static String translateQPath(Path path) throws RepositoryException {
         return path.denotesRoot()
-            ? ""
+            ? "/"
             : PathUtils.concat(translateQPath(path.getAncestor(1)), nameToString(path.getName()));
     }
 

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1151793&r1=1151792&r2=1151793&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Thu Jul 28 11:08:49 2011
@@ -140,7 +140,7 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, NAME);
+                return FACTORY.create(Paths.stringToName(value));
             }
         };
         put(TYPES[NAME], valueFactory);
@@ -151,7 +151,7 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PATH);
+                return FACTORY.create(Paths.stringToPath(value));
             }
         };
         put(TYPES[PATH], valueFactory);
@@ -251,12 +251,12 @@ public final class Values {
         return quoteAndEncode(DATE, ISO8601.format(calendar));
     }
 
-    public static String pathToString(Path path) {
-        return quoteAndEncode(PATH, JsonBuilder.escape(path.getString()));
+    public static String pathToString(Path path) throws RepositoryException {
+        return quoteAndEncode(PATH, JsonBuilder.escape(Paths.pathToString(path)));
     }
 
     public static String nameToString(Name name) {
-        return quoteAndEncode(NAME, JsonBuilder.escape(name.toString()));
+        return quoteAndEncode(NAME, JsonBuilder.escape(Paths.nameToString(name)));
     }
 
     public static String namesToString(Name[] names) {
@@ -300,9 +300,13 @@ public final class Values {
             case DATE:
                 return quoteAndEncode(type, value.getString());
 
-            case URI:
             case NAME:
+                return nameToString(value.getName());
+
             case PATH:
+                return pathToString(value.getPath());
+            
+            case URI:
                 return quoteAndEncode(type, JsonBuilder.escape(value.getString()));
 
             case BINARY:
@@ -363,8 +367,12 @@ public final class Values {
             : 'X';
     }
 
+    private static String quote(String string) {
+        return '"' + string + '"';
+    }
+
     private static String quoteAndEncode(int type, String value) {
-        return "\"" + TYPES[type] + ':' + value + '\"';
+        return quote(TYPES[type] + ":" + value);
     }
 
     private static QValue create(boolean value) {



Mime
View raw message