incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r801743 - /sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java
Date Thu, 06 Aug 2009 17:46:03 GMT
Author: ieb
Date: Thu Aug  6 17:46:03 2009
New Revision: 801743

URL: http://svn.apache.org/viewvc?rev=801743&view=rev
Log:
SLING-1073 Patch from Arthur Taylor
Fixes re-creation of node on upload loosing potential versioning information.
Thanks

Modified:
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java?rev=801743&r1=801742&r2=801743&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java
Thu Aug  6 17:46:03 2009
@@ -155,17 +155,11 @@
                 typeHint = createNtFile ? NT_FILE : NT_RESOURCE;
             }
 
-            // remove node
-            if (parent.hasNode(name)) {
-                parent.getNode(name).remove();
-            }
-
             // create nt:file node if needed
             Node resParent;
             if (createNtFile) {
                 // create nt:file
-                resParent = parent.addNode(name, typeHint);
-                changes.add(Modification.onCreated(resParent.getPath()));
+                resParent = getOrCreateChildNode(parent, name, typeHint, changes);
                 name = JCR_CONTENT;
                 typeHint = NT_RESOURCE;
             } else {
@@ -173,8 +167,7 @@
             }
 
             // create resource node
-            Node res = resParent.addNode(name, typeHint);
-            changes.add(Modification.onCreated(res.getPath()));
+            Node res = getOrCreateChildNode(resParent, name, typeHint, changes);
 
             // get content type
             String contentType = value.getContentType();
@@ -208,4 +201,29 @@
             }
 		}
     }
+
+    private Node getOrCreateChildNode(Node parent, String name, String typeHint,
+            List<Modification> changes) throws RepositoryException {
+        Node result;
+        if (parent.hasNode(name)) {
+            Node existing = parent.getNode(name);
+            if (!existing.isNodeType(typeHint)) {
+                existing.remove();
+                result = createWithChanges(parent, name, typeHint, changes);
+            } else {
+                result = existing;
+            }
+        } else {
+            result = createWithChanges(parent, name, typeHint, changes);
+        }
+        return result;
+    }
+
+    private Node createWithChanges(Node parent, String name, String typeHint, 
+            List<Modification> changes) throws RepositoryException {
+        Node result = parent.addNode(name, typeHint);
+        changes.add(Modification.onCreated(result.getPath()));
+        return result;
+    }
+
 }
\ No newline at end of file



Mime
View raw message