]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - JcrBasicfileAttributes.java
7ce9ca6674e4d3cff9e7d5241fcb8652b9d821d8
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 if (node
.isNodeType(NodeType
.NT_FOLDER
))
68 // all other non file nodes
69 return !(node
.isNodeType(NodeType
.NT_FILE
) || node
.isNodeType(NodeType
.NT_LINKED_FILE
));
70 } catch (RepositoryException e
) {
71 throw new JcrFsException("Cannot check if directory", e
);
76 public boolean isSymbolicLink() {
78 return node
.isNodeType(NodeType
.NT_LINKED_FILE
);
79 } catch (RepositoryException e
) {
80 throw new JcrFsException("Cannot check if linked file", e
);
85 public boolean isOther() {
86 return !(isDirectory() || isRegularFile() || isSymbolicLink());
91 if (isRegularFile()) {
94 binary
= node
.getNode(Property
.JCR_CONTENT
).getProperty(Property
.JCR_DATA
).getBinary();
95 return binary
.getSize();
96 } catch (RepositoryException e
) {
97 throw new JcrFsException("Cannot check size", e
);
99 JcrUtils
.closeQuietly(binary
);
106 public Object
fileKey() {
111 public Node
getNode() {