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;
+ protected String mountPath;
+ protected Path rootPath;
private NavigableMap<String, String> prefixes = new TreeMap<>();
- public FsContentProvider(String mountPath, 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 FsContentProvider() {
+
+ }
+
protected 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));
}
}
-
-
-@Override
+
+ @Override
public String getMountPath() {
return mountPath;
}
- boolean isRoot(Path path) {
+ boolean isMountBase(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));
}
* 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);