use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class StaticServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final String pathInfo = request.getPathInfo();
if (pathInfo == null) {
// huh? What's this, send not found, don't know what to do here
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else if (pathInfo.indexOf(NOVERSION) != -1) {
// no version provided - only remove mapper
String staticRelPath = pathInfo.substring(NOVERSION.length() + 1, pathInfo.length());
String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
if (normalizedRelPath == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else if (normalizedRelPath.endsWith("transparent.gif")) {
deliverStatic(request, response, pathInfo, normalizedRelPath, true);
} else {
deliverStatic(request, response, pathInfo, normalizedRelPath, false);
}
} else if (pathInfo.startsWith(STATIC_DIR_NAME)) {
String staticRelPath = pathInfo.substring(STATIC_DIR_NAME.length() + 1, pathInfo.length());
// customizing
CustomStaticFolderManager folderManager = CoreSpringFactory.getImpl(CustomStaticFolderManager.class);
File file = new File(folderManager.getRootFile(), staticRelPath);
if (file.exists()) {
if (file.isDirectory()) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
} else {
MediaResource resource = new FileMediaResource(file);
ServletUtil.serveResource(request, response, resource);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else {
// version provided - remove it
int start = pathInfo.indexOf("/", 2);
int end = pathInfo.length();
if (start <= end) {
String staticRelPath = pathInfo.substring(start, end);
String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
if (normalizedRelPath == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
boolean expiration = !Settings.isDebuging();
deliverStatic(request, response, pathInfo, normalizedRelPath, expiration);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class CPPrintMapper method deliverCompositePage.
private MediaResource deliverCompositePage(HttpServletRequest request) {
List<NekoHtmlPageHandler> parsedPages = composePrintPage(selectedNodeIds);
StringBuilder sb = new StringBuilder();
sb.append("<html><head>");
for (NekoHtmlPageHandler page : parsedPages) {
sb.append("<!-- Header of -->");
sb.append(page.getHeader()).append("\n\n");
}
injectJavascriptAndCss(sb);
sb.append("</head><body onload='window.focus();window.print()'>");
for (NekoHtmlPageHandler page : parsedPages) {
if (page.isEmpty()) {
String title = page.getTitle();
if (StringHelper.containsNonWhitespace(title)) {
int level = page.getLevel() + 1;
level = Math.min(level, 6);
sb.append("<h").append(level).append(">").append(page.getTitle()).append("</h").append(level).append(">");
}
} else {
bodyDecorator(page, sb);
}
}
sb.append("</body></html>");
MediaResource mr = prepareMediaResource(request, sb.toString(), g_encoding, "text/html");
return mr;
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class CPPrintMapper method deliverFile.
protected MediaResource deliverFile(HttpServletRequest httpRequest, String path) {
// if directory gets renamed root becomes null
if (rootDir == null) {
return new NotFoundMediaResource();
}
VFSLeaf vfsLeaf = null;
VFSItem vfsItem = rootDir.resolve(path);
// only files are allowed, but somehow it happened that folders showed up here
if (vfsItem instanceof VFSLeaf) {
vfsLeaf = (VFSLeaf) vfsItem;
} else {
return new NotFoundMediaResource();
}
MediaResource mr;
// and accept positions of this string at length-3 or length-4
if (path.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (path.length() - 4)) {
// set the http content-type and the encoding
Page page = loadPageWithGuess(vfsLeaf);
g_encoding = page.getEncoding();
if (page.isUseLoadedPageString()) {
mr = prepareMediaResource(httpRequest, page.getPage(), g_encoding, page.getContentType());
} else {
// found a new charset other than iso-8859-1, load string with proper encoding
String content = FileUtils.load(vfsLeaf.getInputStream(), g_encoding);
mr = prepareMediaResource(httpRequest, content, g_encoding, page.getContentType());
}
} else if (path.toLowerCase().lastIndexOf(FILE_SUFFIX_CSS) >= (path.length() - 4)) {
// set the http content-type and the encoding
mr = deliverCssFile(vfsLeaf, httpRequest);
} else if (path.endsWith(FILE_SUFFIX_JS)) {
// a javascript library
VFSMediaResource vmr = new VFSMediaResource(vfsLeaf);
// that loads the .js file
if (jsEncoding != null)
vmr.setEncoding(jsEncoding);
else if (g_encoding != null)
vmr.setEncoding(g_encoding);
mr = vmr;
} else {
// binary data: not .html, not .htm, not .js -> treated as is
mr = new VFSMediaResource(vfsLeaf);
}
return mr;
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class QuestionListController method doExecuteExport.
private void doExecuteExport(UserRequest ureq, StepsRunContext runContext) {
ExportFormatOptions format = (ExportFormatOptions) runContext.get("format");
@SuppressWarnings("unchecked") List<QuestionItemShort> items = (List<QuestionItemShort>) runContext.get("itemsToExport");
MediaResource mr = qpoolService.export(items, format, getLocale());
if (mr != null) {
ureq.getDispatchResult().setResultingMediaResource(mr);
}
}
use of org.olat.core.gui.media.MediaResource in project openolat by klemens.
the class BinderPageListController method doExportBinderAsPdf.
private void doExportBinderAsPdf(UserRequest ureq) {
MediaResource resource = new ExportBinderAsPDFResource(binder, ureq, getLocale());
ureq.getDispatchResult().setResultingMediaResource(resource);
}
Aggregations