use of org.olat.core.gui.media.StringMediaResource in project OpenOLAT by OpenOLAT.
the class OutcomeMapper method createMediaResource.
private MediaResource createMediaResource(String body, String mimeType) {
StringMediaResource mediares = new StringMediaResource();
mediares.setData(body);
mediares.setContentType(mimeType);
mediares.setEncoding("UTF-8");
return mediares;
}
use of org.olat.core.gui.media.StringMediaResource in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class CPPrintMapper method prepareMediaResource.
private StringMediaResource prepareMediaResource(HttpServletRequest httpRequest, String page, String enc, String contentType) {
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) {
// is frameset -> deliver unparsed
smr.setData(page);
} else {
smr.setData(page);
}
return smr;
}
use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.
the class OutcomeMapper method createMediaResource.
private MediaResource createMediaResource(String body, String mimeType) {
StringMediaResource mediares = new StringMediaResource();
mediares.setData(body);
mediares.setContentType(mimeType);
mediares.setEncoding("UTF-8");
return mediares;
}
use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.
the class GlossaryDefinitionMapper 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();
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("GlossaryDefinition delivery failed; path to glossaryFolder not existing: " + relPath, null);
return new NotFoundMediaResource();
}
VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
logWarn("GlossaryDefinition delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
return new NotFoundMediaResource();
}
String glossaryMainTerm = parts[2];
if (parts.length > 2) {
// this handle / or \ in a term
for (int i = 3; i < parts.length; i++) {
glossaryMainTerm += "/" + parts[i];
}
}
// cut away ".html" if necessary
if (glossaryMainTerm.endsWith(".html")) {
glossaryMainTerm = glossaryMainTerm.substring(0, glossaryMainTerm.length() - 5);
}
glossaryMainTerm = glossaryMainTerm.toLowerCase();
Set<String> alternatives = new HashSet<>();
prepareAlternatives(glossaryMainTerm, alternatives);
// 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/html");
List<GlossaryItem> glossItems = gIM.getGlossaryItemListByVFSItem(glossaryFolder);
GlossaryItem foundItem = null;
for (GlossaryItem glossaryItem : glossItems) {
String item = glossaryItem.getGlossTerm().toLowerCase();
if (alternatives.contains(item)) {
foundItem = glossaryItem;
break;
}
}
if (foundItem == null) {
return new NotFoundMediaResource();
}
StringBuilder sb = new StringBuilder();
sb.append("<dd><dt>").append(foundItem.getGlossTerm()).append("</dt><dl>").append(foundItem.getGlossDef()).append("</dl></dd>");
resource.setData(sb.toString());
resource.setEncoding("utf-8");
if (isLogDebugEnabled())
logDebug("loaded definition for " + glossaryMainTerm, null);
return resource;
}
Aggregations