jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r779476 - in /jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit: server/remoting/davex/JsonDiffHandler.java webdav/jcr/DefaultItemCollection.java
Date Thu, 28 May 2009 08:24:58 GMT
Author: angela
Date: Thu May 28 08:24:58 2009
New Revision: 779476

URL: http://svn.apache.org/viewvc?rev=779476&view=rev
Log:
JCR-2003: JCR2SPI / SPI: Add support for JCR 2.0

- initial implementation for Node.setPrimaryType. untested server-side part (spi2dav/spi2davex)

Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java?rev=779476&r1=779475&r2=779476&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java
Thu May 28 08:24:58 2009
@@ -106,6 +106,8 @@
 
             if (JcrConstants.JCR_MIXINTYPES.equals(propName)) {
                 setMixins(parent, extractValuesFromRequest(targetPath));
+            } else if (JcrConstants.JCR_PRIMARYTYPE.equals(propName)) {
+                setPrimaryType(parent, extractValuesFromRequest(targetPath));
             } else {
                 if (diffValue == null || diffValue.length() == 0) {
                     // single valued property with value present in multipart.
@@ -347,6 +349,17 @@
         return n;
     }
 
+    private static void setPrimaryType(Node n, Value[] values) throws RepositoryException,
DiffException {
+        if (values.length == 1) {
+            String ntName = values[0].getString();
+            if (!ntName.equals(n.getPrimaryNodeType().getName())) {
+                n.setPrimaryType(ntName);
+            } // else: same primaryType as before -> nothing to do.
+        } else {
+            throw new DiffException("Invalid diff: jcr:primarytype cannot have multiple values,
nor can it's value be removed.");
+        }
+    }
+
     private static void setMixins(Node n, Value[] values) throws RepositoryException {
         if (values.length == 0) {
             // remove all mixins

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java?rev=779476&r1=779475&r2=779476&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
Thu May 28 08:24:58 2009
@@ -226,8 +226,9 @@
         if (!exists()) {
             throw new DavException(DavServletResponse.SC_NOT_FOUND);
         }
-        if (property.getName().equals(JCR_MIXINNODETYPES)) {
-            Node n = (Node)item;
+        DavPropertyName propName = property.getName();
+        if (JCR_MIXINNODETYPES.equals(propName)) {
+            Node n = (Node) item;
             try {
                 NodeType[] existingMixin = n.getMixinNodeTypes();
                 NodeTypeProperty mix = new NodeTypeProperty(property);
@@ -252,8 +253,23 @@
             } catch (RepositoryException e) {
                 throw new JcrDavException(e);
             }
+        } else if (JCR_PRIMARYNODETYPE.equals(propName)) {
+            Node n = (Node) item;
+            try {
+                NodeTypeProperty ntProp = new NodeTypeProperty(property);
+                Set names = ntProp.getNodeTypeNames();
+                if (names.size() == 1) {
+                    String ntName = names.iterator().next().toString();
+                    n.setPrimaryType(ntName);
+                } else {
+                    // only a single node type can be primary node type.
+                    throw new DavException(DavServletResponse.SC_BAD_REQUEST);
+                }
+            } catch (RepositoryException e) {
+                throw new JcrDavException(e);
+            }
         } else {
-            // all props except for mixinnodetypes are read-only
+            // all props except for mixinnodetypes and primaryType are read-only
             throw new DavException(DavServletResponse.SC_CONFLICT);
         }
     }



Mime
View raw message