X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Facr%2Ffs%2FFsContentProvider.java;h=9d696b07f1cbcf6609f50c29017576250af228f0;hb=7e464c3cedfa41ece64811fb55ddc9ce740a1050;hp=37401a29c7f894117a2a0240910ee0cd3c5fe595;hpb=85015a7cbfe5343c88477d828fa2f8fb754a65cd;p=lgpl%2Fargeo-commons.git 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 37401a29c..9d696b07f 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 @@ -9,35 +9,51 @@ 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; -import org.argeo.api.acr.Content; 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 final boolean isRoot; private NavigableMap prefixes = new TreeMap<>(); - public FsContentProvider(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) + return; for (String name : udfav.list()) { if (name.startsWith(XMLNS_)) { ByteBuffer buf = ByteBuffer.allocate(udfav.size(name)); @@ -82,16 +98,21 @@ public class FsContentProvider implements ContentProvider { } - boolean isRoot(Path path) { + @Override + public String getMountPath() { + return mountPath; + } + + 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 Content get(ProvidedSession session, String mountPath, String relativePath) { + public ProvidedContent get(ProvidedSession session, String relativePath) { return new FsContent(session, this, rootPath.resolve(relativePath)); } @@ -99,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);