use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class FolderTreeModel method buildTree.
private boolean buildTree(TreeNode tParent, VFSContainer parentContainer, String parentPath) {
List<VFSItem> children = parentContainer.getItems(fileFilter);
if (children.size() == 0)
return false;
// sort the children
Collections.sort(children, new Comparator<VFSItem>() {
final Collator c = collator;
public int compare(final VFSItem o1, final VFSItem o2) {
return c.compare(o1.getName(), o2.getName());
}
});
boolean addedAtLeastOneChild = false;
for (Iterator<VFSItem> iter = children.iterator(); iter.hasNext(); ) {
VFSItem child = iter.next();
String childName = child.getName();
if (child instanceof VFSContainer) {
// container node
String filePath = parentPath + childName + "/";
// filePath is the information to be remembered later
GenericTreeNode tChild = new GenericTreeNode(childName, filePath);
tChild.setIconCssClass("o_filetype_folder");
tChild.setAltText(child.getName());
tChild.setAccessible(selectableFolders ? (child.canWrite() == VFSConstants.YES) : false);
tParent.addChild(tChild);
boolean addedChildren = buildTree(tChild, (VFSContainer) child, filePath);
if (foldersOnly || addedChildren) {
addedAtLeastOneChild = true;
} else {
// this directory does not contain anything usefull, remove it again!
tParent.remove(tChild);
}
} else {
// leaf node
if (foldersOnly)
continue;
String filePath = parentPath + childName;
GenericTreeNode tChild = new GenericTreeNode(childName, filePath);
String type = FolderHelper.extractFileType(childName, locale);
if (!FolderHelper.isKnownFileType(type)) {
type = "file";
}
tChild.setIconCssClass("o_filetype_" + type);
tChild.setAltText(childName);
tChild.setAccessible(selectableFiles);
tParent.addChild(tChild);
addedAtLeastOneChild = true;
}
}
return addedAtLeastOneChild;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class ZipUtil method checkLockedFileBeforeUnzip.
// unzip
/**
* Check if a file in the zip is already in the path
* @param zipLeaf
* @param targetDir
* @param identity
* @param isAdmin
* @return the list of files which already exist
*/
public static List<String> checkLockedFileBeforeUnzip(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, Roles isAdmin) {
List<String> lockedFiles = new ArrayList<String>();
InputStream in = zipLeaf.getInputStream();
ZipInputStream oZip = new ZipInputStream(in);
VFSLockManager vfsLockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
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
// directories aren't locked
oZip.closeEntry();
oEntr = oZip.getNextEntry();
continue;
} else {
// search 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) {
// get subdirs
createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, false);
if (createIn == null) {
// sub directories don't exist, and aren't locked
oZip.closeEntry();
oEntr = oZip.getNextEntry();
continue;
}
name = name.substring(dirSepIndex + 1);
}
VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
if (vfsLockManager.isLockedForMe(newEntry, identity, isAdmin)) {
lockedFiles.add(name);
}
}
}
oZip.closeEntry();
oEntr = oZip.getNextEntry();
}
} catch (IOException e) {
return null;
} finally {
FileUtils.closeSafely(oZip);
FileUtils.closeSafely(in);
}
return lockedFiles;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class MailModule method getRootForAttachments.
public VFSContainer getRootForAttachments() {
String root = folderModule.getCanonicalRoot() + attachmentsRoot;
File rootFile = new File(root);
if (!rootFile.exists()) {
rootFile.mkdirs();
}
VFSContainer rootContainer = new LocalFolderImpl(rootFile);
return rootContainer;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class MailManagerImpl method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
VFSContainer root = mailModule.getRootForAttachments();
attachmentStorage = new FileStorage(root);
PublisherData pdata = getPublisherData();
SubscriptionContext scontext = getSubscriptionContext();
notificationsManager.getOrCreatePublisher(scontext, pdata);
Properties p = null;
try {
velocityEngine = new VelocityEngine();
p = new Properties();
p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
p.setProperty(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS, "org.olat.core.gui.render.velocity.InfinispanResourceCache");
p.setProperty("runtime.log.logsystem.log4j.category", "syslog");
velocityEngine.init(p);
} catch (Exception e) {
throw new RuntimeException("config error " + p.toString());
}
}
use of org.olat.core.util.vfs.VFSContainer 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;
}
Aggregations