[exo-jcr-commits] exo-jcr SVN: r272 - in jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav: command and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Oct 13 05:43:21 EDT 2009


Author: dkatayev
Date: 2009-10-13 05:43:21 -0400 (Tue, 13 Oct 2009)
New Revision: 272

Modified:
   jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
   jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java
Log:
EXOJCR-28 auto-version parameter support added.

Modified: jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
===================================================================
--- jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java	2009-10-13 07:27:19 UTC (rev 271)
+++ jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java	2009-10-13 09:43:21 UTC (rev 272)
@@ -125,6 +125,11 @@
     * Initialization initialization "update-policy"-parameter value.
     */
    public static final String INIT_PARAM_UPDATE_POLICY = "update-policy";
+   
+   /**
+    * Initialization "auto-version"-parameter value.
+    */
+   public static final String INIT_PARAM_AUTO_VERSION = "auto-version";
 
    /**
     * Logger.
@@ -165,6 +170,11 @@
     * Update policy.
     */
    private String updatePolicyType = "create-version";
+   
+   /**
+    * Auto-version default value.
+    */
+   private String autoVersionType = "checkout-checkin";
 
    /**
     * The list of allowed methods.
@@ -234,6 +244,13 @@
          updatePolicyType = pUpdatePolicy.getValue();
          log.info(INIT_PARAM_UPDATE_POLICY + " = " + updatePolicyType);
       }
+      
+      ValueParam pAutoVersion = params.getValueParam(INIT_PARAM_AUTO_VERSION);
+      if (pAutoVersion != null)
+      {
+         autoVersionType = pAutoVersion.getValue();
+         log.info(INIT_PARAM_AUTO_VERSION + " = " + autoVersionType);
+      }
 
    }
 
@@ -938,7 +955,7 @@
          NodeTypeUtil.checkContentResourceType(nodeType);
 
          return new PutCommand(nullResourceLocks).put(session, path(repoPath), inputStream, fileNodeType,
-            contentNodeType, NodeTypeUtil.getMixinTypes(mixinTypes), mimeType, encoding, updatePolicyType, tokens);
+            contentNodeType, NodeTypeUtil.getMixinTypes(mixinTypes), mimeType, encoding, updatePolicyType, autoVersionType, tokens);
 
       }
       catch (NoSuchWorkspaceException exc)

Modified: jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java
===================================================================
--- jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java	2009-10-13 07:27:19 UTC (rev 271)
+++ jcr/trunk/component/webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java	2009-10-13 09:43:21 UTC (rev 272)
@@ -74,7 +74,8 @@
     * @return the instance of javax.ws.rs.core.Response
     */
    public Response put(Session session, String path, InputStream inputStream, String fileNodeType,
-      String contentNodeType, List<String> mixins, String mimeType, String encoding, String updatePolicyType, List<String> tokens)
+      String contentNodeType, List<String> mixins, String mimeType, String encoding, String updatePolicyType,
+      String autoVersion, List<String> tokens)
    {
 
       try
@@ -103,8 +104,16 @@
             if ("add".equals(updatePolicyType))
             {
                node = session.getRootNode().addNode(TextUtil.relativizePath(path), fileNodeType);
-               node.addNode("jcr:content", contentNodeType);
-               updateContent(node, inputStream, mimeType, encoding, mixins);
+               if (!node.isNodeType("mix:versionable"))
+               {
+                  node.addNode("jcr:content", contentNodeType);
+                  updateContent(node, inputStream, mimeType, encoding, mixins);
+               }
+               else
+               {
+                  updateVersion(node, inputStream, mimeType, autoVersion, encoding, mixins);
+               }
+
             }
             else if ("create-version".equals(updatePolicyType))
             {
@@ -112,7 +121,14 @@
             }
             else
             {
-               updateContent(node, inputStream, mimeType, encoding, mixins);
+               if (!node.isNodeType("mix:versionable"))
+               {
+                  updateContent(node, inputStream, mimeType, encoding, mixins);
+               }
+               else
+               {
+                  updateVersion(node, inputStream, mimeType, autoVersion, encoding, mixins);
+               }
             }
          }
 
@@ -146,8 +162,8 @@
     * @param mixins list of mixins
     * @throws RepositoryException {@link RepositoryException}
     */
-   private void createVersion(Node fileNode, InputStream inputStream, String mimeType, String encoding, List<String> mixins)
-      throws RepositoryException
+   private void createVersion(Node fileNode, InputStream inputStream, String mimeType, String encoding,
+      List<String> mixins) throws RepositoryException
    {
       if (!fileNode.isNodeType("mix:versionable"))
       {
@@ -188,7 +204,8 @@
 
       Node content = node.getNode("jcr:content");
       content.setProperty("jcr:mimeType", mimeType);
-      if (encoding != null) {
+      if (encoding != null)
+      {
          content.setProperty("jcr:encoding", encoding);
       }
       content.setProperty("jcr:lastModified", Calendar.getInstance());
@@ -205,4 +222,36 @@
 
    }
 
+   /**
+    * Updates the content of the versionable file according to auto-version value.
+    * 
+    * @param fileNode Node to update
+    * @param inputStream input stream that contains the content of
+    *          file
+    * @param mimeType content type
+    * @param autoVersion auto-version value
+    * @param mixins list of mixins
+    * @throws RepositoryException {@link RepositoryException}
+    */
+   private void updateVersion(Node fileNode, InputStream inputStream, String mimeType, String encoding,
+      String autoVersion, List<String> mixins) throws RepositoryException
+   {
+      if (!fileNode.isCheckedOut())
+      {
+         fileNode.checkout();
+         fileNode.getSession().save();
+      }
+      if ("checkout".equals(autoVersion))
+      {
+         updateContent(fileNode, inputStream, mimeType, encoding, mixins);
+      }
+      else if ("checkout-checkin".equals(autoVersion))
+      {
+         updateContent(fileNode, inputStream, mimeType, encoding, mixins);
+         fileNode.getSession().save();
+         fileNode.checkin();
+      }
+      fileNode.getSession().save();
+   }
+
 }



More information about the exo-jcr-commits mailing list