Search in sources :

Example 6 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class CmdCreateFile method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // create the file
    fileName = textElement.getValue();
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.createChildLeaf(fileName);
    if (item == null) {
        status = FolderCommandStatus.STATUS_FAILED;
        notifyFinished(ureq);
    } else {
        if (item instanceof MetaTagged) {
            MetaInfo meta = ((MetaTagged) item).getMetaInfo();
            meta.setAuthor(ureq.getIdentity());
            if (licenseModule.isEnabled(licenseHandler)) {
                License license = licenseService.createDefaultLicense(licenseHandler, getIdentity());
                meta.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
                meta.setLicenseTypeName(license.getLicenseType().getName());
                meta.setLicensor(license.getLicensor());
                meta.setLicenseText(LicenseUIFactory.getLicenseText(license));
            }
            meta.write();
        }
        // start HTML editor with the folders root folder as base and the file
        // path as a relative path from the root directory. But first check if the
        // root directory is wirtable at all (e.g. not the case in users personal
        // briefcase), and seach for the next higher directory that is writable.
        String relFilePath = "/" + fileName;
        // add current container path if not at root level
        if (!folderComponent.getCurrentContainerPath().equals("/")) {
            relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
        }
        VFSContainer writableRootContainer = folderComponent.getRootContainer();
        ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
        if (result != null) {
            writableRootContainer = result.getContainer();
            relFilePath = result.getFileName();
        } else {
            // use fallback that always work: current directory and current file
            relFilePath = fileName;
            writableRootContainer = folderComponent.getCurrentContainer();
        }
        if (relFilePath.endsWith(".html") || relFilePath.endsWith(".htm")) {
            editorCtr = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true);
            ((HTMLEditorController) editorCtr).setNewFile(true);
        } else {
            editorCtr = new PlainTextEditorController(ureq, getWindowControl(), (VFSLeaf) writableRootContainer.resolve(relFilePath), "utf-8", true, true, null);
        }
        listenTo(editorCtr);
        initialPanel.setContent(editorCtr.getInitialComponent());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) PlainTextEditorController(org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) License(org.olat.core.commons.services.license.License) VFSItem(org.olat.core.util.vfs.VFSItem) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

Example 7 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class FolderManager method getFileInfosRecursively.

private static void getFileInfosRecursively(OlatRelPathImpl relPath, List<FileInfo> fileInfos, long newerThan, int basePathlen) {
    if (relPath instanceof VFSLeaf) {
        // is a file
        long lastModified = ((VFSLeaf) relPath).getLastModified();
        if (lastModified > newerThan) {
            MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPath);
            String bcrootPath = relPath.getRelPath();
            String bcRelPath = bcrootPath.substring(basePathlen);
            fileInfos.add(new FileInfo(bcRelPath, meta, new Date(lastModified)));
        }
    } else {
        // is a folder
        OlatRootFolderImpl container = (OlatRootFolderImpl) relPath;
        for (VFSItem item : container.getItems(new SystemItemFilter())) {
            getFileInfosRecursively((OlatRelPathImpl) item, fileInfos, newerThan, basePathlen);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaInfoFactory(org.olat.core.commons.modules.bc.meta.MetaInfoFactory) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date)

Example 8 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class CmdCreateFolder method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // create the folder
    String name = textElement.getValue();
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.createChildContainer(name);
    if (item instanceof OlatRelPathImpl) {
        // update meta data
        MetaInfo meta = metaInfoFactory.createMetaInfoFor((OlatRelPathImpl) item);
        meta.setAuthor(ureq.getIdentity());
        meta.write();
        status = FolderCommandStatus.STATUS_FAILED;
        fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FOLDER_EVENT, folderName));
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    } else {
        status = FolderCommandStatus.STATUS_FAILED;
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    }
}
Also used : OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 9 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class FileCopyController method finishSuccessfullUpload.

private void finishSuccessfullUpload(String fileName, UserRequest ureq) {
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.resolve(fileName);
    if (item instanceof OlatRootFileImpl) {
        OlatRootFileImpl relPathItem = (OlatRootFileImpl) item;
        // create meta data
        MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPathItem);
        meta.setAuthor(ureq.getIdentity());
        // if overwrite an older file
        meta.clearThumbnails();
        meta.write();
    }
    ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_COPIED, getClass(), CoreLoggingResourceable.wrapUploadFile(fileName));
    // Notify listeners about upload
    fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FILE_EVENT, newFile.getName()));
    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) MetaInfoFactory(org.olat.core.commons.modules.bc.meta.MetaInfoFactory) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)

Example 10 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class MetaTaggedComparator method compare.

public int compare(MetaTagged i1, MetaTagged i2) {
    MetaInfo m1 = i1.getMetaInfo();
    MetaInfo m2 = i2.getMetaInfo();
    return comparator.compare(m1, m2);
}
Also used : MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo)

Aggregations

MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)108 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)86 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 VFSItem (org.olat.core.util.vfs.VFSItem)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)40 Date (java.util.Date)18 OutputStream (java.io.OutputStream)14 File (java.io.File)12 IOException (java.io.IOException)12 Versionable (org.olat.core.util.vfs.version.Versionable)12 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 FolderEvent (org.olat.core.commons.modules.bc.FolderEvent)10 MediaResource (org.olat.core.gui.media.MediaResource)10 Identity (org.olat.core.id.Identity)10 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)10 FileInfo (org.olat.core.commons.modules.bc.FileInfo)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)8 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)8