Search in sources :

Example 81 with MediaResource

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

the class QTIEditorMainController method doExportDocx.

private void doExportDocx(UserRequest ureq) {
    AssessmentNode rootNode = (AssessmentNode) menuTreeModel.getRootNode();
    VFSContainer editorContainer = qtiPackage.getBaseDir();
    exportLatch = new CountDownLatch(1);
    MediaResource mr = new QTIWordExport(rootNode, editorContainer, getLocale(), "UTF-8", exportLatch);
    ureq.getDispatchResult().setResultingMediaResource(mr);
}
Also used : AssessmentNode(org.olat.ims.qti.editor.tree.AssessmentNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) MediaResource(org.olat.core.gui.media.MediaResource) CountDownLatch(java.util.concurrent.CountDownLatch) QTIWordExport(org.olat.ims.qti.export.QTIWordExport)

Example 82 with MediaResource

use of org.olat.core.gui.media.MediaResource 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 83 with MediaResource

use of org.olat.core.gui.media.MediaResource 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)

Example 84 with MediaResource

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

the class OpenMeetingsRecordingController method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (source == downloadLink) {
        try {
            String url = openMeetingsManager.getRecordingURL(recording);
            MediaResource downloadUrl = new RedirectMediaResource(url);
            ureq.getDispatchResult().setResultingMediaResource(downloadUrl);
        } catch (OpenMeetingsException e) {
            logError("", e);
        }
    }
}
Also used : RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) OpenMeetingsException(org.olat.modules.openmeetings.manager.OpenMeetingsException) MediaResource(org.olat.core.gui.media.MediaResource) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource)

Example 85 with MediaResource

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

the class QuestionPoolServiceImpl method export.

@Override
public MediaResource export(List<QuestionItemShort> items, ExportFormatOptions format, Locale locale) {
    MediaResource mr = null;
    if (DefaultExportFormat.ZIP_EXPORT_FORMAT.equals(format)) {
        List<Long> keys = toKeys(items);
        List<QuestionItemFull> fullItems = questionItemDao.loadByIds(keys);
        mr = new ExportQItemsZipResource("UTF-8", locale, fullItems);
    // make a zip with all items
    } else {
        QPoolSPI selectedSp = null;
        List<QPoolSPI> sps = qpoolModule.getQuestionPoolProviders();
        for (QPoolSPI sp : sps) {
            if (sp.getTestExportFormats().contains(format)) {
                selectedSp = sp;
                break;
            }
        }
        if (selectedSp != null) {
            mr = selectedSp.exportTest(items, format, locale);
        }
    }
    return mr;
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolSPI(org.olat.modules.qpool.QPoolSPI) MediaResource(org.olat.core.gui.media.MediaResource)

Aggregations

MediaResource (org.olat.core.gui.media.MediaResource)141 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)36 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)32 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)30 Identity (org.olat.core.id.Identity)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 File (java.io.File)16 ArrayList (java.util.ArrayList)16 RedirectMediaResource (org.olat.core.gui.media.RedirectMediaResource)16 IOException (java.io.IOException)13 FileMediaResource (org.olat.core.gui.media.FileMediaResource)12 List (java.util.List)10 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)10 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)10 StringMediaResource (org.olat.core.gui.media.StringMediaResource)8 AssertException (org.olat.core.logging.AssertException)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)8 InputStream (java.io.InputStream)6 OLATResourceable (org.olat.core.id.OLATResourceable)6