use of org.olat.core.gui.media.StringMediaResource in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.
the class ScormAPIMapper method handle.
public MediaResource handle(String relPath, HttpServletRequest request) {
check();
String apiCall = request.getParameter("apiCall");
String apiCallParamOne = request.getParameter("apiCallParamOne");
String apiCallParamTwo = request.getParameter("apiCallParamTwo");
if (log.isDebug()) {
log.debug("scorm api request by user:" + identity.getName() + ": " + apiCall + "('" + apiCallParamOne + "' , '" + apiCallParamTwo + "')");
}
StringMediaResource smr = new StringMediaResource();
smr.setContentType("text/html");
smr.setEncoding("utf-8");
if (apiCall != null && apiCall.equals("initcall")) {
// used for Mozilla / firefox only to get more time for fireing the onunload stuff triggered by overwriting the content.
smr.setData("<html><body></body></html>");
return smr;
}
String returnValue = "";
if (apiCall != null) {
if (apiCall.equals(LMS_INITIALIZE)) {
returnValue = scormAdapter.LMSInitialize(apiCallParamOne);
} else if (apiCall.equals(LMS_GETVALUE)) {
returnValue = scormAdapter.LMSGetValue(apiCallParamOne);
} else if (apiCall.equals(LMS_SETVALUE)) {
returnValue = scormAdapter.LMSSetValue(apiCallParamOne, apiCallParamTwo);
} else if (apiCall.equals(LMS_COMMIT)) {
returnValue = scormAdapter.LMSCommit(apiCallParamOne);
} else if (apiCall.equals(LMS_FINISH)) {
returnValue = scormAdapter.LMSFinish(apiCallParamOne);
} else if (apiCall.equals(LMS_GETLASTERROR)) {
returnValue = scormAdapter.LMSGetLastError();
} else if (apiCall.equals(LMS_GETDIAGNOSTIC)) {
returnValue = scormAdapter.LMSGetDiagnostic(apiCallParamOne);
} else if (apiCall.equals(LMS_GETERRORSTRING)) {
returnValue = scormAdapter.LMSGetErrorString(apiCallParamOne);
}
smr.setData("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><p>" + returnValue + "</p></body></html>");
return smr;
}
smr.setData("");
return smr;
}
use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.
the class CalendarPrintMapper method handle.
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
StringBuilder sb = new StringBuilder();
sb.append("<html><head><title>").append("Calendar").append("</title>").append("<meta http-equiv='Content-type' content='text/html; charset=utf-8' />").append("<link href='").append(themeBaseUri).append("theme.css' rel='stylesheet' type='text/css' />\n").append("<!--[if IE 9]><link id='o_theme_css_ie' href='").append(themeBaseUri).append("theme_ie_completions.css' rel='stylesheet' type='text/css' /><![endif]-->\n").append("</head><body class='o_cal_print' onload='window.focus();window.print()'>");
// collect all events
List<KalendarEventRenderWrapper> sortedEventsWithin = new ArrayList<>();
collectEvents(sortedEventsWithin, calendarWrappers);
Collections.sort(sortedEventsWithin, KalendarEventDateComparator.getInstance());
// list of events
renderEvents(sb, sortedEventsWithin, from, to);
// list of calendars
renderCalendars(sb);
sb.append("</body></html>");
StringMediaResource smr = new StringMediaResource();
smr.setContentType("text/html");
smr.setEncoding("UTF-8");
smr.setData(sb.toString());
return smr;
}
use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.
the class CmdServeResource method execute.
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
VFSSecurityCallback inheritedSecCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
if (inheritedSecCallback != null && !inheritedSecCallback.canRead())
throw new RuntimeException("Illegal read attempt: " + folderComponent.getCurrentContainerPath());
// extract file
String path = ureq.getModuleURI();
MediaResource mr = null;
VFSItem vfsitem = folderComponent.getRootContainer().resolve(path);
if (vfsitem == null) {
// double decoding of ++
vfsitem = FolderCommandHelper.tryDoubleDecoding(ureq, folderComponent);
}
if (vfsitem == null) {
mr = new NotFoundMediaResource();
} else if (!(vfsitem instanceof VFSLeaf)) {
mr = new NotFoundMediaResource();
} else {
VFSLeaf vfsfile = (VFSLeaf) vfsitem;
boolean forceDownload = FolderManager.isDownloadForcedFileType(vfsfile.getName());
if (path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm")) {
// setCurrentURI(path);
// set the http content-type and the encoding
// try to load in iso-8859-1
InputStream is = vfsfile.getInputStream();
if (is == null) {
mr = new NotFoundMediaResource();
} else {
String page = FileUtils.load(is, DEFAULT_ENCODING);
// search for the <meta content="text/html; charset=utf-8"
// http-equiv="Content-Type" /> tag
// if none found, assume iso-8859-1
String enc = DEFAULT_ENCODING;
boolean useLoaded = false;
// <meta.*charset=([^"]*)"
Matcher m = PATTERN_ENCTYPE.matcher(page);
boolean found = m.find();
if (found) {
String htmlcharset = m.group(1);
enc = htmlcharset;
if (htmlcharset.equals(DEFAULT_ENCODING)) {
useLoaded = true;
}
} else {
useLoaded = true;
}
// set the new encoding to remember for any following .js file loads
g_encoding = enc;
if (useLoaded) {
StringMediaResource smr = new StringMediaResource();
String mimetype = forceDownload ? VFSMediaResource.MIME_TYPE_FORCE_DOWNLOAD : "text/html;charset=" + enc;
smr.setContentType(mimetype);
smr.setEncoding(enc);
smr.setData(page);
if (forceDownload) {
smr.setDownloadable(true, vfsfile.getName());
}
mr = smr;
} else {
// found a new charset other than iso-8859-1 -> let it load again
// as bytes (so we do not need to convert to string and back
// again)
VFSMediaResource vmr = new VFSMediaResource(vfsfile);
vmr.setEncoding(enc);
if (forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr;
}
}
} else if (path.endsWith(".js")) {
// a javascript library
VFSMediaResource vmr = new VFSMediaResource(vfsfile);
// that loads the .js file
if (g_encoding != null) {
vmr.setEncoding(g_encoding);
}
if (forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr;
} else if (path.endsWith(".txt")) {
// text files created in OpenOLAT are utf-8, prefer this encoding
VFSMediaResource vmr = new VFSMediaResource(vfsfile);
vmr.setEncoding("utf-8");
if (forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr;
} else {
// binary data: not .html, not .htm, not .js -> treated as is
VFSMediaResource vmr = new VFSMediaResource(vfsfile);
if (forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr;
}
}
ThreadLocalUserActivityLogger.log(FolderLoggingAction.BC_FILE_READ, getClass(), CoreLoggingResourceable.wrapBCFile(path));
ureq.getDispatchResult().setResultingMediaResource(mr);
// update download counter
if (vfsitem instanceof MetaTagged) {
MetaTagged itemWithMeta = (MetaTagged) vfsitem;
MetaInfo meta = itemWithMeta.getMetaInfo();
meta.increaseDownloadCount();
meta.write();
}
return null;
}
use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.
the class IFrameDeliveryMapper method prepareMediaResource.
private StringMediaResource prepareMediaResource(HttpServletRequest httpRequest, String page, String enc, String contentType, boolean isPopUp) {
StringMediaResource smr = new StringMediaResource();
if (XHTML_CONTENT_TYPE.equals(contentType)) {
// check if the application/xhtml+xml is supported (not supported by IEs)
// if not, replace the content type by text/html for compatibility
String accept = httpRequest.getHeader("Accept");
if (accept == null || accept.indexOf(XHTML_CONTENT_TYPE) < 0) {
contentType = DEFAULT_CONTENT_TYPE;
}
}
String mimetype = contentType + ";charset=" + StringHelper.check4xMacRoman(enc);
smr.setContentType(mimetype);
smr.setEncoding(enc);
// inject some javascript code to size iframe to proper height, but only when not a page with framesets
if (page.indexOf(TAG_FRAMESET) != -1 || page.indexOf(TAG_FRAMESET_UPPERC) != -1 || isPopUp) {
// is frameset -> deliver unparsed
smr.setData(page);
} else {
String agent = httpRequest.getHeader("User-Agent");
boolean firefoxWorkaround = agent != null && agent.indexOf("Firefox/") > 0;
if (rawContent) {
smr.setData(page);
} else {
smr.setData(injectJavaScript(page, mimetype, checkForInlineEvent, firefoxWorkaround));
}
// When loading next page, check if it was an inline user click
this.checkForInlineEvent = true;
}
return smr;
}
Aggregations