incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r823834 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/ test/java/org/apache/sling/jcr/resource/internal/
Date Sat, 10 Oct 2009 09:29:20 GMT
Author: cziegeler
Date: Sat Oct 10 09:29:20 2009
New Revision: 823834

URL: http://svn.apache.org/viewvc?rev=823834&view=rev
Log:
SLING-1149 : JcrPropertyMap doesn't allow "./property" style access any more

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMap.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrPropertyMap.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMap.java?rev=823834&r1=823833&r2=823834&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMap.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMap.java
Sat Oct 10 09:29:20 2009
@@ -67,7 +67,8 @@
     /**
      * @see java.util.Map#put(java.lang.Object, java.lang.Object)
      */
-    public Object put(String key, Object value) {
+    public Object put(String aKey, Object value) {
+        final String key = checkKey(aKey);
         if ( key == null || key.indexOf('/') != -1 ) {
             throw new IllegalArgumentException("Invalid key: " + key);
         }
@@ -107,7 +108,11 @@
     /**
      * @see java.util.Map#remove(java.lang.Object)
      */
-    public Object remove(Object key) {
+    public Object remove(Object aKey) {
+        if ( aKey == null ) {
+            return null;
+        }
+        final String key = checkKey(aKey.toString());
         readFully();
         final Object oldValue = this.cache.remove(key);
         this.valueCache.remove(key);

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrPropertyMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrPropertyMap.java?rev=823834&r1=823833&r2=823834&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrPropertyMap.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrPropertyMap.java
Sat Oct 10 09:29:20 2009
@@ -101,11 +101,22 @@
 
     // ---------- ValueMap
 
+    protected String checkKey(final String key) {
+        if ( key != null && key.startsWith("./") ) {
+            return key.substring(2);
+        }
+        return key;
+    }
+
     /**
      * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Class)
      */
     @SuppressWarnings("unchecked")
-    public <T> T get(final String key, final Class<T> type) {
+    public <T> T get(final String aKey, final Class<T> type) {
+        if ( aKey == null ) {
+            return null;
+        }
+        final String key = checkKey(aKey);
         if (type == null) {
             return (T) get(key);
         }
@@ -124,7 +135,11 @@
      * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Object)
      */
     @SuppressWarnings("unchecked")
-    public <T> T get(final String key,final T defaultValue) {
+    public <T> T get(final String aKey,final T defaultValue) {
+        if ( aKey == null ) {
+            return null;
+        }
+        final String key = checkKey(aKey);
         if (defaultValue == null) {
             return (T) get(key);
         }
@@ -146,13 +161,14 @@
     /**
      * @see java.util.Map#get(java.lang.Object)
      */
-    public Object get(final Object key) {
-        if ( key == null ) {
+    public Object get(final Object aKey) {
+        if ( aKey == null ) {
             return null;
         }
+        final String key = checkKey(aKey.toString());
         CacheEntry entry = cache.get(key);
         if (entry == null) {
-            entry = read((String)key);
+            entry = read(key);
         }
         final Object value = (entry == null ? null : entry.defaultValue);
         return value;

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java?rev=823834&r1=823833&r2=823834&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
Sat Oct 10 09:29:20 2009
@@ -251,6 +251,16 @@
         search(vm.values().iterator(), "value");
     }
 
+    public void testDotSlash() throws Exception {
+        final String prop = "myProp";
+        final String value = "value";
+        this.rootNode.setProperty(prop, value);
+        final ValueMap vm = this.createPropertyMap(this.rootNode);
+        assertEquals(value, vm.get(prop));
+        assertEquals(value, vm.get("./" + prop));
+        assertTrue(vm.containsKey("./" + prop));
+    }
+
     protected void search(Iterator<?> i, Object value) {
         boolean found = false;
         while ( !found && i.hasNext() ) {



Mime
View raw message