jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1133002 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Tue, 07 Jun 2011 13:24:28 GMT
Author: mduerig
Date: Tue Jun  7 13:24:28 2011
New Revision: 1133002

URL: http://svn.apache.org/viewvc?rev=1133002&view=rev
Log:
spi2microkernel prototype (WIP)
write support: addProperty

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1133002&r1=1133001&r2=1133002&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Tue Jun  7 13:24:28 2011
@@ -376,18 +376,12 @@ public class RepositoryServiceImpl exten
         }
 
         public void addNode(NodeId parentId, Name nodeName, Name nodetypeName, String uuid)
throws RepositoryException {
-            String wspName = sessionInfo.getWorkspaceName();
-            Path path = parentId.getPath();
-            String mkPath = Paths.translateQPath(wspName, path);
-            mkPath = PathUtil.relativize("/", mkPath);
-            String name = Paths.translateQName(nodeName);
-
-            sb.append('+').append(PathUtil.concat(mkPath, name)).append(" : {}\n");
+            sb.append('+').append(target(parentId, nodeName)).append(" : {}\n");
         }
 
         public void addProperty(NodeId parentId, Name propertyName, QValue value) throws
RepositoryException {
-            // todo implement addProperty
-            throw new UnsupportedRepositoryOperationException("addProperty");
+            String val = Values.create(value);
+            sb.append('^').append(target(parentId, propertyName)).append(" : ").append(val);
         }
 
         public void addProperty(NodeId parentId, Name propertyName, QValue[] values) throws
RepositoryException {
@@ -435,6 +429,12 @@ public class RepositoryServiceImpl exten
             rev = microKernel.commit("/", sb.toString(), rev);
             setRevision(sessionInfo, rev);
         }
+
+        private String target(NodeId parentId, Name itemName) throws RepositoryException
{
+            String path = Paths.translateQPath(sessionInfo.getWorkspaceName(), parentId.getPath());
+            String name = Paths.translateQName(itemName);
+            return PathUtil.concat(PathUtil.relativize("/", path), name);
+        }
     }
 
     private static class ChangeLog extends ConsolidatingChangeLog {

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java?rev=1133002&r1=1133001&r2=1133002&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonBuilder.java
Tue Jun  7 13:24:28 2011
@@ -236,6 +236,64 @@ public final class JsonBuilder {
         }
     }
 
+    /**
+     * Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through
U+001F).
+     */
+    public static String escape(String string) {
+        if(string == null) {
+            return null;
+        }
+
+        StringBuffer sb = new StringBuffer();
+        for(int i = 0; i < string.length(); i++) {
+            char ch = string.charAt(i);
+            switch(ch) {
+                case '"':
+                    sb.append("\\\"");
+                    break;
+                case '\\':
+                    sb.append("\\\\");
+                    break;
+                case '\b':
+                    sb.append("\\b");
+                    break;
+                case '\f':
+                    sb.append("\\f");
+                    break;
+                case '\n':
+                    sb.append("\\n");
+                    break;
+                case '\r':
+                    sb.append("\\r");
+                    break;
+                case '\t':
+                    sb.append("\\t");
+                    break;
+                case '/':
+                    sb.append("\\/");
+                    break;
+                default:
+                    //Reference: http://www.unicode.org/versions/Unicode5.1.0/
+                    if (ch >= '\u0000' && ch <= '\u001F' ||
+                            ch >= '\u007F' && ch <= '\u009F' ||
+                            ch >= '\u2000' && ch <= '\u20FF') {
+
+                        String ss = Integer.toHexString(ch);
+                        sb.append("\\u");
+                        for (int k = 0; k < 4 - ss.length(); k++) {
+                            sb.append('0');
+                        }
+                        sb.append(ss.toUpperCase());
+                    }
+                    else {
+                        sb.append(ch);
+                    }
+            }
+        }
+
+        return sb.toString();
+    }
+
     //------------------------------------------< private >---
 
     private static String quote(String string) {
@@ -243,7 +301,7 @@ public final class JsonBuilder {
     }
 
     private static String encode(String value) {
-        return quote(escape(value)); 
+        return quote(escape(value));
     }
 
     private static String encode(int value) {
@@ -251,7 +309,7 @@ public final class JsonBuilder {
     }
 
     private static String encode(long value) {
-        return Long.toString(value); 
+        return Long.toString(value);
     }
 
     private static String encode(float value) {
@@ -271,7 +329,7 @@ public final class JsonBuilder {
     }
 
     private static String encode(boolean value) {
-        return Boolean.toString(value); 
+        return Boolean.toString(value);
     }
 
     private static String encode(String[] values) {
@@ -386,62 +444,4 @@ public final class JsonBuilder {
         return sb.toString();
     }
 
-    /**
-     * Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through
U+001F).
-     */
-    private static String escape(String string) {
-        if(string == null) {
-            return null;
-        }
-
-        StringBuffer sb = new StringBuffer();
-		for(int i = 0; i < string.length(); i++) {
-			char ch = string.charAt(i);
-			switch(ch) {
-                case '"':
-                    sb.append("\\\"");
-                    break;
-                case '\\':
-                    sb.append("\\\\");
-                    break;
-                case '\b':
-                    sb.append("\\b");
-                    break;
-                case '\f':
-                    sb.append("\\f");
-                    break;
-                case '\n':
-                    sb.append("\\n");
-                    break;
-                case '\r':
-                    sb.append("\\r");
-                    break;
-                case '\t':
-                    sb.append("\\t");
-                    break;
-                case '/':
-                    sb.append("\\/");
-                    break;
-                default:
-                    //Reference: http://www.unicode.org/versions/Unicode5.1.0/
-                    if (ch >= '\u0000' && ch <= '\u001F' ||
-                        ch >= '\u007F' && ch <= '\u009F' ||
-                        ch >= '\u2000' && ch <= '\u20FF') {
-
-                        String ss = Integer.toHexString(ch);
-                        sb.append("\\u");
-                        for (int k = 0; k < 4 - ss.length(); k++) {
-                            sb.append('0');
-                        }
-                        sb.append(ss.toUpperCase());
-                    }
-                    else {
-                        sb.append(ch);
-                    }
-			}
-		}
-
-        return sb.toString();
-	}
-
 }

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=1133002&r1=1133001&r2=1133002&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
Tue Jun  7 13:24:28 2011
@@ -82,6 +82,31 @@ public final class Values {
         }
     }
 
+    public static String create(QValue value) throws RepositoryException {
+        switch(value.getType()) {
+            case PropertyType.STRING:
+                return JsonBuilder.escape(value.getString());
+
+            case PropertyType.LONG:
+                return value.getString();
+
+            // todo implement other types
+            case PropertyType.BINARY:
+            case PropertyType.DOUBLE:
+            case PropertyType.DATE:
+            case PropertyType.BOOLEAN:
+            case PropertyType.NAME:
+            case PropertyType.PATH:
+            case PropertyType.REFERENCE:
+            case PropertyType.WEAKREFERENCE:
+            case PropertyType.URI:
+            case PropertyType.DECIMAL:
+            default:
+                throw new UnsupportedRepositoryOperationException("Cannot handle value of
type " +
+                        PropertyType.nameFromValue(value.getType()));
+        }
+    }
+
     //------------------------------------------< private >---
 
     private static QValue create(boolean value) {

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=1133002&r1=1133001&r2=1133002&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
Tue Jun  7 13:24:28 2011
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.spi2microk
 import org.apache.jackrabbit.mk.MicroKernelImpl;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import javax.imageio.spi.ServiceRegistry;
@@ -211,15 +212,45 @@ public class RepositoryTest {
 
         Session session2 = getRepository().login();
         try {
-            assertTrue(session.nodeExists("/bar/new"));
+            assertTrue(session2.nodeExists("/bar/new"));
         }
         finally {
             session2.logout();
         }
     }
 
+    @Test
+    public void addStringProperty() throws RepositoryException {
+        Node parentNode = getNode("/bar");
+        addProperty(parentNode, "string", getSession().getValueFactory().createValue("string
value"));
+    }
+
+    @Test
+    @Ignore  // todo fix in microkernel
+    public void addLongProperty() throws RepositoryException {
+        Node parentNode = getNode("/bar");
+        addProperty(parentNode, "long", getSession().getValueFactory().createValue(42L));
+    }
+
     //------------------------------------------< private >---
 
+    private void addProperty(Node parentNode, String name, Value value) throws RepositoryException
{
+        String propertyPath = parentNode.getPath() + '/' + name;
+        assertFalse(getSession().propertyExists(propertyPath));
+
+        parentNode.setProperty(name, value);
+        getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            assertTrue(session2.propertyExists(propertyPath));
+            assertEquals(value, session2.getProperty(propertyPath).getValue());
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
     private Repository getRepository() throws RepositoryException {
         if (repository == null) {
             Iterator<RepositoryFactory> factories = ServiceRegistry.lookupProviders(RepositoryFactory.class);



Mime
View raw message