Search in sources :

Example 21 with VFSItem

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

the class VFSResourceRoot method delete.

@Override
public boolean delete(WebResource resource) {
    boolean deleted = false;
    if (resource instanceof VFSResource) {
        VFSResource vfsResource = (VFSResource) resource;
        VFSItem item = vfsResource.getItem();
        if (item != null && VFSConstants.YES.equals(item.canDelete())) {
            VFSStatus status = item.delete();
            deleted = (status == VFSConstants.YES || status == VFSConstants.SUCCESS);
        }
    }
    return deleted;
}
Also used : VFSStatus(org.olat.core.util.vfs.VFSStatus) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 22 with VFSItem

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

the class VFSResourceRoot method mkdir.

@Override
public boolean mkdir(String path) {
    // remove trailing /
    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    int lastSlash = path.lastIndexOf('/');
    if (lastSlash == -1)
        return false;
    String parentPath = path.substring(0, lastSlash);
    VFSItem parentItem = resolveFile(parentPath);
    if (parentItem instanceof VFSLeaf) {
        return false;
    } else if (parentItem instanceof VFSContainer) {
        String name = path.substring(lastSlash + 1);
        VFSContainer folder = (VFSContainer) parentItem;
        if (folder.canWrite() == VFSConstants.YES) {
            VFSContainer dir = folder.createChildContainer(name);
            return dir != null && dir.exists();
        }
    }
    return false;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 23 with VFSItem

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

the class VFSResourceRoot method canWrite.

@Override
public boolean canWrite(String name) {
    // resolve item if it already exists
    VFSItem item = resolveFile(name);
    if (item == null) {
        // try to resolve parent in case the item does not yet exist
        int lastSlash = name.lastIndexOf("/");
        if (lastSlash > 0) {
            String containerName = name.substring(0, lastSlash);
            item = resolveFile(containerName);
        }
    }
    if (item == null) {
        return false;
    }
    VFSStatus status;
    if (item instanceof VFSContainer) {
        status = item.canWrite();
    } else {
        // read/write is not defined on item level, only on directory level
        status = item.getParentContainer().canWrite();
    }
    return VFSConstants.YES.equals(status);
}
Also used : VFSStatus(org.olat.core.util.vfs.VFSStatus) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 24 with VFSItem

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

the class VFSResourceRoot method write.

@Override
public boolean write(String path, InputStream is, boolean overwrite, WebResource movedFrom) throws QuotaExceededException {
    VFSLeaf childLeaf;
    VFSItem file = resolveFile(path);
    if (file instanceof VFSLeaf) {
        if (overwrite) {
            // overwrite the file
            childLeaf = (VFSLeaf) file;
            // versioning
            if (childLeaf instanceof Versionable && ((Versionable) childLeaf).getVersions().isVersioned()) {
                if (childLeaf.getSize() == 0) {
                    VersionsManager.getInstance().createVersionsFor(childLeaf, true);
                } else {
                    VersionsManager.getInstance().addToRevisions((Versionable) childLeaf, identity, "");
                }
            }
        } else {
            return false;
        }
    } else if (file instanceof VFSContainer) {
        return false;
    } else {
        // create a new file
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash == -1)
            return false;
        String parentPath = path.substring(0, lastSlash);
        VFSItem parentItem = resolveFile(parentPath);
        if (parentItem instanceof VFSContainer) {
            VFSContainer folder = (VFSContainer) parentItem;
            String name = path.substring(lastSlash + 1);
            childLeaf = folder.createChildLeaf(name);
        } else {
            return false;
        }
    }
    if (childLeaf == null) {
        return false;
    }
    try {
        copyVFS(childLeaf, is);
    } catch (QuotaExceededException e) {
        throw e;
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
    VFSContainer inheritingCont = VFSManager.findInheritingSecurityCallbackContainer(childLeaf.getParentContainer());
    if (inheritingCont != null) {
        VFSSecurityCallback callback = inheritingCont.getLocalSecurityCallback();
        if (callback != null && callback.getSubscriptionContext() != null) {
            SubscriptionContext subContext = callback.getSubscriptionContext();
            NotificationsManager.getInstance().markPublisherNews(subContext, null, true);
        }
    }
    if (childLeaf instanceof MetaTagged && identity != null) {
        MetaInfo infos = ((MetaTagged) childLeaf).getMetaInfo();
        if (infos != null && !infos.hasAuthorIdentity()) {
            infos.setAuthor(identity);
            addLicense(infos, identity);
            infos.clearThumbnails();
        // infos.write(); the clearThumbnails call write()
        }
    }
    if (movedFrom instanceof VFSResource) {
        VFSResource vfsResource = (VFSResource) movedFrom;
        if (vfsResource.getItem() instanceof Versionable && ((Versionable) vfsResource.getItem()).getVersions().isVersioned()) {
            VFSLeaf currentVersion = (VFSLeaf) vfsResource.getItem();
            VersionsManager.getInstance().move(currentVersion, childLeaf, identity);
        }
    }
    return true;
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuotaExceededException(org.olat.core.util.vfs.QuotaExceededException) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) IOException(java.io.IOException) QuotaExceededException(org.olat.core.util.vfs.QuotaExceededException)

Example 25 with VFSItem

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

the class WebdavStatus method deleteCollection.

/**
 * Deletes a collection.
 *
 * @param path Path to the collection to be deleted
 * @param errorList Contains the list of the errors which occurred
 */
private void deleteCollection(HttpServletRequest req, String path, Map<String, Integer> errorList) {
    if (log.isDebug())
        log.debug("Delete:" + path);
    // Prevent deletion of special subdirectories
    if (isSpecialPath(path)) {
        errorList.put(path, new Integer(WebdavStatus.SC_FORBIDDEN));
        return;
    }
    String ifHeader = req.getHeader("If");
    if (ifHeader == null)
        ifHeader = "";
    String lockTokenHeader = req.getHeader("Lock-Token");
    if (lockTokenHeader == null)
        lockTokenHeader = "";
    final WebResourceRoot resources = getResources(req);
    Collection<VFSItem> entries = resources.list(path);
    UserSession usess = webDAVManager.getUserSession(req);
    for (VFSItem entry : entries) {
        String childName = path;
        if (!childName.equals("/")) {
            childName += "/";
        }
        childName += entry.getName();
        WebResource childResource = resources.getResource(childName);
        if (lockManager.isLocked(childResource, ifHeader + lockTokenHeader, usess.getIdentity())) {
            errorList.put(childName, new Integer(WebdavStatus.SC_LOCKED));
        } else {
            if (childResource.isDirectory()) {
                deleteCollection(req, childName, errorList);
            }
            if (!resources.delete(childResource)) {
                if (!childResource.isDirectory()) {
                    // If it's not a collection, then it's an unknown error
                    errorList.put(childName, new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
                }
            }
        }
    }
}
Also used : UserSession(org.olat.core.util.UserSession) VFSItem(org.olat.core.util.vfs.VFSItem)

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