X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Facr%2Ffs%2FFsContentProvider.java;h=47cd64af343dc2aec976cb554b82be229c6547ad;hp=9b1b9668303f066e2106de3aa4a296edcabbf55d;hb=a4e2def61f587de89a03037aec2b95c54732ec55;hpb=93832291a83666434bd589a0b3fd11f956224bfc diff --git a/org.argeo.cms/src/org/argeo/cms/acr/fs/FsContentProvider.java b/org.argeo.cms/src/org/argeo/cms/acr/fs/FsContentProvider.java index 9b1b96683..47cd64af3 100644 --- a/org.argeo.cms/src/org/argeo/cms/acr/fs/FsContentProvider.java +++ b/org.argeo.cms/src/org/argeo/cms/acr/fs/FsContentProvider.java @@ -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 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 */