use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSResourceRoot method delete.
@Override
public boolean delete(WebResource resource) {
boolean deleted = false;
if (resource instanceof VFSResource) {
VFSResource vfsResource = (VFSResource) resource;
VFSItem item = vfsResource.getItem();
if (item != null && VFSConstants.YES.equals(item.canDelete())) {
VFSStatus status = item.delete();
deleted = (status == VFSConstants.YES || status == VFSConstants.SUCCESS);
}
}
return deleted;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSResourceRoot method mkdir.
@Override
public boolean mkdir(String path) {
// remove trailing /
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
int lastSlash = path.lastIndexOf('/');
if (lastSlash == -1)
return false;
String parentPath = path.substring(0, lastSlash);
VFSItem parentItem = resolveFile(parentPath);
if (parentItem instanceof VFSLeaf) {
return false;
} else if (parentItem instanceof VFSContainer) {
String name = path.substring(lastSlash + 1);
VFSContainer folder = (VFSContainer) parentItem;
if (folder.canWrite() == VFSConstants.YES) {
VFSContainer dir = folder.createChildContainer(name);
return dir != null && dir.exists();
}
}
return false;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSResourceRoot method canWrite.
@Override
public boolean canWrite(String name) {
// resolve item if it already exists
VFSItem item = resolveFile(name);
if (item == null) {
// try to resolve parent in case the item does not yet exist
int lastSlash = name.lastIndexOf("/");
if (lastSlash > 0) {
String containerName = name.substring(0, lastSlash);
item = resolveFile(containerName);
}
}
if (item == null) {
return false;
}
VFSStatus status;
if (item instanceof VFSContainer) {
status = item.canWrite();
} else {
// read/write is not defined on item level, only on directory level
status = item.getParentContainer().canWrite();
}
return VFSConstants.YES.equals(status);
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSResourceRoot method write.
@Override
public boolean write(String path, InputStream is, boolean overwrite, WebResource movedFrom) throws QuotaExceededException {
VFSLeaf childLeaf;
VFSItem file = resolveFile(path);
if (file instanceof VFSLeaf) {
if (overwrite) {
// overwrite the file
childLeaf = (VFSLeaf) file;
// versioning
if (childLeaf instanceof Versionable && ((Versionable) childLeaf).getVersions().isVersioned()) {
if (childLeaf.getSize() == 0) {
VersionsManager.getInstance().createVersionsFor(childLeaf, true);
} else {
VersionsManager.getInstance().addToRevisions((Versionable) childLeaf, identity, "");
}
}
} else {
return false;
}
} else if (file instanceof VFSContainer) {
return false;
} else {
// create a new file
int lastSlash = path.lastIndexOf('/');
if (lastSlash == -1)
return false;
String parentPath = path.substring(0, lastSlash);
VFSItem parentItem = resolveFile(parentPath);
if (parentItem instanceof VFSContainer) {
VFSContainer folder = (VFSContainer) parentItem;
String name = path.substring(lastSlash + 1);
childLeaf = folder.createChildLeaf(name);
} else {
return false;
}
}
if (childLeaf == null) {
return false;
}
try {
copyVFS(childLeaf, is);
} catch (QuotaExceededException e) {
throw e;
} catch (Exception e) {
log.error("", e);
return false;
}
VFSContainer inheritingCont = VFSManager.findInheritingSecurityCallbackContainer(childLeaf.getParentContainer());
if (inheritingCont != null) {
VFSSecurityCallback callback = inheritingCont.getLocalSecurityCallback();
if (callback != null && callback.getSubscriptionContext() != null) {
SubscriptionContext subContext = callback.getSubscriptionContext();
NotificationsManager.getInstance().markPublisherNews(subContext, null, true);
}
}
if (childLeaf instanceof MetaTagged && identity != null) {
MetaInfo infos = ((MetaTagged) childLeaf).getMetaInfo();
if (infos != null && !infos.hasAuthorIdentity()) {
infos.setAuthor(identity);
addLicense(infos, identity);
infos.clearThumbnails();
// infos.write(); the clearThumbnails call write()
}
}
if (movedFrom instanceof VFSResource) {
VFSResource vfsResource = (VFSResource) movedFrom;
if (vfsResource.getItem() instanceof Versionable && ((Versionable) vfsResource.getItem()).getVersions().isVersioned()) {
VFSLeaf currentVersion = (VFSLeaf) vfsResource.getItem();
VersionsManager.getInstance().move(currentVersion, childLeaf, identity);
}
}
return true;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class WebdavStatus method deleteCollection.
/**
* Deletes a collection.
*
* @param path Path to the collection to be deleted
* @param errorList Contains the list of the errors which occurred
*/
private void deleteCollection(HttpServletRequest req, String path, Map<String, Integer> errorList) {
if (log.isDebug())
log.debug("Delete:" + path);
// Prevent deletion of special subdirectories
if (isSpecialPath(path)) {
errorList.put(path, new Integer(WebdavStatus.SC_FORBIDDEN));
return;
}
String ifHeader = req.getHeader("If");
if (ifHeader == null)
ifHeader = "";
String lockTokenHeader = req.getHeader("Lock-Token");
if (lockTokenHeader == null)
lockTokenHeader = "";
final WebResourceRoot resources = getResources(req);
Collection<VFSItem> entries = resources.list(path);
UserSession usess = webDAVManager.getUserSession(req);
for (VFSItem entry : entries) {
String childName = path;
if (!childName.equals("/")) {
childName += "/";
}
childName += entry.getName();
WebResource childResource = resources.getResource(childName);
if (lockManager.isLocked(childResource, ifHeader + lockTokenHeader, usess.getIdentity())) {
errorList.put(childName, new Integer(WebdavStatus.SC_LOCKED));
} else {
if (childResource.isDirectory()) {
deleteCollection(req, childName, errorList);
}
if (!resources.delete(childResource)) {
if (!childResource.isDirectory()) {
// If it's not a collection, then it's an unknown error
errorList.put(childName, new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
}
}
}
}
}
Aggregations