@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
- if (ContentAttributeView.class.isAssignableFrom(type))
+ if (ContentFileAttributeView.class.isAssignableFrom(type))
return true;
return false;
}
@Override
public boolean supportsFileAttributeView(String name) {
- if (ContentAttributeView.NAME.equals(name))
+ if (ContentFileAttributeView.NAME.equals(name))
return true;
return false;
}
@Override
public Set<String> supportedFileAttributeViews() {
- return Collections.singleton(ContentAttributeView.NAME);
+ return Collections.singleton(ContentFileAttributeView.NAME);
}
@Override
private ProvidedRepository contentRepository;
-
public void start() {
-
+
}
-
+
public void stop() {
-
+
}
-
+
@Override
public String getScheme() {
return "cms";
public void checkAccess(Path path, AccessMode... modes) throws IOException {
}
+ @SuppressWarnings("unchecked")
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
- // TODO Auto-generated method stub
+ CmsPath cmsPath = (CmsPath) path;
+ if (BasicFileAttributes.class.isAssignableFrom(type))
+ return (V) new ContentFileAttributeView(cmsPath.getContent());
+ else if (ContentFileAttributeView.class.isAssignableFrom(type))
+ return (V) new ContentFileAttributeView(cmsPath.getContent());
return null;
}
+ @SuppressWarnings("unchecked")
@Override
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options)
throws IOException {
- // TODO Auto-generated method stub
- return null;
+ CmsPath cmsPath = (CmsPath) path;
+ return (A) new ContentAttributes(cmsPath.getContent());
}
@Override
+++ /dev/null
-package org.argeo.cms.file.provider;
-
-import java.nio.file.attribute.FileAttributeView;
-
-import org.argeo.api.acr.Content;
-
-public class ContentAttributeView implements FileAttributeView {
- final static String NAME = "content";
-
- private final Content content;
-
- public ContentAttributeView(Content content) {
- this.content = content;
- }
-
- @Override
- public String name() {
- return NAME;
- }
-
- public Content getContent() {
- return content;
- }
-}
--- /dev/null
+package org.argeo.cms.file.provider;
+
+import java.nio.file.attribute.BasicFileAttributes;
+import java.nio.file.attribute.FileTime;
+import java.time.Instant;
+
+import org.argeo.api.acr.Content;
+import org.argeo.api.acr.DName;
+
+public class ContentAttributes implements BasicFileAttributes {
+ // TODO optimise for FS-based content
+ private final Content content;
+
+ public ContentAttributes(Content content) {
+ assert content != null;
+ this.content = content;
+ }
+
+ @Override
+ public FileTime lastModifiedTime() {
+ Instant t = content.get(DName.getlastmodified, Instant.class).orElseThrow();
+ return FileTime.from(t);
+ }
+
+ @Override
+ public FileTime lastAccessTime() {
+ // TODO implement the concept in ACR ?
+ return FileTime.fromMillis(0l);
+ }
+
+ @Override
+ public FileTime creationTime() {
+ Instant t = content.get(DName.getlastmodified, Instant.class).orElseThrow();
+ return FileTime.from(t);
+ }
+
+ @Override
+ public boolean isRegularFile() {
+ return isRegularFile(content);
+ }
+
+ @Override
+ public boolean isDirectory() {
+ return isDirectory(content);
+ }
+
+ @Override
+ public boolean isSymbolicLink() {
+ // TODO supports links in ACR
+ return false;
+ }
+
+ @Override
+ public boolean isOther() {
+ return !isDirectory() && !isRegularFile() && !isSymbolicLink();
+ }
+
+ @Override
+ public long size() {
+ long size = content.get(DName.getcontentlength, Long.class).orElse(-1l);
+ return size;
+ }
+
+ @Override
+ public Object fileKey() {
+ // TODO check for UUIDs, etc.
+ return null;
+ }
+
+ static boolean isDirectory(Content c) {
+ return !isRegularFile(c);
+// return c.isContentClass(DName.collection);
+ }
+
+ static boolean isRegularFile(Content c) {
+// return c.containsKey(DName.getcontenttype.qName());
+ return !c.get(DName.getcontenttype, String.class).isEmpty();
+ }
+
+}
import java.util.Iterator;
import org.argeo.api.acr.Content;
-import org.argeo.api.acr.DName;
public class ContentDirectoryStream implements DirectoryStream<Path> {
private final CmsPath dir;
return iterator;
}
- static boolean isFile(Content c) {
- return !c.get(DName.getcontenttype, String.class).isEmpty();
- }
-
- static boolean isDirectory(Content c) {
- return c.isContentClass(DName.collection);
- }
-
class FilesAndCollectionsIterator implements Iterator<Path> {
private Content next;
private final Iterator<Content> it;
public FilesAndCollectionsIterator() {
Content content = dir.getContent();
- if (!content.isContentClass(DName.collection))
+ if (!ContentAttributes.isDirectory(content))
throw new IllegalStateException("Content " + content + " is not a collection");
it = content.iterator();
findNext();
private void findNext() {
next = null;
- while (it.hasNext() && next != null) {
+ while (it.hasNext() && next == null) {
Content n = it.next();
- if (isFile(n) || isDirectory(n)) {
+ if (ContentAttributes.isRegularFile(n) || ContentAttributes.isDirectory(n)) {
if (filter != null) {
try {
if (filter.accept(new CmsPath(dir.getFileSystem(), n)))
--- /dev/null
+package org.argeo.cms.file.provider;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.file.attribute.BasicFileAttributeView;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.nio.file.attribute.FileTime;
+import java.nio.file.attribute.UserDefinedFileAttributeView;
+import java.util.List;
+
+import org.argeo.api.acr.Content;
+import org.argeo.api.acr.DName;
+
+public class ContentFileAttributeView implements BasicFileAttributeView, UserDefinedFileAttributeView {
+ final static String NAME = "content";
+
+ private final Content content;
+
+ public ContentFileAttributeView(Content content) {
+ this.content = content;
+ }
+
+ @Override
+ public String name() {
+ return NAME;
+ }
+
+ /*
+ * BasicFileAttributeView
+ */
+
+ @Override
+ public BasicFileAttributes readAttributes() throws IOException {
+ return new ContentAttributes(content);
+ }
+
+ @Override
+ public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException {
+ if (lastModifiedTime != null)
+ content.put(DName.getlastmodified, lastModifiedTime.toInstant());
+ if (createTime != null)
+ content.put(DName.getlastmodified, createTime.toInstant());
+ // ignore last accessed time
+ }
+
+ /*
+ * UserDefinedFileAttributeView
+ */
+
+ @Override
+ public List<String> list() throws IOException {
+// List<String> res = new ArrayList<>();
+ return null;
+ }
+
+ @Override
+ public int size(String name) throws IOException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int read(String name, ByteBuffer dst) throws IOException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int write(String name, ByteBuffer src) throws IOException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void delete(String name) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Content getContent() {
+ return content;
+ }
+}
} else if ("app".equals(uiName)) {
Path rootPath = cmsFileSystemProvider.getPath(URI.create("cms:///"));
- SimpleFsBrowser view = new SimpleFsBrowser(parent, 0);
+ SimpleFsBrowser view = new SimpleFsBrowser(cmsUi, 0);
view.setInput(rootPath);
view.setLayoutData(CmsSwtUtils.fillAll());