Search in sources :

Example 16 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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 17 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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 18 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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 19 with VFSContainer

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

the class HtmlStaticPageComponent method setCurrentURI.

/**
 * Sets the start html page, may be null
 *
 * @param currentURI The currentURI to set
 */
public void setCurrentURI(String currentURI) {
    if (!isFileTypeSupported(currentURI)) {
        throw new AssertException("can only accept files which are inline renderable(.html, .htm, .txt), but given filename is:" + currentURI);
    }
    this.currentURI = currentURI;
    setDirty(true);
    VFSItem sourceItem = null;
    if (rootContainer != null)
        sourceItem = rootContainer.resolve(currentURI);
    if (sourceItem == null || (sourceItem instanceof VFSContainer)) {
        jsOnLoad = null;
        htmlHead = null;
        htmlContent = "File not found: " + currentURI;
        return;
    }
    getFileContent((VFSLeaf) sourceItem);
}
Also used : AssertException(org.olat.core.logging.AssertException) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 20 with VFSContainer

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

the class GlossaryTermMapper method handle.

/**
 * @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String,
 *      javax.servlet.http.HttpServletRequest)
 */
public MediaResource handle(String relPath, HttpServletRequest request) {
    GlossaryItemManager gIM = GlossaryItemManager.getInstance();
    // security checks are done by MapperRegistry
    String[] parts = relPath.split("/");
    String glossaryId = parts[1];
    String glossaryFolderString = FolderConfig.getCanonicalRoot() + FolderConfig.getRepositoryHome() + "/" + glossaryId + "/" + GlossaryMarkupItemController.INTERNAL_FOLDER_NAME;
    File glossaryFolderFile = new File(glossaryFolderString);
    if (!glossaryFolderFile.isDirectory()) {
        logWarn("GlossaryTerms delivery failed; path to glossaryFolder not existing: " + relPath, null);
        return new NotFoundMediaResource();
    }
    VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
    if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
        logWarn("GlossaryTerms delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
        return new NotFoundMediaResource();
    }
    // Create a media resource
    StringMediaResource resource = new StringMediaResource() {

        @Override
        public void prepare(HttpServletResponse hres) {
        // don't use normal string media headers which prevent caching,
        // use standard browser caching based on last modified timestamp
        }
    };
    resource.setLastModified(gIM.getGlossaryLastModifiedTime(glossaryFolder));
    resource.setContentType("text/javascript");
    // Get data
    String glossaryArrayData = TextMarkerJsGenerator.loadGlossaryItemListAsJSArray(glossaryFolder);
    resource.setData(glossaryArrayData);
    // UTF-8 encoding used in this js file since explicitly set in the ajax
    // call (usually js files are 8859-1)
    resource.setEncoding("utf-8");
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) StringMediaResource(org.olat.core.gui.media.StringMediaResource) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

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