]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr/src/org/argeo/jcr/fs/JcrBasicfileAttributes.java
1 package org
.argeo
.jcr
.fs
;
3 import static javax
.jcr
.Property
.JCR_CREATED
;
4 import static javax
.jcr
.Property
.JCR_LAST_MODIFIED
;
6 import java
.nio
.file
.attribute
.FileTime
;
7 import java
.time
.Instant
;
9 import javax
.jcr
.Binary
;
10 import javax
.jcr
.Node
;
11 import javax
.jcr
.Property
;
12 import javax
.jcr
.RepositoryException
;
13 import javax
.jcr
.nodetype
.NodeType
;
15 import org
.argeo
.jcr
.JcrUtils
;
17 public class JcrBasicfileAttributes
implements NodeFileAttributes
{
18 private final Node node
;
20 private final static FileTime EPOCH
= FileTime
.fromMillis(0);
22 public JcrBasicfileAttributes(Node node
) {
24 throw new JcrFsException("Node underlying the attributes cannot be null");
29 public FileTime
lastModifiedTime() {
31 if (node
.hasProperty(JCR_LAST_MODIFIED
)) {
32 Instant instant
= node
.getProperty(JCR_LAST_MODIFIED
).getDate().toInstant();
33 return FileTime
.from(instant
);
34 } else if (node
.hasProperty(JCR_CREATED
)) {
35 Instant instant
= node
.getProperty(JCR_CREATED
).getDate().toInstant();
36 return FileTime
.from(instant
);
38 // if (node.isNodeType(NodeType.MIX_LAST_MODIFIED)) {
39 // Instant instant = node.getProperty(Property.JCR_LAST_MODIFIED).getDate().toInstant();
40 // return FileTime.from(instant);
43 } catch (RepositoryException e
) {
44 throw new JcrFsException("Cannot get last modified time", e
);
49 public FileTime
lastAccessTime() {
50 return lastModifiedTime();
54 public FileTime
creationTime() {
56 if (node
.hasProperty(JCR_CREATED
)) {
57 Instant instant
= node
.getProperty(JCR_CREATED
).getDate().toInstant();
58 return FileTime
.from(instant
);
59 } else if (node
.hasProperty(JCR_LAST_MODIFIED
)) {
60 Instant instant
= node
.getProperty(JCR_LAST_MODIFIED
).getDate().toInstant();
61 return FileTime
.from(instant
);
63 // if (node.isNodeType(NodeType.MIX_CREATED)) {
64 // Instant instant = node.getProperty(JCR_CREATED).getDate().toInstant();
65 // return FileTime.from(instant);
68 } catch (RepositoryException e
) {
69 throw new JcrFsException("Cannot get creation time", e
);
74 public boolean isRegularFile() {
76 return node
.isNodeType(NodeType
.NT_FILE
);
77 } catch (RepositoryException e
) {
78 throw new JcrFsException("Cannot check if regular file", e
);
83 public boolean isDirectory() {
85 if (node
.isNodeType(NodeType
.NT_FOLDER
))
87 // all other non file nodes
88 return !(node
.isNodeType(NodeType
.NT_FILE
) || node
.isNodeType(NodeType
.NT_LINKED_FILE
));
89 } catch (RepositoryException e
) {
90 throw new JcrFsException("Cannot check if directory", e
);
95 public boolean isSymbolicLink() {
97 return node
.isNodeType(NodeType
.NT_LINKED_FILE
);
98 } catch (RepositoryException e
) {
99 throw new JcrFsException("Cannot check if linked file", e
);
104 public boolean isOther() {
105 return !(isDirectory() || isRegularFile() || isSymbolicLink());
110 if (isRegularFile()) {
111 Binary binary
= null;
113 binary
= node
.getNode(Property
.JCR_CONTENT
).getProperty(Property
.JCR_DATA
).getBinary();
114 return binary
.getSize();
115 } catch (RepositoryException e
) {
116 throw new JcrFsException("Cannot check size", e
);
118 JcrUtils
.closeQuietly(binary
);
125 public Object
fileKey() {
127 return node
.getIdentifier();
128 } catch (RepositoryException e
) {
129 throw new JcrFsException("Cannot get identifier", e
);
134 public Node
getNode() {