Search in sources :

Example 1 with NotFoundMediaResource

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

the class DialogElementController method doDownload.

private void doDownload(UserRequest ureq) {
    VFSLeaf file = dialogElmsMgr.getDialogLeaf(element);
    if (file != null) {
        ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(file));
        ThreadLocalUserActivityLogger.log(CourseLoggingAction.DIALOG_ELEMENT_FILE_DOWNLOADED, getClass(), LoggingResourceable.wrapBCFile(element.getFilename()));
    } else {
        ureq.getDispatchResult().setResultingMediaResource(new NotFoundMediaResource());
        logError("No file to discuss: " + element, null);
    }
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 2 with NotFoundMediaResource

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

the class QTI21AssessmentRunController method doDownloadSignature.

private void doDownloadSignature(UserRequest ureq) {
    MediaResource resource = null;
    if (courseNode instanceof IQTESTCourseNode) {
        IQTESTCourseNode testCourseNode = (IQTESTCourseNode) courseNode;
        AssessmentEntry assessmentEntry = testCourseNode.getUserAssessmentEntry(userCourseEnv);
        AssessmentTestSession session = qtiService.getAssessmentTestSession(assessmentEntry.getAssessmentId());
        File signature = qtiService.getAssessmentResultSignature(session);
        if (signature.exists()) {
            resource = new DownloadeableMediaResource(signature);
        }
    }
    if (resource == null) {
        resource = new NotFoundMediaResource();
    }
    ureq.getDispatchResult().setResultingMediaResource(resource);
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) DownloadeableMediaResource(org.olat.fileresource.DownloadeableMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) DownloadeableMediaResource(org.olat.fileresource.DownloadeableMediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) File(java.io.File)

Example 3 with NotFoundMediaResource

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

the class MessageListController method doDeliverAttachment.

private void doDeliverAttachment(UserRequest ureq, String cmd) {
    MediaResource res = null;
    try {
        int index = cmd.lastIndexOf("_");
        String attachmentPosition = cmd.substring(cmd.indexOf("_") + 1, index);
        String messageKey = cmd.substring(index + 1);
        int position = Integer.parseInt(attachmentPosition);
        Long key = new Long(messageKey);
        for (MessageView view : backupViews) {
            if (view.getKey().equals(key)) {
                List<VFSItem> attachments = view.getAttachments();
                // velocity counter start with 1
                VFSLeaf attachment = (VFSLeaf) attachments.get(position - 1);
                VFSMediaResource fileResource = new VFSMediaResource(attachment);
                // prevent XSS attack
                fileResource.setDownloadable(true);
                res = fileResource;
            }
        }
    } catch (Exception e) {
        logError("Cannot deliver message attachment", e);
    }
    if (res == null) {
        res = new NotFoundMediaResource();
    }
    ureq.getDispatchResult().setResultingMediaResource(res);
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) 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 4 with NotFoundMediaResource

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

the class CatalogEntryImageMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    if (relPath.startsWith("/")) {
        relPath = relPath.substring(1, relPath.length());
    }
    VFSContainer categoryResources = catalogManager.getCatalogResourcesHome();
    VFSItem image = categoryResources.resolve(relPath);
    MediaResource resource = null;
    if (image instanceof VFSLeaf) {
        if (image instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) image).getMetaInfo();
            if (info != null) {
                VFSLeaf thumbnail = info.getThumbnail(180, 180, true);
                if (thumbnail != null) {
                    resource = new VFSMediaResource(thumbnail);
                }
            }
        }
        if (resource == null) {
            resource = new VFSMediaResource((VFSLeaf) image);
        }
    } else {
        resource = new NotFoundMediaResource();
    }
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) 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) 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 5 with NotFoundMediaResource

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

the class TunnelMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest hreq) {
    String method = hreq.getMethod();
    String uri = relPath;
    HttpUriRequest meth = null;
    try {
        URIBuilder builder = new URIBuilder();
        builder.setScheme(proto).setHost(host).setPort(port.intValue());
        if (uri == null) {
            uri = (startUri == null) ? "" : startUri;
        }
        if (uri.length() > 0 && uri.charAt(0) != '/') {
            uri = "/" + uri;
        }
        if (StringHelper.containsNonWhitespace(uri)) {
            builder.setPath(uri);
        }
        if (method.equals("GET")) {
            String queryString = hreq.getQueryString();
            if (StringHelper.containsNonWhitespace(queryString)) {
                builder.setCustomQuery(queryString);
            }
            meth = new HttpGet(builder.build());
        } else if (method.equals("POST")) {
            Map<String, String[]> params = hreq.getParameterMap();
            HttpPost pmeth = new HttpPost(builder.build());
            List<BasicNameValuePair> pairs = new ArrayList<>();
            for (String key : params.keySet()) {
                String[] vals = params.get(key);
                for (String val : vals) {
                    pairs.add(new BasicNameValuePair(key, val));
                }
            }
            HttpEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
            pmeth.setEntity(entity);
            meth = pmeth;
        }
        // test page e.g. http://cgi.algonet.se/htbin/cgiwrap/ug/test.py
        if ("enabled".equals(CoreSpringFactory.getImpl(BaseSecurityModule.class).getUserInfosTunnelCourseBuildingBlock())) {
            User u = ident.getUser();
            meth.addHeader("X-OLAT-USERNAME", ident.getName());
            meth.addHeader("X-OLAT-LASTNAME", u.getProperty(UserConstants.LASTNAME, null));
            meth.addHeader("X-OLAT-FIRSTNAME", u.getProperty(UserConstants.FIRSTNAME, null));
            meth.addHeader("X-OLAT-EMAIL", u.getProperty(UserConstants.EMAIL, null));
            meth.addHeader("X-OLAT-USERIP", ipAddress);
        }
        HttpResponse response = httpClient.execute(meth);
        if (response == null) {
            // error
            return new NotFoundMediaResource();
        }
        // get or post successfully
        Header responseHeader = response.getFirstHeader("Content-Type");
        if (responseHeader == null) {
            // error
            EntityUtils.consumeQuietly(response.getEntity());
            return new NotFoundMediaResource();
        }
        return new HttpRequestMediaResource(response);
    } catch (ClientProtocolException | URISyntaxException e) {
        log.error("", e);
        return null;
    } catch (IOException e) {
        log.error("Error loading URI: " + (meth == null ? "???" : meth.getURI()), e);
        return null;
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) HttpPost(org.apache.http.client.methods.HttpPost) HttpRequestMediaResource(org.olat.core.gui.media.HttpRequestMediaResource) User(org.olat.core.id.User) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URIBuilder(org.apache.http.client.utils.URIBuilder) ClientProtocolException(org.apache.http.client.ClientProtocolException) Header(org.apache.http.Header) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

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