]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java
Disable debug in file visitor.
[lgpl/argeo-commons.git] / org.argeo.jcr / src / org / argeo / jcr / fs / JcrFileSystem.java
1 package org.argeo.jcr.fs;
2
3 import java.io.IOException;
4 import java.nio.file.FileStore;
5 import java.nio.file.FileSystem;
6 import java.nio.file.Path;
7 import java.nio.file.PathMatcher;
8 import java.nio.file.WatchService;
9 import java.nio.file.attribute.UserPrincipalLookupService;
10 import java.nio.file.spi.FileSystemProvider;
11 import java.util.HashSet;
12 import java.util.Set;
13
14 import javax.jcr.Node;
15 import javax.jcr.RepositoryException;
16 import javax.jcr.Session;
17 import javax.jcr.nodetype.NodeType;
18
19 import org.argeo.jcr.JcrUtils;
20
21 public class JcrFileSystem extends FileSystem {
22 private final JcrFileSystemProvider provider;
23 private final Session session;
24 private String userHomePath = null;
25
26 public JcrFileSystem(JcrFileSystemProvider provider, Session session) throws IOException {
27 super();
28 this.provider = provider;
29 this.session = session;
30 Node userHome = provider.getUserHome(session);
31 if (userHome != null)
32 try {
33 userHomePath = userHome.getPath();
34 } catch (RepositoryException e) {
35 throw new IOException("Cannot retrieve user home path", e);
36 }
37 }
38
39 /** Whetehr this node should be skippe din directory listings */
40 public boolean skipNode(Node node) throws RepositoryException {
41 if (node.isNodeType(NodeType.NT_HIERARCHY_NODE) || node.isNodeType("node:userHome")
42 || node.isNodeType("node:groupHome"))
43 return false;
44 return true;
45 }
46
47 public String getUserHomePath() {
48 return userHomePath;
49 }
50
51 @Override
52 public FileSystemProvider provider() {
53 return provider;
54 }
55
56 @Override
57 public void close() throws IOException {
58 JcrUtils.logoutQuietly(session);
59 }
60
61 @Override
62 public boolean isOpen() {
63 return session.isLive();
64 }
65
66 @Override
67 public boolean isReadOnly() {
68 return false;
69 }
70
71 @Override
72 public String getSeparator() {
73 return "/";
74 }
75
76 @Override
77 public Iterable<Path> getRootDirectories() {
78 try {
79 Set<Path> single = new HashSet<>();
80 single.add(new JcrPath(this, session.getRootNode()));
81 return single;
82 } catch (RepositoryException e) {
83 throw new JcrFsException("Cannot get root path", e);
84 }
85 }
86
87 @Override
88 public Iterable<FileStore> getFileStores() {
89 throw new UnsupportedOperationException();
90 }
91
92 @Override
93 public Set<String> supportedFileAttributeViews() {
94 try {
95 String[] prefixes = session.getNamespacePrefixes();
96 Set<String> res = new HashSet<>();
97 for (String prefix : prefixes)
98 res.add(prefix);
99 res.add("basic");
100 return res;
101 } catch (RepositoryException e) {
102 throw new JcrFsException("Cannot get supported file attributes views", e);
103 }
104 }
105
106 @Override
107 public Path getPath(String first, String... more) {
108 StringBuilder sb = new StringBuilder(first);
109 // TODO Make it more robust
110 for (String part : more)
111 sb.append('/').append(part);
112 return new JcrPath(this, sb.toString());
113 }
114
115 @Override
116 public PathMatcher getPathMatcher(String syntaxAndPattern) {
117 throw new UnsupportedOperationException();
118 }
119
120 @Override
121 public UserPrincipalLookupService getUserPrincipalLookupService() {
122 throw new UnsupportedOperationException();
123 }
124
125 @Override
126 public WatchService newWatchService() throws IOException {
127 throw new UnsupportedOperationException();
128 }
129
130 public Session getSession() {
131 return session;
132 }
133
134 }