Search in sources :

Example 31 with VFSItem

use of org.olat.core.util.vfs.VFSItem 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)

Example 32 with VFSItem

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

the class VFSLockManagerImpl method getVFSLock.

/**
 * Return a lock info base on the VFS lock
 *
 * @param resource
 * @return
 */
public LockInfo getVFSLock(WebResource resource) {
    VFSItem item = extractItem(resource);
    MetaInfoFileImpl info = getMetaInfo(item);
    if (info != null && info.isLocked()) {
        File file = extractFile(item);
        LockInfo lock = null;
        if (fileLocks.containsKey(file)) {
            lock = fileLocks.get(file);
            if (lock != null) {
                lock.setVfsLock(true);
            }
        }
        if (lock == null) {
            lock = new LockInfo(info.getLockedBy(), false, true);
            lock.setWebResource(resource);
            lock.setCreationDate(info.getLockedDate());
            lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy());
            lock.setDepth(1);
            lock.addToken(generateLockToken(lock, info.getLockedBy()));
            fileLocks.put(file, lock);
        }
        return lock;
    }
    return null;
}
Also used : MetaInfoFileImpl(org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File)

Example 33 with VFSItem

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

the class VersionsFileManager method pruneVersionHistory.

private void pruneVersionHistory(VFSContainer container, long maxHistoryLength, ProgressDelegate progress, int count) {
    List<VFSItem> children = container.getItems(new SystemItemFilter());
    for (VFSItem child : children) {
        if (child instanceof VFSContainer) {
            if (progress != null)
                progress.setActual(++count);
            pruneVersionHistory((VFSContainer) child, maxHistoryLength, progress, count);
        }
        if (child instanceof VFSLeaf) {
            VFSLeaf versionsLeaf = (VFSLeaf) child;
            pruneVersionHistory(versionsLeaf, maxHistoryLength, progress);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 34 with VFSItem

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

the class VersionsFileManager method restore.

@Override
public boolean restore(VFSContainer container, VFSRevision revision) {
    String filename = revision.getName();
    VFSItem restoredItem = container.resolve(filename);
    if (restoredItem == null) {
        restoredItem = container.createChildLeaf(filename);
    }
    if (restoredItem instanceof VFSLeaf) {
        VFSLeaf restoredLeaf = (VFSLeaf) restoredItem;
        InputStream inStream = revision.getInputStream();
        if (VFSManager.copyContent(inStream, restoredLeaf)) {
            VFSLeaf versionFile = getCanonicalVersionXmlFile(restoredLeaf, true);
            Versions versions = readVersions(restoredLeaf, versionFile);
            if (versions instanceof VersionsFileImpl) {
                versions.getRevisions().remove(revision);
                ((VersionsFileImpl) versions).setRevisionNr(getNextRevisionNr(versions));
            }
            XStreamHelper.writeObject(mystream, versionFile, versions);
            return true;
        }
    }
    return false;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 35 with VFSItem

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

the class VersionsFileManager method getDeletedFiles.

@Override
public List<Versions> getDeletedFiles(VFSContainer container) {
    List<Versions> deletedRevisions = new ArrayList<Versions>();
    VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
    if (versionContainer != null) {
        Set<String> currentNames = new HashSet<String>();
        for (VFSItem item : container.getItems(new VFSLeafFilter())) {
            currentNames.add(item.getName() + ".xml");
        }
        List<VFSItem> versionItems = versionContainer.getItems(new VFSItemSuffixFilter(new String[] { "xml" }));
        for (VFSItem versionItem : versionItems) {
            String name = versionItem.getName();
            if (versionItem instanceof VFSLeaf && !currentNames.contains(name) && isVersionsXmlFile((VFSLeaf) versionItem)) {
                Versions versions = readVersions(null, (VFSLeaf) versionItem);
                if (versions != null) {
                    List<VFSRevision> revisions = versions.getRevisions();
                    if (!revisions.isEmpty()) {
                        deletedRevisions.add(versions);
                    }
                }
            }
        }
    }
    return deletedRevisions;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) HashSet(java.util.HashSet) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter)

Aggregations

VFSItem (org.olat.core.util.vfs.VFSItem)546 VFSContainer (org.olat.core.util.vfs.VFSContainer)356 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)272 File (java.io.File)78 Test (org.junit.Test)68 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)68 ArrayList (java.util.ArrayList)64 InputStream (java.io.InputStream)52 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)52 Identity (org.olat.core.id.Identity)50 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)48 IOException (java.io.IOException)42 Date (java.util.Date)40 URI (java.net.URI)38 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)38 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)34 OutputStream (java.io.OutputStream)30 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)28 HttpResponse (org.apache.http.HttpResponse)22 URL (java.net.URL)20