Adapt to MS Windows
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / fs / FsContentProvider.java
index 9b1b9668303f066e2106de3aa4a296edcabbf55d..47cd64af343dc2aec976cb554b82be229c6547ad 100644 (file)
@@ -13,6 +13,8 @@ import java.util.Objects;
 import java.util.TreeMap;
 import java.util.stream.Collectors;
 
+import javax.xml.namespace.QName;
+
 import org.argeo.api.acr.ArgeoNamespace;
 import org.argeo.api.acr.ContentResourceException;
 import org.argeo.api.acr.NamespaceUtils;
@@ -20,28 +22,36 @@ import org.argeo.api.acr.RuntimeNamespaceContext;
 import org.argeo.api.acr.spi.ContentProvider;
 import org.argeo.api.acr.spi.ProvidedContent;
 import org.argeo.api.acr.spi.ProvidedSession;
+import org.argeo.cms.util.OS;
 
 /** Access a file system as a {@link ContentProvider}. */
 public class FsContentProvider implements ContentProvider {
-       final static String XMLNS_ = "xmlns:";
 
        protected String mountPath;
        protected Path rootPath;
 
        private NavigableMap<String, String> prefixes = new TreeMap<>();
 
+       private final boolean isNtfs;
+       private final String XMLNS_;
+
        public FsContentProvider(String mountPath, Path rootPath) {
                Objects.requireNonNull(mountPath);
                Objects.requireNonNull(rootPath);
 
                this.mountPath = mountPath;
                this.rootPath = rootPath;
+
+               this.isNtfs = OS.LOCAL.isMSWindows();
+               this.XMLNS_ = isNtfs ? "xmlns%3A" : "xmlns:";
+
                // FIXME make it more robust
                initNamespaces();
        }
 
        protected FsContentProvider() {
-
+               this.isNtfs = OS.LOCAL.isMSWindows();
+               this.XMLNS_ = isNtfs ? "xmlns%3A" : "xmlns:";
        }
 
        protected void initNamespaces() {
@@ -117,6 +127,27 @@ public class FsContentProvider implements ContentProvider {
                return Files.exists(rootPath.resolve(relativePath));
        }
 
+       /*
+        * ATTRIBUTE NAMES
+        */
+       /**
+        * Make sure that the prefixed name is compatible with the underlying file
+        * system for file names/attributes (NTFS does not accept :)
+        */
+       String toFsPrefixedName(QName key) {
+               return isNtfs ? NamespaceUtils.toPrefixedName(this, key).replace(":", "%3A")
+                               : NamespaceUtils.toPrefixedName(this, key);
+       }
+
+       /**
+        * PArse a prefixed name which is compatible with the underlying file system for
+        * file names/attributes (NTFS does not accept :)
+        */
+       QName fromFsPrefixedName(String name) {
+               return isNtfs ? NamespaceUtils.parsePrefixedName(this, name.replace("%3A", ":"))
+                               : NamespaceUtils.parsePrefixedName(this, name);
+       }
+
        /*
         * NAMESPACE CONTEXT
         */