use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
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 klemens.
the class SubmitDocumentsController method doCreateDocumentEditor.
private void doCreateDocumentEditor(UserRequest ureq, String documentName) {
if (newDocumentEditorCtrl != null)
return;
if (maxDocs > 0 && maxDocs <= model.getRowCount()) {
showWarning("error.max.documents");
} else {
VFSItem item = documentsContainer.resolve(documentName);
if (item == null) {
documentsContainer.createChildLeaf(documentName);
} else {
documentName = VFSManager.rename(documentsContainer, documentName);
documentsContainer.createChildLeaf(documentName);
}
// add missing identity in meta info
item = documentsContainer.resolve(documentName);
if (item instanceof MetaTagged) {
MetaInfo metadata = ((MetaTagged) item).getMetaInfo();
metadata.setAuthor(ureq.getIdentity());
metadata.write();
}
newDocumentEditorCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), documentsContainer, documentName, "media", true, true);
newDocumentEditorCtrl.getRichTextConfiguration().disableMedia();
newDocumentEditorCtrl.getRichTextConfiguration().setAllowCustomMediaFactory(false);
newDocumentEditorCtrl.setNewFile(true);
listenTo(newDocumentEditorCtrl);
cmc = new CloseableModalController(getWindowControl(), "close", newDocumentEditorCtrl.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
the class ZipUtil method getAllSubdirs.
/**
* Get the whole subpath.
* @param create the missing directories
* @param base
* @param subDirPath
* @return Returns the last container of this subpath.
*/
public static VFSContainer getAllSubdirs(VFSContainer base, String subDirPath, Identity identity, boolean create) {
StringTokenizer st;
if (subDirPath.indexOf("/") != -1) {
st = new StringTokenizer(subDirPath, "/", false);
} else {
// try it windows style, backslash is also valid format
st = new StringTokenizer(subDirPath, "\\", false);
}
VFSContainer currentPath = base;
while (st.hasMoreTokens()) {
String nextSubpath = st.nextToken();
VFSItem vfsSubpath = currentPath.resolve(nextSubpath);
if (vfsSubpath == null && !create) {
return null;
}
if (vfsSubpath == null || (vfsSubpath instanceof VFSLeaf)) {
vfsSubpath = currentPath.createChildContainer(nextSubpath);
if (vfsSubpath == null)
return null;
if (identity != null && vfsSubpath instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) vfsSubpath).getMetaInfo();
if (info != null) {
info.setAuthor(identity);
info.write();
}
}
}
currentPath = (VFSContainer) vfsSubpath;
}
return currentPath;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
the class ZipUtil method unzip.
/**
* Unzip an inputstream to a directory using the versioning system of VFS
* @param zipLeaf The file to unzip
* @param targetDir The directory to unzip the file to
* @param the identity of who unzip the file
* @param versioning enabled or not
* @return True if successfull, false otherwise
*/
private static boolean unzip(InputStream in, VFSContainer targetDir, Identity identity, boolean versioning) {
ZipInputStream oZip = new ZipInputStream(in);
try {
// unzip files
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 klemens.
the class VFSLockManagerImpl method unlock.
/**
* Unlock the VFS lock only
*/
@Override
public boolean unlock(VFSItem item, Identity identity, Roles roles) {
if (item instanceof MetaTagged) {
MetaInfoFileImpl info = (MetaInfoFileImpl) ((MetaTagged) item).getMetaInfo();
if (info == null)
return false;
info.setLockedBy(null);
info.setLockedDate(null);
info.setLocked(false);
info.write();
boolean unlocked = false;
File file = extractFile(item);
if (file != null && fileLocks.containsKey(file)) {
LockInfo lock = fileLocks.get(file);
if (lock.isWebDAVLock()) {
lock.setVfsLock(false);
} else {
if (lock.getWebPath() != null) {
// LOCK resourceLocks.remove(lock.getWebPath());
}
fileLocks.remove(file);
unlocked = true;
}
} else {
unlocked = true;
}
return unlocked;
}
return false;
}
Aggregations