use of org.structr.web.entity.AbstractFile in project structr by structr.
the class LsCommand method listFolder.
// ----- private methods -----
private void listFolder(final StructrShellCommand parent, final Iterable<AbstractFile> folder) throws FrameworkException, IOException {
boolean hasContents = false;
for (final AbstractFile child : folder) {
if (parent.isAllowed(child, Permission.read, false)) {
hasContents = true;
if (child instanceof Folder) {
term.setBold(true);
term.setTextColor(4);
term.print(child.getName() + " ");
term.setTextColor(7);
term.setBold(false);
} else {
term.print(child.getName() + " ");
}
}
}
if (hasContents) {
term.println();
}
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class FtpTest method createFTPFile.
protected File createFTPFile(final String path, final String name) throws FrameworkException {
PropertyMap props = new PropertyMap();
props.put(StructrApp.key(File.class, "name"), name);
props.put(StructrApp.key(File.class, "size"), 0L);
props.put(StructrApp.key(File.class, "owner"), ftpUser);
File file = (File) createTestNodes(File.class, 1, props).get(0);
if (StringUtils.isNotBlank(path)) {
AbstractFile parent = FileHelper.getFileByAbsolutePath(securityContext, path);
if (parent != null && parent instanceof Folder) {
Folder parentFolder = (Folder) parent;
file.setParent(parentFolder);
}
}
logger.info("FTP file {} created successfully.", file);
return file;
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class FtpTest method createFTPDirectory.
protected Folder createFTPDirectory(final String path, final String name) throws FrameworkException {
PropertyMap props = new PropertyMap();
props.put(Folder.name, name);
props.put(Folder.owner, ftpUser);
Folder dir = (Folder) createTestNodes(Folder.class, 1, props).get(0);
if (StringUtils.isNotBlank(path)) {
AbstractFile parent = FileHelper.getFileByAbsolutePath(securityContext, path);
if (parent != null && parent instanceof Folder) {
Folder parentFolder = (Folder) parent;
dir.setParent(parentFolder);
}
}
logger.info("FTP directory {} created successfully.", dir);
return dir;
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class UnarchiveCommand method handleFile.
private void handleFile(final SecurityContext securityContext, final InputStream in, final Folder existingParentFolder, final String entryPath) throws FrameworkException, IOException {
final PropertyKey<Folder> parentKey = StructrApp.key(AbstractFile.class, "parent");
final PropertyKey<Boolean> hasParentKey = StructrApp.key(AbstractFile.class, "hasParent");
final String filePath = (existingParentFolder != null ? existingParentFolder.getPath() : "") + PathHelper.PATH_SEP + PathHelper.clean(entryPath);
final String name = PathHelper.getName(entryPath);
final AbstractFile newFile = ImageHelper.isImageType(name) ? ImageHelper.createImage(securityContext, in, null, Image.class, name, false) : FileHelper.createFile(securityContext, in, null, File.class, name);
final String folderPath = StringUtils.substringBeforeLast(filePath, PathHelper.PATH_SEP);
final Folder parentFolder = FileHelper.createFolderPath(securityContext, folderPath);
if (parentFolder != null) {
final PropertyMap properties = new PropertyMap();
properties.put(parentKey, parentFolder);
properties.put(hasParentKey, true);
newFile.setProperties(securityContext, properties);
}
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class CMISNavigationService method recursivelyCollectDescendants.
private void recursivelyCollectDescendants(final List<ObjectInFolderContainer> list, final AbstractFile child, final int maxDepth, final int depth, final Boolean includeAllowableActions) throws FrameworkException {
if (depth > maxDepth) {
return;
}
final PropertyKey<Folder> parent = StructrApp.key(AbstractFile.class, "parent");
final PropertyKey<Boolean> hasParent = StructrApp.key(AbstractFile.class, "hasParent");
final PropertyKey<Boolean> isThumbnail = StructrApp.key(Image.class, "isThumbnail");
final CMISObjectInFolderWrapper wrapper = new CMISObjectInFolderWrapper(includeAllowableActions);
final ObjectInFolderContainerImpl impl = new ObjectInFolderContainerImpl();
final List<ObjectInFolderContainer> childContainerList = new LinkedList<>();
final String pathSegment = child.getName();
impl.setObject(wrapper.wrapObjectData(wrapper.wrapGraphObject(child), pathSegment));
impl.setChildren(childContainerList);
// add wrapped object to current list
list.add(impl);
if (child.getProperty(AbstractNode.type).equals("Folder")) {
final App app = StructrApp.getInstance();
// descend into children
for (final AbstractFile folderChild : app.nodeQuery(AbstractFile.class).sort(AbstractNode.name).and(parent, (Folder) child).and(isThumbnail, false).getAsList()) {
recursivelyCollectDescendants(childContainerList, folderChild, maxDepth, depth + 1, includeAllowableActions);
}
}
}
Aggregations