You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by sa...@apache.org on 2011/06/09 15:59:59 UTC

svn commit: r1133876 - /ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java

Author: sascharodekamp
Date: Thu Jun  9 13:59:59 2011
New Revision: 1133876

URL: http://svn.apache.org/viewvc?rev=1133876&view=rev
Log:
Update - Extend the file upload/update function to generate new file versions after an update.

Modified:
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java

Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java?rev=1133876&r1=1133875&r2=1133876&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java Thu Jun  9 13:59:59 2011
@@ -530,18 +530,35 @@ public class OfbizRepositoryMappingJackr
             language = UtilProperties.getPropertyValue("general", "locale.properties.fallback");
         }
 
-        Node folder = (Node) createNewRepositoryNode(this.node.getPath() + "/" + fileName, PROPERTY_FIELDS.FILE.getType()).get("node");
+        Node folder = null;
+        // set an indicator if the file should be updated or not
+        Boolean update = Boolean.FALSE;
+        // check if the node already exists, if not create else update
+        if (!this.node.hasNode(fileName)) {
+            folder = (Node) createNewRepositoryNode(this.node.getPath() + "/" + fileName, PROPERTY_FIELDS.FILE.getType()).get("node");
+            folder.addMixin(PROPERTY_FIELDS.mixInLANGUAGE.getType());
+            folder.addMixin(PROPERTY_FIELDS.mixInTITLE.getType());
+        } else {
+            folder = this.node.getNode(fileName);
+            checkOutNode(folder);
+            update = Boolean.TRUE;
+        }
+
 
         // set additional file informations
-        folder.addMixin(PROPERTY_FIELDS.mixInLANGUAGE.getType());
-        folder.addMixin(PROPERTY_FIELDS.mixInTITLE.getType());
         folder.setProperty(PROPERTY_FIELDS.LANGUAGE.getType(), language);
         folder.setProperty(PROPERTY_FIELDS.TITLE.getType(), fileName);
         if (UtilValidate.isNotEmpty(description)) {
             folder.setProperty(PROPERTY_FIELDS.DESCRIPTION.getType(), description);
         }
 
-        Node resource = (Node) createNewRepositoryNode(folder.getPath() + "/jcr:content", PROPERTY_FIELDS.RESOURCE.getType()).get("node");
+        Node resource = null;
+        if(!update) {
+            resource = (Node) createNewRepositoryNode(folder.getPath() + "/jcr:content", PROPERTY_FIELDS.RESOURCE.getType()).get("node");
+        } else {
+            resource = folder.getNode("jcr:content");
+            checkOutNode(resource);
+        }
         Binary binary = this.session.getValueFactory().createBinary(file);
 
         String mimeType = getMimeTypeFromInputStream(file);
@@ -1044,7 +1061,7 @@ public class OfbizRepositoryMappingJackr
     }
 
     /**
-     * Get the node object from the repository. If an exceptions rasises null
+     * Get the node object from the repository. If an exceptions raises null
      * will be returned.
      *
      * @param nodePath