Search in sources :

Example 21 with MetaInfo

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

the class RepositoryEntryImageMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    if (rootContainer == null) {
        rootContainer = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
    }
    if (relPath.startsWith("/")) {
        relPath = relPath.substring(1, relPath.length());
    }
    MediaResource resource = null;
    VFSItem image = rootContainer.resolve(relPath);
    if (image instanceof VFSLeaf) {
        if (image instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) image).getMetaInfo();
            if (info != null) {
                // 121 is needed to fill the div
                VFSLeaf thumbnail = info.getThumbnail(180, 120, true);
                if (thumbnail != null) {
                    resource = new VFSMediaResource(thumbnail);
                }
            }
        }
        if (resource == null) {
            resource = new VFSMediaResource((VFSLeaf) image);
        }
    }
    return resource;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) 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) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 22 with MetaInfo

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

the class CompareEvaluationsFormController method createFileUploadCompareWrapper.

private FileUploadCompareWrapper createFileUploadCompareWrapper(UserRequest ureq, FileUpload element, EvaluationFormResponse response) {
    Identity evaluator = response.getSession().getIdentity();
    String color = evaluatorToColors.get(evaluator);
    String evaluatorName = getLegend(evaluator);
    String filename = response.getStringuifiedResponse();
    String filesize = null;
    String mapperUri = null;
    String iconCss = null;
    String thumbUri = null;
    VFSLeaf leaf = evaluationFormManager.loadResponseLeaf(response);
    if (leaf != null) {
        filename = leaf.getName();
        filesize = Formatter.formatBytes((leaf).getSize());
        mapperUri = registerCacheableMapper(ureq, "file-upload-" + element.getId() + "-" + leaf.getLastModified(), new VFSMediaMapper(leaf));
        iconCss = CSSHelper.createFiletypeIconCssClassFor(leaf.getName());
        if (leaf instanceof MetaTagged) {
            MetaTagged metaTaggedLeaf = (MetaTagged) leaf;
            MetaInfo meta = metaTaggedLeaf.getMetaInfo();
            if (meta != null && meta.isThumbnailAvailable()) {
                VFSLeaf thumb = meta.getThumbnail(200, 200, false);
                if (thumb != null) {
                    thumbUri = registerCacheableMapper(ureq, "file-upload-thumb" + element.getId() + "-" + leaf.getLastModified(), new VFSMediaMapper(thumb));
                    ;
                }
            }
        }
    }
    return new FileUploadCompareWrapper(color, evaluatorName, filename, filesize, mapperUri, iconCss, thumbUri);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSMediaMapper(org.olat.core.util.vfs.VFSMediaMapper) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) FileUploadCompareWrapper(org.olat.modules.forms.ui.model.FileUploadCompareWrapper) Identity(org.olat.core.id.Identity)

Example 23 with MetaInfo

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

the class FileArtefactHandler method prefillArtefactAccordingToSource.

/**
 * @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact,
 *      java.lang.Object)
 */
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
    super.prefillArtefactAccordingToSource(artefact, source);
    if (source instanceof VFSItem) {
        VFSItem fileSource = (VFSItem) source;
        ((FileArtefact) artefact).setFilename(fileSource.getName());
        MetaInfo meta = null;
        if (fileSource instanceof MetaTagged) {
            meta = ((MetaTagged) fileSource).getMetaInfo();
        }
        if (meta != null && StringHelper.containsNonWhitespace(meta.getTitle())) {
            artefact.setTitle(meta.getTitle());
        } else {
            artefact.setTitle(fileSource.getName());
        }
        if (meta != null && StringHelper.containsNonWhitespace(meta.getComment())) {
            artefact.setDescription(meta.getComment());
        }
        artefact.setSignature(60);
        String path = ((OlatRootFileImpl) fileSource).getRelPath();
        String[] pathElements = path.split("/");
        String finalBusinessPath = null;
        String sourceInfo = null;
        // used to rebuild businessPath and source for a file:
        if (pathElements[1].equals("homes") && meta != null && pathElements[2].equals(meta.getAuthor())) {
            // from users briefcase
            String lastParts = "/";
            for (int i = 4; i < (pathElements.length - 1); i++) {
                lastParts = lastParts + pathElements[i] + "/";
            }
            sourceInfo = "Home -> " + pathElements[3] + " -> " + lastParts + fileSource.getName();
        } else if (pathElements[3].equals("BusinessGroup")) {
            // out of a businessgroup
            String lastParts = "/";
            for (int i = 5; i < (pathElements.length - 1); i++) {
                lastParts = lastParts + pathElements[i] + "/";
            }
            BusinessGroup bGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(new Long(pathElements[4]));
            if (bGroup != null) {
                sourceInfo = bGroup.getName() + " -> " + lastParts + " -> " + fileSource.getName();
            }
            finalBusinessPath = "[BusinessGroup:" + pathElements[4] + "][toolfolder:0][path=" + lastParts + fileSource.getName() + ":0]";
        } else if (pathElements[4].equals("coursefolder")) {
            // the course folder
            sourceInfo = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(new Long(pathElements[2])) + " -> " + fileSource.getName();
        } else if (pathElements[1].equals("course") && pathElements[3].equals("foldernodes")) {
            // folders inside a course
            sourceInfo = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(new Long(pathElements[2])) + " -> " + pathElements[4] + " -> " + fileSource.getName();
            finalBusinessPath = "[RepositoryEntry:" + pathElements[2] + "][CourseNode:" + pathElements[4] + "]";
        }
        if (sourceInfo == null) {
            // unknown source, keep full path
            sourceInfo = VFSManager.getRealPath(fileSource.getParentContainer()) + "/" + fileSource.getName();
        }
        artefact.setBusinessPath(finalBusinessPath);
        artefact.setSource(sourceInfo);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) VFSItem(org.olat.core.util.vfs.VFSItem) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)

Example 24 with MetaInfo

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

the class VideoHandler method getInformations.

@Override
public MediaInformations getInformations(Object mediaObject) {
    String title = null;
    String description = null;
    if (mediaObject instanceof MetaTagged) {
        MetaInfo meta = ((MetaTagged) mediaObject).getMetaInfo();
        title = meta.getTitle();
        description = meta.getComment();
    }
    return new Informations(title, description);
}
Also used : MediaInformations(org.olat.modules.portfolio.MediaInformations) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo)

Example 25 with MetaInfo

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

the class RepositoryManager method setImage.

public boolean setImage(VFSLeaf newImageFile, RepositoryEntry re) {
    VFSLeaf currentImage = getImage(re);
    if (currentImage != null) {
        if (currentImage instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) currentImage).getMetaInfo();
            if (info != null) {
                info.clearThumbnails();
            }
        }
        currentImage.delete();
    }
    if (newImageFile == null || !newImageFile.exists() || newImageFile.getSize() <= 0) {
        return false;
    }
    String targetExtension = ".png";
    String extension = FileUtils.getFileSuffix(newImageFile.getName());
    if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension)) {
        targetExtension = ".jpg";
    }
    VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
    VFSLeaf repoImage = repositoryHome.createChildLeaf(re.getResourceableId() + targetExtension);
    if (targetExtension.equals(".png") || targetExtension.equals(".jpg")) {
        Size newImageSize = imageHelper.getSize(newImageFile, extension);
        if (newImageSize != null && newImageSize.getWidth() <= PICTURE_WIDTH && newImageSize.getHeight() <= PICTURE_HEIGHT) {
            boolean success = VFSManager.copyContent(newImageFile, repoImage);
            return success;
        }
    }
    Size size = imageHelper.scaleImage(newImageFile, repoImage, PICTURE_WIDTH, PICTURE_WIDTH, false);
    return size != null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Size(org.olat.core.commons.services.image.Size) 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) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

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