Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 15763 invoked from network); 29 Feb 2008 06:40:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Feb 2008 06:40:54 -0000 Received: (qmail 73602 invoked by uid 500); 29 Feb 2008 06:40:49 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 73588 invoked by uid 500); 29 Feb 2008 06:40:49 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 73579 invoked by uid 99); 29 Feb 2008 06:40:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Feb 2008 22:40:48 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Feb 2008 06:40:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 473A81A9832; Thu, 28 Feb 2008 22:40:29 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: sling-commits@incubator.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080229064029.473A81A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 mixinNodeTypes; private List properties; private List children; @@ -35,7 +35,7 @@ * @return the children */ List 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(); + if (children == null) { + children = new ArrayList(); } - this.children.add(child); + children.add(child); } } @@ -55,7 +55,7 @@ * @return the mixinNodeTypes */ Set 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(); + if (mixinNodeTypes == null) { + mixinNodeTypes = new HashSet(); } - 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 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(); + if (properties == null) { + properties = new ArrayList(); } - 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()));