jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1330383 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache...
Date Wed, 25 Apr 2012 16:18:58 GMT
Author: reschke
Date: Wed Apr 25 16:18:58 2012
New Revision: 1330383

URL: http://svn.apache.org/viewvc?rev=1330383&view=rev
Log:
OAK-61: use NameMapper in ValueFactoryImpl and ValueImpl

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java?rev=1330383&r1=1330382&r2=1330383&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
Wed Apr 25 16:18:58 2012
@@ -51,6 +51,7 @@ public class JcrPathParser {
         // shortcut
         if (len == 1 && jcrPath.charAt(0) == '/') {
             listener.root();
+            return;
         }
 
         if (len == 0) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java?rev=1330383&r1=1330382&r2=1330383&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
Wed Apr 25 16:18:58 2012
@@ -209,7 +209,12 @@ public final class Paths {
     
     public static String toOakPath(String jcrPath, final NameMapper mapper) {
         final List<String> elements = new ArrayList<String>();
-        
+
+        if ("/".equals(jcrPath)) {
+            // avoid the need to special case the root path later on
+            return "/";
+        }
+
         JcrPathParser.Listener listener = new JcrPathParser.Listener() {
             @Override
             public void root() {
@@ -274,6 +279,8 @@ public final class Paths {
             }
         }
         
+        // root path is special-cased early on so it does not need to
+        // be considered here
         oakPath.deleteCharAt(oakPath.length() - 1);
         return oakPath.toString();
     }
@@ -281,6 +288,11 @@ public final class Paths {
     public static String toJcrPath(String oakPath, final NameMapper mapper) {
         final List<String> elements = new ArrayList<String>();
         
+        if ("/".equals(oakPath)) {
+            // avoid the need to special case the root path later on
+            return "/";
+        }
+
         JcrPathParser.Listener listener = new JcrPathParser.Listener() {
             @Override
             public void root() {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java?rev=1330383&r1=1330382&r2=1330383&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java
Wed Apr 25 16:18:58 2012
@@ -83,6 +83,7 @@ public class PathsTest {
 
     @Test
     public void testJcrToOak() {
+        assertEquals("/", Paths.toOakPath("/", mapper));
         assertEquals("/oak-foo:bar", Paths.toOakPath("/foo:bar", mapper));
         assertEquals("/oak-foo:bar/oak-quu:qux",
                 Paths.toOakPath("/foo:bar/quu:qux", mapper));

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1330383&r1=1330382&r2=1330383&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Wed Apr 25 16:18:58 2012
@@ -76,7 +76,7 @@ public class SessionImpl extends Abstrac
     SessionImpl(GlobalContext globalContext, ContentSession contentSession) {
         this.globalContext = globalContext;
         this.contentSession = contentSession;
-        this.valueFactory = new ValueFactoryImpl(contentSession.getCoreValueFactory());
+        this.valueFactory = new ValueFactoryImpl(contentSession.getCoreValueFactory(), nameMapper);
         this.nsreg = new NamespaceRegistryImpl(contentSession);
         this.workspace = new WorkspaceImpl(sessionContext, this.nsreg);
         this.root = contentSession.getCurrentRoot();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java?rev=1330383&r1=1330382&r2=1330383&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
Wed Apr 25 16:18:58 2012
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.oak.jcr.va
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
+import org.apache.jackrabbit.oak.namepath.Paths;
 import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,15 +48,15 @@ public class ValueFactoryImpl implements
     private static final Logger log = LoggerFactory.getLogger(ValueFactoryImpl.class);
 
     private final CoreValueFactory factory;
-    private final DummyNamePathResolver resolver; // TODO: add proper name/path conversion
+    private final NameMapper nameMapper;
 
     /**
      *
      * @param factory
      */
-    public ValueFactoryImpl(CoreValueFactory factory/*, NamePathResolver resolver*/) {
+    public ValueFactoryImpl(CoreValueFactory factory, NameMapper nameMapper) {
         this.factory = factory;
-        this.resolver = new DummyNamePathResolver();
+        this.nameMapper = nameMapper;
     }
 
     public CoreValueFactory getCoreValueFactory() {
@@ -62,7 +64,7 @@ public class ValueFactoryImpl implements
     }
 
     public Value createValue(CoreValue coreValue) {
-        return new ValueImpl(coreValue, resolver);
+        return new ValueImpl(coreValue, nameMapper);
     }
 
     public CoreValue getCoreValue(Value jcrValue) {
@@ -91,39 +93,39 @@ public class ValueFactoryImpl implements
     @Override
     public Value createValue(String value) {
         CoreValue cv = factory.createValue(value, PropertyType.STRING);
-        return new ValueImpl(cv, resolver);
+        return new ValueImpl(cv, nameMapper);
     }
 
     @Override
     public Value createValue(long value) {
         CoreValue cv = factory.createValue(value);
-        return new ValueImpl(cv, resolver);
+        return new ValueImpl(cv, nameMapper);
     }
 
     @Override
     public Value createValue(double value) {
         CoreValue cv = factory.createValue(value);
-        return new ValueImpl(cv, resolver);
+        return new ValueImpl(cv, nameMapper);
     }
 
     @Override
     public Value createValue(boolean value) {
         CoreValue cv = factory.createValue(value);
-        return new ValueImpl(cv, resolver);
+        return new ValueImpl(cv, nameMapper);
     }
 
     @Override
     public Value createValue(Calendar value) {
         String dateStr = ISO8601.format(value);
         CoreValue cv = factory.createValue(dateStr, PropertyType.DATE);
-        return new ValueImpl(cv, resolver);
+        return new ValueImpl(cv, nameMapper);
     }
 
     @Override
     public Value createValue(InputStream value) {
         try {
             CoreValue cv = factory.createValue(value);
-            return new ValueImpl(cv, resolver);
+            return new ValueImpl(cv, nameMapper);
         } catch (IOException ex) {
             throw new RuntimeException(ex);
         } finally {
@@ -141,14 +143,14 @@ public class ValueFactoryImpl implements
     public Value createValue(String value, int type) throws ValueFormatException {
         CoreValue cv;
         if (type == PropertyType.NAME) {
-            cv = factory.createValue(resolver.getInternalName(value), type);
+            cv = factory.createValue(nameMapper.getOakName(value), type);
         } else if (type == PropertyType.PATH) {
-            cv = factory.createValue(resolver.getInternalPath(value), type);
+            cv = factory.createValue(Paths.toOakPath(value, nameMapper), type);
         } else {
             cv = factory.createValue(value, type);
         }
 
-        return new ValueImpl(cv, resolver);
+        return new ValueImpl(cv, nameMapper);
     }
 
     @Override
@@ -169,12 +171,12 @@ public class ValueFactoryImpl implements
     @Override
     public Value createValue(BigDecimal value) {
         CoreValue cv = factory.createValue(value);
-        return new ValueImpl(cv, resolver);
+        return new ValueImpl(cv, nameMapper);
     }
 
     @Override
     public Value createValue(Node value, boolean weak) throws RepositoryException {
         CoreValue cv = factory.createValue(value.getUUID(), weak ? PropertyType.WEAKREFERENCE
: PropertyType.REFERENCE);
-        return new ValueImpl(cv, resolver);
+        return new ValueImpl(cv, nameMapper);
     }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java?rev=1330383&r1=1330382&r2=1330383&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
Wed Apr 25 16:18:58 2012
@@ -18,6 +18,8 @@ package org.apache.jackrabbit.oak.jcr.va
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
+import org.apache.jackrabbit.oak.namepath.Paths;
 import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,19 +48,17 @@ class ValueImpl implements Value {
     private static final Logger log = LoggerFactory.getLogger(ValueImpl.class);
 
     private final CoreValue value;
-
-    // TODO need utility to convert the internal NAME/PATH format to JCR format
-    private final DummyNamePathResolver resolver;
+    private final NameMapper nameMapper;
 
     /**
      * Constructs a {@code ValueImpl} object based on a {@code CoreValue}
      *
      * @param value the value object this {@code ValueImpl} should represent
-     * @param resolver
+     * @param nameMapper
      */
-    public ValueImpl(CoreValue value, DummyNamePathResolver resolver) {
+    public ValueImpl(CoreValue value, NameMapper nameMapper) {
         this.value = value;
-        this.resolver = resolver;
+        this.nameMapper = nameMapper;
     }
 
     CoreValue unwrap() {
@@ -151,9 +151,9 @@ class ValueImpl implements Value {
     public String getString() throws RepositoryException {
         switch (getType()) {
             case PropertyType.NAME :
-                return resolver.getJCRName(value.toString());
+                return nameMapper.getJcrName(value.toString());
             case PropertyType.PATH:
-                return resolver.getJCRPath(value.toString());
+                return Paths.toJcrPath(value.toString(), nameMapper);
             case PropertyType.BINARY:
                 InputStream stream = getStream();
                 try {



Mime
View raw message