jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1435216 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/memory/ main/java/org/apache/jackrabbit/oak/plugins/value/ test/java/org/apache/jackrabbit/oak/plugins/memory/
Date Fri, 18 Jan 2013 16:09:14 GMT
Author: mduerig
Date: Fri Jan 18 16:09:14 2013
New Revision: 1435216

URL: http://svn.apache.org/viewvc?rev=1435216&view=rev
Log:
OAK-554: PropertyStates#createProperty ignores namespace mappings when creating states of
type NAME and PATH

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStatesTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java?rev=1435216&r1=1435215&r2=1435216&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
Fri Jan 18 16:09:14 2013
@@ -32,6 +32,7 @@ import org.apache.jackrabbit.oak.api.Blo
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.ValueImpl;
 
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
 
@@ -52,10 +53,11 @@ public final class PropertyStates {
      */
     @Nonnull
     public static PropertyState createProperty(String name, Value value) throws RepositoryException
{
+
         int type = value.getType();
         switch (type) {
             case PropertyType.STRING:
-                return StringPropertyState.stringProperty(name, value.getString());
+                return StringPropertyState.stringProperty(name, getString(value, type));
             case PropertyType.BINARY:
                 return BinaryPropertyState.binaryProperty(name, value);
             case PropertyType.LONG:
@@ -69,7 +71,7 @@ public final class PropertyStates {
             case PropertyType.DECIMAL:
                 return DecimalPropertyState.decimalProperty(name, value.getDecimal());
             default:
-                return new GenericPropertyState(name, value.getString(), Type.fromTag(type,
false));
+                return new GenericPropertyState(name, getString(value, type), Type.fromTag(type,
false));
         }
     }
 
@@ -96,7 +98,7 @@ public final class PropertyStates {
             case PropertyType.STRING:
                 List<String> strings = Lists.newArrayList();
                 for (Value value : values) {
-                    strings.add(value.getString());
+                    strings.add(getString(value, type));
                 }
                 return MultiStringPropertyState.stringProperty(name, strings);
             case PropertyType.BINARY:
@@ -138,12 +140,24 @@ public final class PropertyStates {
             default:
                 List<String> vals = Lists.newArrayList();
                 for (Value value : values) {
-                    vals.add(value.getString());
+                    vals.add(getString(value, type));
                 }
                 return new MultiGenericPropertyState(name, vals, Type.fromTag(type, true));
         }
     }
 
+    private static String getString(Value value, int type) throws RepositoryException {
+        if (value instanceof ValueImpl) {
+            return ((ValueImpl) value).getOakString();
+        }
+        else if (type == PropertyType.NAME || type == PropertyType.PATH) {
+            throw new IllegalArgumentException("Cannot create name of path property state
from Value " +
+                    "of class '" + value.getClass() + '\'');
+        } else {
+            return value.getString();
+        }
+    }
+
     /**
      * Create a {@code PropertyState} from a string.
      * @param name  The name of the property state

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java?rev=1435216&r1=1435215&r2=1435216&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java
Fri Jan 18 16:09:14 2013
@@ -73,6 +73,15 @@ public class ValueImpl implements Value 
         this(checkSingleValued(property), 0, namePathMapper);
     }
 
+    /**
+     * Same as {@link #getString()} unless that names and paths are returned in their
+     * Oak representation instead of being mapped to their JCR representation.
+     * @return  A String representation of the value of this property.
+     */
+    public String getOakString() {
+        return propertyState.getValue(Type.STRING, index);
+    }
+
     private static PropertyState checkSingleValued(PropertyState property) {
         checkArgument(!property.isArray());
         return property;
@@ -208,9 +217,9 @@ public class ValueImpl implements Value 
 
         switch (getType()) {
             case PropertyType.NAME:
-                return namePathMapper.getJcrName(propertyState.getValue(Type.STRING, index));
+                return namePathMapper.getJcrName(getOakString());
             case PropertyType.PATH:
-                String s = propertyState.getValue(Type.STRING, index);
+                String s = getOakString();
                 if (s.startsWith("[") && s.endsWith("]")) {
                     // identifier paths are returned as-is (JCR 2.0, 3.4.3.1)
                     return s;
@@ -218,7 +227,7 @@ public class ValueImpl implements Value 
                     return namePathMapper.getJcrPath(s);
                 }
             default:
-                return propertyState.getValue(Type.STRING, index);
+                return getOakString();
         }
     }
 
@@ -273,13 +282,13 @@ public class ValueImpl implements Value 
             return propertyState.getValue(Type.BINARY, index).hashCode();
         }
         else {
-            return propertyState.getValue(Type.STRING, index).hashCode();
+            return getOakString().hashCode();
         }
     }
 
     @Override
     public String toString() {
-        return propertyState.getValue(Type.STRING, index);
+        return getOakString();
     }
 
     private static int compare(PropertyState p1, int i1, PropertyState p2, int i2) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStatesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStatesTest.java?rev=1435216&r1=1435215&r2=1435216&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStatesTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStatesTest.java
Fri Jan 18 16:09:14 2013
@@ -27,7 +27,6 @@ import org.apache.jackrabbit.oak.TestNam
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static java.util.Collections.singletonMap;
@@ -40,7 +39,6 @@ public class PropertyStatesTest {
         singletonMap("jcr-prefix", TestNameMapper.TEST_URI) ));
 
     @Test
-    @Ignore  // FIXME OAK-554
     public void namePropertyFromNameValue() throws RepositoryException {
         PropertyState nameProperty = PropertyStates.createProperty("name", "oak-prefix:value",
PropertyType.NAME);
         Value nameValue = ValueFactoryImpl.createValue(nameProperty, namePathMapper);
@@ -49,7 +47,6 @@ public class PropertyStatesTest {
     }
 
     @Test
-    @Ignore  // FIXME OAK-554
     public void pathPropertyFromPathValue() throws RepositoryException {
         PropertyState pathProperty = PropertyStates.createProperty("path", "oak-prefix:a/oak-prefix:b",
PropertyType.PATH);
         Value nameValue = ValueFactoryImpl.createValue(pathProperty, namePathMapper);



Mime
View raw message