]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/acr/fs/FsContentProvider.java
Clean up and refactor ACR and component register.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / fs / FsContentProvider.java
index 65bdd343ef72b213289e982008f917940877c8c2..e17384b942162d7cefbde3fde1fdb0682ad3674f 100644 (file)
@@ -17,18 +17,21 @@ import org.argeo.api.acr.ContentResourceException;
 import org.argeo.api.acr.CrName;
 import org.argeo.api.acr.NamespaceUtils;
 import org.argeo.api.acr.spi.ContentProvider;
+import org.argeo.api.acr.spi.ProvidedContent;
 import org.argeo.api.acr.spi.ProvidedSession;
 
 /** Access a file system as a {@link ContentProvider}. */
 public class FsContentProvider implements ContentProvider {
        final static String XMLNS_ = "xmlns:";
 
+       private final String mountPath;
        private final Path rootPath;
        private final boolean isRoot;
 
        private NavigableMap<String, String> prefixes = new TreeMap<>();
 
-       public FsContentProvider(Path rootPath, boolean isRoot) {
+       public FsContentProvider(String mountPath, Path rootPath, boolean isRoot) {
+               this.mountPath = mountPath;
                this.rootPath = rootPath;
                this.isRoot = isRoot;
                initNamespaces();
@@ -64,11 +67,30 @@ public class FsContentProvider implements ContentProvider {
                        throws IOException {
                if (!prefixes.containsKey(prefix)) {
                        ByteBuffer bb = ByteBuffer.wrap(namespace.getBytes(StandardCharsets.UTF_8));
-                       int size = udfav.write(XMLNS_ + prefix, bb);
+                       udfav.write(XMLNS_ + prefix, bb);
                        prefixes.put(prefix, namespace);
                }
        }
 
+       public void registerPrefix(String prefix, String namespace) {
+               if (prefixes.containsKey(prefix))
+                       prefixes.remove(prefix);
+               try {
+                       UserDefinedFileAttributeView udfav = Files.getFileAttributeView(rootPath,
+                                       UserDefinedFileAttributeView.class);
+                       addDefaultNamespace(udfav, prefix, namespace);
+               } catch (IOException e) {
+                       throw new RuntimeException("Cannot register namespace " + prefix + " " + namespace + " on " + rootPath, e);
+               }
+
+       }
+       
+       
+@Override
+       public String getMountPath() {
+               return mountPath;
+       }
+
        boolean isRoot(Path path) {
                try {
                        return isRoot && Files.isSameFile(rootPath, path);
@@ -78,7 +100,7 @@ public class FsContentProvider implements ContentProvider {
        }
 
        @Override
-       public Content get(ProvidedSession session, String mountPath, String relativePath) {
+       public ProvidedContent get(ProvidedSession session, String mountPath, String relativePath) {
                return new FsContent(session, this, rootPath.resolve(relativePath));
        }