Adapt to MS Windows
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / fs / FsContent.java
index f0c7338579c5f67f319c5122c06a2cebc072948e..5920c420370c78a4051f9000820af7d16c1c34da 100644 (file)
@@ -36,6 +36,7 @@ import org.argeo.api.acr.ContentName;
 import org.argeo.api.acr.ContentResourceException;
 import org.argeo.api.acr.CrAttributeType;
 import org.argeo.api.acr.CrName;
+import org.argeo.api.acr.DName;
 import org.argeo.api.acr.NamespaceUtils;
 import org.argeo.api.acr.spi.ContentProvider;
 import org.argeo.api.acr.spi.ProvidedContent;
@@ -43,7 +44,7 @@ import org.argeo.api.acr.spi.ProvidedSession;
 import org.argeo.api.cms.CmsLog;
 import org.argeo.cms.acr.AbstractContent;
 import org.argeo.cms.acr.ContentUtils;
-import org.argeo.util.FsUtils;
+import org.argeo.cms.util.FsUtils;
 
 /** Content persisted as a filesystem {@link Path}. */
 public class FsContent extends AbstractContent implements ProvidedContent {
@@ -55,14 +56,15 @@ public class FsContent extends AbstractContent implements ProvidedContent {
        private static final Map<QName, String> POSIX_KEYS;
        static {
                BASIC_KEYS = new HashMap<>();
-               BASIC_KEYS.put(CrName.creationTime.qName(), "basic:creationTime");
-               BASIC_KEYS.put(CrName.lastModifiedTime.qName(), "basic:lastModifiedTime");
-               BASIC_KEYS.put(CrName.size.qName(), "basic:size");
+               BASIC_KEYS.put(DName.creationdate.qName(), "basic:creationTime");
+               BASIC_KEYS.put(DName.getlastmodified.qName(), "basic:lastModifiedTime");
+               BASIC_KEYS.put(DName.getcontentlength.qName(), "basic:size");
+
                BASIC_KEYS.put(CrName.fileKey.qName(), "basic:fileKey");
 
                POSIX_KEYS = new HashMap<>(BASIC_KEYS);
-               POSIX_KEYS.put(CrName.owner.qName(), "owner:owner");
-               POSIX_KEYS.put(CrName.group.qName(), "posix:group");
+               POSIX_KEYS.put(DName.owner.qName(), "owner:owner");
+               POSIX_KEYS.put(DName.group.qName(), "posix:group");
                POSIX_KEYS.put(CrName.permissions.qName(), "posix:permissions");
        }
 
@@ -88,7 +90,7 @@ public class FsContent extends AbstractContent implements ProvidedContent {
                } else {
 
                        // TODO should we support prefixed name for known types?
-                       QName providerName = NamespaceUtils.parsePrefixedName(provider, path.getFileName().toString());
+                       QName providerName = provider.fromFsPrefixedName(path.getFileName().toString());
 //                     QName providerName = new QName(path.getFileName().toString());
                        // TODO remove extension if mounted?
                        this.name = new ContentName(providerName, session);
@@ -124,7 +126,7 @@ public class FsContent extends AbstractContent implements ProvidedContent {
                        } else {
                                UserDefinedFileAttributeView udfav = Files.getFileAttributeView(path,
                                                UserDefinedFileAttributeView.class);
-                               String prefixedName = NamespaceUtils.toPrefixedName(provider, key);
+                               String prefixedName = provider.toFsPrefixedName(key);
                                if (!udfav.list().contains(prefixedName))
                                        return Optional.empty();
                                ByteBuffer buf = ByteBuffer.allocate(udfav.size(prefixedName));
@@ -196,7 +198,7 @@ public class FsContent extends AbstractContent implements ProvidedContent {
                if (udfav != null) {
                        try {
                                for (String name : udfav.list()) {
-                                       QName providerName = NamespaceUtils.parsePrefixedName(provider, name);
+                                       QName providerName = provider.fromFsPrefixedName(name);
                                        if (providerName.getNamespaceURI().equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
                                                continue; // skip prefix mapping
                                        QName sessionName = new ContentName(providerName, getSession());
@@ -213,7 +215,7 @@ public class FsContent extends AbstractContent implements ProvidedContent {
        protected void removeAttr(QName key) {
                UserDefinedFileAttributeView udfav = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
                try {
-                       udfav.delete(NamespaceUtils.toPrefixedName(provider, key));
+                       udfav.delete(provider.toFsPrefixedName(key));
                } catch (IOException e) {
                        throw new ContentResourceException("Cannot delete attribute " + key + " for " + path, e);
                }
@@ -237,7 +239,7 @@ public class FsContent extends AbstractContent implements ProvidedContent {
                UserDefinedFileAttributeView udfav = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
                ByteBuffer bb = ByteBuffer.wrap(toWrite.getBytes(StandardCharsets.UTF_8));
                try {
-                       udfav.write(NamespaceUtils.toPrefixedName(provider, key), bb);
+                       udfav.write(provider.toFsPrefixedName(key), bb);
                } catch (IOException e) {
                        throw new ContentResourceException("Cannot delete attribute " + key + " for " + path, e);
                }
@@ -248,7 +250,7 @@ public class FsContent extends AbstractContent implements ProvidedContent {
                if (POSIX_KEYS.containsKey(key))
                        return POSIX_KEYS.get(key);
                else
-                       return USER_ + NamespaceUtils.toPrefixedName(provider, key);
+                       return USER_ + provider.toFsPrefixedName(key);
        }
 
        /*
@@ -283,8 +285,8 @@ public class FsContent extends AbstractContent implements ProvidedContent {
        public Content add(QName name, QName... classes) {
                FsContent fsContent;
                try {
-                       Path newPath = path.resolve(NamespaceUtils.toPrefixedName(provider, name));
-                       if (ContentName.contains(classes, CrName.collection.qName()))
+                       Path newPath = path.resolve(provider.toFsPrefixedName(name));
+                       if (ContentName.contains(classes, DName.collection.qName()))
                                Files.createDirectory(newPath);
                        else
                                Files.createFile(newPath);
@@ -360,13 +362,13 @@ public class FsContent extends AbstractContent implements ProvidedContent {
        @Override
        public List<QName> getContentClasses() {
                List<QName> res = new ArrayList<>();
-               List<String> value = getMultiple(CrName.cc.qName(), String.class);
+               List<String> value = getMultiple(DName.resourcetype.qName(), String.class);
                for (String s : value) {
                        QName name = NamespaceUtils.parsePrefixedName(provider, s);
                        res.add(name);
                }
                if (Files.isDirectory(path))
-                       res.add(CrName.collection.qName());
+                       res.add(DName.collection.qName());
                return res;
        }
 
@@ -374,14 +376,14 @@ public class FsContent extends AbstractContent implements ProvidedContent {
        public void addContentClasses(QName... contentClass) {
                List<String> toWrite = new ArrayList<>();
                for (QName cc : getContentClasses()) {
-                       if (cc.equals(CrName.collection.qName()))
+                       if (cc.equals(DName.collection.qName()))
                                continue; // skip
                        toWrite.add(NamespaceUtils.toPrefixedName(provider, cc));
                }
                for (QName cc : contentClass) {
                        toWrite.add(NamespaceUtils.toPrefixedName(provider, cc));
                }
-               put(CrName.cc.qName(), toWrite);
+               put(DName.resourcetype.qName(), toWrite);
        }
 
        /*
@@ -398,7 +400,7 @@ public class FsContent extends AbstractContent implements ProvidedContent {
         */
        @SuppressWarnings("unchecked")
        public <A> CompletableFuture<A> write(Class<A> clss) {
-               if (isContentClass(CrName.collection.qName())) {
+               if (isContentClass(DName.collection.qName())) {
                        throw new IllegalStateException("Cannot directly write to a collection");
                }
                if (InputStream.class.isAssignableFrom(clss)) {