1 package org
.argeo
.jcr
.fs
;
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
;
14 import javax
.jcr
.Node
;
15 import javax
.jcr
.RepositoryException
;
16 import javax
.jcr
.Session
;
18 import org
.argeo
.jcr
.JcrUtils
;
20 public class JcrFileSystem
extends FileSystem
{
21 private final JcrFileSystemProvider provider
;
22 private final Session session
;
23 private String userHomePath
= null;
25 public JcrFileSystem(JcrFileSystemProvider provider
, Session session
) throws IOException
{
27 this.provider
= provider
;
28 this.session
= session
;
29 Node userHome
= provider
.getUserHome(session
);
32 userHomePath
= userHome
.getPath();
33 } catch (RepositoryException e
) {
34 throw new IOException("Cannot retrieve user home path", e
);
38 public String
getUserHomePath() {
43 public FileSystemProvider
provider() {
48 public void close() throws IOException
{
49 JcrUtils
.logoutQuietly(session
);
53 public boolean isOpen() {
54 return session
.isLive();
58 public boolean isReadOnly() {
63 public String
getSeparator() {
68 public Iterable
<Path
> getRootDirectories() {
70 Set
<Path
> single
= new HashSet
<>();
71 single
.add(new JcrPath(this, session
.getRootNode()));
73 } catch (RepositoryException e
) {
74 throw new JcrFsException("Cannot get root path", e
);
79 public Iterable
<FileStore
> getFileStores() {
80 throw new UnsupportedOperationException();
84 public Set
<String
> supportedFileAttributeViews() {
86 String
[] prefixes
= session
.getNamespacePrefixes();
87 Set
<String
> res
= new HashSet
<>();
88 for (String prefix
: prefixes
)
92 } catch (RepositoryException e
) {
93 throw new JcrFsException("Cannot get supported file attributes views", e
);
98 public Path
getPath(String first
, String
... more
) {
99 StringBuilder sb
= new StringBuilder(first
);
100 // TODO Make it more robust
101 for (String part
: more
)
102 sb
.append('/').append(part
);
103 return new JcrPath(this, sb
.toString());
107 public PathMatcher
getPathMatcher(String syntaxAndPattern
) {
108 throw new UnsupportedOperationException();
112 public UserPrincipalLookupService
getUserPrincipalLookupService() {
113 throw new UnsupportedOperationException();
117 public WatchService
newWatchService() throws IOException
{
118 throw new UnsupportedOperationException();
121 public Session
getSession() {