Introduce set mime type.
[lgpl/argeo-commons.git] / org.argeo.jcr / src / org / argeo / jcr / JcrUtils.java
index 79ae6cf62555afa9be184e8c80e431e654c46433..cb9fe6e471797a9289a7ff945c53d4530221ff33 100644 (file)
@@ -727,7 +727,7 @@ public class JcrUtils {
                Workspace fromWorkspace = fromSession.getWorkspace();
                Workspace toWorkspace = toSession.getWorkspace();
                String errorMsg = "Cannot copy workspace " + fromWorkspace + " to " + toWorkspace + " via XML.";
-               
+
                try (PipedInputStream in = new PipedInputStream(1024 * 1024);) {
                        new Thread(() -> {
                                try (PipedOutputStream out = new PipedOutputStream(in)) {
@@ -1468,6 +1468,8 @@ public class JcrUtils {
                // the new access control list must be applied otherwise this call:
                // acl.removeAccessControlEntry(ace); has no effect
                acm.setPolicy(path, acl);
+               session.refresh(true);
+               session.save();
        }
 
        /*
@@ -1619,6 +1621,7 @@ public class JcrUtils {
                        }
                        binary = contentNode.getSession().getValueFactory().createBinary(in);
                        contentNode.setProperty(Property.JCR_DATA, binary);
+                       updateLastModified(contentNode);
                        return fileNode;
                } catch (RepositoryException e) {
                        throw new JcrException("Cannot create file node " + fileName + " under " + folderNode, e);
@@ -1632,6 +1635,19 @@ public class JcrUtils {
                return fileNode.getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA).getBinary().getStream();
        }
 
+       /**
+        * Set the properties of {@link NodeType#MIX_MIMETYPE} on the content of this
+        * file node.
+        */
+       public static void setFileMimeType(Node fileNode, String mimeType, String encoding) throws RepositoryException {
+               Node contentNode = fileNode.getNode(Node.JCR_CONTENT);
+               if (mimeType != null)
+                       contentNode.setProperty(Property.JCR_MIMETYPE, mimeType);
+               if (encoding != null)
+                       contentNode.setProperty(Property.JCR_ENCODING, encoding);
+               // TODO remove properties if args are null?
+       }
+
        /**
         * Computes the checksum of an nt:file.
         *