jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1151116 - in /jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel: RepositoryServiceImpl.java util/Values.java
Date Tue, 26 Jul 2011 14:31:58 GMT
Author: mduerig
Date: Tue Jul 26 14:31:57 2011
New Revision: 1151116

URL: http://svn.apache.org/viewvc?rev=1151116&view=rev
Log:
spi2microkernel (WIP)
- support from mix:created

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=1151116&r1=1151115&r2=1151116&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 14:31:57 2011
@@ -68,6 +68,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -535,6 +536,12 @@ public class RepositoryServiceImpl exten
                     .build();
 
                 jsop.append('+').append(target(parentId, nodeName)).append(" : ").append(sb.toString()).append('\n');
+
+                // todo: factor out setting of default values
+                if (isSubType(nodetypeName, MIX_CREATED)) {
+                    setProperty(target(parentId, nodeName, JCR_CREATED), Values.dateToString(GregorianCalendar.getInstance()));
+                    setProperty(target(parentId, nodeName, JCR_CREATEDBY), '"' + sessionInfo.getUserID()
+ '"');
+                }
             }
             catch (IOException e) {
                 throw new RepositoryException(e);
@@ -588,10 +595,15 @@ public class RepositoryServiceImpl exten
                 setProperty(nodeId, JCR_MIXINTYPES, Values.namesToString(mixinNodeTypeNames));
             }
 
+            // todo: factor out setting of default values
             if (contains(mixinNodeTypeNames, MIX_REFERENCEABLE)) {
                 // todo uuid is not stable across move operations
                 setProperty(nodeId, JCR_UUID, Values.pathToString(getPath(nodeId)));
             }
+            else if (contains(mixinNodeTypeNames, MIX_CREATED)) {
+                setProperty(nodeId, JCR_CREATED, Values.dateToString(GregorianCalendar.getInstance()));
+                setProperty(nodeId, JCR_CREATEDBY, '"' + sessionInfo.getUserID() + '"');
+            }
         }
 
         public void setPrimaryType(NodeId nodeId, Name primaryNodeTypeName) throws RepositoryException
{
@@ -611,20 +623,41 @@ public class RepositoryServiceImpl exten
             });
         }
 
+        // todo implement more general sub type relation
+        private boolean isSubType(Name name1, Name name2) throws RepositoryException {
+            if (MIX_CREATED.equals(name2)) {
+              return NT_HIERARCHYNODE.equals(name1) ||
+                     NT_FILE.equals(name1) ||
+                     NT_FOLDER.equals(name1);
+            }
+
+            throw new RepositoryException("Cannot determine subtype relation: " + name1 +
" > " + name2);
+        }
+
         private String target(NodeId nodeId) throws RepositoryException {
             return '\"' + JsonBuilder.escape(
                 PathUtils.relativize("/", Paths.pathToString(sessionInfo.getWorkspaceName(),
getPath(nodeId)))) + '\"';
         }
 
-        private String target(NodeId parentId, Name itemName) throws RepositoryException
{
+        private String target(NodeId parentId, Name... itemNames) throws RepositoryException
{
             String path = Paths.pathToString(sessionInfo.getWorkspaceName(), getPath(parentId));
-            String name = Paths.nameToString(itemName);
-            return '\"' + JsonBuilder.escape(PathUtils.concat(PathUtils.relativize("/", path),
name)) + '\"';
+            String relPath = PathUtils.relativize("/", path);
+
+            for (Name itemName : itemNames) {
+                String name = Paths.nameToString(itemName);
+                relPath = PathUtils.concat(relPath, name);
+            }
+            return '\"' + JsonBuilder.escape(relPath) + '\"';
         }
 
         private void setProperty(NodeId parentId, Name propertyName, String jsonValue) throws
RepositoryException {
-            jsop.append('^').append(target(parentId, propertyName)).append(" : ").append(jsonValue).append('\n');
+            setProperty(target(parentId, propertyName), jsonValue);
         }
+
+        private void setProperty(String target, String jsonValue) {
+            jsop.append('^').append(target).append(" : ").append(jsonValue).append('\n');
+        }
+
     }
 
     private static class ChangeLog extends ConsolidatingChangeLog {

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=1151116&r1=1151115&r2=1151116&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 14:31:57 2011
@@ -26,11 +26,13 @@ import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 import org.apache.jackrabbit.util.Base64;
+import org.apache.jackrabbit.util.ISO8601;
 
 import javax.jcr.RepositoryException;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -245,6 +247,10 @@ public final class Values {
         }
     }
 
+    public static String dateToString(Calendar calendar) {
+        return typeEncode(DATE, ISO8601.format(calendar));
+    }
+
     public static String pathToString(Path path) {
         return typeEncode(PATH, JsonBuilder.escape(path.getString()));
     }
@@ -273,7 +279,7 @@ public final class Values {
 
     public static String valueToString(QValue value, Function1<QValue, String> binaryHandler)
throws RepositoryException {
         int type = value.getType();
-        
+
         switch(type) {
             case STRING:
                 String s = value.getString();
@@ -289,7 +295,7 @@ public final class Values {
             case LONG:
             case BOOLEAN:
                 return value.getString();
-            
+
             case DECIMAL:
             case DATE:
                 return typeEncode(type, value.getString());
@@ -298,7 +304,7 @@ public final class Values {
             case NAME:
             case PATH:
                 return typeEncode(type, JsonBuilder.escape(value.getString()));
-            
+
             case BINARY:
                 if (value.getLength() > 0xffff) {
                     try {
@@ -319,14 +325,14 @@ public final class Values {
                         return typeEncode(type, JsonBuilder.escape(sw.toString()));
                     }
                     catch (IOException e) {
-                        throw new RepositoryException(e); 
+                        throw new RepositoryException(e);
                     }
                 }
 
             case REFERENCE:
             case WEAKREFERENCE:
                 return typeEncode(type, JsonBuilder.escape(value.getString()));
-            
+
             default:
                 throw new RepositoryException("Cannot handle value of type " +
                         nameFromValue(value.getType()));



Mime
View raw message