use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class FileArtefactHandler method prefillArtefactAccordingToSource.
/**
* @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact,
* java.lang.Object)
*/
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
super.prefillArtefactAccordingToSource(artefact, source);
if (source instanceof VFSItem) {
VFSItem fileSource = (VFSItem) source;
((FileArtefact) artefact).setFilename(fileSource.getName());
MetaInfo meta = null;
if (fileSource instanceof MetaTagged) {
meta = ((MetaTagged) fileSource).getMetaInfo();
}
if (meta != null && StringHelper.containsNonWhitespace(meta.getTitle())) {
artefact.setTitle(meta.getTitle());
} else {
artefact.setTitle(fileSource.getName());
}
if (meta != null && StringHelper.containsNonWhitespace(meta.getComment())) {
artefact.setDescription(meta.getComment());
}
artefact.setSignature(60);
String path = ((OlatRootFileImpl) fileSource).getRelPath();
String[] pathElements = path.split("/");
String finalBusinessPath = null;
String sourceInfo = null;
// used to rebuild businessPath and source for a file:
if (pathElements[1].equals("homes") && meta != null && pathElements[2].equals(meta.getAuthor())) {
// from users briefcase
String lastParts = "/";
for (int i = 4; i < (pathElements.length - 1); i++) {
lastParts = lastParts + pathElements[i] + "/";
}
sourceInfo = "Home -> " + pathElements[3] + " -> " + lastParts + fileSource.getName();
} else if (pathElements[3].equals("BusinessGroup")) {
// out of a businessgroup
String lastParts = "/";
for (int i = 5; i < (pathElements.length - 1); i++) {
lastParts = lastParts + pathElements[i] + "/";
}
BusinessGroup bGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(new Long(pathElements[4]));
if (bGroup != null) {
sourceInfo = bGroup.getName() + " -> " + lastParts + " -> " + fileSource.getName();
}
finalBusinessPath = "[BusinessGroup:" + pathElements[4] + "][toolfolder:0][path=" + lastParts + fileSource.getName() + ":0]";
} else if (pathElements[4].equals("coursefolder")) {
// the course folder
sourceInfo = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(new Long(pathElements[2])) + " -> " + fileSource.getName();
} else if (pathElements[1].equals("course") && pathElements[3].equals("foldernodes")) {
// folders inside a course
sourceInfo = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(new Long(pathElements[2])) + " -> " + pathElements[4] + " -> " + fileSource.getName();
finalBusinessPath = "[RepositoryEntry:" + pathElements[2] + "][CourseNode:" + pathElements[4] + "]";
}
if (sourceInfo == null) {
// unknown source, keep full path
sourceInfo = VFSManager.getRealPath(fileSource.getParentContainer()) + "/" + fileSource.getName();
}
artefact.setBusinessPath(finalBusinessPath);
artefact.setSource(sourceInfo);
}
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class VideoHandler method getThumbnail.
@Override
public VFSLeaf getThumbnail(MediaLight media, Size size) {
String storagePath = media.getStoragePath();
VFSLeaf thumbnail = null;
if (StringHelper.containsNonWhitespace(storagePath)) {
VFSContainer storageContainer = fileStorage.getMediaContainer(media);
VFSItem item = storageContainer.resolve(media.getRootFilename());
if (item instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) item;
if (leaf instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) leaf).getMetaInfo();
thumbnail = metaInfo.getThumbnail(size.getHeight(), size.getWidth(), true);
}
}
}
return thumbnail;
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class VideoHandler method getInformations.
@Override
public MediaInformations getInformations(Object mediaObject) {
String title = null;
String description = null;
if (mediaObject instanceof MetaTagged) {
MetaInfo meta = ((MetaTagged) mediaObject).getMetaInfo();
title = meta.getTitle();
description = meta.getComment();
}
return new Informations(title, description);
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class RepositoryManager method setImage.
public boolean setImage(VFSLeaf newImageFile, RepositoryEntry re) {
VFSLeaf currentImage = getImage(re);
if (currentImage != null) {
if (currentImage instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) currentImage).getMetaInfo();
if (info != null) {
info.clearThumbnails();
}
}
currentImage.delete();
}
if (newImageFile == null || !newImageFile.exists() || newImageFile.getSize() <= 0) {
return false;
}
String targetExtension = ".png";
String extension = FileUtils.getFileSuffix(newImageFile.getName());
if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension)) {
targetExtension = ".jpg";
}
VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
VFSLeaf repoImage = repositoryHome.createChildLeaf(re.getResourceableId() + targetExtension);
if (targetExtension.equals(".png") || targetExtension.equals(".jpg")) {
Size newImageSize = imageHelper.getSize(newImageFile, extension);
if (newImageSize != null && newImageSize.getWidth() <= PICTURE_WIDTH && newImageSize.getHeight() <= PICTURE_HEIGHT) {
boolean success = VFSManager.copyContent(newImageFile, repoImage);
return success;
}
}
Size size = imageHelper.scaleImage(newImageFile, repoImage, PICTURE_WIDTH, PICTURE_WIDTH, false);
return size != null;
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class CatalogManager method setImage.
public boolean setImage(VFSLeaf newImageFile, CatalogEntryRef re) {
VFSLeaf currentImage = getImage(re);
if (currentImage != null) {
if (currentImage instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) currentImage).getMetaInfo();
if (info != null) {
info.clearThumbnails();
}
}
currentImage.delete();
}
String extension = FileUtils.getFileSuffix(newImageFile.getName());
if (StringHelper.containsNonWhitespace(extension)) {
extension = extension.toLowerCase();
}
boolean ok = false;
VFSContainer catalogResourceHome = getCatalogResourcesHome();
try {
if ("jpeg".equals(extension) || "jpg".equals(extension)) {
VFSLeaf repoImage = catalogResourceHome.createChildLeaf(re.getKey() + ".jpg");
ok = VFSManager.copyContent(newImageFile, repoImage);
} else if ("png".equals(extension)) {
VFSLeaf repoImage = catalogResourceHome.createChildLeaf(re.getKey() + ".png");
ok = VFSManager.copyContent(newImageFile, repoImage);
} else {
// scale to default and png
VFSLeaf repoImage = catalogResourceHome.createChildLeaf(re.getKey() + ".png");
Size size = imageHelper.scaleImage(newImageFile, repoImage, 570, 570, true);
ok = size != null;
}
} catch (Exception e) {
log.error("", e);
}
return ok;
}
Aggregations