use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class ForumWebService method getAttachment.
/**
* Retrieves the attachment of the message
* @response.representation.200.mediaType application/octet-stream
* @response.representation.200.doc The portrait as image
* @response.representation.404.doc The identity or the portrait not found
* @param messageKey The identity key of the user being searched
* @param filename The name of the attachment
* @param request The REST request
* @return The attachment
*/
@GET
@Path("posts/{messageKey}/attachments/{filename}")
@Produces({ "*/*", MediaType.APPLICATION_OCTET_STREAM })
public Response getAttachment(@PathParam("messageKey") Long messageKey, @PathParam("filename") String filename, @Context Request request) {
// load message
Message mess = fom.loadMessage(messageKey);
if (mess == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
if (!forum.equalsByPersistableKey(mess.getForum())) {
return Response.serverError().status(Status.CONFLICT).build();
}
VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
VFSItem item = container.resolve(filename);
if (item instanceof LocalFileImpl) {
// local file -> the length is given to the client which is good
Date lastModified = new Date(item.getLastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
File attachment = ((LocalFileImpl) item).getBasefile();
String mimeType = WebappHelper.getMimeType(attachment.getName());
if (mimeType == null)
mimeType = "application/octet-stream";
response = Response.ok(attachment).lastModified(lastModified).type(mimeType).cacheControl(cc);
}
return response.build();
} else if (item instanceof VFSLeaf) {
// stream -> the length is not given to the client which is not nice
Date lastModified = new Date(item.getLastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
StreamingOutput attachment = new VFSStreamingOutput((VFSLeaf) item);
String mimeType = WebappHelper.getMimeType(item.getName());
if (mimeType == null)
mimeType = "application/octet-stream";
response = Response.ok(attachment).lastModified(lastModified).type(mimeType).cacheControl(cc);
}
return response.build();
}
return Response.serverError().status(Status.NOT_FOUND).build();
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class GlossaryManagerImpl method getAsMediaResource.
/**
* Export the glossary as a media resource. The resource name is set to the
* resources display name
*
* @param res
* @return
*/
@Override
public MediaResource getAsMediaResource(OLATResourceable res) {
RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(res, false);
String exportFileName = repoEntry.getDisplayname();
// OO-135 check for special / illegal chars in filename
exportFileName = StringHelper.transformDisplayNameToFileSystemName(exportFileName);
try {
File tmpDir = new File(WebappHelper.getTmpDir());
File fExportZIP = File.createTempFile(exportFileName, ".zip", tmpDir);
VFSContainer glossaryRoot = getGlossaryRootFolder(res);
ZipUtil.zip(glossaryRoot.getItems(), new LocalFileImpl(fExportZIP), false);
return new CleanupAfterDeliveryFileMediaResource(fExportZIP);
} catch (IOException e) {
logError("Cannot export glossar: " + res, e);
return null;
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class MovieServiceImpl method getFrameCount.
@Override
public long getFrameCount(VFSLeaf media, String suffix) {
File file = null;
if (media instanceof VFSCPNamedItem) {
media = ((VFSCPNamedItem) media).getDelegate();
}
if (media instanceof LocalFileImpl) {
file = ((LocalFileImpl) media).getBasefile();
}
if (file == null) {
return -1;
}
if (extensions.contains(suffix)) {
try (RandomAccessFile accessFile = new RandomAccessFile(file, "r")) {
FileChannel ch = accessFile.getChannel();
FileChannelWrapper in = new FileChannelWrapper(ch);
MP4Demuxer demuxer1 = new MP4Demuxer(in);
return demuxer1.getVideoTrack().getFrameCount();
} catch (Exception | AssertionError e) {
log.error("Cannot extract num. of frames of: " + media, e);
}
}
return -1;
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class MovieServiceImpl method getDuration.
@Override
public long getDuration(VFSLeaf media, String suffix) {
File file = null;
if (media instanceof VFSCPNamedItem) {
media = ((VFSCPNamedItem) media).getDelegate();
}
if (media instanceof LocalFileImpl) {
file = ((LocalFileImpl) media).getBasefile();
}
if (file == null) {
return -1;
}
if (extensions.contains(suffix)) {
try (RandomAccessFile accessFile = new RandomAccessFile(file, "r")) {
FileChannel ch = accessFile.getChannel();
FileChannelWrapper in = new FileChannelWrapper(ch);
MP4Demuxer demuxer1 = new MP4Demuxer(in);
MovieBox movie = demuxer1.getMovie();
long duration = movie.getDuration();
int timescale = movie.getTimescale();
if (timescale < 1) {
timescale = 1;
}
// Simple calculation. Ignore NTSC and other issues for now
return duration / timescale * 1000;
} catch (Exception | AssertionError e) {
log.error("Cannot extract duration of: " + media, e);
}
}
return -1;
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class HTMLEditorController method getFileDebuggingPath.
/**
* Helper method to get a meaningful debugging filename from the vfs
* container and the file path
*
* @param root
* @param relPath
* @return
*/
private static String getFileDebuggingPath(VFSContainer root, String relPath) {
String path = relPath;
VFSItem item = root.resolve(relPath);
if (item instanceof LocalFileImpl) {
LocalFileImpl file = (LocalFileImpl) item;
path = file.getBasefile().getAbsolutePath();
} else {
VFSContainer dir = root;
while (dir != null) {
path = "/" + dir.getName() + path;
dir = dir.getParentContainer();
}
}
return path;
}
Aggregations