You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2010/06/01 17:12:50 UTC

svn commit: r950105 - /sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java

Author: justin
Date: Tue Jun  1 15:12:49 2010
New Revision: 950105

URL: http://svn.apache.org/viewvc?rev=950105&view=rev
Log:
SLING-1532 - just overwriting properties for resource nodes

Modified:
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java?rev=950105&r1=950104&r2=950105&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java (original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java Tue Jun  1 15:12:49 2010
@@ -417,20 +417,7 @@ public class DefaultContentCreator imple
      */
     public void createProperty(String name, Object value)
     throws RepositoryException {
-        final Node node = this.parentNodeStack.peek();
-        // check if the property already exists, don't overwrite it in this case
-        if (node.hasProperty(name)
-            && !node.getProperty(name).isNew()) {
-            return;
-        }
-        if ( value == null ) {
-            if ( node.hasProperty(name) ) {
-                node.getProperty(name).remove();
-            }
-        } else {
-            final Value jcrValue = this.createValue(node.getSession().getValueFactory(), value);
-            node.setProperty(name, jcrValue);
-        }
+       createProperty(name, value, false);
     }
 
     /**
@@ -438,23 +425,7 @@ public class DefaultContentCreator imple
      */
     public void createProperty(String name, Object[] values)
     throws RepositoryException {
-        final Node node = this.parentNodeStack.peek();
-        // check if the property already exists, don't overwrite it in this case
-        if (node.hasProperty(name)
-            && !node.getProperty(name).isNew()) {
-            return;
-        }
-        if ( values == null || values.length == 0 ) {
-            if ( node.hasProperty(name) ) {
-                node.getProperty(name).remove();
-            }
-        } else {
-            final Value[] jcrValues = new Value[values.length];
-            for(int i = 0; i < values.length; i++) {
-                jcrValues[i] = this.createValue(node.getSession().getValueFactory(), values[i]);
-            }
-            node.setProperty(name, jcrValues);
-        }
+        createProperty(name, values, false);
     }
 
     /**
@@ -613,6 +584,45 @@ public class DefaultContentCreator imple
       return null;
     }
 
+    private void createProperty(String name, Object value, boolean overwriteExisting)
+    throws RepositoryException {
+        final Node node = this.parentNodeStack.peek();
+        // check if the property already exists, don't overwrite it in this case
+        if (node.hasProperty(name)
+            && !node.getProperty(name).isNew() && !overwriteExisting) {
+            return;
+        }
+        if ( value == null ) {
+            if ( node.hasProperty(name) ) {
+                node.getProperty(name).remove();
+            }
+        } else {
+            final Value jcrValue = this.createValue(node.getSession().getValueFactory(), value);
+            node.setProperty(name, jcrValue);
+        }
+    }
+
+    private void createProperty(String name, Object[] values, boolean overwriteExisting)
+    throws RepositoryException {
+        final Node node = this.parentNodeStack.peek();
+        // check if the property already exists, don't overwrite it in this case
+        if (node.hasProperty(name)
+            && !node.getProperty(name).isNew() && !overwriteExisting) {
+            return;
+        }
+        if ( values == null || values.length == 0 ) {
+            if ( node.hasProperty(name) ) {
+                node.getProperty(name).remove();
+            }
+        } else {
+            final Value[] jcrValues = new Value[values.length];
+            for(int i = 0; i < values.length; i++) {
+                jcrValues[i] = this.createValue(node.getSession().getValueFactory(), values[i]);
+            }
+            node.setProperty(name, jcrValues);
+        }
+    }
+
     /**
      * @see org.apache.sling.jcr.contentloader.internal.ContentCreator#createFileAndResourceNode(java.lang.String, java.io.InputStream, java.lang.String, long)
      */
@@ -626,12 +636,15 @@ public class DefaultContentCreator imple
         final Node parentNode = this.parentNodeStack.peek();
 
         // if node already exists but should be overwritten, delete it
-        if (this.configuration.isOverwrite() && parentNode.hasNode(name)) {
-            parentNode.getNode(name).remove();
-        } else if (parentNode.hasNode(name)) {
+        if (parentNode.hasNode(name)) {
             this.parentNodeStack.push(parentNode.getNode(name));
             this.parentNodeStack.push(parentNode.getNode(name).getNode("jcr:content"));
-            return;
+            if (!this.configuration.isOverwrite()) {
+                return;
+            }
+        } else {
+            this.createNode(name, "nt:file", null);
+            this.createNode("jcr:content", "nt:resource", null);
         }
 
         // ensure content type
@@ -649,12 +662,9 @@ public class DefaultContentCreator imple
         if (lastModified <= 0) {
             lastModified = System.currentTimeMillis();
         }
-
-        this.createNode(name, "nt:file", null);
-        this.createNode("jcr:content", "nt:resource", null);
-        this.createProperty("jcr:mimeType", mimeType);
-        this.createProperty("jcr:lastModified", lastModified);
-        this.createProperty("jcr:data", data);
+        this.createProperty("jcr:mimeType", mimeType, true);
+        this.createProperty("jcr:lastModified", lastModified, true);
+        this.createProperty("jcr:data", data, true);
     }
 
     /**