use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class WebdavStatus method copyResource.
/**
* Copy a collection.
*
* @param errorList Hashtable containing the list of errors which occurred
* during the copy operation
* @param source Path of the resource to be copied
* @param dest Destination path
*/
private boolean copyResource(HttpServletRequest req, Hashtable<String, Integer> errorList, String source, String dest, boolean moved) {
if (log.isDebug())
log.debug("Copy: " + source + " To: " + dest);
WebResourceRoot resources = getResources(req);
WebResource sourceResource = resources.getResource(source);
if (sourceResource.isDirectory()) {
if (!resources.mkdir(dest)) {
WebResource destResource = resources.getResource(dest);
if (!destResource.isDirectory()) {
errorList.put(dest, new Integer(WebdavStatus.SC_CONFLICT));
return false;
}
}
Collection<VFSItem> entries = resources.list(source);
for (VFSItem entry : entries) {
String childDest = dest;
if (!childDest.equals("/")) {
childDest += "/";
}
childDest += entry.getName();
String childSrc = source;
if (!childSrc.equals("/")) {
childSrc += "/";
}
childSrc += entry.getName();
copyResource(req, errorList, childSrc, childDest, moved);
}
} else if (sourceResource.isFile()) {
WebResource destResource = resources.getResource(dest);
if (!destResource.exists() && !destResource.getPath().endsWith("/")) {
int lastSlash = destResource.getPath().lastIndexOf('/');
if (lastSlash > 0) {
String parent = destResource.getPath().substring(0, lastSlash);
WebResource parentResource = resources.getResource(parent);
if (!parentResource.isDirectory()) {
errorList.put(source, new Integer(WebdavStatus.SC_CONFLICT));
return false;
}
}
}
WebResource movedFrom = moved ? sourceResource : null;
try {
if (!resources.write(dest, sourceResource.getInputStream(), false, movedFrom)) {
errorList.put(source, new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
return false;
}
} catch (QuotaExceededException e) {
errorList.put(source, new Integer(WebdavStatus.SC_INSUFFICIENT_STORAGE));
return false;
}
} else {
errorList.put(source, new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
return false;
}
return true;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class HtmlStaticPageComponent method setCurrentURI.
/**
* Sets the start html page, may be null
*
* @param currentURI The currentURI to set
*/
public void setCurrentURI(String currentURI) {
if (!isFileTypeSupported(currentURI)) {
throw new AssertException("can only accept files which are inline renderable(.html, .htm, .txt), but given filename is:" + currentURI);
}
this.currentURI = currentURI;
setDirty(true);
VFSItem sourceItem = null;
if (rootContainer != null)
sourceItem = rootContainer.resolve(currentURI);
if (sourceItem == null || (sourceItem instanceof VFSContainer)) {
jsOnLoad = null;
htmlHead = null;
htmlContent = "File not found: " + currentURI;
return;
}
getFileContent((VFSLeaf) sourceItem);
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class OlatRootFolderTreeModel method makeChildren.
/**
* Add children to the node
*
* @param node
* @param root
*/
protected void makeChildren(OlatRootFolderTreeNode node, OlatRootFolderImpl root) {
List<VFSItem> children = root.getItems(filter);
if (comparator != null) {
Collections.sort(children, comparator);
}
for (VFSItem child : children) {
// create a node for each child and add it
if (child instanceof OlatRelPathImpl) {
OlatRootFolderTreeNode childNode = createNode((OlatRelPathImpl) child);
node.addChild(childNode);
if (child instanceof OlatRootFolderImpl) {
// add the child's children recursively
makeChildren(childNode, (OlatRootFolderImpl) child);
}
}
}
}
use of org.olat.core.util.vfs.VFSItem 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.VFSItem in project OpenOLAT by OpenOLAT.
the class MailManagerImpl method deleteMail.
private void deleteMail(DBMailLight mail, Identity identity, boolean forceRemoveRecipient) {
boolean delete = true;
List<DBMailRecipient> updates = new ArrayList<DBMailRecipient>();
if (mail.getFrom() != null && mail.getFrom().getRecipient() != null) {
if (identity.equalsByPersistableKey(mail.getFrom().getRecipient())) {
DBMailRecipient from = mail.getFrom();
from.setDeleted(Boolean.TRUE);
if (forceRemoveRecipient) {
from.setRecipient(null);
}
updates.add(from);
}
if (mail.getFrom().getDeleted() != null) {
delete &= mail.getFrom().getDeleted().booleanValue();
}
}
for (DBMailRecipient recipient : mail.getRecipients()) {
if (recipient == null)
continue;
if (recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
recipient.setDeleted(Boolean.TRUE);
if (forceRemoveRecipient) {
recipient.setRecipient(null);
}
updates.add(recipient);
}
if (recipient.getDeleted() != null) {
delete &= recipient.getDeleted().booleanValue();
}
}
if (delete) {
Set<String> paths = new HashSet<String>();
// all marked as deleted -> delete the mail
List<DBMailAttachment> attachments = getAttachments(mail);
for (DBMailAttachment attachment : attachments) {
// reload from the hibernate session
mail = attachment.getMail();
dbInstance.deleteObject(attachment);
if (StringHelper.containsNonWhitespace(attachment.getPath())) {
paths.add(attachment.getPath());
}
}
dbInstance.deleteObject(mail);
// try to remove orphans file
for (String path : paths) {
int count = countAttachment(path);
if (count == 0) {
VFSItem item = mailModule.getRootForAttachments().resolve(path);
if (item instanceof VFSLeaf) {
((VFSLeaf) item).delete();
}
}
}
} else {
for (DBMailRecipient update : updates) {
dbInstance.updateObject(update);
}
}
}
Aggregations