]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/acr/fs/FsContentProvider.java
Improve ACR.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / fs / FsContentProvider.java
index 59f9f450dec129dda9044f17472d23506b919c05..9d696b07f1cbcf6609f50c29017576250af228f0 100644 (file)
@@ -9,6 +9,7 @@ import java.nio.file.attribute.UserDefinedFileAttributeView;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.NavigableMap;
+import java.util.Objects;
 import java.util.TreeMap;
 import java.util.stream.Collectors;
 
@@ -25,22 +26,33 @@ public class FsContentProvider implements ContentProvider {
 
        private final String mountPath;
        private final Path rootPath;
-       private final boolean isRoot;
+//     private final boolean isRoot;
 
        private NavigableMap<String, String> prefixes = new TreeMap<>();
 
-       public FsContentProvider(String mountPath, Path rootPath, boolean isRoot) {
+       public FsContentProvider(String mountPath, Path rootPath) {
+               Objects.requireNonNull(mountPath);
+               Objects.requireNonNull(rootPath);
+
                this.mountPath = mountPath;
                this.rootPath = rootPath;
-               this.isRoot = isRoot;
+               // FIXME make it more robust
                initNamespaces();
        }
 
-       protected void initNamespaces() {
+//     @Deprecated
+//     public FsContentProvider(String mountPath, Path rootPath, boolean isRoot) {
+//             this.mountPath = mountPath;
+//             this.rootPath = rootPath;
+////           this.isRoot = isRoot;
+////           initNamespaces();
+//     }
+
+       private void initNamespaces() {
                try {
                        UserDefinedFileAttributeView udfav = Files.getFileAttributeView(rootPath,
                                        UserDefinedFileAttributeView.class);
-                       if(udfav==null)
+                       if (udfav == null)
                                return;
                        for (String name : udfav.list()) {
                                if (name.startsWith(XMLNS_)) {
@@ -85,23 +97,22 @@ public class FsContentProvider implements ContentProvider {
                }
 
        }
-       
-       
-@Override
+
+       @Override
        public String getMountPath() {
                return mountPath;
        }
 
-       boolean isRoot(Path path) {
+       boolean isMountRoot(Path path) {
                try {
-                       return isRoot && Files.isSameFile(rootPath, path);
+                       return Files.isSameFile(rootPath, path);
                } catch (IOException e) {
                        throw new ContentResourceException(e);
                }
        }
 
        @Override
-       public ProvidedContent get(ProvidedSession session, String mountPath, String relativePath) {
+       public ProvidedContent get(ProvidedSession session, String relativePath) {
                return new FsContent(session, this, rootPath.resolve(relativePath));
        }
 
@@ -109,6 +120,11 @@ public class FsContentProvider implements ContentProvider {
         * NAMESPACE CONTEXT
         */
 
+       @Override
+       public boolean exists(ProvidedSession session, String relativePath) {
+               return Files.exists(rootPath.resolve(relativePath));
+       }
+
        @Override
        public String getNamespaceURI(String prefix) {
                return NamespaceUtils.getNamespaceURI((p) -> prefixes.get(p), prefix);