From 7ae5f41eea45126e72b017615e0e654358aa28d1 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 28 Nov 2015 09:12:16 +0000 Subject: [PATCH] Start working on JCR FS git-svn-id: https://svn.argeo.org/commons/trunk@8649 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../src/org/argeo/jcr/fs/JcrFileStore.java | 72 +++++++ .../src/org/argeo/jcr/fs/JcrFileSystem.java | 97 +++++++++ .../argeo/jcr/fs/JcrFileSystemProvider.java | 142 +++++++++++++ .../src/org/argeo/jcr/fs/JcrFsException.java | 15 ++ .../src/org/argeo/jcr/fs/JcrPath.java | 199 ++++++++++++++++++ 5 files changed, 525 insertions(+) create mode 100644 org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileStore.java create mode 100644 org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java create mode 100644 org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java create mode 100644 org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFsException.java create mode 100644 org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrPath.java 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 index 000000000..32a3ecb5f --- /dev/null +++ b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileStore.java @@ -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 type) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean supportsFileAttributeView(String name) { + // TODO Auto-generated method stub + return false; + } + + @Override + public V getFileStoreAttributeView( + Class 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 index 000000000..40328e8a0 --- /dev/null +++ b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java @@ -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 getRootDirectories() { + return null; + } + + @Override + public Iterable getFileStores() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Set 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 index 000000000..8ea4cca2e --- /dev/null +++ b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java @@ -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 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 options, FileAttribute... attrs) + throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public DirectoryStream newDirectoryStream(Path dir, + Filter 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 getFileAttributeView(Path path, + Class type, LinkOption... options) { + // TODO Auto-generated method stub + return null; + } + + @Override + public A readAttributes(Path path, + Class type, LinkOption... options) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map 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 index 000000000..f214fdc44 --- /dev/null +++ b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrFsException.java @@ -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 index 000000000..e25293517 --- /dev/null +++ b/org.argeo.server.jcr/src/org/argeo/jcr/fs/JcrPath.java @@ -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 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); + } + } + +} -- 2.30.2