use of org.structr.web.entity.Folder in project structr by structr.
the class CdCommand method execute.
@Override
public void execute(final StructrShellCommand parent) throws IOException {
final App app = StructrApp.getInstance();
final Folder currentFolder = parent.getCurrentFolder();
try (final Tx tx = app.tx()) {
if (target != null) {
switch(target) {
case "..":
if (currentFolder != null) {
final Folder parentFolder = currentFolder.getParent();
if (parentFolder != null) {
if (parent.isAllowed(parentFolder, Permission.read, true)) {
parent.setCurrentFolder(parentFolder);
}
} else {
parent.setCurrentFolder(null);
}
}
break;
case ".":
break;
case "/":
parent.setCurrentFolder(null);
break;
case "~":
parent.setCurrentFolder(user.getHomeDirectory());
break;
default:
setFolder(parent, currentFolder, target);
break;
}
} else {
parent.setCurrentFolder(user.getHomeDirectory());
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
use of org.structr.web.entity.Folder in project structr by structr.
the class LsCommand method execute.
@Override
public void execute(final StructrShellCommand parent) throws IOException {
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
final Folder currentFolder = parent.getCurrentFolder();
if (currentFolder != null) {
listFolder(parent, currentFolder.getChildren());
} else {
listFolder(parent, app.nodeQuery(AbstractFile.class).and(StructrApp.key(AbstractFile.class, "parent"), null).getAsList());
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
use of org.structr.web.entity.Folder 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.Folder in project structr by structr.
the class CreateArchiveFunction method apply.
@Override
public Object apply(ActionContext ctx, Object caller, Object[] sources) throws FrameworkException {
if (!(sources[1] instanceof File || sources[1] instanceof Folder || sources[1] instanceof Collection || sources.length < 2)) {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
final ConfigurationProvider config = StructrApp.getConfiguration();
try {
java.io.File newArchive = java.io.File.createTempFile(sources[0].toString(), "zip");
ZipArchiveOutputStream zaps = new ZipArchiveOutputStream(newArchive);
zaps.setEncoding("UTF8");
zaps.setUseLanguageEncodingFlag(true);
zaps.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS);
zaps.setFallbackToUTF8(true);
if (sources[1] instanceof File) {
File file = (File) sources[1];
addFileToZipArchive(file.getProperty(AbstractFile.name), file, zaps);
} else if (sources[1] instanceof Folder) {
Folder folder = (Folder) sources[1];
addFilesToArchive(folder.getProperty(Folder.name) + "/", folder.getFiles(), zaps);
addFoldersToArchive(folder.getProperty(Folder.name) + "/", folder.getFolders(), zaps);
} else if (sources[1] instanceof Collection) {
for (Object fileOrFolder : (Collection) sources[1]) {
if (fileOrFolder instanceof File) {
File file = (File) fileOrFolder;
addFileToZipArchive(file.getProperty(AbstractFile.name), file, zaps);
} else if (fileOrFolder instanceof Folder) {
Folder folder = (Folder) fileOrFolder;
addFilesToArchive(folder.getProperty(Folder.name) + "/", folder.getFiles(), zaps);
addFoldersToArchive(folder.getProperty(Folder.name) + "/", folder.getFolders(), zaps);
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
zaps.close();
Class archiveClass = null;
if (sources.length > 2) {
archiveClass = config.getNodeEntityClass(sources[2].toString());
}
if (archiveClass == null) {
archiveClass = org.structr.web.entity.File.class;
}
try (final FileInputStream fis = new FileInputStream(newArchive)) {
return FileHelper.createFile(ctx.getSecurityContext(), fis, "application/zip", archiveClass, sources[0].toString() + ".zip");
}
} catch (IOException e) {
logException(caller, e, sources);
}
return null;
}
use of org.structr.web.entity.Folder in project structr by structr.
the class MkdirCommand method execute.
@Override
public void execute(final StructrShellCommand parent) throws IOException {
final App app = StructrApp.getInstance();
final Folder currentFolder = parent.getCurrentFolder();
try (final Tx tx = app.tx()) {
if (target != null) {
switch(target) {
case "..":
case ".":
case "/":
case "~":
term.println("Folder " + target + " already exists");
break;
default:
createFolder(parent, currentFolder, target);
break;
}
} else {
term.println("mkdir needs parameter");
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
Aggregations