X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2Ffs%2FJcrBasicfileAttributes.java;h=f9f605eee60e989408b22bec6fe45306f7eee858;hb=25e4528153640a2e211e217468f8f5aa01607cf0;hp=7ce9ca6674e4d3cff9e7d5241fcb8652b9d821d8;hpb=17f36c3a0db9f665ae4826f1057a6249f31621b0;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/src/org/argeo/jcr/fs/JcrBasicfileAttributes.java b/org.argeo.jcr/src/org/argeo/jcr/fs/JcrBasicfileAttributes.java index 7ce9ca667..f9f605eee 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/fs/JcrBasicfileAttributes.java +++ b/org.argeo.jcr/src/org/argeo/jcr/fs/JcrBasicfileAttributes.java @@ -1,5 +1,8 @@ package org.argeo.jcr.fs; +import static javax.jcr.Property.JCR_CREATED; +import static javax.jcr.Property.JCR_LAST_MODIFIED; + import java.nio.file.attribute.FileTime; import java.time.Instant; @@ -14,19 +17,28 @@ import org.argeo.jcr.JcrUtils; public class JcrBasicfileAttributes implements NodeFileAttributes { private final Node node; - private FileTime EPOCH = FileTime.fromMillis(0); + private final static FileTime EPOCH = FileTime.fromMillis(0); public JcrBasicfileAttributes(Node node) { + if (node == null) + throw new JcrFsException("Node underlying the attributes cannot be null"); this.node = node; } @Override public FileTime lastModifiedTime() { try { - if (node.isNodeType(NodeType.MIX_LAST_MODIFIED)) { - Instant instant = node.getProperty(Property.JCR_LAST_MODIFIED).getDate().toInstant(); + if (node.hasProperty(JCR_LAST_MODIFIED)) { + Instant instant = node.getProperty(JCR_LAST_MODIFIED).getDate().toInstant(); + return FileTime.from(instant); + } else if (node.hasProperty(JCR_CREATED)) { + Instant instant = node.getProperty(JCR_CREATED).getDate().toInstant(); return FileTime.from(instant); } +// if (node.isNodeType(NodeType.MIX_LAST_MODIFIED)) { +// Instant instant = node.getProperty(Property.JCR_LAST_MODIFIED).getDate().toInstant(); +// return FileTime.from(instant); +// } return EPOCH; } catch (RepositoryException e) { throw new JcrFsException("Cannot get last modified time", e); @@ -41,10 +53,17 @@ public class JcrBasicfileAttributes implements NodeFileAttributes { @Override public FileTime creationTime() { try { - if (node.isNodeType(NodeType.MIX_CREATED)) { - Instant instant = node.getProperty(Property.JCR_CREATED).getDate().toInstant(); + if (node.hasProperty(JCR_CREATED)) { + Instant instant = node.getProperty(JCR_CREATED).getDate().toInstant(); + return FileTime.from(instant); + } else if (node.hasProperty(JCR_LAST_MODIFIED)) { + Instant instant = node.getProperty(JCR_LAST_MODIFIED).getDate().toInstant(); return FileTime.from(instant); } +// if (node.isNodeType(NodeType.MIX_CREATED)) { +// Instant instant = node.getProperty(JCR_CREATED).getDate().toInstant(); +// return FileTime.from(instant); +// } return EPOCH; } catch (RepositoryException e) { throw new JcrFsException("Cannot get creation time", e);