X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2FJcrUtils.java;h=416d035f8b5925555e421c46ede06e21e85dd231;hb=2afabd9e7b225f80b341063e25188314394c9aef;hp=3e7c8737403ed969378e9c93972508abea85293b;hpb=5ec9d72c96b13bf18d702bf01dc2c03b0aee43a4;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java b/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java index 3e7c87374..416d035f8 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java +++ b/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java @@ -1308,23 +1308,30 @@ public class JcrUtils { return true; } - /** Gets access control list for this path, throws exception if not found */ + /** + * Gets the first available access control list for this path, throws exception + * if not found + */ public synchronized static AccessControlList getAccessControlList(AccessControlManager acm, String path) throws RepositoryException { // search for an access control list AccessControlList acl = null; AccessControlPolicyIterator policyIterator = acm.getApplicablePolicies(path); - if (policyIterator.hasNext()) { + applicablePolicies: if (policyIterator.hasNext()) { while (policyIterator.hasNext()) { AccessControlPolicy acp = policyIterator.nextAccessControlPolicy(); - if (acp instanceof AccessControlList) + if (acp instanceof AccessControlList) { acl = ((AccessControlList) acp); + break applicablePolicies; + } } } else { AccessControlPolicy[] existingPolicies = acm.getPolicies(path); - for (AccessControlPolicy acp : existingPolicies) { - if (acp instanceof AccessControlList) + existingPolicies: for (AccessControlPolicy acp : existingPolicies) { + if (acp instanceof AccessControlList) { acl = ((AccessControlList) acp); + break existingPolicies; + } } } if (acl != null) @@ -1497,7 +1504,7 @@ public class JcrUtils { contentNode = fileNode.getNode(Node.JCR_CONTENT); } else { fileNode = folderNode.addNode(fileName, NodeType.NT_FILE); - contentNode = fileNode.addNode(Node.JCR_CONTENT, NodeType.NT_RESOURCE); + contentNode = fileNode.addNode(Node.JCR_CONTENT, NodeType.NT_UNSTRUCTURED); } binary = contentNode.getSession().getValueFactory().createBinary(in); contentNode.setProperty(Property.JCR_DATA, binary); @@ -1509,6 +1516,11 @@ public class JcrUtils { } } + /** Read an an nt:file as an {@link InputStream}. */ + public static InputStream getFileAsStream(Node fileNode) throws RepositoryException { + return fileNode.getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA).getBinary().getStream(); + } + /** * Computes the checksum of an nt:file. * @@ -1516,14 +1528,11 @@ public class JcrUtils { */ @Deprecated public static String checksumFile(Node fileNode, String algorithm) { - Binary data = null; try (InputStream in = fileNode.getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA).getBinary() .getStream()) { return digest(algorithm, in); } catch (RepositoryException | IOException e) { throw new ArgeoJcrException("Cannot checksum file " + fileNode, e); - } finally { - closeQuietly(data); } }