use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged 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.tagged.MetaTagged 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;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
the class FileDocumentFactory method getDocumentFromCurrentIndex.
private Document getDocumentFromCurrentIndex(SearchResourceContext leafResourceContext, VFSLeaf leaf) {
try {
String resourceUrl = leafResourceContext.getResourceUrl();
SearchService searchService = CoreSpringFactory.getImpl(SearchServiceImpl.class);
Document indexedDoc = searchService.doSearch(resourceUrl);
if (indexedDoc != null) {
String timestamp = indexedDoc.get(AbstractOlatDocument.TIME_STAMP_NAME);
if (timestamp != null) {
Date indexLastModification = DateTools.stringToDate(timestamp);
Date docLastModificationDate = new Date(leaf.getLastModified());
if (leaf instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) leaf).getMetaInfo();
Date metaDate = metaInfo.getMetaLastModified();
if (metaDate != null && metaDate.after(docLastModificationDate)) {
docLastModificationDate = metaDate;
}
}
if (docLastModificationDate.compareTo(indexLastModification) < 0) {
OlatDocument olatDoc = new OlatDocument(indexedDoc);
return olatDoc.getLuceneDocument();
}
}
}
} catch (ServiceNotAvailableException | ParseException | QueryException | java.text.ParseException e) {
log.error("", e);
}
return null;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
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.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
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;
}
Aggregations