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
;
17 import javax
.jcr
.nodetype
.NodeType
;
19 import org
.argeo
.jcr
.JcrUtils
;
21 public class JcrFileSystem
extends FileSystem
{
22 private final JcrFileSystemProvider provider
;
23 private final Session session
;
24 private String userHomePath
= null;
26 public JcrFileSystem(JcrFileSystemProvider provider
, Session session
) throws IOException
{
28 this.provider
= provider
;
29 this.session
= session
;
30 Node userHome
= provider
.getUserHome(session
);
33 userHomePath
= userHome
.getPath();
34 } catch (RepositoryException e
) {
35 throw new IOException("Cannot retrieve user home path", e
);
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"))
47 public String
getUserHomePath() {
52 public FileSystemProvider
provider() {
57 public void close() throws IOException
{
58 JcrUtils
.logoutQuietly(session
);
62 public boolean isOpen() {
63 return session
.isLive();
67 public boolean isReadOnly() {
72 public String
getSeparator() {
77 public Iterable
<Path
> getRootDirectories() {
79 Set
<Path
> single
= new HashSet
<>();
80 single
.add(new JcrPath(this, session
.getRootNode()));
82 } catch (RepositoryException e
) {
83 throw new JcrFsException("Cannot get root path", e
);
88 public Iterable
<FileStore
> getFileStores() {
89 throw new UnsupportedOperationException();
93 public Set
<String
> supportedFileAttributeViews() {
95 String
[] prefixes
= session
.getNamespacePrefixes();
96 Set
<String
> res
= new HashSet
<>();
97 for (String prefix
: prefixes
)
101 } catch (RepositoryException e
) {
102 throw new JcrFsException("Cannot get supported file attributes views", e
);
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());
116 public PathMatcher
getPathMatcher(String syntaxAndPattern
) {
117 throw new UnsupportedOperationException();
121 public UserPrincipalLookupService
getUserPrincipalLookupService() {
122 throw new UnsupportedOperationException();
126 public WatchService
newWatchService() throws IOException
{
127 throw new UnsupportedOperationException();
130 public Session
getSession() {