use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class RepositoryEntryImageMapper method handle.
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
if (rootContainer == null) {
rootContainer = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
}
if (relPath.startsWith("/")) {
relPath = relPath.substring(1, relPath.length());
}
MediaResource resource = null;
VFSItem image = rootContainer.resolve(relPath);
if (image instanceof VFSLeaf) {
if (image instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) image).getMetaInfo();
if (info != null) {
// 121 is needed to fill the div
VFSLeaf thumbnail = info.getThumbnail(180, 120, true);
if (thumbnail != null) {
resource = new VFSMediaResource(thumbnail);
}
}
}
if (resource == null) {
resource = new VFSMediaResource((VFSLeaf) image);
}
}
return resource;
}
use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class WikiHandler method getAsMediaResource.
@Override
public MediaResource getAsMediaResource(OLATResourceable res, boolean backwardsCompatible) {
VFSContainer rootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(res);
VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(rootContainer);
return new VFSMediaResource(wikiZip);
}
use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class CatalogEntryImageMapper method handle.
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
if (relPath.startsWith("/")) {
relPath = relPath.substring(1, relPath.length());
}
VFSContainer categoryResources = catalogManager.getCatalogResourcesHome();
VFSItem image = categoryResources.resolve(relPath);
MediaResource resource = null;
if (image instanceof VFSLeaf) {
if (image instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) image).getMetaInfo();
if (info != null) {
VFSLeaf thumbnail = info.getThumbnail(180, 180, true);
if (thumbnail != null) {
resource = new VFSMediaResource(thumbnail);
}
}
}
if (resource == null) {
resource = new VFSMediaResource((VFSLeaf) image);
}
} else {
resource = new NotFoundMediaResource();
}
return resource;
}
use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class FileArtefactDetailsController method initFileView.
private void initFileView(VFSItem file, UserRequest ureq) {
vC = createVelocityContainer("fileDetails");
DownloadComponent downlC = new DownloadComponent("download", (VFSLeaf) file);
vC.put("download", downlC);
vC.contextPut("filename", fArtefact.getFilename());
if (file instanceof MetaTagged) {
MetaInfo meta = ((MetaTagged) file).getMetaInfo();
vC.contextPut("meta", meta);
// show a preview thumbnail if possible
if (meta.isThumbnailAvailable()) {
VFSLeaf thumb = meta.getThumbnail(200, 200, false);
if (thumb != null) {
mr = new VFSMediaResource(thumb);
}
if (mr != null) {
String thumbMapper = registerMapper(ureq, new Mapper() {
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
return mr;
}
});
vC.contextPut("thumbMapper", thumbMapper);
}
}
}
if (!readOnlyMode) {
// allow to delete
delLink = LinkFactory.createLink("delete.file", vC, this);
delLink.setUserObject(file);
}
viewPanel.setContent(vC);
}
use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class CmdServeResource method execute.
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
VFSSecurityCallback inheritedSecCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
if (inheritedSecCallback != null && !inheritedSecCallback.canRead())
throw new RuntimeException("Illegal read attempt: " + folderComponent.getCurrentContainerPath());
// extract file
String path = ureq.getModuleURI();
MediaResource mr = null;
VFSItem vfsitem = folderComponent.getRootContainer().resolve(path);
if (vfsitem == null) {
// double decoding of ++
vfsitem = FolderCommandHelper.tryDoubleDecoding(ureq, folderComponent);
}
if (vfsitem == null) {
mr = new NotFoundMediaResource();
} else if (!(vfsitem instanceof VFSLeaf)) {
mr = new NotFoundMediaResource();
} else {
VFSLeaf vfsfile = (VFSLeaf) vfsitem;
boolean forceDownload = FolderManager.isDownloadForcedFileType(vfsfile.getName());
if (path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm")) {
// setCurrentURI(path);
// set the http content-type and the encoding
// try to load in iso-8859-1
InputStream is = vfsfile.getInputStream();
if (is == null) {
mr = new NotFoundMediaResource();
} else {
String page = FileUtils.load(is, DEFAULT_ENCODING);
// search for the <meta content="text/html; charset=utf-8"
// http-equiv="Content-Type" /> tag
// if none found, assume iso-8859-1
String enc = DEFAULT_ENCODING;
boolean useLoaded = false;
// <meta.*charset=([^"]*)"
Matcher m = PATTERN_ENCTYPE.matcher(page);
boolean found = m.find();
if (found) {
String htmlcharset = m.group(1);
enc = htmlcharset;
if (htmlcharset.equals(DEFAULT_ENCODING)) {
useLoaded = true;
}
} else {
useLoaded = true;
}
// set the new encoding to remember for any following .js file loads
g_encoding = enc;
if (useLoaded) {
StringMediaResource smr = new StringMediaResource();
String mimetype = forceDownload ? VFSMediaResource.MIME_TYPE_FORCE_DOWNLOAD : "text/html;charset=" + enc;
smr.setContentType(mimetype);
smr.setEncoding(enc);
smr.setData(page);
if (forceDownload) {
smr.setDownloadable(true, vfsfile.getName());
}
mr = smr;
} else {
// found a new charset other than iso-8859-1 -> let it load again
// as bytes (so we do not need to convert to string and back
// again)
VFSMediaResource vmr = new VFSMediaResource(vfsfile);
vmr.setEncoding(enc);
if (forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr;
}
}
} else if (path.endsWith(".js")) {
// a javascript library
VFSMediaResource vmr = new VFSMediaResource(vfsfile);
// that loads the .js file
if (g_encoding != null) {
vmr.setEncoding(g_encoding);
}
if (forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr;
} else if (path.endsWith(".txt")) {
// text files created in OpenOLAT are utf-8, prefer this encoding
VFSMediaResource vmr = new VFSMediaResource(vfsfile);
vmr.setEncoding("utf-8");
if (forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr;
} else {
// binary data: not .html, not .htm, not .js -> treated as is
VFSMediaResource vmr = new VFSMediaResource(vfsfile);
if (forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr;
}
}
ThreadLocalUserActivityLogger.log(FolderLoggingAction.BC_FILE_READ, getClass(), CoreLoggingResourceable.wrapBCFile(path));
ureq.getDispatchResult().setResultingMediaResource(mr);
// update download counter
if (vfsitem instanceof MetaTagged) {
MetaTagged itemWithMeta = (MetaTagged) vfsitem;
MetaInfo meta = itemWithMeta.getMetaInfo();
meta.increaseDownloadCount();
meta.write();
}
return null;
}
Aggregations