jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1151189 - in /jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel: RepositoryServiceImpl.java util/Values.java
Date Tue, 26 Jul 2011 17:59:48 GMT
Author: mduerig
Date: Tue Jul 26 17:59:48 2011
New Revision: 1151189

URL: http://svn.apache.org/viewvc?rev=1151189&view=rev
Log:
spi2microkernel (WIP)
- refator value encoding

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.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=1151189&r1=1151188&r2=1151189&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 Jul 26 17:59:48 2011
@@ -78,10 +78,12 @@ import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 
+import static javax.jcr.PropertyType.NAME;
 import static javax.jcr.Repository.*;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.*;
 import static org.apache.jackrabbit.spi2microkernel.util.Arrays.contains;
 import static org.apache.jackrabbit.spi2microkernel.util.ItemInfos.*;
+import static org.apache.jackrabbit.spi2microkernel.util.Values.encodeValue;
 
 public class RepositoryServiceImpl extends AbstractRepositoryService {
     static final Logger log = LoggerFactory.getLogger(RepositoryServiceImpl.class);
@@ -115,7 +117,7 @@ public class RepositoryServiceImpl exten
     public RepositoryServiceImpl(MicroKernel microKernel) throws RepositoryException {
         super(DESCRIPTORS, Collections.<String, String>emptyMap(), new QNodeTypeDefinition[0]);
 
-        try {
+        try { 
             this.microKernel = microKernel;  // fixme who disposes the micro kernel?
 
             String head = microKernel.getHeadRevision();
@@ -532,7 +534,7 @@ public class RepositoryServiceImpl exten
             try {
                 StringBuilder sb = new StringBuilder();
                 JsonBuilder.create(sb)
-                    .value(Paths.nameToString(JCR_PRIMARYTYPE), "7:" + nodetypeName.toString())
 // fixme factor type encoding out
+                    .value(Paths.nameToString(JCR_PRIMARYTYPE), encodeValue(NAME, nodetypeName.toString()))
 
                     .build();
 
                 jsop.append('+').append(target(parentId, nodeName)).append(" : ").append(sb.toString()).append('\n');

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=1151189&r1=1151188&r2=1151189&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 Jul 26 17:59:48 2011
@@ -248,15 +248,15 @@ public final class Values {
     }
 
     public static String dateToString(Calendar calendar) {
-        return typeEncode(DATE, ISO8601.format(calendar));
+        return quoteAndEncode(DATE, ISO8601.format(calendar));
     }
 
     public static String pathToString(Path path) {
-        return typeEncode(PATH, JsonBuilder.escape(path.getString()));
+        return quoteAndEncode(PATH, JsonBuilder.escape(path.getString()));
     }
 
     public static String nameToString(Name name) {
-        return typeEncode(NAME, JsonBuilder.escape(name.toString()));
+        return quoteAndEncode(NAME, JsonBuilder.escape(name.toString()));
     }
 
     public static String namesToString(Name[] names) {
@@ -284,12 +284,12 @@ public final class Values {
             case STRING:
                 String s = value.getString();
                 return s.length() >= 2 && s.charAt(1) == ':'
-                    ? typeEncode(type, JsonBuilder.escape(s))
+                    ? quoteAndEncode(type, JsonBuilder.escape(s))
                     : JsonBuilder.quote(JsonBuilder.escape(s));
 
             case DOUBLE:
                 return Double.isNaN(value.getDouble())
-                    ? typeEncode(type, "NaN")
+                    ? quoteAndEncode(type, "NaN")
                     : value.getString();
 
             case LONG:
@@ -298,18 +298,18 @@ public final class Values {
 
             case DECIMAL:
             case DATE:
-                return typeEncode(type, value.getString());
+                return quoteAndEncode(type, value.getString());
 
             case URI:
             case NAME:
             case PATH:
-                return typeEncode(type, JsonBuilder.escape(value.getString()));
+                return quoteAndEncode(type, JsonBuilder.escape(value.getString()));
 
             case BINARY:
                 if (value.getLength() > 0xffff) {
                     try {
                         String blobId = binaryHandler.apply(value);
-                        return typeEncode(BLOB_REF_TYPE, blobId);
+                        return quoteAndEncode(BLOB_REF_TYPE, blobId);
                     }
                     catch (RepositoryException e) {
                         throw e;
@@ -322,7 +322,7 @@ public final class Values {
                     try {
                         StringWriter sw = new StringWriter();
                         Base64.encode(value.getStream(), sw);
-                        return typeEncode(type, JsonBuilder.escape(sw.toString()));
+                        return quoteAndEncode(type, JsonBuilder.escape(sw.toString()));
                     }
                     catch (IOException e) {
                         throw new RepositoryException(e);
@@ -331,7 +331,7 @@ public final class Values {
 
             case REFERENCE:
             case WEAKREFERENCE:
-                return typeEncode(type, JsonBuilder.escape(value.getString()));
+                return quoteAndEncode(type, JsonBuilder.escape(value.getString()));
 
             default:
                 throw new RepositoryException("Cannot handle value of type " +
@@ -355,6 +355,10 @@ public final class Values {
         return sb.toString();
     }
 
+    public static String encodeValue(int type, String value) {
+        return TYPES[type] + ":" + value;
+    }
+
     //------------------------------------------< private >---
 
     private static Character toHex(int i) {
@@ -363,8 +367,8 @@ public final class Values {
             : 'X';
     }
 
-    private static String typeEncode(int type, String value) {
-        return "\"" + TYPES[type] + ':' + value + '\"';
+    private static String quoteAndEncode(int type, String value) {
+        return '\"' + encodeValue(type, value) + '\"';
     }
 
     private static QValue create(boolean value) {



Mime
View raw message