use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class IFrameDeliveryMapper method deliverFile.
protected MediaResource deliverFile(HttpServletRequest httpRequest, String path, boolean isPopUp) {
MediaResource mr;
VFSLeaf vfsLeaf = null;
VFSItem vfsItem = null;
// if directory gets renamed root becomes null
if (rootDir == null) {
return new NotFoundMediaResource();
} else {
vfsItem = rootDir.resolve(path);
}
// only files are allowed, but somehow it happened that folders showed up here
if (vfsItem instanceof VFSLeaf) {
vfsLeaf = (VFSLeaf) rootDir.resolve(path);
} else {
mr = new NotFoundMediaResource();
}
if (vfsLeaf == null) {
mr = new NotFoundMediaResource();
} else {
// 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);
String pageEncoding = page.getEncoding();
if (page.isUseLoadedPageString()) {
mr = prepareMediaResource(httpRequest, page.getPage(), pageEncoding, page.getContentType(), isPopUp);
} else {
// found a new charset other than iso-8859-1, load string with proper encoding
String content = FileUtils.load(vfsLeaf.getInputStream(), pageEncoding);
mr = prepareMediaResource(httpRequest, content, pageEncoding, page.getContentType(), isPopUp);
}
if (contentEncoding == null) {
contentEncoding = pageEncoding;
}
} 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 (contentEncoding != null) {
vmr.setEncoding(contentEncoding);
}
mr = vmr;
} else {
// binary data: not .html, not .htm, not .js -> treated as is
VFSMediaResource vmr = new VFSMediaResource(vfsLeaf);
String filename = vfsLeaf.getName();
// This is to prevent the login prompt in Excel, Word and PowerPoint
if (filename.endsWith(".xlsx") || filename.endsWith(".pptx") || filename.endsWith(".docx")) {
vmr.setDownloadable(true);
}
mr = vmr;
}
}
return mr;
}
use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class DialogElementListController method doFileDelivery.
/**
* deliver the selected file and show in a popup
*
* @param ureq
* @param command
*/
private void doFileDelivery(UserRequest ureq, DialogElement element) {
VFSContainer forumContainer = dialogElementsManager.getDialogContainer(element);
List<VFSItem> items = forumContainer.getItems(new VFSLeafFilter());
if (items.size() > 0 && items.get(0) instanceof VFSLeaf) {
VFSLeaf vl = (VFSLeaf) items.get(0);
ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(vl));
ThreadLocalUserActivityLogger.log(CourseLoggingAction.DIALOG_ELEMENT_FILE_DOWNLOADED, getClass(), LoggingResourceable.wrapBCFile(vl.getName()));
} else {
logError("No file to discuss: " + forumContainer, null);
}
}
use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class TaskController method doFileDelivery.
/**
* deliver the selected file and show in a popup
* tableController*
* @param ureq
* @param command
*/
private boolean doFileDelivery(UserRequest ureq, String taskFile) {
OlatRootFolderImpl forumContainer = new OlatRootFolderImpl(TACourseNode.getTaskFolderPathRelToFolderRoot(courseEnv, node), null);
VFSItem item = forumContainer.resolve(taskFile);
if (item instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) item;
ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(leaf));
return true;
} else if (item == null) {
log.warn("Can not cast to VFSLeaf. item==null, taskFile=" + taskFile);
return false;
} else {
log.warn("Can not cast to VFSLeaf. item.class.name=" + item.getClass().getName() + ", taskFile=" + taskFile);
return false;
}
}
use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class HtmlStaticMapper method handle.
public MediaResource handle(String relPath, HttpServletRequest request) {
if (log.isDebug())
log.debug("CPComponent Mapper relPath=" + relPath);
VFSItem currentItem = mapperRootContainer.resolve(relPath);
if (currentItem == null || (currentItem instanceof VFSContainer)) {
return new NotFoundMediaResource();
}
VFSMediaResource vmr = new VFSMediaResource((VFSLeaf) currentItem);
String encoding = SimpleHtmlParser.extractHTMLCharset(((VFSLeaf) currentItem));
if (log.isDebug())
log.debug("CPComponent Mapper set encoding=" + encoding);
//
vmr.setEncoding(encoding);
return vmr;
}
Aggregations