]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr/src/org/argeo/jcr/fs/JcrBasicfileAttributes.java
e59abbc70a8a1fc1f65556c4208b7946eb2c5b96
1 package org
.argeo
.jcr
.fs
;
3 import java
.nio
.file
.attribute
.FileTime
;
4 import java
.time
.Instant
;
6 import javax
.jcr
.Binary
;
8 import javax
.jcr
.Property
;
9 import javax
.jcr
.RepositoryException
;
10 import javax
.jcr
.nodetype
.NodeType
;
12 import org
.argeo
.jcr
.JcrUtils
;
14 public class JcrBasicfileAttributes
implements NodeFileAttributes
{
15 private final Node node
;
17 private FileTime EPOCH
= FileTime
.fromMillis(0);
19 public JcrBasicfileAttributes(Node node
) {
24 public FileTime
lastModifiedTime() {
26 if (node
.isNodeType(NodeType
.MIX_LAST_MODIFIED
)) {
27 Instant instant
= node
.getProperty(Property
.JCR_LAST_MODIFIED
).getDate().toInstant();
28 return FileTime
.from(instant
);
31 } catch (RepositoryException e
) {
32 throw new JcrFsException("Cannot get last modified time", e
);
37 public FileTime
lastAccessTime() {
38 return lastModifiedTime();
42 public FileTime
creationTime() {
44 if (node
.isNodeType(NodeType
.MIX_CREATED
)) {
45 Instant instant
= node
.getProperty(Property
.JCR_CREATED
).getDate().toInstant();
46 return FileTime
.from(instant
);
49 } catch (RepositoryException e
) {
50 throw new JcrFsException("Cannot get creation time", e
);
55 public boolean isRegularFile() {
57 return node
.isNodeType(NodeType
.NT_FILE
);
58 } catch (RepositoryException e
) {
59 throw new JcrFsException("Cannot check if regular file", e
);
64 public boolean isDirectory() {
66 return node
.isNodeType(NodeType
.NT_FOLDER
);
67 } catch (RepositoryException e
) {
68 throw new JcrFsException("Cannot check if directory", e
);
73 public boolean isSymbolicLink() {
75 return node
.isNodeType(NodeType
.NT_LINKED_FILE
);
76 } catch (RepositoryException e
) {
77 throw new JcrFsException("Cannot check if linked file", e
);
82 public boolean isOther() {
83 return !(isDirectory() || isRegularFile() || isSymbolicLink());
88 if (isRegularFile()) {
91 binary
= node
.getNode(Property
.JCR_DATA
).getProperty(Property
.JCR_CONTENT
).getBinary();
92 return binary
.getSize();
93 } catch (RepositoryException e
) {
94 throw new JcrFsException("Cannot check size", e
);
96 JcrUtils
.closeQuietly(binary
);
103 public Object
fileKey() {
108 public Node
getNode() {