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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations