]> git.argeo.org Git - lgpl/argeo-commons.git/blob - fs/JcrFileSystem.java
Prepare next development cycle
[lgpl/argeo-commons.git] / 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.RepositoryException;
15 import javax.jcr.Session;
16
17 import org.argeo.jcr.JcrUtils;
18
19 public class JcrFileSystem extends FileSystem {
20 private final JcrFileSystemProvider provider;
21 private final Session session;
22
23 public JcrFileSystem(JcrFileSystemProvider provider, Session session) {
24 super();
25 this.provider = provider;
26 this.session = session;
27 }
28
29 @Override
30 public FileSystemProvider provider() {
31 return provider;
32 }
33
34 @Override
35 public void close() throws IOException {
36 JcrUtils.logoutQuietly(session);
37 }
38
39 @Override
40 public boolean isOpen() {
41 return session.isLive();
42 }
43
44 @Override
45 public boolean isReadOnly() {
46 return false;
47 }
48
49 @Override
50 public String getSeparator() {
51 return "/";
52 }
53
54 @Override
55 public Iterable<Path> getRootDirectories() {
56 try {
57 Set<Path> single = new HashSet<>();
58 single.add(new JcrPath(this, session.getRootNode()));
59 return single;
60 } catch (RepositoryException e) {
61 throw new JcrFsException("Cannot get root path", e);
62 }
63 }
64
65 @Override
66 public Iterable<FileStore> getFileStores() {
67 throw new UnsupportedOperationException();
68 }
69
70 @Override
71 public Set<String> supportedFileAttributeViews() {
72 try {
73 String[] prefixes = session.getNamespacePrefixes();
74 Set<String> res = new HashSet<>();
75 for (String prefix : prefixes)
76 res.add(prefix);
77 res.add("basic");
78 return res;
79 } catch (RepositoryException e) {
80 throw new JcrFsException("Cannot get supported file attributes views", e);
81 }
82 }
83
84 @Override
85 public Path getPath(String first, String... more) {
86 StringBuilder sb = new StringBuilder(first);
87 // TODO Make it more robust
88 for (String part : more)
89 sb.append('/').append(part);
90 return new JcrPath(this, sb.toString());
91 }
92
93 @Override
94 public PathMatcher getPathMatcher(String syntaxAndPattern) {
95 throw new UnsupportedOperationException();
96 }
97
98 @Override
99 public UserPrincipalLookupService getUserPrincipalLookupService() {
100 throw new UnsupportedOperationException();
101 }
102
103 @Override
104 public WatchService newWatchService() throws IOException {
105 throw new UnsupportedOperationException();
106 }
107
108 public Session getSession() {
109 return session;
110 }
111
112 }