use of org.olat.core.gui.media.StringMediaResource in project openolat by klemens.
the class SourceViewController method showjavaSource.
/**
* provide a class name with path and you will get an string media resource you can display
* @param cl
* @return
* @throws IOException
*/
public static MediaResource showjavaSource(String cl) throws IOException {
cl = cl.replace('.', '/');
String javaSourcePath = WebappHelper.getSourcePath() + "/" + cl + ".java";
File file = new File(javaSourcePath);
StringWriter writer = new StringWriter();
writer.append(HTML_START);
if (file.exists()) {
JavaSource jsource = new JavaSourceParser().parse(file);
// Create a converter and write the JavaSource object as Html
JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter();
converter.convert(jsource, JavaSourceConversionOptions.getDefault(), writer);
} else {
appendError(writer, javaSourcePath);
}
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 OpenOLAT.
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 OpenOLAT.
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;
}
use of org.olat.core.gui.media.StringMediaResource in project OpenOLAT by OpenOLAT.
the class SourceViewController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == viewVeloctiySource) {
String velocityTemplatePath = WebappHelper.getSourcePath() + "/" + vc.getPage();
String vcContent = FileUtils.load(new File(velocityTemplatePath), "utf-8");
sourceview.contextPut("content", vcContent);
sourceview.contextPut("vcname", vc.getPage());
view = new CloseableModalController(getWindowControl(), "close...", sourceview);
listenTo(view);
view.activate();
} else if (source == viewJSource) {
// Parse the raw text to a JavaSource object
JavaSource jsource = null;
try {
String className = clazz.getCanonicalName();
className = className.replace('.', '/');
String sourcePath = WebappHelper.getSourcePath() + "/" + className + ".java";
jsource = new JavaSourceParser().parse(new File(sourcePath));
} catch (IOException e) {
showInfo("todo");
}
// Create a converter and write the JavaSource object as Html
JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter();
StringWriter writer = new StringWriter();
writer.append(HTML_START);
try {
JavaSourceConversionOptions options = JavaSourceConversionOptions.getDefault();
options.setShowLineNumbers(true);
converter.convert(jsource, options, writer);
} catch (IOException e) {
//
}
StringMediaResource mr = new StringMediaResource();
mr.setContentType(TEXT_HTML_CHARSET_UTF_8);
writer.append(HTML_STOP);
mr.setData(writer.toString());
ureq.getDispatchResult().setResultingMediaResource(mr);
}
}
use of org.olat.core.gui.media.StringMediaResource in project OpenOLAT by OpenOLAT.
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;
}
Aggregations