use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class SendDocumentsByEMailController method execute.
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
VFSContainer currentContainer = folderComponent.getCurrentContainer();
VFSContainer rootContainer = folderComponent.getRootContainer();
if (!VFSManager.exists(currentContainer)) {
status = FolderCommandStatus.STATUS_FAILED;
showError(translator.translate("FileDoesNotExist"));
return null;
}
status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
if (status == FolderCommandStatus.STATUS_FAILED) {
return null;
}
selection = new FileSelection(ureq, folderComponent.getCurrentContainerPath());
status = FolderCommandHelper.sanityCheck3(wControl, folderComponent, selection);
if (status == FolderCommandStatus.STATUS_FAILED) {
return null;
}
boolean selectionWithContainer = false;
List<String> filenames = selection.getFiles();
List<VFSLeaf> leafs = new ArrayList<VFSLeaf>();
for (String file : filenames) {
VFSItem item = currentContainer.resolve(file);
if (item instanceof VFSContainer) {
selectionWithContainer = true;
} else if (item instanceof VFSLeaf) {
leafs.add((VFSLeaf) item);
}
}
if (selectionWithContainer) {
if (leafs.isEmpty()) {
wControl.setError(getTranslator().translate("send.mail.noFileSelected"));
return null;
} else {
setFormWarning(getTranslator().translate("send.mail.selectionContainsFolder"));
}
}
setFiles(rootContainer, leafs);
return this;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSLockManagerImpl method getVFSLock.
/**
* Return a lock info base on the VFS lock
*
* @param resource
* @return
*/
public LockInfo getVFSLock(WebResource resource) {
VFSItem item = extractItem(resource);
MetaInfoFileImpl info = getMetaInfo(item);
if (info != null && info.isLocked()) {
File file = extractFile(item);
LockInfo lock = null;
if (fileLocks.containsKey(file)) {
lock = fileLocks.get(file);
if (lock != null) {
lock.setVfsLock(true);
}
}
if (lock == null) {
lock = new LockInfo(info.getLockedBy(), false, true);
lock.setWebResource(resource);
lock.setCreationDate(info.getLockedDate());
lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy());
lock.setDepth(1);
lock.addToken(generateLockToken(lock, info.getLockedBy()));
fileLocks.put(file, lock);
}
return lock;
}
return null;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method pruneVersionHistory.
private void pruneVersionHistory(VFSContainer container, long maxHistoryLength, ProgressDelegate progress, int count) {
List<VFSItem> children = container.getItems(new SystemItemFilter());
for (VFSItem child : children) {
if (child instanceof VFSContainer) {
if (progress != null)
progress.setActual(++count);
pruneVersionHistory((VFSContainer) child, maxHistoryLength, progress, count);
}
if (child instanceof VFSLeaf) {
VFSLeaf versionsLeaf = (VFSLeaf) child;
pruneVersionHistory(versionsLeaf, maxHistoryLength, progress);
}
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method restore.
@Override
public boolean restore(VFSContainer container, VFSRevision revision) {
String filename = revision.getName();
VFSItem restoredItem = container.resolve(filename);
if (restoredItem == null) {
restoredItem = container.createChildLeaf(filename);
}
if (restoredItem instanceof VFSLeaf) {
VFSLeaf restoredLeaf = (VFSLeaf) restoredItem;
InputStream inStream = revision.getInputStream();
if (VFSManager.copyContent(inStream, restoredLeaf)) {
VFSLeaf versionFile = getCanonicalVersionXmlFile(restoredLeaf, true);
Versions versions = readVersions(restoredLeaf, versionFile);
if (versions instanceof VersionsFileImpl) {
versions.getRevisions().remove(revision);
((VersionsFileImpl) versions).setRevisionNr(getNextRevisionNr(versions));
}
XStreamHelper.writeObject(mystream, versionFile, versions);
return true;
}
}
return false;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method getDeletedFiles.
@Override
public List<Versions> getDeletedFiles(VFSContainer container) {
List<Versions> deletedRevisions = new ArrayList<Versions>();
VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
if (versionContainer != null) {
Set<String> currentNames = new HashSet<String>();
for (VFSItem item : container.getItems(new VFSLeafFilter())) {
currentNames.add(item.getName() + ".xml");
}
List<VFSItem> versionItems = versionContainer.getItems(new VFSItemSuffixFilter(new String[] { "xml" }));
for (VFSItem versionItem : versionItems) {
String name = versionItem.getName();
if (versionItem instanceof VFSLeaf && !currentNames.contains(name) && isVersionsXmlFile((VFSLeaf) versionItem)) {
Versions versions = readVersions(null, (VFSLeaf) versionItem);
if (versions != null) {
List<VFSRevision> revisions = versions.getRevisions();
if (!revisions.isEmpty()) {
deletedRevisions.add(versions);
}
}
}
}
}
return deletedRevisions;
}
Aggregations