use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class MovieServiceImpl method generateThumbnail.
@Override
public FinalSize generateThumbnail(VFSLeaf file, VFSLeaf thumbnailFile, int maxWidth, int maxHeight, boolean fill) throws CannotGenerateThumbnailException {
FinalSize size = null;
if (file instanceof LocalFileImpl && thumbnailFile instanceof LocalFileImpl) {
try {
WorkThreadInformations.setInfoFiles(null, file);
WorkThreadInformations.set("Generate thumbnail (video) VFSLeaf=" + file);
File baseFile = ((LocalFileImpl) file).getBasefile();
File scaledImage = ((LocalFileImpl) thumbnailFile).getBasefile();
BufferedImage frame = FrameGrab.getFrame(baseFile, 20);
Size scaledSize = ImageHelperImpl.calcScaledSize(frame, maxWidth, maxHeight);
if (ImageHelperImpl.writeTo(frame, scaledImage, scaledSize, "jpeg")) {
size = new FinalSize(scaledSize.getWidth(), scaledSize.getHeight());
}
// NullPointerException can be thrown if the jcodec cannot handle the codec of the movie
// ArrayIndexOutOfBoundsException
} catch (Exception | AssertionError e) {
log.error("", e);
} finally {
WorkThreadInformations.unset();
}
}
return size;
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class SendDocumentsByEMailController method setFiles.
protected void setFiles(VFSContainer rootContainer, List<VFSLeaf> leafs) {
this.files = leafs;
StringBuilder subjectSb = new StringBuilder();
if (StringHelper.containsNonWhitespace(subjectElement.getValue())) {
subjectSb.append(subjectElement.getValue()).append('\n').append('\n');
}
StringBuilder bodySb = new StringBuilder();
if (StringHelper.containsNonWhitespace(bodyElement.getValue())) {
bodySb.append(bodyElement.getValue()).append('\n').append('\n');
}
attachments = new ArrayList<File>();
long fileSize = 0l;
for (VFSLeaf file : files) {
MetaInfo infos = null;
if (file instanceof MetaTagged) {
infos = ((MetaTagged) file).getMetaInfo();
}
// subject
appendToSubject(file, infos, subjectSb);
// body
appendMetadatas(file, infos, bodySb);
appendBusinessPath(rootContainer, file, bodySb);
bodySb.append('\n').append('\n');
fileSize += file.getSize();
if (allowAttachments && file instanceof LocalFileImpl) {
File f = ((LocalFileImpl) file).getBasefile();
attachments.add(f);
}
}
int mailQuota = CoreSpringFactory.getImpl(MailModule.class).getMaxSizeForAttachement();
long fileSizeInMB = fileSize / (1024l * 1024l);
if (allowAttachments) {
if (fileSizeInMB > mailQuota) {
attachments.clear();
setFormWarning("send.mail.fileToBigForAttachments", new String[] { String.valueOf(mailQuota), String.valueOf(fileSizeInMB) });
} else {
List<FileInfo> infos = new ArrayList<FileInfo>(files.size());
for (VFSLeaf file : files) {
final String name = file.getName();
final double size = file.getSize() / (1024.0 * 1024.0);
final String sizeStr = formatMb.format(size);
final String cssClass = CSSHelper.createFiletypeIconCssClassFor(file.getName());
infos.add(new FileInfo(name, sizeStr, cssClass));
}
attachmentsLayout.contextPut("attachments", infos);
}
}
subjectElement.setValue(subjectSb.toString());
bodyElement.setValue(bodySb.toString());
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class HotspotEditorController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (readOnly)
return;
itemBuilder.setTitle(titleEl.getValue());
// set the question with the text entries
String questionText = textEl.getRawValue();
itemBuilder.setQuestion(questionText);
itemBuilder.setResponsive(responsiveEl.isAtLeastSelected(1));
File objectImg = null;
if (backgroundImage != null) {
objectImg = backgroundImage;
} else if (initialBackgroundImage != null) {
objectImg = initialBackgroundImage;
}
if (cardinalityEl.isOneSelected()) {
String selectedCardinality = cardinalityEl.getSelectedKey();
itemBuilder.setCardinality(Cardinality.valueOf(selectedCardinality));
}
boolean updateHotspot = true;
if (objectImg != null) {
String filename = objectImg.getName();
String mimeType = WebappHelper.getMimeType(filename);
Size currentSize = imageService.getSize(new LocalFileImpl(objectImg), null);
Size size = currentSize;
if (resizeEl.isVisible() && !resizeEl.isSelected(0)) {
int maxSize = Integer.parseInt(resizeEl.getSelectedKey());
if (maxSize < currentSize.getHeight() || maxSize < currentSize.getWidth()) {
String extension = FileUtils.getFileSuffix(filename);
size = imageService.scaleImage(objectImg, extension, objectImg, maxSize, maxSize, false);
setBackgroundSize(size);
scaleHotspot(currentSize, size);
optimizeResizeEl(size, false);
updateHotspot = false;
}
}
int height = -1;
int width = -1;
if (size != null) {
height = size.getHeight();
width = size.getWidth();
}
String relPath = itemFile.getParentFile().toPath().relativize(objectImg.toPath()).toString();
itemBuilder.setBackground(relPath, mimeType, height, width);
}
if (updateHotspot) {
updateHotspots(ureq);
}
if (layoutEl.isOneSelected()) {
String selectedLayout = layoutEl.getSelectedKey();
for (HotspotLayouts layout : HotspotLayouts.values()) {
itemBuilder.removeHotspotInteractionClass(layout.cssClass());
}
itemBuilder.addHotspotInteractionClass(selectedLayout);
}
if (shadowEl.isAtLeastSelected(1)) {
itemBuilder.removeHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW);
} else {
itemBuilder.addHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW);
}
fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.hotspot));
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class ScormExportManager method collectData.
private void collectData(String username, VFSContainer scoFolder, ScormExportVisitor visitor) {
List<VFSItem> contents = scoFolder.getItems(new XMLFilter());
for (VFSItem file : contents) {
ScoDocument document = new ScoDocument(null);
try {
if (file instanceof LocalFileImpl) {
document.loadDocument(((LocalFileImpl) file).getBasefile());
} else {
logger.warn("Cannot use this type of VSFItem to load a SCO Datamodel: " + file.getClass().getName(), null);
continue;
}
String[][] scoModel = document.getScoModel();
ScoDatas parsedDatas = parseScoModel(file.getName(), username, scoModel);
visitor.visit(parsedDatas);
} catch (Exception e) {
logger.error("Cannot load a SCO Datamodel", e);
}
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class ScormAssessmentManager method getSequencerModel.
/**
* Load the SequencerModel
* @param username
* @param courseEnv
* @param node
* @return can be null if the user hasn't visited the course
*/
public SequencerModel getSequencerModel(String username, CourseEnvironment courseEnv, ScormCourseNode node) {
VFSContainer scoDirectory = ScormDirectoryHelper.getScoDirectory(username, courseEnv, node);
if (scoDirectory == null)
return null;
VFSItem reloadSettingsFile = scoDirectory.resolve(RELOAD_SETTINGS_FILE);
if (reloadSettingsFile instanceof LocalFileImpl) {
LocalFileImpl fileImpl = (LocalFileImpl) reloadSettingsFile;
return new SequencerModel(fileImpl.getBasefile(), null);
} else if (reloadSettingsFile != null) {
throw new OLATRuntimeException(this.getClass(), "Programming error, SCORM results must be file based", null);
}
return null;
}
Aggregations