Search in sources :

Example 21 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class FolderTreeModel method buildTree.

private boolean buildTree(TreeNode tParent, VFSContainer parentContainer, String parentPath) {
    List<VFSItem> children = parentContainer.getItems(fileFilter);
    if (children.size() == 0)
        return false;
    // sort the children
    Collections.sort(children, new Comparator<VFSItem>() {

        final Collator c = collator;

        public int compare(final VFSItem o1, final VFSItem o2) {
            return c.compare(o1.getName(), o2.getName());
        }
    });
    boolean addedAtLeastOneChild = false;
    for (Iterator<VFSItem> iter = children.iterator(); iter.hasNext(); ) {
        VFSItem child = iter.next();
        String childName = child.getName();
        if (child instanceof VFSContainer) {
            // container node
            String filePath = parentPath + childName + "/";
            // filePath is the information to be remembered later
            GenericTreeNode tChild = new GenericTreeNode(childName, filePath);
            tChild.setIconCssClass("o_filetype_folder");
            tChild.setAltText(child.getName());
            tChild.setAccessible(selectableFolders ? (child.canWrite() == VFSConstants.YES) : false);
            tParent.addChild(tChild);
            boolean addedChildren = buildTree(tChild, (VFSContainer) child, filePath);
            if (foldersOnly || addedChildren) {
                addedAtLeastOneChild = true;
            } else {
                // this directory does not contain anything usefull, remove it again!
                tParent.remove(tChild);
            }
        } else {
            // leaf node
            if (foldersOnly)
                continue;
            String filePath = parentPath + childName;
            GenericTreeNode tChild = new GenericTreeNode(childName, filePath);
            String type = FolderHelper.extractFileType(childName, locale);
            if (!FolderHelper.isKnownFileType(type)) {
                type = "file";
            }
            tChild.setIconCssClass("o_filetype_" + type);
            tChild.setAltText(childName);
            tChild.setAccessible(selectableFiles);
            tParent.addChild(tChild);
            addedAtLeastOneChild = true;
        }
    }
    return addedAtLeastOneChild;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Collator(java.text.Collator)

Example 22 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class ZipUtil method checkLockedFileBeforeUnzip.

// unzip
/**
 * Check if a file in the zip is already in the path
 * @param zipLeaf
 * @param targetDir
 * @param identity
 * @param isAdmin
 * @return the list of files which already exist
 */
public static List<String> checkLockedFileBeforeUnzip(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, Roles isAdmin) {
    List<String> lockedFiles = new ArrayList<String>();
    InputStream in = zipLeaf.getInputStream();
    ZipInputStream oZip = new ZipInputStream(in);
    VFSLockManager vfsLockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
    try {
        // unzip files
        ZipEntry oEntr = oZip.getNextEntry();
        while (oEntr != null) {
            if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
                if (oEntr.isDirectory()) {
                    // skip MacOSX specific metadata directory
                    // directories aren't locked
                    oZip.closeEntry();
                    oEntr = oZip.getNextEntry();
                    continue;
                } else {
                    // search file
                    VFSContainer createIn = targetDir;
                    String name = oEntr.getName();
                    // check if entry has directories which did not show up as
                    // directories above
                    int dirSepIndex = name.lastIndexOf('/');
                    if (dirSepIndex == -1) {
                        // try it windows style, backslash is also valid format
                        dirSepIndex = name.lastIndexOf('\\');
                    }
                    if (dirSepIndex > 0) {
                        // get subdirs
                        createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, false);
                        if (createIn == null) {
                            // sub directories don't exist, and aren't locked
                            oZip.closeEntry();
                            oEntr = oZip.getNextEntry();
                            continue;
                        }
                        name = name.substring(dirSepIndex + 1);
                    }
                    VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
                    if (vfsLockManager.isLockedForMe(newEntry, identity, isAdmin)) {
                        lockedFiles.add(name);
                    }
                }
            }
            oZip.closeEntry();
            oEntr = oZip.getNextEntry();
        }
    } catch (IOException e) {
        return null;
    } finally {
        FileUtils.closeSafely(oZip);
        FileUtils.closeSafely(in);
    }
    return lockedFiles;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VFSLockManager(org.olat.core.util.vfs.VFSLockManager)

Example 23 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class MailModule method getRootForAttachments.

public VFSContainer getRootForAttachments() {
    String root = folderModule.getCanonicalRoot() + attachmentsRoot;
    File rootFile = new File(root);
    if (!rootFile.exists()) {
        rootFile.mkdirs();
    }
    VFSContainer rootContainer = new LocalFolderImpl(rootFile);
    return rootContainer;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 24 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class MailManagerImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    VFSContainer root = mailModule.getRootForAttachments();
    attachmentStorage = new FileStorage(root);
    PublisherData pdata = getPublisherData();
    SubscriptionContext scontext = getSubscriptionContext();
    notificationsManager.getOrCreatePublisher(scontext, pdata);
    Properties p = null;
    try {
        velocityEngine = new VelocityEngine();
        p = new Properties();
        p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
        p.setProperty(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS, "org.olat.core.gui.render.velocity.InfinispanResourceCache");
        p.setProperty("runtime.log.logsystem.log4j.category", "syslog");
        velocityEngine.init(p);
    } catch (Exception e) {
        throw new RuntimeException("config error " + p.toString());
    }
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileStorage(org.olat.core.util.vfs.FileStorage) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Properties(java.util.Properties) PublisherData(org.olat.core.commons.services.notifications.PublisherData) SendFailedException(javax.mail.SendFailedException) ParseErrorException(org.apache.velocity.exception.ParseErrorException) IOException(java.io.IOException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) MessagingException(javax.mail.MessagingException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) AddressException(javax.mail.internet.AddressException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 25 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class SendDocumentsByEMailController method execute.

public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSContainer rootContainer = folderComponent.getRootContainer();
    if (!VFSManager.exists(currentContainer)) {
        status = FolderCommandStatus.STATUS_FAILED;
        showError(translator.translate("FileDoesNotExist"));
        return null;
    }
    status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    selection = new FileSelection(ureq, folderComponent.getCurrentContainerPath());
    status = FolderCommandHelper.sanityCheck3(wControl, folderComponent, selection);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    boolean selectionWithContainer = false;
    List<String> filenames = selection.getFiles();
    List<VFSLeaf> leafs = new ArrayList<VFSLeaf>();
    for (String file : filenames) {
        VFSItem item = currentContainer.resolve(file);
        if (item instanceof VFSContainer) {
            selectionWithContainer = true;
        } else if (item instanceof VFSLeaf) {
            leafs.add((VFSLeaf) item);
        }
    }
    if (selectionWithContainer) {
        if (leafs.isEmpty()) {
            wControl.setError(getTranslator().translate("send.mail.noFileSelected"));
            return null;
        } else {
            setFormWarning(getTranslator().translate("send.mail.selectionContainsFolder"));
        }
    }
    setFiles(rootContainer, leafs);
    return this;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34