use of org.olat.core.util.vfs.VFSMediaResource in project openolat by klemens.
the class CertificateDispatcher method execute.
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uriPrefix = DispatcherModule.getLegacyUriPrefix(request);
final String origUri = request.getRequestURI();
String uuid = origUri.substring(uriPrefix.length());
int indexSuffix = uuid.indexOf('/');
if (indexSuffix > 0) {
uuid = uuid.substring(0, indexSuffix);
}
MediaResource resource;
Certificate certificate = certificatesManager.getCertificateByUuid(uuid);
if (certificate == null) {
resource = new NotFoundMediaResource();
} else {
VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(certificate);
resource = new VFSMediaResource(certificateFile);
}
ServletUtil.serveResource(request, response, resource);
}
use of org.olat.core.util.vfs.VFSMediaResource in project openolat by klemens.
the class CPDisplayController method switchToPage.
public void switchToPage(UserRequest ureq, TreeNode tn) {
String identifierRes = (String) tn.getUserObject();
OLATResourceable ores = OresHelper.createOLATResourceableInstanceWithoutCheck("path=" + identifierRes, 0l);
addToHistory(ureq, ores, null);
// security check
if (identifierRes.indexOf("../") != -1)
throw new AssertException("a non-normalized url encountered in a manifest item:" + identifierRes);
// Check also for XML resources that use XSLT for rendering
if (identifierRes.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (identifierRes.length() - 4) || identifierRes.toLowerCase().endsWith(FILE_SUFFIX_XML)) {
// display html files inline or in an iframe
if (cpContentCtr != null)
cpContentCtr.setCurrentURI(identifierRes);
if (cpComponent != null)
cpComponent.setCurrentURI(identifierRes);
} else {
// initialized. Delegates displaying to the browser (and its plugins).
if (cpContentCtr != null) {
cpContentCtr.setCurrentURI(identifierRes);
} else {
// if an entry in a manifest points e.g. to a pdf file and the iframe
// controller has not been initialized display it non-inline
VFSItem currentItem = rootContainer.resolve(identifierRes);
MediaResource mr;
if (currentItem == null || !(currentItem instanceof VFSLeaf))
mr = new NotFoundMediaResource();
else
mr = new VFSMediaResource((VFSLeaf) currentItem);
ureq.getDispatchResult().setResultingMediaResource(mr);
// Prevent 'don't reload' warning
cpTree.setDirty(false);
}
}
updateNextPreviousLink(tn);
ThreadLocalUserActivityLogger.log(CourseLoggingAction.CP_GET_FILE, getClass(), LoggingResourceable.wrapCpNode(identifierRes));
}
use of org.olat.core.util.vfs.VFSMediaResource in project openolat by klemens.
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;
}
Aggregations