Search in sources :

Example 16 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class CmdServeThumbnailResource method execute.

@Override
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    VFSSecurityCallback inheritedSecCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
    if (inheritedSecCallback != null && !inheritedSecCallback.canRead())
        throw new RuntimeException("Illegal read attempt: " + folderComponent.getCurrentContainerPath());
    // extract file
    String path = ureq.getModuleURI();
    MediaResource mr = null;
    VFSLeaf vfsfile = (VFSLeaf) folderComponent.getRootContainer().resolve(path);
    if (vfsfile == null) {
        // double decoding of ++
        vfsfile = (VFSLeaf) FolderCommandHelper.tryDoubleDecoding(ureq, folderComponent);
    }
    if (vfsfile instanceof MetaTagged) {
        MetaInfo info = ((MetaTagged) vfsfile).getMetaInfo();
        if (info != null && info.isThumbnailAvailable()) {
            VFSLeaf thumbnail = info.getThumbnail(200, 200, false);
            if (thumbnail != null) {
                mr = new VFSMediaResource(thumbnail);
            }
        }
    }
    if (mr == null) {
        mr = new NotFoundMediaResource();
    }
    ureq.getDispatchResult().setResultingMediaResource(mr);
    return null;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) 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) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 17 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class GlossaryDefinitionMapper 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();
    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("GlossaryDefinition delivery failed; path to glossaryFolder not existing: " + relPath, null);
        return new NotFoundMediaResource();
    }
    VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
    if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
        logWarn("GlossaryDefinition delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
        return new NotFoundMediaResource();
    }
    String glossaryMainTerm = parts[2];
    if (parts.length > 2) {
        // this handle / or \ in a term
        for (int i = 3; i < parts.length; i++) {
            glossaryMainTerm += "/" + parts[i];
        }
    }
    // cut away ".html" if necessary
    if (glossaryMainTerm.endsWith(".html")) {
        glossaryMainTerm = glossaryMainTerm.substring(0, glossaryMainTerm.length() - 5);
    }
    glossaryMainTerm = glossaryMainTerm.toLowerCase();
    Set<String> alternatives = new HashSet<>();
    prepareAlternatives(glossaryMainTerm, alternatives);
    // 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/html");
    List<GlossaryItem> glossItems = gIM.getGlossaryItemListByVFSItem(glossaryFolder);
    GlossaryItem foundItem = null;
    for (GlossaryItem glossaryItem : glossItems) {
        String item = glossaryItem.getGlossTerm().toLowerCase();
        if (alternatives.contains(item)) {
            foundItem = glossaryItem;
            break;
        }
    }
    if (foundItem == null) {
        return new NotFoundMediaResource();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<dd><dt>").append(foundItem.getGlossTerm()).append("</dt><dl>").append(foundItem.getGlossDef()).append("</dl></dd>");
    resource.setData(sb.toString());
    resource.setEncoding("utf-8");
    if (isLogDebugEnabled())
        logDebug("loaded definition for " + glossaryMainTerm, null);
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpServletResponse(javax.servlet.http.HttpServletResponse) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) StringMediaResource(org.olat.core.gui.media.StringMediaResource) File(java.io.File) HashSet(java.util.HashSet) GlossaryItem(org.olat.core.commons.modules.glossary.GlossaryItem)

Example 18 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class MailAttachmentMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    if (relPath != null && relPath.indexOf(ATTACHMENT_CONTEXT) >= 0) {
        int startIndex = relPath.indexOf(ATTACHMENT_CONTEXT);
        int endIndex = relPath.indexOf("/", startIndex + ATTACHMENT_CONTEXT.length());
        if (startIndex >= 0 && endIndex > startIndex) {
            String attachmentKey = relPath.substring(startIndex + ATTACHMENT_CONTEXT.length(), endIndex);
            try {
                Long key = new Long(attachmentKey);
                VFSLeaf datas = mailManager.getAttachmentDatas(key);
                MediaResource resource = new VFSMediaResource(datas);
                return resource;
            } catch (NumberFormatException e) {
                return new NotFoundMediaResource();
            }
        }
    }
    return new NotFoundMediaResource();
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 19 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class ResourcesMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    String filename = null;
    MediaResource resource = null;
    try {
        File root = new File(assessmentObjectUri.getPath());
        String href = request.getParameter("href");
        if (StringHelper.containsNonWhitespace(href)) {
            filename = href;
        } else if (StringHelper.containsNonWhitespace(relPath)) {
            filename = relPath;
            if (filename.startsWith("/")) {
                filename = filename.substring(1, filename.length());
            }
        }
        File file = new File(root.getParentFile(), filename);
        if (file.exists()) {
            if (file.getName().endsWith(".xml")) {
                resource = new ForbiddenMediaResource();
            } else if (FileUtils.isInSubDirectory(root.getParentFile(), file)) {
                resource = new FileMediaResource(file, true);
            } else {
                resource = new ForbiddenMediaResource();
            }
        } else if (filename.endsWith("/raw/_noversion_/images/transparent.gif")) {
            String realPath = request.getServletContext().getRealPath("/static/images/transparent.gif");
            resource = new FileMediaResource(new File(realPath), true);
        } else {
            String submissionName = null;
            File storage = null;
            if (filename.startsWith("submissions/")) {
                String submission = filename.substring("submissions/".length());
                int candidateSessionIndex = submission.indexOf('/');
                if (candidateSessionIndex > 0) {
                    submissionName = submission.substring(candidateSessionIndex + 1);
                    if (submissionDirectory != null) {
                        storage = submissionDirectory;
                    } else if (submissionDirectoryMaps != null) {
                        String sessionKey = submission.substring(0, candidateSessionIndex);
                        if (StringHelper.isLong(sessionKey)) {
                            try {
                                storage = submissionDirectoryMaps.get(new Long(sessionKey));
                            } catch (Exception e) {
                                log.error("", e);
                            }
                        }
                    }
                }
            }
            if (storage != null && StringHelper.containsNonWhitespace(submissionName)) {
                File submissionFile = new File(storage, submissionName);
                if (submissionFile.exists()) {
                    resource = new FileMediaResource(submissionFile, true);
                } else {
                    resource = new NotFoundMediaResource();
                }
            } else {
                resource = new NotFoundMediaResource();
            }
        }
    } catch (Exception e) {
        log.error("", e);
        resource = new NotFoundMediaResource();
    }
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) ForbiddenMediaResource(org.olat.core.gui.media.ForbiddenMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) ForbiddenMediaResource(org.olat.core.gui.media.ForbiddenMediaResource) File(java.io.File)

Example 20 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class CPDisplayController method switchToPage.

public void switchToPage(UserRequest ureq, TreeNode tn) {
    String identifierRes = (String) tn.getUserObject();
    OLATResourceable ores = OresHelper.createOLATResourceableInstanceWithoutCheck("path=" + identifierRes, 0l);
    addToHistory(ureq, ores, null);
    // security check
    if (identifierRes.indexOf("../") != -1)
        throw new AssertException("a non-normalized url encountered in a manifest item:" + identifierRes);
    // Check also for XML resources that use XSLT for rendering
    if (identifierRes.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (identifierRes.length() - 4) || identifierRes.toLowerCase().endsWith(FILE_SUFFIX_XML)) {
        // display html files inline or in an iframe
        if (cpContentCtr != null)
            cpContentCtr.setCurrentURI(identifierRes);
        if (cpComponent != null)
            cpComponent.setCurrentURI(identifierRes);
    } else {
        // initialized. Delegates displaying to the browser (and its plugins).
        if (cpContentCtr != null) {
            cpContentCtr.setCurrentURI(identifierRes);
        } else {
            // if an entry in a manifest points e.g. to a pdf file and the iframe
            // controller has not been initialized display it non-inline
            VFSItem currentItem = rootContainer.resolve(identifierRes);
            MediaResource mr;
            if (currentItem == null || !(currentItem instanceof VFSLeaf))
                mr = new NotFoundMediaResource();
            else
                mr = new VFSMediaResource((VFSLeaf) currentItem);
            ureq.getDispatchResult().setResultingMediaResource(mr);
            // Prevent 'don't reload' warning
            cpTree.setDirty(false);
        }
    }
    updateNextPreviousLink(tn);
    ThreadLocalUserActivityLogger.log(CourseLoggingAction.CP_GET_FILE, getClass(), LoggingResourceable.wrapCpNode(identifierRes));
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) VFSItem(org.olat.core.util.vfs.VFSItem) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Aggregations

NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)38 MediaResource (org.olat.core.gui.media.MediaResource)26 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)24 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)24 VFSItem (org.olat.core.util.vfs.VFSItem)16 StringMediaResource (org.olat.core.gui.media.StringMediaResource)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 File (java.io.File)8 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)6 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 GlossaryItemManager (org.olat.core.commons.modules.glossary.GlossaryItemManager)4 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2