Search in sources :

Example 11 with Mapper

use of org.olat.core.dispatcher.mapper.Mapper in project openolat by klemens.

the class RichTextConfiguration method setDocumentMediaBase.

/**
 * Set the documents media base that is used to deliver media files
 * referenced by the content.
 *
 * @param documentBaseContainer
 *            the vfs container that contains the media files
 * @param relFilePath
 *            The file path of the HTML file relative to the
 *            documentBaseContainer
 * @param usess
 *            The user session
 */
private void setDocumentMediaBase(final VFSContainer documentBaseContainer, String relFilePath, UserSession usess) {
    linkBrowserRelativeFilePath = relFilePath;
    // get a usersession-local mapper for the file storage (and tinymce's references to images and such)
    Mapper contentMapper = new VFSContainerMapper(documentBaseContainer);
    // Register mapper for this user. This mapper is cleaned up in the
    // dispose method (RichTextElementImpl will clean it up)
    // Register mapper as cacheable
    String mapperID = VFSManager.getRealPath(documentBaseContainer);
    if (mapperID == null) {
        // Can't cache mapper, no cacheable context available
        contentMapperKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, contentMapper);
    } else {
        // Add classname to the file path to remove conflicts with other
        // usages of the same file path
        mapperID = this.getClass().getSimpleName() + ":" + mapperID + ":" + CodeHelper.getRAMUniqueID();
        contentMapperKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, mapperID, contentMapper);
    }
    if (relFilePath != null) {
        // remove filename, path must end with slash
        int lastSlash = relFilePath.lastIndexOf("/");
        if (lastSlash == -1) {
            relFilePath = "";
        } else if (lastSlash + 1 < relFilePath.length()) {
            relFilePath = relFilePath.substring(0, lastSlash + 1);
        } else {
            String containerPath = documentBaseContainer.getName();
            // try to get more information if it's a local folder impl
            if (documentBaseContainer instanceof LocalFolderImpl) {
                LocalFolderImpl folder = (LocalFolderImpl) documentBaseContainer;
                containerPath = folder.getBasefile().getAbsolutePath();
            }
            log.warn("Could not parse relative file path::" + relFilePath + " in container::" + containerPath);
        }
    } else {
        relFilePath = "";
        // set empty relative file path to prevent nullpointers later on
        linkBrowserRelativeFilePath = relFilePath;
    }
    mapperUri = contentMapperKey.getUrl() + "/" + relFilePath;
    setQuotedConfigValue(DOCUMENT_BASE_URL, mapperUri);
}
Also used : VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) Mapper(org.olat.core.dispatcher.mapper.Mapper) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 12 with Mapper

use of org.olat.core.dispatcher.mapper.Mapper in project OpenOLAT by OpenOLAT.

the class LTIRunController method doBasicLTI.

private void doBasicLTI(UserRequest ureq, VelocityContainer container) {
    String url = getUrl();
    container.contextPut("url", url == null ? "" : url);
    String oauth_consumer_key = (String) config.get(LTIConfigForm.CONFIGKEY_KEY);
    String oauth_secret = (String) config.get(LTIConfigForm.CONFIGKEY_PASS);
    String debug = (String) config.get(LTIConfigForm.CONFIG_KEY_DEBUG);
    String serverUri = Settings.createServerURI();
    String sourcedId = courseEnv.getCourseResourceableId() + "_" + courseNode.getIdent() + "_" + getIdentity().getKey();
    container.contextPut("sourcedId", sourcedId);
    OLATResource courseResource = courseEnv.getCourseGroupManager().getCourseResource();
    Mapper talkbackMapper = new TalkBackMapper(getLocale(), getWindowControl().getWindowBackOffice().getWindow().getGuiTheme().getBaseURI());
    String backMapperUrl = registerCacheableMapper(ureq, sourcedId + "_talkback", talkbackMapper);
    String backMapperUri = serverUri + backMapperUrl + "/";
    Mapper outcomeMapper = new CourseNodeOutcomeMapper(getIdentity(), courseResource, courseNode.getIdent(), oauth_consumer_key, oauth_secret, sourcedId);
    String outcomeMapperUrl = registerCacheableMapper(ureq, sourcedId, outcomeMapper, LTIManager.EXPIRATION_TIME);
    String outcomeMapperUri = serverUri + outcomeMapperUrl + "/";
    boolean sendname = config.getBooleanSafe(LTIConfigForm.CONFIG_KEY_SENDNAME, false);
    boolean sendmail = config.getBooleanSafe(LTIConfigForm.CONFIG_KEY_SENDEMAIL, false);
    String ltiRoles = getLTIRoles();
    String target = config.getStringValue(BasicLTICourseNode.CONFIG_DISPLAY);
    String width = config.getStringValue(BasicLTICourseNode.CONFIG_WIDTH);
    String height = config.getStringValue(BasicLTICourseNode.CONFIG_HEIGHT);
    String custom = (String) config.get(LTIConfigForm.CONFIG_KEY_CUSTOM);
    container.contextPut("height", height);
    container.contextPut("width", width);
    LTIContext context = new LTICourseNodeContext(courseEnv, courseNode, ltiRoles, sourcedId, backMapperUri, outcomeMapperUri, custom, target, width, height);
    Map<String, String> unsignedProps = ltiManager.forgeLTIProperties(getIdentity(), getLocale(), context, sendname, sendmail, true);
    Mapper contentMapper = new PostDataMapper(unsignedProps, url, oauth_consumer_key, oauth_secret, "true".equals(debug));
    String mapperUri = registerMapper(ureq, contentMapper);
    container.contextPut("mapperUri", mapperUri + "/");
}
Also used : TalkBackMapper(org.olat.ims.lti.ui.TalkBackMapper) Mapper(org.olat.core.dispatcher.mapper.Mapper) PostDataMapper(org.olat.ims.lti.ui.PostDataMapper) TalkBackMapper(org.olat.ims.lti.ui.TalkBackMapper) OLATResource(org.olat.resource.OLATResource) LTIContext(org.olat.ims.lti.LTIContext) PostDataMapper(org.olat.ims.lti.ui.PostDataMapper)

Example 13 with Mapper

use of org.olat.core.dispatcher.mapper.Mapper in project OpenOLAT by OpenOLAT.

the class HtmlStaticPageComponent method getAsyncMediaResource.

/**
 * @see org.olat.core.gui.media.AsyncMediaResponsible#getAsyncMediaResource(org.olat.core.gui.UserRequest)
 */
public MediaResource getAsyncMediaResource(UserRequest ureq) {
    // is the path to the desired resource (put together by the webbrowser by
    // combining latesturl and relative link)
    String moduleURI = ureq.getModuleURI();
    MediaResource mr = null;
    if (moduleURI != null) {
        // 1. check for an olat command (special link to indicate a command)
        if (moduleURI.startsWith(OLAT_CMD_PREFIX)) {
            String cmdAndSub = moduleURI.substring(OLAT_CMD_PREFIX.length());
            int slpos = cmdAndSub.indexOf('/');
            if (slpos != -1) {
                String cmd = cmdAndSub.substring(0, slpos);
                String subcmd = cmdAndSub.substring(slpos + 1);
                OlatCmdEvent aev = new OlatCmdEvent(cmd, subcmd);
                fireEvent(ureq, aev);
                // Mediaresourse)
                if (aev.isAccepted())
                    return null;
            }
        // else ignore (syntax error in command
        }
        // make sure moduleURI does not contain ".." or such (hack attempt)
        // -> ok, userrequest class asserts this.
        VFSItem sourceItem = rootContainer.resolve(moduleURI);
        // return 404 if the requested file does not exist
        if (sourceItem == null || (sourceItem instanceof VFSContainer)) {
            return new NotFoundMediaResource();
        }
        // we know the file exists.
        boolean checkRegular = true;
        // check for special case: render the follwing link in a new (server) window and all following clicks as well
        if ((ureq.getParameter("olatsite") != null) || ((moduleURI.endsWith(".html") || moduleURI.endsWith(".htm")) && (ureq.getParameter("olatraw") != null))) {
            log.debug("moduleURI=" + moduleURI);
            ExternalSiteEvent ese = new ExternalSiteEvent(moduleURI);
            fireEvent(ureq, ese);
            if (ese.isAccepted()) {
                mr = ese.getResultingMediaResource();
                log.debug("ExternalSiteEvent is accepted");
                checkRegular = false;
            } else {
                // it is a html page with olatraw parameter => redirect to mapper
                Mapper mapper = new HtmlStaticMapper(rootContainer);
                // NOTE: do not deregister this mapper, since it could be used a lot later (since it is opened in a new browser window)
                // Register mapper as cacheable
                String mapperID = VFSManager.getRealPath(rootContainer);
                if (mapperID == null) {
                    // Can't cache mapper, no cacheable context available
                    amapPath = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapper);
                } else {
                    // Add classname to the file path to remove conflicts with other
                    // usages of the same file path
                    mapperID = this.getClass().getSimpleName() + ":" + mapperID;
                    amapPath = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapperID, mapper);
                }
                String path = amapPath.getUrl() + "/" + moduleURI;
                ese.setResultingMediaResource(new RedirectMediaResource(path));
                if (log.isDebug())
                    log.debug("RedirectMediaResource=" + path);
                ese.accept();
                mr = ese.getResultingMediaResource();
                checkRegular = false;
            }
        }
        if (checkRegular) {
            // mediaresource (raw inputstream)
            if ((moduleURI.endsWith(".html") || moduleURI.endsWith(".htm")) && (ureq.getParameter("olatraw") == null)) {
                // we remember what to render inline later and return null to indicate
                // inline rendering
                currentURI = moduleURI;
                getFileContent((VFSLeaf) sourceItem);
                fireEvent(ureq, new NewInlineUriEvent(currentURI));
            } else {
                // it is indeed an image or such -> serve it
                mr = new VFSMediaResource((VFSLeaf) sourceItem);
            }
        }
    }
    // -> do a normal inline rendering (reload)
    return mr;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Mapper(org.olat.core.dispatcher.mapper.Mapper) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 14 with Mapper

use of org.olat.core.dispatcher.mapper.Mapper in project openolat by klemens.

the class WikiMarkupComponent method setImageMapperUri.

/**
 * if the wiki need to serve images you have to set the image mapper uri first!
 * The mapper creates an user session based mapper for the media files which can be requested by calling @see getImageBaseUri()
 * @param ureq
 * @param wikiContainer
 */
public void setImageMapperUri(UserRequest ureq, final VFSContainer wikiContainer) {
    // get a usersession-local mapper for images in this wiki
    Mapper contentMapper = new VFSContainerMapper(wikiContainer);
    // Register mapper as cacheable
    String mapperID = VFSManager.getRealPath(wikiContainer);
    if (mapperID == null) {
        // Can't cache mapper, no cacheable context available
        mapperKey = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), contentMapper);
    } else {
        // Add classname to the file path to remove conflicts with other
        // usages of the same file path
        mapperID = this.getClass().getSimpleName() + ":" + mapperID;
        mapperKey = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapperID, contentMapper);
    }
    imageBaseUri = mapperKey.getUrl() + "/" + WikiContainer.MEDIA_FOLDER_NAME + "/";
}
Also used : VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) Mapper(org.olat.core.dispatcher.mapper.Mapper)

Example 15 with Mapper

use of org.olat.core.dispatcher.mapper.Mapper in project openolat by klemens.

the class HtmlStaticPageComponent method getAsyncMediaResource.

/**
 * @see org.olat.core.gui.media.AsyncMediaResponsible#getAsyncMediaResource(org.olat.core.gui.UserRequest)
 */
public MediaResource getAsyncMediaResource(UserRequest ureq) {
    // is the path to the desired resource (put together by the webbrowser by
    // combining latesturl and relative link)
    String moduleURI = ureq.getModuleURI();
    MediaResource mr = null;
    if (moduleURI != null) {
        // 1. check for an olat command (special link to indicate a command)
        if (moduleURI.startsWith(OLAT_CMD_PREFIX)) {
            String cmdAndSub = moduleURI.substring(OLAT_CMD_PREFIX.length());
            int slpos = cmdAndSub.indexOf('/');
            if (slpos != -1) {
                String cmd = cmdAndSub.substring(0, slpos);
                String subcmd = cmdAndSub.substring(slpos + 1);
                OlatCmdEvent aev = new OlatCmdEvent(cmd, subcmd);
                fireEvent(ureq, aev);
                // Mediaresourse)
                if (aev.isAccepted())
                    return null;
            }
        // else ignore (syntax error in command
        }
        // make sure moduleURI does not contain ".." or such (hack attempt)
        // -> ok, userrequest class asserts this.
        VFSItem sourceItem = rootContainer.resolve(moduleURI);
        // return 404 if the requested file does not exist
        if (sourceItem == null || (sourceItem instanceof VFSContainer)) {
            return new NotFoundMediaResource();
        }
        // we know the file exists.
        boolean checkRegular = true;
        // check for special case: render the follwing link in a new (server) window and all following clicks as well
        if ((ureq.getParameter("olatsite") != null) || ((moduleURI.endsWith(".html") || moduleURI.endsWith(".htm")) && (ureq.getParameter("olatraw") != null))) {
            log.debug("moduleURI=" + moduleURI);
            ExternalSiteEvent ese = new ExternalSiteEvent(moduleURI);
            fireEvent(ureq, ese);
            if (ese.isAccepted()) {
                mr = ese.getResultingMediaResource();
                log.debug("ExternalSiteEvent is accepted");
                checkRegular = false;
            } else {
                // it is a html page with olatraw parameter => redirect to mapper
                Mapper mapper = new HtmlStaticMapper(rootContainer);
                // NOTE: do not deregister this mapper, since it could be used a lot later (since it is opened in a new browser window)
                // Register mapper as cacheable
                String mapperID = VFSManager.getRealPath(rootContainer);
                if (mapperID == null) {
                    // Can't cache mapper, no cacheable context available
                    amapPath = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapper);
                } else {
                    // Add classname to the file path to remove conflicts with other
                    // usages of the same file path
                    mapperID = this.getClass().getSimpleName() + ":" + mapperID;
                    amapPath = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapperID, mapper);
                }
                String path = amapPath.getUrl() + "/" + moduleURI;
                ese.setResultingMediaResource(new RedirectMediaResource(path));
                if (log.isDebug())
                    log.debug("RedirectMediaResource=" + path);
                ese.accept();
                mr = ese.getResultingMediaResource();
                checkRegular = false;
            }
        }
        if (checkRegular) {
            // mediaresource (raw inputstream)
            if ((moduleURI.endsWith(".html") || moduleURI.endsWith(".htm")) && (ureq.getParameter("olatraw") == null)) {
                // we remember what to render inline later and return null to indicate
                // inline rendering
                currentURI = moduleURI;
                getFileContent((VFSLeaf) sourceItem);
                fireEvent(ureq, new NewInlineUriEvent(currentURI));
            } else {
                // it is indeed an image or such -> serve it
                mr = new VFSMediaResource((VFSLeaf) sourceItem);
            }
        }
    }
    // -> do a normal inline rendering (reload)
    return mr;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Mapper(org.olat.core.dispatcher.mapper.Mapper) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Aggregations

Mapper (org.olat.core.dispatcher.mapper.Mapper)20 LTIContext (org.olat.ims.lti.LTIContext)6 PostDataMapper (org.olat.ims.lti.ui.PostDataMapper)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 PersistedMapper (org.olat.core.dispatcher.mapper.model.PersistedMapper)4 MediaResource (org.olat.core.gui.media.MediaResource)4 VFSContainerMapper (org.olat.core.util.vfs.VFSContainerMapper)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)4 HashMap (java.util.HashMap)2 JSONArray (org.json.JSONArray)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 DownloadComponent (org.olat.core.gui.components.download.DownloadComponent)2 JSAndCSSComponent (org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 JSONMediaResource (org.olat.core.gui.media.JSONMediaResource)2 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)2 RedirectMediaResource (org.olat.core.gui.media.RedirectMediaResource)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2