jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1133831 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Thu, 09 Jun 2011 12:37:30 GMT
Author: thomasm
Date: Thu Jun  9 12:37:30 2011
New Revision: 1133831

URL: http://svn.apache.org/viewvc?rev=1133831&view=rev
Log:
Support multi-value properties

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java?rev=1133831&r1=1133830&r2=1133831&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
Thu Jun  9 12:37:30 2011
@@ -35,6 +35,7 @@ import org.json.simple.parser.ParseExcep
 
 import javax.jcr.RepositoryException;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 
@@ -146,7 +147,9 @@ public final class Json {
 
         private String currentKey;
         private boolean isObjectEmpty;
+        private boolean isArray;
         private NodeInfoBuilder nodeInfoBuilder;
+        private ArrayList<Object> values;
 
         public JsonHandler(Path parent, InfoListener infoListener) {
             this.infoListener = infoListener;
@@ -197,6 +200,15 @@ public final class Json {
 
         @Override
         public boolean primitive(Object value) throws ParseException, IOException {
+            if (isArray) {
+                values.add(value);
+                return true;
+            } else {
+                return handleValue(value, null);
+            }
+        }
+
+        private boolean handleValue(Object value, ArrayList<Object> values) throws
ParseException {
             if (":name".equals(currentKey)) {
                 Name name = Paths.translateName((String) value);
                 nodeInfoBuilder.setName(name);
@@ -211,7 +223,14 @@ public final class Json {
                 PropertyInfoBuilder propertyInfoBuilder = nodeInfoBuilder.createPropertyInfo();
                 Name name = Paths.translateName(currentKey);
                 propertyInfoBuilder.setName(name);
-                propertyInfoBuilder.addValue(Values.create(value));
+                if (value != null) {
+                    propertyInfoBuilder.addValue(Values.create(value));
+                } else {
+                    propertyInfoBuilder.setMultivalued(true);
+                    for (Object o : values) {
+                        propertyInfoBuilder.addValue(Values.create(o));
+                    }
+                }
                 propertyInfoBuilder.build();
                 return !infoListener.done();
             }
@@ -220,6 +239,21 @@ public final class Json {
             }
         }
 
+        @Override
+        public boolean startArray() throws ParseException, IOException {
+            isArray = true;
+            values = new ArrayList<Object>();
+            return true;
+        }
+
+        @Override
+        public boolean endArray() throws ParseException, IOException {
+            boolean result = handleValue(null, values);
+            isArray = false;
+            values = null;
+            return result;
+        }
+
     }
 
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1133831&r1=1133830&r2=1133831&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Thu Jun  9 12:37:30 2011
@@ -261,7 +261,6 @@ public class RepositoryTest {
         addProperty(parentNode, "decimal", getSession().getValueFactory().createValue(BigDecimal.valueOf(21)));
     }
 
-    @Ignore  // todo fix in microkernel
     @Test
     public void addMultiValuedProperty() throws RepositoryException {
         Node parentNode = getNode(testPath);
@@ -305,7 +304,6 @@ public class RepositoryTest {
         }
     }
 
-    @Ignore  // todo fix in microkernel
     @Test
     public void setMultiValuedProperty() throws RepositoryException {
         Node parentNode = getNode(testPath);



Mime
View raw message