sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r632234 - in /incubator/sling/trunk/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/loader/ test/java/org/apache/sling/jcr/resource/internal/loader/
Date Fri, 29 Feb 2008 06:40:28 GMT
Author: fmeschbe
Date: Thu Feb 28 22:40:26 2008
New Revision: 632234

URL: http://svn.apache.org/viewvc?rev=632234&view=rev
Log:
SLING-293 If no primary node type is declared on import, use the default primary node type
provided by the repository instead of defaulting to nt:unstructured.

Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Node.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/JsonReaderTest.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/XJsonReaderTest.java

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java?rev=632234&r1=632233&r2=632234&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java
Thu Feb 28 22:40:26 2008
@@ -340,8 +340,18 @@
         // ensure repository node
         Node node;
         if (parentNode.hasNode(clNode.getName())) {
+            
+            // use existing node
             node = parentNode.getNode(clNode.getName());
+            
+        } else if (clNode.getPrimaryNodeType() == null) {
+            
+            // node explicit node type, use repository default
+            node = parentNode.addNode(clNode.getName());
+            
         } else {
+            
+            // explicit primary node type
             node = parentNode.addNode(clNode.getName(),
                 clNode.getPrimaryNodeType());
         }

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Node.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Node.java?rev=632234&r1=632233&r2=632234&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Node.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Node.java
Thu Feb 28 22:40:26 2008
@@ -26,7 +26,7 @@
 class Node {
 
     private String name;
-    private String primaryNodeType = "nt:unstructured";
+    private String primaryNodeType;
     private Set<String> mixinNodeTypes;
     private List<Property> properties;
     private List<Node> children;
@@ -35,7 +35,7 @@
      * @return the children
      */
     List<Node> getChildren() {
-        return this.children;
+        return children;
     }
 
     /**
@@ -43,11 +43,11 @@
      */
     void addChild(Node child) {
         if (child != null) {
-            if (this.children == null) {
-                this.children = new ArrayList<Node>();
+            if (children == null) {
+                children = new ArrayList<Node>();
             }
 
-            this.children.add(child);
+            children.add(child);
         }
     }
 
@@ -55,7 +55,7 @@
      * @return the mixinNodeTypes
      */
     Set<String> getMixinNodeTypes() {
-        return this.mixinNodeTypes;
+        return mixinNodeTypes;
     }
 
     /**
@@ -63,11 +63,11 @@
      */
     void addMixinNodeType(String mixinNodeType) {
         if (mixinNodeType != null && mixinNodeType.length() > 0) {
-            if (this.mixinNodeTypes == null) {
-                this.mixinNodeTypes = new HashSet<String>();
+            if (mixinNodeTypes == null) {
+                mixinNodeTypes = new HashSet<String>();
             }
 
-            this.mixinNodeTypes.add(mixinNodeType);
+            mixinNodeTypes.add(mixinNodeType);
         }
     }
 
@@ -75,7 +75,7 @@
      * @return the name
      */
     String getName() {
-        return this.name;
+        return name;
     }
 
     /**
@@ -89,7 +89,7 @@
      * @return the primaryNodeType
      */
     String getPrimaryNodeType() {
-        return this.primaryNodeType;
+        return primaryNodeType;
     }
 
     /**
@@ -103,7 +103,7 @@
      * @return the properties
      */
     List<Property> getProperties() {
-        return this.properties;
+        return properties;
     }
 
     /**
@@ -111,16 +111,20 @@
      */
     void addProperty(Property property) {
         if (property != null) {
-            if (this.properties == null) {
-                this.properties = new ArrayList<Property>();
+            if (properties == null) {
+                properties = new ArrayList<Property>();
             }
 
-            this.properties.add(property);
+            properties.add(property);
         }
     }
 
     public int hashCode() {
-        return this.getName().hashCode() * 17 + this.getPrimaryNodeType().hashCode();
+        int code = getName().hashCode() * 17;
+        if (getPrimaryNodeType() != null) {
+            code += getPrimaryNodeType().hashCode();
+        }
+        return code;
     }
 
     public boolean equals(Object obj) {
@@ -131,15 +135,16 @@
         }
 
         Node other = (Node) obj;
-        return this.getName().equals(other.getName())
-            && this.getPrimaryNodeType().equals(other.getPrimaryNodeType())
-            && this.equals(this.getMixinNodeTypes(), other.getMixinNodeTypes())
-            && this.equals(this.getProperties(), other.getProperties())
-            && this.equals(this.getChildren(), other.getChildren());
+        return getName().equals(other.getName())
+            && equals(getPrimaryNodeType(), other.getPrimaryNodeType())
+            && equals(getMixinNodeTypes(), other.getMixinNodeTypes())
+            && equals(getProperties(), other.getProperties())
+            && equals(getChildren(), other.getChildren());
     }
 
     public String toString() {
-        return "Node " + this.getName() + ", primary=" + this.getPrimaryNodeType() + ", mixins="
+ this.getMixinNodeTypes();
+        return "Node " + getName() + ", primary=" + getPrimaryNodeType()
+            + ", mixins=" + getMixinNodeTypes();
     }
 
     private boolean equals(Object o1, Object o2) {

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/JsonReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/JsonReaderTest.java?rev=632234&r1=632233&r2=632234&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/JsonReaderTest.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/JsonReaderTest.java
Thu Feb 28 22:40:26 2008
@@ -67,7 +67,7 @@
         Node node = this.parse(json);
         assertNotNull("Expecting node", node);
         assertEquals(name, node.getName());
-        assertEquals("nt:unstructured", node.getPrimaryNodeType());
+        assertNull(node.getPrimaryNodeType());
         assertNull("No mixins expected", node.getMixinNodeTypes());
         assertNull("No properties expected", node.getProperties());
         assertNull("No children expected", node.getChildren());
@@ -79,7 +79,7 @@
         Node node = this.parse(json);
         assertNotNull("Expecting node", node);
         assertEquals(name, node.getName());
-        assertEquals("nt:unstructured", node.getPrimaryNodeType());
+        assertNull(node.getPrimaryNodeType());
         assertNull("No mixins expected", node.getMixinNodeTypes());
         assertNull("No properties expected", node.getProperties());
         assertNull("No children expected", node.getChildren());
@@ -91,7 +91,7 @@
         Node node = this.parse(json);
         assertNotNull("Expecting node", node);
         assertEquals(name, node.getName());
-        assertEquals("nt:unstructured", node.getPrimaryNodeType());
+        assertNull(node.getPrimaryNodeType());
         assertNull("No mixins expected", node.getMixinNodeTypes());
         assertNull("No properties expected", node.getProperties());
         assertNull("No children expected", node.getChildren());
@@ -103,7 +103,7 @@
         Node node = this.parse(json);
         assertNotNull("Expecting node", node);
         assertEquals(name, node.getName());
-        assertEquals("nt:unstructured", node.getPrimaryNodeType());
+        assertNull(node.getPrimaryNodeType());
         assertNull("No mixins expected", node.getMixinNodeTypes());
         assertNull("No properties expected", node.getProperties());
         assertNull("No children expected", node.getChildren());
@@ -331,7 +331,10 @@
         JSONObject obj = new JSONObject();
 
         obj.putOpt("name", node.getName());
-        obj.putOpt("primaryNodeType", node.getPrimaryNodeType());
+        
+        if (node.getPrimaryNodeType() != null) {
+            obj.putOpt("primaryNodeType", node.getPrimaryNodeType());
+        }
 
         if (node.getMixinNodeTypes() != null) {
             obj.putOpt("mixinNodeTypes", this.toJsonArray(node.getMixinNodeTypes()));

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/XJsonReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/XJsonReaderTest.java?rev=632234&r1=632233&r2=632234&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/XJsonReaderTest.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/loader/XJsonReaderTest.java
Thu Feb 28 22:40:26 2008
@@ -65,7 +65,7 @@
         String json = "{}";
         Node node = this.parse(json);
         assertNotNull("Expecting node", node);
-        assertEquals("nt:unstructured", node.getPrimaryNodeType());
+        assertNull(node.getPrimaryNodeType());
         assertNull("No mixins expected", node.getMixinNodeTypes());
         assertNull("No properties expected", node.getProperties());
         assertNull("No children expected", node.getChildren());
@@ -75,7 +75,7 @@
         String json = "     {  }     ";
         Node node = this.parse(json);
         assertNotNull("Expecting node", node);
-        assertEquals("nt:unstructured", node.getPrimaryNodeType());
+        assertNull(node.getPrimaryNodeType());
         assertNull("No mixins expected", node.getMixinNodeTypes());
         assertNull("No properties expected", node.getProperties());
         assertNull("No children expected", node.getChildren());
@@ -85,7 +85,7 @@
         String json = "";
         Node node = this.parse(json);
         assertNotNull("Expecting node", node);
-        assertEquals("nt:unstructured", node.getPrimaryNodeType());
+        assertNull(node.getPrimaryNodeType());
         assertNull("No mixins expected", node.getMixinNodeTypes());
         assertNull("No properties expected", node.getProperties());
         assertNull("No children expected", node.getChildren());
@@ -95,7 +95,7 @@
         String json = "             ";
         Node node = this.parse(json);
         assertNotNull("Expecting node", node);
-        assertEquals("nt:unstructured", node.getPrimaryNodeType());
+        assertNull(node.getPrimaryNodeType());
         assertNull("No mixins expected", node.getMixinNodeTypes());
         assertNull("No properties expected", node.getProperties());
         assertNull("No children expected", node.getChildren());
@@ -321,7 +321,9 @@
     private JSONObject toJsonObject(Node node) throws JSONException {
         JSONObject obj = new JSONObject();
 
-        obj.putOpt("jcr:primaryType", node.getPrimaryNodeType());
+        if (node.getPrimaryNodeType() != null) {
+            obj.putOpt("jcr:primaryType", node.getPrimaryNodeType());
+        }
 
         if (node.getMixinNodeTypes() != null) {
             obj.putOpt("jcr:mixinTypes", this.toJsonArray(node.getMixinNodeTypes()));



Mime
View raw message