use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class ZipUtil method unzipNonStrict.
/**
* Unzip with jazzlib
* @param in
* @param targetDir
* @param identity
* @param versioning
* @return
*/
private static boolean unzipNonStrict(InputStream in, VFSContainer targetDir, Identity identity, boolean versioning) {
net.sf.jazzlib.ZipInputStream oZip = new net.sf.jazzlib.ZipInputStream(in);
try {
// unzip files
net.sf.jazzlib.ZipEntry oEntr = oZip.getNextEntry();
while (oEntr != null) {
if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
if (oEntr.isDirectory()) {
// skip MacOSX specific metadata directory
// create directories
getAllSubdirs(targetDir, oEntr.getName(), identity, true);
} else {
// create file
VFSContainer createIn = targetDir;
String name = oEntr.getName();
// check if entry has directories which did not show up as
// directories above
int dirSepIndex = name.lastIndexOf('/');
if (dirSepIndex == -1) {
// try it windows style, backslash is also valid format
dirSepIndex = name.lastIndexOf('\\');
}
if (dirSepIndex > 0) {
// create subdirs
createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, true);
if (createIn == null) {
if (log.isDebug())
log.debug("Error creating directory structure for zip entry: " + oEntr.getName());
return false;
}
name = name.substring(dirSepIndex + 1);
}
if (versioning) {
VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
if (newEntry == null) {
newEntry = createIn.createChildLeaf(name);
OutputStream out = newEntry.getOutputStream(false);
if (!FileUtils.copy(oZip, out))
return false;
FileUtils.closeSafely(out);
} else if (newEntry instanceof Versionable) {
Versionable versionable = (Versionable) newEntry;
if (versionable.getVersions().isVersioned()) {
versionable.getVersions().addVersion(identity, "", oZip);
}
}
if (newEntry instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) newEntry).getMetaInfo();
if (info != null) {
info.setAuthor(identity);
info.write();
}
}
} else {
VFSLeaf newEntry = createIn.createChildLeaf(name);
if (newEntry != null) {
OutputStream out = newEntry.getOutputStream(false);
if (!FileUtils.copy(oZip, out))
return false;
FileUtils.closeSafely(out);
}
if (newEntry instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) newEntry).getMetaInfo();
if (info != null && identity != null) {
info.setAuthor(identity);
info.write();
}
}
}
}
}
oZip.closeEntry();
oEntr = oZip.getNextEntry();
}
} catch (IOException e) {
return false;
} finally {
FileUtils.closeSafely(oZip);
}
return true;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class GTANotifications method getAuthor.
private String getAuthor(File file, VFSContainer container) {
String author = null;
VFSItem item = container.resolve(file.getName());
if (item instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) item).getMetaInfo();
if (info != null) {
String username = info.getAuthor();
if (username != null) {
author = userManager.getUserDisplayName(username);
}
}
}
return author == null ? "" : author;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class FileHandler 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.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class VFSResource method increaseDownloadCount.
@Override
public void increaseDownloadCount() {
try {
if (item instanceof VFSLeaf && item instanceof MetaTagged) {
MetaTagged itemWithMeta = (MetaTagged) item;
MetaInfo meta = itemWithMeta.getMetaInfo();
meta.increaseDownloadCount();
meta.write();
}
} catch (Exception e) {
log.error("Cannot increase download counter: " + item, e);
}
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class CmdServeThumbnailResource method execute.
@Override
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
VFSSecurityCallback inheritedSecCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
if (inheritedSecCallback != null && !inheritedSecCallback.canRead())
throw new RuntimeException("Illegal read attempt: " + folderComponent.getCurrentContainerPath());
// extract file
String path = ureq.getModuleURI();
MediaResource mr = null;
VFSLeaf vfsfile = (VFSLeaf) folderComponent.getRootContainer().resolve(path);
if (vfsfile == null) {
// double decoding of ++
vfsfile = (VFSLeaf) FolderCommandHelper.tryDoubleDecoding(ureq, folderComponent);
}
if (vfsfile instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) vfsfile).getMetaInfo();
if (info != null && info.isThumbnailAvailable()) {
VFSLeaf thumbnail = info.getThumbnail(200, 200, false);
if (thumbnail != null) {
mr = new VFSMediaResource(thumbnail);
}
}
}
if (mr == null) {
mr = new NotFoundMediaResource();
}
ureq.getDispatchResult().setResultingMediaResource(mr);
return null;
}
Aggregations