Search in sources :

Example 21 with StringMediaResource

use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.

the class SourceViewController method showVelocitySource.

public static MediaResource showVelocitySource(String velocityTemplatePath) throws IOException {
    File file = new File(velocityTemplatePath);
    StringWriter writer = new StringWriter();
    writer.append(HTML_START);
    if (file.exists()) {
        writer.append(FileUtils.load(file, "UTF-8"));
    } else {
        appendError(writer, velocityTemplatePath);
    }
    writer.append(HTML_STOP);
    StringMediaResource mr = new StringMediaResource();
    mr.setContentType(TEXT_HTML_CHARSET_UTF_8);
    mr.setData(writer.toString());
    return mr;
}
Also used : StringWriter(java.io.StringWriter) StringMediaResource(org.olat.core.gui.media.StringMediaResource) File(java.io.File)

Example 22 with StringMediaResource

use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.

the class GlossaryTermMapper 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();
    // security checks are done by MapperRegistry
    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("GlossaryTerms delivery failed; path to glossaryFolder not existing: " + relPath, null);
        return new NotFoundMediaResource();
    }
    VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
    if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
        logWarn("GlossaryTerms delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
        return new NotFoundMediaResource();
    }
    // 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/javascript");
    // Get data
    String glossaryArrayData = TextMarkerJsGenerator.loadGlossaryItemListAsJSArray(glossaryFolder);
    resource.setData(glossaryArrayData);
    // UTF-8 encoding used in this js file since explicitly set in the ajax
    // call (usually js files are 8859-1)
    resource.setEncoding("utf-8");
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) StringMediaResource(org.olat.core.gui.media.StringMediaResource) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 23 with StringMediaResource

use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.

the class AjaxController method extractMediaResource.

public MediaResource extractMediaResource(boolean wrapHTML) {
    JSONObject json = getAndClearJSON(true);
    String res;
    if (wrapHTML) {
        // most ajax responses are a lot smaller than 16k
        StringBuilder sb = new StringBuilder(16384);
        sb.append("<html><head><script type=\"text/javascript\">\n/* <![CDATA[ */\nfunction invoke(){var r=").append(json.toString()).append("; ").append("if (parent!=self&&parent.window.o_info) {").append("  parent.window.o_ainvoke(r);").append(" try{ parent.window.o_removeIframe(document.defaultView.frameElement.id); } catch(e) {} ").append("} else {").append("  this.document.location=\"").append(StaticMediaDispatcher.createStaticURIFor("msg/json/en/info.html")).append("\";").append("}}").append("\n/* ]]> */\n</script></head><body onLoad=\"invoke()\"></body></html>");
        res = sb.toString();
    } else {
        res = json.toString();
    }
    StringMediaResource smr = new StringMediaResource();
    smr.setContentType("text/html;charset=utf-8");
    smr.setEncoding("utf-8");
    smr.setData(res);
    return smr;
}
Also used : JSONObject(org.json.JSONObject) StringMediaResource(org.olat.core.gui.media.StringMediaResource)

Example 24 with StringMediaResource

use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.

the class PostDataMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    Map<String, String> props = CoreSpringFactory.getImpl(LTIManager.class).sign(unsignedProps, baseUrl, oauthKey, oauthSecret);
    String postData = BasicLTIUtil.postLaunchHTML(props, launchUrl, debug);
    StringMediaResource mediares = new StringMediaResource();
    mediares.setData(postData);
    mediares.setContentType("text/html");
    mediares.setEncoding("UTF-8");
    return mediares;
}
Also used : LTIManager(org.olat.ims.lti.LTIManager) StringMediaResource(org.olat.core.gui.media.StringMediaResource)

Example 25 with StringMediaResource

use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.

the class TalkBackMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    StringMediaResource mediares = new StringMediaResource();
    StringBuilder sb = new StringBuilder();
    sb.append("<html><head>").append("\n<link rel=\"stylesheet\" type=\"text/css\" id=\"ocontentcss\" href=\"").append(themeBaseUri).append("content.css\" />\n").append("<title>").append(trans.translate("talkback.title")).append("</title></head><body>").append("<div class='o_lti_talkback'>").append("<h1>").append(trans.translate("talkback.title")).append("</h1>").append("<p class='o_info'>").append(trans.translate("talkback.info")).append("</p>");
    String lti_msg = request.getParameter("lti_msg");
    if (StringHelper.containsNonWhitespace(lti_msg)) {
        sb.append("<div class='o_note'><h3>").append(trans.translate("talkback.msg")).append("</h3><p>").append(request.getParameter("lti_msg")).append("</p></div>");
    }
    String lti_errormsg = request.getParameter("lti_errormsg");
    if (StringHelper.containsNonWhitespace(lti_errormsg)) {
        sb.append("<div class='o_error'><h3>").append(trans.translate("talkback.errormsg")).append("</h3><p>").append(lti_errormsg).append("</p></div>");
    }
    String lti_log = request.getParameter("lti_log");
    if (StringHelper.containsNonWhitespace(lti_log)) {
        sb.append("<h3>").append(trans.translate("talkback.log")).append("</h3><pre>\n").append(lti_log).append("\n</pre>");
    }
    String lti_errorlog = request.getParameter("lti_errorlog");
    if (StringHelper.containsNonWhitespace(lti_errorlog)) {
        sb.append("<h3>").append(trans.translate("talkback.errorlog")).append("</h3><pre>\n").append(lti_errorlog).append("\n</pre>");
    }
    sb.append("</div></body></html>");
    if (log.isDebug()) {
        ServletUtil.printOutRequestParameters(request);
    }
    mediares.setData(sb.toString());
    mediares.setContentType("text/html");
    mediares.setEncoding("UTF-8");
    return mediares;
}
Also used : StringMediaResource(org.olat.core.gui.media.StringMediaResource)

Aggregations

StringMediaResource (org.olat.core.gui.media.StringMediaResource)26 File (java.io.File)8 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)6 StringWriter (java.io.StringWriter)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 GlossaryItemManager (org.olat.core.commons.modules.glossary.GlossaryItemManager)4 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 JavaSource2HTMLConverter (de.java2html.converter.JavaSource2HTMLConverter)3 JavaSource (de.java2html.javasource.JavaSource)3 JavaSourceParser (de.java2html.javasource.JavaSourceParser)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Matcher (java.util.regex.Matcher)2 JSONObject (org.json.JSONObject)2 KalendarEventRenderWrapper (org.olat.commons.calendar.ui.components.KalendarEventRenderWrapper)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 GlossaryItem (org.olat.core.commons.modules.glossary.GlossaryItem)2