Search in sources :

Example 61 with Folder

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);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder)

Example 62 with Folder

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);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder)

Example 63 with Folder

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();
    }
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) Folder(org.structr.web.entity.Folder)

Example 64 with Folder

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;
}
Also used : ConfigurationProvider(org.structr.schema.ConfigurationProvider) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) IOException(java.io.IOException) Folder(org.structr.web.entity.Folder) FileInputStream(java.io.FileInputStream) Collection(java.util.Collection) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File)

Example 65 with Folder

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);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder)

Aggregations

Folder (org.structr.web.entity.Folder)95 Tx (org.structr.core.graph.Tx)64 FrameworkException (org.structr.common.error.FrameworkException)60 AbstractFile (org.structr.web.entity.AbstractFile)42 App (org.structr.core.app.App)35 StructrApp (org.structr.core.app.StructrApp)35 File (org.structr.web.entity.File)34 Test (org.junit.Test)23 StructrUiTest (org.structr.web.StructrUiTest)21 IOException (java.io.IOException)20 PropertyMap (org.structr.core.property.PropertyMap)16 Path (java.nio.file.Path)14 LinkedList (java.util.LinkedList)10 NodeAttribute (org.structr.core.graph.NodeAttribute)9 InputStream (java.io.InputStream)5 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 CMISRootFolder (org.structr.files.cmis.repository.CMISRootFolder)5 User (org.structr.web.entity.User)5 Page (org.structr.web.entity.dom.Page)5 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4