Search in sources :

Example 56 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class CatCommand 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 57 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class CatCommand method displayAutocompleteSuggestions.

private void displayAutocompleteSuggestions(final StructrShellCommand parent, final Iterable<AbstractFile> files, final String line) throws IOException {
    final StringBuilder buf = new StringBuilder();
    for (final AbstractFile file : files) {
        if (parent.isAllowed(file, Permission.read, false)) {
            buf.append(file.getName());
            if (file instanceof Folder) {
                buf.append("/  ");
            }
        }
    }
    if (buf.length() > 0) {
        term.println();
        term.print(buf.toString());
        term.println();
        parent.displayPrompt();
        term.print(line);
    }
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) Folder(org.structr.web.entity.Folder)

Example 58 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class CatCommand method handleTabCompletion.

@Override
public void handleTabCompletion(final StructrShellCommand parent, final String line, final int tabCount) throws IOException {
    if (line.contains(" ") && line.length() >= 3) {
        String incompletePath = line.substring(line.indexOf(" ") + 1);
        Folder baseFolder = null;
        String lastPathPart = null;
        if (incompletePath.startsWith("\"")) {
            incompletePath = incompletePath.substring(1);
        }
        final App app = StructrApp.getInstance();
        if ("..".equals(incompletePath)) {
            term.handleCharacter('/');
            return;
        }
        if (incompletePath.startsWith("/")) {
            incompletePath = incompletePath.substring(1);
        } else {
            baseFolder = parent.getCurrentFolder();
        }
        // identify full path parts and find folders
        final String[] parts = incompletePath.split("[/]+");
        final int partCount = parts.length;
        try (final Tx tx = app.tx()) {
            // only a single path part
            if (partCount == 1) {
                lastPathPart = parts[0];
            } else {
                lastPathPart = parts[partCount - 1];
                // more than a single path part, find preceding folders
                for (int i = 0; i < partCount - 1; i++) {
                    // skip empty path parts
                    if (StringUtils.isNotBlank(parts[i])) {
                        baseFolder = app.nodeQuery(Folder.class).and(StructrApp.key(AbstractFile.class, "parent"), baseFolder).and(Folder.name, parts[i]).getFirst();
                        if (baseFolder == null) {
                            return;
                        }
                    }
                }
            }
            final List<AbstractFile> allFiles = new LinkedList<>();
            final List<AbstractFile> files = new LinkedList<>();
            if (baseFolder != null) {
                allFiles.addAll(Iterables.toList(baseFolder.getChildren()));
            } else {
                allFiles.addAll(app.nodeQuery(AbstractFile.class).and(StructrApp.key(File.class, "parent"), null).getAsList());
            }
            for (final AbstractFile file : allFiles) {
                if (file.getName().startsWith(lastPathPart)) {
                    files.add(file);
                }
            }
            if (files.size() > 1) {
                // only display autocomplete suggestions after second tab
                if (tabCount > 1) {
                    displayAutocompleteSuggestions(parent, files, line);
                }
            } else if (!files.isEmpty()) {
                final AbstractFile file = files.get(0);
                if (file instanceof Folder) {
                    final Folder folder = (Folder) file;
                    if (parent.isAllowed(folder, Permission.read, false)) {
                        if (lastPathPart.equals(folder.getName())) {
                            // only display autocomplete suggestions after second tab
                            if (tabCount > 1) {
                                displayAutocompleteSuggestions(parent, folder.getChildren(), line);
                            } else {
                                if (!line.endsWith("/")) {
                                    term.handleCharacter('/');
                                }
                            }
                        } else {
                            displayAutocompleteItem(folder, lastPathPart);
                        }
                    }
                } else {
                    final AbstractFile existingFile = files.get(0);
                    if (parent.isAllowed(existingFile, Permission.read, false)) {
                        if (!lastPathPart.equals(existingFile.getName())) {
                            displayAutocompleteItem(existingFile, lastPathPart);
                        }
                    }
                }
            }
            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) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) LinkedList(java.util.LinkedList)

Example 59 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class CdCommand method displayAutocompleteSuggestions.

private void displayAutocompleteSuggestions(final StructrShellCommand parent, final Iterable<Folder> folders, final String line) throws IOException {
    final StringBuilder buf = new StringBuilder();
    for (final Folder folder : folders) {
        if (parent.isAllowed(folder, Permission.read, false)) {
            buf.append(folder.getName()).append("/  ");
        }
    }
    if (buf.length() > 0) {
        term.println();
        term.print(buf.toString());
        term.println();
        parent.displayPrompt();
        term.print(line);
    }
}
Also used : Folder(org.structr.web.entity.Folder)

Example 60 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class CdCommand method setFolder.

// ----- private methods -----
private void setFolder(final StructrShellCommand parent, final Folder currentFolder, final String targetFolderName) throws IOException, FrameworkException {
    final App app = StructrApp.getInstance();
    String target = targetFolderName;
    // remove trailing slash
    if (target.endsWith("/")) {
        target = target.substring(0, target.length() - 1);
    }
    if (target.startsWith("/")) {
        final Folder folder = app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "path"), target).getFirst();
        if (folder != null) {
            if (parent.isAllowed(folder, Permission.read, true)) {
                parent.setCurrentFolder(folder);
            } else {
                term.println("Permission denied");
            }
        } else {
            term.println("Folder " + target + " does not exist");
        }
    } else {
        final Folder newFolder = parent.findRelativeFolder(currentFolder, target);
        if (newFolder == null) {
            term.println("Folder " + target + " does not exist");
        } else {
            if (parent.isAllowed(newFolder, Permission.read, true)) {
                parent.setCurrentFolder(newFolder);
            } else {
                term.println("Permission denied");
            }
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) 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