use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class RepositoryEditDescriptionController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == dateTypesEl) {
updateDatesVisibility();
} else if (source == licenseEl) {
LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
;
} else if (source == fileUpload) {
if (FileElementEvent.DELETE.equals(event.getCommand())) {
fileUpload.clearError();
VFSLeaf img = repositoryManager.getImage(repositoryEntry);
if (fileUpload.getUploadFile() != null && fileUpload.getUploadFile() != fileUpload.getInitialFile()) {
fileUpload.reset();
if (img != null) {
fileUpload.setInitialFile(((LocalFileImpl) img).getBasefile());
}
} else if (img != null) {
repositoryManager.deleteImage(repositoryEntry);
fileUpload.setInitialFile(null);
}
flc.setDirty(true);
}
} else if (source == movieUpload) {
if (FileElementEvent.DELETE.equals(event.getCommand())) {
movieUpload.clearError();
VFSLeaf movie = repositoryService.getIntroductionMovie(repositoryEntry);
if (movieUpload.getUploadFile() != null && movieUpload.getUploadFile() != movieUpload.getInitialFile()) {
movieUpload.reset();
if (movie != null) {
movieUpload.setInitialFile(((LocalFileImpl) movie).getBasefile());
}
} else if (movie != null) {
movie.delete();
movieUpload.setInitialFile(null);
}
flc.setDirty(true);
}
}
super.formInnerEvent(ureq, source, event);
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class VideoManagerImpl method getFrameWithFilter.
@Override
public boolean getFrameWithFilter(OLATResource videoResource, int frameNumber, long duration, VFSLeaf frame) {
File videoFile = ((LocalFileImpl) getMasterVideoFile(videoResource)).getBasefile();
BufferedImage bufImg = null;
boolean imgBlack = true;
int countBlack = 0;
try (RandomAccessFile randomAccessFile = new RandomAccessFile(videoFile, "r")) {
OutputStream frameOutputStream = frame.getOutputStream(false);
FileChannel ch = randomAccessFile.getChannel();
FileChannelWrapper in = new FileChannelWrapper(ch);
FrameGrab frameGrab = new FrameGrab(in).seekToFrameSloppy(frameNumber);
bufImg = frameGrab.getFrame();
int xmin = bufImg.getMinX();
int ymin = bufImg.getMinY();
int xmax = xmin + bufImg.getWidth();
int ymax = ymin + bufImg.getHeight();
int pixelCount = bufImg.getWidth() * bufImg.getHeight();
for (int x = xmin; x < xmax; x++) {
for (int y = ymin; y < ymax; y++) {
int rgb = bufImg.getRGB(x, y);
// int alpha = (0xff000000 & rgb) >>> 24;
int r = (0x00ff0000 & rgb) >> 16;
int g = (0x0000ff00 & rgb) >> 8;
int b = (0x000000ff & rgb);
if (r < 30 && g < 30 && b < 30) {
countBlack++;
}
}
}
if (countBlack > (int) (0.7F * pixelCount)) {
imgBlack = true;
} else {
imgBlack = false;
ImageIO.write(bufImg, "JPG", frameOutputStream);
}
// avoid endless loop
if (frameNumber > duration) {
imgBlack = false;
}
// close everything to prevent resource leaks
frameOutputStream.close();
in.close();
ch.close();
return imgBlack;
} catch (Exception | AssertionError e) {
log.error("Could not get frame::" + frameNumber + " for video::" + videoFile.getAbsolutePath(), e);
return false;
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class VideoManagerImpl method getFrame.
/**
* write the the given frame at frameNumber in the frame leaf
* @param videoResource videoresource
* @param frameNumber the frameNumber at which the frame should be taken from
* @param frame the VFSLeaf to write the picked image to
*/
@Override
public boolean getFrame(OLATResource videoResource, int frameNumber, VFSLeaf frame) {
File videoFile = ((LocalFileImpl) getMasterVideoFile(videoResource)).getBasefile();
try (RandomAccessFile randomAccessFile = new RandomAccessFile(videoFile, "r")) {
FileChannel ch = randomAccessFile.getChannel();
FileChannelWrapper in = new FileChannelWrapper(ch);
FrameGrab frameGrab = new FrameGrab(in).seekToFrameSloppy(frameNumber);
OutputStream frameOutputStream = frame.getOutputStream(false);
BufferedImage bufImg = frameGrab.getFrame();
ImageIO.write(bufImg, "JPG", frameOutputStream);
// close everything to prevent resource leaks
frameOutputStream.close();
in.close();
ch.close();
return true;
} catch (Exception | AssertionError e) {
log.error("Could not get frame::" + frameNumber + " for video::" + videoFile.getAbsolutePath(), e);
return false;
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class ScormAssessmentManager method collectData.
/**
* Collects the cmi data of the given Scorm-file.
* @param scoFile
* @return
*/
private List<CmiData> collectData(VFSItem scoFile) {
List<CmiData> datas = new ArrayList<CmiData>();
ScoDocument document = new ScoDocument(null);
try {
if (scoFile instanceof LocalFileImpl) {
document.loadDocument(((LocalFileImpl) scoFile).getBasefile());
} else {
logger.warn("Cannot use this type of VSFItem to load a SCO Datamodel: " + scoFile.getClass().getName(), null);
return null;
}
String fileName = scoFile.getName();
String itemId = fileName.substring(0, fileName.length() - 4);
String[][] scoModel = document.getScoModel();
for (String[] line : scoModel) {
datas.add(new CmiData(itemId, line[0], line[1]));
}
} catch (Exception e) {
logger.error("Cannot load a SCO Datamodel", e);
}
return datas;
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class ItemSequence method archiveScoData.
// <OLATCE-289>
/**
* This method copies the current cmi-file to a new file with timestamp so that all attempts
* can be evaluated by the assessment tool.
* @return
*/
public boolean archiveScoData() {
File currentCmiFile = _scoDataModel.getFile().getAbsoluteFile();
LocalFileImpl currentCmiFileVFS = new LocalFileImpl(_scoDataModel.getFile().getAbsoluteFile());
String suffix = "." + FileUtils.getFileSuffix(currentCmiFile.getName());
String newFileName = currentCmiFile.getName().substring(0, currentCmiFile.getName().indexOf(suffix)) + "_" + String.valueOf(System.currentTimeMillis() + suffix);
File outf = new File(currentCmiFile.getParentFile(), newFileName);
OutputStream os = null;
try {
os = new FileOutputStream(outf);
} catch (FileNotFoundException e) {
return false;
}
InputStream is = currentCmiFileVFS.getInputStream();
FileUtils.copy(is, os);
FileUtils.closeSafely(os);
FileUtils.closeSafely(is);
return true;
}
Aggregations