]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java
Make workspace indexer and JCR file system more robust.
[lgpl/argeo-commons.git] / org.argeo.jcr / src / org / argeo / jcr / fs / JcrFileSystem.java
index 40328e8a093c2fce05b3a84ac7032686052554fc..65edf1d91bffde5d44f23722888bde750c994d35 100644 (file)
@@ -8,20 +8,44 @@ import java.nio.file.PathMatcher;
 import java.nio.file.WatchService;
 import java.nio.file.attribute.UserPrincipalLookupService;
 import java.nio.file.spi.FileSystemProvider;
+import java.util.HashSet;
 import java.util.Set;
 
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
 
 import org.argeo.jcr.JcrUtils;
 
 public class JcrFileSystem extends FileSystem {
        private final JcrFileSystemProvider provider;
        private final Session session;
+       private String userHomePath = null;
 
-       public JcrFileSystem(JcrFileSystemProvider provider, Session session) {
+       public JcrFileSystem(JcrFileSystemProvider provider, Session session) throws IOException {
                super();
                this.provider = provider;
                this.session = session;
+               Node userHome = provider.getUserHome(session);
+               if (userHome != null)
+                       try {
+                               userHomePath = userHome.getPath();
+                       } catch (RepositoryException e) {
+                               throw new IOException("Cannot retrieve user home path", e);
+                       }
+       }
+
+       /** Whetehr this node should be skippe din directory listings */
+       public boolean skipNode(Node node) throws RepositoryException {
+               if (node.isNodeType(NodeType.NT_HIERARCHY_NODE) || node.isNodeType("node:userHome")
+                               || node.isNodeType("node:groupHome"))
+                       return false;
+               return true;
+       }
+
+       public String getUserHomePath() {
+               return userHomePath;
        }
 
        @Override
@@ -51,43 +75,56 @@ public class JcrFileSystem extends FileSystem {
 
        @Override
        public Iterable<Path> getRootDirectories() {
-               return null;
+               try {
+                       Set<Path> single = new HashSet<>();
+                       single.add(new JcrPath(this, session.getRootNode()));
+                       return single;
+               } catch (RepositoryException e) {
+                       throw new JcrFsException("Cannot get root path", e);
+               }
        }
 
        @Override
        public Iterable<FileStore> getFileStores() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new UnsupportedOperationException();
        }
 
        @Override
        public Set<String> supportedFileAttributeViews() {
-               // TODO Auto-generated method stub
-               return null;
+               try {
+                       String[] prefixes = session.getNamespacePrefixes();
+                       Set<String> res = new HashSet<>();
+                       for (String prefix : prefixes)
+                               res.add(prefix);
+                       res.add("basic");
+                       return res;
+               } catch (RepositoryException e) {
+                       throw new JcrFsException("Cannot get supported file attributes views", e);
+               }
        }
 
        @Override
        public Path getPath(String first, String... more) {
-               // TODO Auto-generated method stub
-               return null;
+               StringBuilder sb = new StringBuilder(first);
+               // TODO Make it more robust
+               for (String part : more)
+                       sb.append('/').append(part);
+               return new JcrPath(this, sb.toString());
        }
 
        @Override
        public PathMatcher getPathMatcher(String syntaxAndPattern) {
-               // TODO Auto-generated method stub
-               return null;
+               throw new UnsupportedOperationException();
        }
 
        @Override
        public UserPrincipalLookupService getUserPrincipalLookupService() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new UnsupportedOperationException();
        }
 
        @Override
        public WatchService newWatchService() throws IOException {
-               // TODO Auto-generated method stub
-               return null;
+               throw new UnsupportedOperationException();
        }
 
        public Session getSession() {