Start working on JCR FS
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 28 Nov 2015 09:12:16 +0000 (09:12 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 28 Nov 2015 09:12:16 +0000 (09:12 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@8649 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileStore.java [new file with mode: 0644]
org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java [new file with mode: 0644]
org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java [new file with mode: 0644]
org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFsException.java [new file with mode: 0644]
org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrPath.java [new file with mode: 0644]

diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileStore.java b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileStore.java
new file mode 100644 (file)
index 0000000..32a3ecb
--- /dev/null
@@ -0,0 +1,72 @@
+package org.argeo.jcr.fs;
+
+import java.io.IOException;
+import java.nio.file.FileStore;
+import java.nio.file.attribute.FileAttributeView;
+import java.nio.file.attribute.FileStoreAttributeView;
+
+public class JcrFileStore extends FileStore {
+
+       @Override
+       public String name() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public String type() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public boolean isReadOnly() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public long getTotalSpace() throws IOException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public long getUsableSpace() throws IOException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public long getUnallocatedSpace() throws IOException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public boolean supportsFileAttributeView(
+                       Class<? extends FileAttributeView> type) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean supportsFileAttributeView(String name) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public <V extends FileStoreAttributeView> V getFileStoreAttributeView(
+                       Class<V> type) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Object getAttribute(String attribute) throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+}
diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java
new file mode 100644 (file)
index 0000000..40328e8
--- /dev/null
@@ -0,0 +1,97 @@
+package org.argeo.jcr.fs;
+
+import java.io.IOException;
+import java.nio.file.FileStore;
+import java.nio.file.FileSystem;
+import java.nio.file.Path;
+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.Set;
+
+import javax.jcr.Session;
+
+import org.argeo.jcr.JcrUtils;
+
+public class JcrFileSystem extends FileSystem {
+       private final JcrFileSystemProvider provider;
+       private final Session session;
+
+       public JcrFileSystem(JcrFileSystemProvider provider, Session session) {
+               super();
+               this.provider = provider;
+               this.session = session;
+       }
+
+       @Override
+       public FileSystemProvider provider() {
+               return provider;
+       }
+
+       @Override
+       public void close() throws IOException {
+               JcrUtils.logoutQuietly(session);
+       }
+
+       @Override
+       public boolean isOpen() {
+               return session.isLive();
+       }
+
+       @Override
+       public boolean isReadOnly() {
+               return false;
+       }
+
+       @Override
+       public String getSeparator() {
+               return "/";
+       }
+
+       @Override
+       public Iterable<Path> getRootDirectories() {
+               return null;
+       }
+
+       @Override
+       public Iterable<FileStore> getFileStores() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Set<String> supportedFileAttributeViews() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path getPath(String first, String... more) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public PathMatcher getPathMatcher(String syntaxAndPattern) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public UserPrincipalLookupService getUserPrincipalLookupService() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public WatchService newWatchService() throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public Session getSession() {
+               return session;
+       }
+
+}
diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java
new file mode 100644 (file)
index 0000000..8ea4cca
--- /dev/null
@@ -0,0 +1,142 @@
+package org.argeo.jcr.fs;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.channels.SeekableByteChannel;
+import java.nio.file.AccessMode;
+import java.nio.file.CopyOption;
+import java.nio.file.DirectoryStream;
+import java.nio.file.DirectoryStream.Filter;
+import java.nio.file.FileStore;
+import java.nio.file.FileSystem;
+import java.nio.file.LinkOption;
+import java.nio.file.OpenOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.FileAttributeView;
+import java.nio.file.spi.FileSystemProvider;
+import java.util.Map;
+import java.util.Set;
+
+public class JcrFileSystemProvider extends FileSystemProvider {
+
+       @Override
+       public String getScheme() {
+               return "jcr";
+       }
+
+       @Override
+       public FileSystem newFileSystem(URI uri, Map<String, ?> env)
+                       throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public FileSystem getFileSystem(URI uri) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path getPath(URI uri) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public SeekableByteChannel newByteChannel(Path path,
+                       Set<? extends OpenOption> options, FileAttribute<?>... attrs)
+                       throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public DirectoryStream<Path> newDirectoryStream(Path dir,
+                       Filter<? super Path> filter) throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void createDirectory(Path dir, FileAttribute<?>... attrs)
+                       throws IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public void delete(Path path) throws IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public void copy(Path source, Path target, CopyOption... options)
+                       throws IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public void move(Path source, Path target, CopyOption... options)
+                       throws IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public boolean isSameFile(Path path, Path path2) throws IOException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean isHidden(Path path) throws IOException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public FileStore getFileStore(Path path) throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void checkAccess(Path path, AccessMode... modes) throws IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public <V extends FileAttributeView> V getFileAttributeView(Path path,
+                       Class<V> type, LinkOption... options) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public <A extends BasicFileAttributes> A readAttributes(Path path,
+                       Class<A> type, LinkOption... options) throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Map<String, Object> readAttributes(Path path, String attributes,
+                       LinkOption... options) throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void setAttribute(Path path, String attribute, Object value,
+                       LinkOption... options) throws IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+}
diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFsException.java b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFsException.java
new file mode 100644 (file)
index 0000000..f214fdc
--- /dev/null
@@ -0,0 +1,15 @@
+package org.argeo.jcr.fs;
+
+
+/** Exception related to the JCR FS */
+public class JcrFsException extends RuntimeException {
+       private static final long serialVersionUID = -7973896038244922980L;
+
+       public JcrFsException(String message, Throwable e) {
+               super(message, e);
+       }
+
+       public JcrFsException(String message) {
+               super(message);
+       }
+}
diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrPath.java b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrPath.java
new file mode 100644 (file)
index 0000000..e252935
--- /dev/null
@@ -0,0 +1,199 @@
+package org.argeo.jcr.fs;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.WatchEvent.Kind;
+import java.nio.file.WatchEvent.Modifier;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchService;
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+public class JcrPath implements Path {
+       private JcrFileSystem filesSystem;
+       private String path;
+
+       private Node node;
+
+       public JcrPath(JcrFileSystem filesSystem, Node node) {
+               super();
+               this.filesSystem = filesSystem;
+               this.node = node;
+       }
+
+       @Override
+       public FileSystem getFileSystem() {
+               return filesSystem;
+       }
+
+       @Override
+       public boolean isAbsolute() {
+               return path.startsWith("/");
+       }
+
+       @Override
+       public Path getRoot() {
+               try {
+                       return new JcrPath(filesSystem, node.getSession().getRootNode());
+               } catch (RepositoryException e) {
+                       throw new JcrFsException("Cannot get root", e);
+               }
+       }
+
+       @Override
+       public Path getFileName() {
+               return null;
+       }
+
+       @Override
+       public Path getParent() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public int getNameCount() {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public Path getName(int index) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path subpath(int beginIndex, int endIndex) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public boolean startsWith(Path other) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean startsWith(String other) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean endsWith(Path other) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean endsWith(String other) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public Path normalize() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path resolve(Path other) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path resolve(String other) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path resolveSibling(Path other) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path resolveSibling(String other) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path relativize(Path other) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public URI toUri() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path toAbsolutePath() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Path toRealPath(LinkOption... options) throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public File toFile() {
+               throw new UnsupportedOperationException();
+       }
+
+       @Override
+       public WatchKey register(WatchService watcher, Kind<?>[] events,
+                       Modifier... modifiers) throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public WatchKey register(WatchService watcher, Kind<?>... events)
+                       throws IOException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Iterator<Path> iterator() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public int compareTo(Path other) {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       public Node getNode() {
+               if (!isAbsolute())// TODO default dir
+                       throw new JcrFsException("Cannot get node from relative path");
+               try {
+                       if (node == null)
+                               node = filesSystem.getSession().getNode(path);
+                       return node;
+               } catch (RepositoryException e) {
+                       throw new JcrFsException("Cannot get node", e);
+               }
+       }
+
+}