use of org.olat.core.util.vfs.lock.LockInfo in project openolat by klemens.
the class WebdavStatus method parseLockNullProperties.
/**
* Propfind helper method. Displays the properties of a lock-null resource.
*
* @param resources Resources object associated with this context
* @param generatedXML XML response to the Propfind request
* @param path Path of the current resource
* @param type Propfind type
* @param propertiesVector If the propfind type is find properties by
* name, then this Vector contains those properties
*/
private void parseLockNullProperties(HttpServletRequest req, XMLWriter generatedXML, final String path, int type, Vector<String> propertiesVector) {
// Exclude any resource in the /WEB-INF and /META-INF subdirectories
if (isSpecialPath(path))
return;
final WebResourceRoot resources = getResources(req);
final WebResource resource = resources.getResource(path);
// Retrieving the lock associated with the lock-null resource
LockInfo lock = lockManager.getResourceLock(resource);
if (lock == null)
return;
generatedXML.writeElement("D", "response", XMLWriter.OPENING);
String status = "HTTP/1.1 " + WebdavStatus.SC_OK + " " + WebdavStatus.getStatusText(WebdavStatus.SC_OK);
// Generating href element
generatedXML.writeElement("D", "href", XMLWriter.OPENING);
String absoluteUri = req.getRequestURI();
String relativePath = getRelativePath(req);
String toAppend = path.substring(relativePath.length());
if (!toAppend.startsWith("/"))
toAppend = "/" + toAppend;
String normalizedUrl = RequestUtil.normalize(absoluteUri + toAppend);
String nfcNormalizedUrl = Normalizer.normalize(normalizedUrl, Normalizer.Form.NFC);
generatedXML.writeText(rewriteUrl(nfcNormalizedUrl));
generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
String resourceName = Normalizer.normalize(path, Normalizer.Form.NFC);
int lastSlash = path.lastIndexOf('/');
if (lastSlash != -1) {
resourceName = resourceName.substring(lastSlash + 1);
}
switch(type) {
case FIND_ALL_PROP:
generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
generatedXML.writeProperty("D", "creationdate", getISOCreationDate(lock.getCreationDate().getTime()));
generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
generatedXML.writeData(resourceName);
generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
generatedXML.writeProperty("D", "getlastmodified", FastHttpDateFormat.formatDate(lock.getCreationDate().getTime(), null));
generatedXML.writeProperty("D", "getcontentlength", String.valueOf(0));
generatedXML.writeProperty("D", "getcontenttype", "");
generatedXML.writeProperty("D", "getetag", "");
generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
generatedXML.writeElement("D", "lock-null", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "resourcetype", XMLWriter.CLOSING);
generatedXML.writeProperty("D", "source", "");
String supportedLocks = "<D:lockentry>" + "<D:lockscope><D:exclusive/></D:lockscope>" + "<D:locktype><D:write/></D:locktype>" + "</D:lockentry>" + "<D:lockentry>" + "<D:lockscope><D:shared/></D:lockscope>" + "<D:locktype><D:write/></D:locktype>" + "</D:lockentry>";
generatedXML.writeElement("D", "supportedlock", XMLWriter.OPENING);
generatedXML.writeText(supportedLocks);
generatedXML.writeElement("D", "supportedlock", XMLWriter.CLOSING);
generateLockDiscovery(resource, path, generatedXML);
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
break;
case FIND_PROPERTY_NAMES:
generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
generatedXML.writeElement("D", "creationdate", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "displayname", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getcontentlanguage", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getcontentlength", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getcontenttype", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getetag", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getlastmodified", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "resourcetype", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "source", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
break;
case FIND_BY_PROPERTY:
Vector<String> propertiesNotFound = new Vector<>();
// Parse the list of properties
generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
Enumeration<String> properties = propertiesVector.elements();
while (properties.hasMoreElements()) {
String property = properties.nextElement();
if (property.equals("creationdate")) {
generatedXML.writeProperty("D", "creationdate", getISOCreationDate(lock.getCreationDate().getTime()));
} else if (property.equals("displayname")) {
generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
generatedXML.writeData(resourceName);
generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
} else if (property.equals("getcontentlanguage")) {
generatedXML.writeElement("D", "getcontentlanguage", XMLWriter.NO_CONTENT);
} else if (property.equals("getcontentlength")) {
generatedXML.writeProperty("D", "getcontentlength", (String.valueOf(0)));
} else if (property.equals("getcontenttype")) {
generatedXML.writeProperty("D", "getcontenttype", "");
} else if (property.equals("getetag")) {
generatedXML.writeProperty("D", "getetag", "");
} else if (property.equals("getlastmodified")) {
generatedXML.writeProperty("D", "getlastmodified", FastHttpDateFormat.formatDate(lock.getCreationDate().getTime(), null));
} else if (property.equals("resourcetype")) {
generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
generatedXML.writeElement("D", "lock-null", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "resourcetype", XMLWriter.CLOSING);
} else if (property.equals("source")) {
generatedXML.writeProperty("D", "source", "");
} else if (property.equals("supportedlock")) {
supportedLocks = "<D:lockentry>" + "<D:lockscope><D:exclusive/></D:lockscope>" + "<D:locktype><D:write/></D:locktype>" + "</D:lockentry>" + "<D:lockentry>" + "<D:lockscope><D:shared/></D:lockscope>" + "<D:locktype><D:write/></D:locktype>" + "</D:lockentry>";
generatedXML.writeElement("D", "supportedlock", XMLWriter.OPENING);
generatedXML.writeText(supportedLocks);
generatedXML.writeElement("D", "supportedlock", XMLWriter.CLOSING);
} else if (property.equals("lockdiscovery")) {
if (!generateLockDiscovery(resource, path, generatedXML))
propertiesNotFound.addElement(property);
} else {
propertiesNotFound.addElement(property);
}
}
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
Enumeration<String> propertiesNotFoundList = propertiesNotFound.elements();
if (propertiesNotFoundList.hasMoreElements()) {
status = "HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND + " " + WebdavStatus.getStatusText(WebdavStatus.SC_NOT_FOUND);
generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
while (propertiesNotFoundList.hasMoreElements()) {
generatedXML.writeElement("D", propertiesNotFoundList.nextElement(), XMLWriter.NO_CONTENT);
}
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
}
break;
}
generatedXML.writeElement("D", "response", XMLWriter.CLOSING);
}
use of org.olat.core.util.vfs.lock.LockInfo in project openolat by klemens.
the class WebdavStatus method doLock.
/**
* LOCK Method.
*/
public void doLock(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (isLocked(req)) {
resp.sendError(WebdavStatus.SC_LOCKED);
return;
}
final String path = getRelativePath(req);
final WebResourceRoot resources = getResources(req);
if (!resources.canWrite(path)) {
resp.sendError(WebdavStatus.SC_FORBIDDEN);
return;
}
UserSession usess = webDAVManager.getUserSession(req);
LockInfo lock = new LockInfo(usess.getIdentity().getKey(), true, false);
// Parsing lock request
// Parsing depth header
String depthStr = req.getHeader("Depth");
if (depthStr == null) {
lock.setDepth(maxDepth);
} else {
if (depthStr.equals("0")) {
lock.setDepth(0);
} else {
lock.setDepth(maxDepth);
}
}
if (log.isDebug()) {
log.debug("Lock the ressource: " + path + " with depth:" + lock.getDepth());
}
// Parsing timeout header
int lockDuration = DEFAULT_TIMEOUT;
String lockDurationStr = req.getHeader("Timeout");
if (lockDurationStr == null) {
lockDuration = DEFAULT_TIMEOUT;
} else {
int commaPos = lockDurationStr.indexOf(",");
// If multiple timeouts, just use the first
if (commaPos != -1) {
lockDurationStr = lockDurationStr.substring(0, commaPos);
}
if (lockDurationStr.startsWith("Second-")) {
lockDuration = (new Integer(lockDurationStr.substring(7))).intValue();
} else {
if (lockDurationStr.equalsIgnoreCase("infinity")) {
lockDuration = MAX_TIMEOUT;
} else {
try {
lockDuration = (new Integer(lockDurationStr)).intValue();
} catch (NumberFormatException e) {
lockDuration = MAX_TIMEOUT;
}
}
}
if (lockDuration == 0) {
lockDuration = DEFAULT_TIMEOUT;
}
if (lockDuration > MAX_TIMEOUT) {
lockDuration = MAX_TIMEOUT;
}
}
lock.setExpiresAt(System.currentTimeMillis() + (lockDuration * 1000));
int lockRequestType = LOCK_CREATION;
Node lockInfoNode = null;
DocumentBuilder documentBuilder = getDocumentBuilder(req);
try {
Document document = documentBuilder.parse(new InputSource(req.getInputStream()));
// Get the root element of the document
Element rootElement = document.getDocumentElement();
lockInfoNode = rootElement;
} catch (IOException e) {
lockRequestType = LOCK_REFRESH;
} catch (SAXException e) {
lockRequestType = LOCK_REFRESH;
}
if (lockInfoNode != null) {
// Reading lock information
NodeList childList = lockInfoNode.getChildNodes();
StringWriter strWriter = null;
DOMWriter domWriter = null;
Node lockScopeNode = null;
Node lockTypeNode = null;
Node lockOwnerNode = null;
for (int i = 0; i < childList.getLength(); i++) {
Node currentNode = childList.item(i);
switch(currentNode.getNodeType()) {
case Node.TEXT_NODE:
break;
case Node.ELEMENT_NODE:
String nodeName = currentNode.getNodeName();
if (nodeName.endsWith("lockscope")) {
lockScopeNode = currentNode;
}
if (nodeName.endsWith("locktype")) {
lockTypeNode = currentNode;
}
if (nodeName.endsWith("owner")) {
lockOwnerNode = currentNode;
}
break;
}
}
if (lockScopeNode != null) {
childList = lockScopeNode.getChildNodes();
for (int i = 0; i < childList.getLength(); i++) {
Node currentNode = childList.item(i);
switch(currentNode.getNodeType()) {
case Node.TEXT_NODE:
break;
case Node.ELEMENT_NODE:
String tempScope = currentNode.getNodeName();
if (tempScope.indexOf(':') != -1) {
lock.setScope(tempScope.substring(tempScope.indexOf(':') + 1));
} else {
lock.setScope(tempScope);
}
break;
}
}
if (lock.getScope() == null) {
// Bad request
resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
}
} else {
// Bad request
resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
}
if (lockTypeNode != null) {
childList = lockTypeNode.getChildNodes();
for (int i = 0; i < childList.getLength(); i++) {
Node currentNode = childList.item(i);
switch(currentNode.getNodeType()) {
case Node.TEXT_NODE:
break;
case Node.ELEMENT_NODE:
String tempType = currentNode.getNodeName();
if (tempType.indexOf(':') != -1) {
lock.setType(tempType.substring(tempType.indexOf(':') + 1));
} else {
lock.setType(tempType);
}
break;
}
}
if (lock.getType() == null) {
// Bad request
resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
}
} else {
// Bad request
resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
}
if (lockOwnerNode != null) {
childList = lockOwnerNode.getChildNodes();
for (int i = 0; i < childList.getLength(); i++) {
Node currentNode = childList.item(i);
switch(currentNode.getNodeType()) {
case Node.TEXT_NODE:
lock.setOwner(lock.getOwner() + currentNode.getNodeValue());
break;
case Node.ELEMENT_NODE:
strWriter = new StringWriter();
domWriter = new DOMWriter(strWriter, true);
domWriter.print(currentNode);
lock.setOwner(lock.getOwner() + strWriter.toString());
break;
}
}
if (lock.getOwner() == null) {
// Bad request
resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
}
} else {
lock.setOwner("");
}
}
final WebResource resource = resources.getResource(path);
lock.setWebResource(resource);
Iterator<LockInfo> locksList = null;
if (lockRequestType == LOCK_CREATION) {
// Generating lock id
String lockToken = lockManager.generateLockToken(lock, usess.getIdentity().getKey());
if (resource.isDirectory() && lock.getDepth() == maxDepth) {
// Locking a collection (and all its member resources)
// Checking if a child resource of this collection is
// already locked
Vector<String> lockPaths = new Vector<String>();
locksList = lockManager.getCollectionLocks();
while (locksList.hasNext()) {
LockInfo currentLock = locksList.next();
if (currentLock.hasExpired()) {
WebResource currentLockedResource = resources.getResource(currentLock.getWebPath());
lockManager.removeResourceLock(currentLockedResource);
continue;
}
if ((currentLock.getWebPath().startsWith(lock.getWebPath())) && ((currentLock.isExclusive()) || (lock.isExclusive()))) {
// A child collection of this collection is locked
lockPaths.addElement(currentLock.getWebPath());
}
}
locksList = lockManager.getResourceLocks();
while (locksList.hasNext()) {
LockInfo currentLock = locksList.next();
if (currentLock.hasExpired()) {
WebResource currentLockedResource = resources.getResource(currentLock.getWebPath());
lockManager.removeResourceLock(currentLockedResource);
continue;
}
if ((currentLock.getWebPath().startsWith(lock.getWebPath())) && ((currentLock.isExclusive()) || (lock.isExclusive()))) {
// A child resource of this collection is locked
lockPaths.addElement(currentLock.getWebPath());
}
}
if (!lockPaths.isEmpty()) {
// One of the child paths was locked
// We generate a multistatus error report
Enumeration<String> lockPathsList = lockPaths.elements();
resp.setStatus(WebdavStatus.SC_CONFLICT);
XMLWriter generatedXML = new XMLWriter();
generatedXML.writeXMLHeader();
generatedXML.writeElement("D", DEFAULT_NAMESPACE, "multistatus", XMLWriter.OPENING);
while (lockPathsList.hasMoreElements()) {
generatedXML.writeElement("D", "response", XMLWriter.OPENING);
generatedXML.writeElement("D", "href", XMLWriter.OPENING);
generatedXML.writeText(lockPathsList.nextElement());
generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText("HTTP/1.1 " + WebdavStatus.SC_LOCKED + " " + WebdavStatus.getStatusText(WebdavStatus.SC_LOCKED));
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "response", XMLWriter.CLOSING);
}
generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);
Writer writer = resp.getWriter();
writer.write(generatedXML.toString());
writer.close();
return;
}
boolean addLock = true;
// Checking if there is already a shared lock on this path
locksList = lockManager.getCollectionLocks();
while (locksList.hasNext()) {
LockInfo currentLock = locksList.next();
if (currentLock.getWebPath().equals(lock.getWebPath())) {
if (currentLock.isExclusive()) {
resp.sendError(WebdavStatus.SC_LOCKED);
return;
} else {
if (lock.isExclusive()) {
resp.sendError(WebdavStatus.SC_LOCKED);
return;
}
}
currentLock.addToken(lockToken);
lock = currentLock;
addLock = false;
}
}
if (addLock) {
lock.addToken(lockToken);
lockManager.addCollectionLock(lock);
}
} else {
// Locking a single resource
// Retrieving an already existing lock on that resource
WebResource lockedResource = resources.getResource(lock.getWebPath());
LockInfo presentLock = lockManager.getResourceLock(lockedResource);
if (presentLock != null) {
if ((presentLock.isExclusive()) || (lock.isExclusive())) {
// If either lock is exclusive, the lock can't be
// granted
resp.sendError(WebdavStatus.SC_PRECONDITION_FAILED);
return;
} else {
presentLock.setWebDAVLock(true);
presentLock.addToken(lockToken);
lock = presentLock;
}
} else {
lock.addToken(lockToken);
lockManager.putResourceLock(lockedResource, lock);
// Checking if a resource exists at this path
if (!resource.exists()) {
// "Creating" a lock-null resource
int slash = lock.getWebPath().lastIndexOf('/');
String parentPath = lock.getWebPath().substring(0, slash);
WebResource parentResource = resources.getResource(parentPath);
Vector<String> lockNulls = lockManager.getLockNullResource(parentResource);
if (lockNulls == null) {
lockNulls = new Vector<String>();
lockManager.putLockNullResource(parentPath, lockNulls);
}
lockNulls.addElement(lock.getWebPath());
}
// Add the Lock-Token header as by RFC 2518 8.10.1
// - only do this for newly created locks
resp.addHeader("Lock-Token", "<opaquelocktoken:" + lockToken + ">");
}
}
}
if (lockRequestType == LOCK_REFRESH) {
String ifHeader = req.getHeader("If");
if (ifHeader == null)
ifHeader = "";
// Checking resource locks
LockInfo toRenew = lockManager.getResourceLock(resource);
if (toRenew != null) {
// At least one of the tokens of the locks must have been given
Iterator<String> tokenList = toRenew.tokens();
while (tokenList.hasNext()) {
String token = tokenList.next();
if (ifHeader.indexOf(token) != -1) {
toRenew.setExpiresAt(lock.getExpiresAt());
toRenew.setWebDAVLock(true);
lock = toRenew;
}
}
}
// Checking inheritable collection locks
Iterator<LockInfo> collectionLocksList = lockManager.getCollectionLocks();
while (collectionLocksList.hasNext()) {
toRenew = collectionLocksList.next();
if (path.equals(toRenew.getWebPath())) {
Iterator<String> tokenList = toRenew.tokens();
while (tokenList.hasNext()) {
String token = tokenList.next();
if (ifHeader.indexOf(token) != -1) {
toRenew.setExpiresAt(lock.getExpiresAt());
lock = toRenew;
}
}
}
}
}
// Set the status, then generate the XML response containing
// the lock information
XMLWriter generatedXML = new XMLWriter();
generatedXML.writeXMLHeader();
generatedXML.writeElement("D", DEFAULT_NAMESPACE, "prop", XMLWriter.OPENING);
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
lock.toXML(generatedXML);
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.CLOSING);
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
resp.setStatus(WebdavStatus.SC_OK);
resp.setContentType("text/xml; charset=UTF-8");
Writer writer = resp.getWriter();
writer.write(generatedXML.toString());
writer.close();
}
use of org.olat.core.util.vfs.lock.LockInfo in project OpenOLAT by OpenOLAT.
the class WebDAVCommandsTest method testLock_guilike_lockedWithWebdAV.
/**
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void testLock_guilike_lockedWithWebdAV() throws IOException, URISyntaxException {
// create a user
Identity user = JunitTestHelper.createAndPersistIdentityAsAuthor("webdav-2c-" + UUID.randomUUID().toString());
// create a file
String publicPath = FolderConfig.getUserHomes() + "/" + user.getName() + "/public";
VFSContainer vfsPublic = new OlatRootFolderImpl(publicPath, null);
VFSItem item = createFile(vfsPublic, "test.txt");
// lock the item with WebDAV
WebDAVConnection conn = new WebDAVConnection();
conn.setCredentials(user.getName(), "A6B7C8");
// author check file
URI textUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test.txt").build();
String textPropfind = conn.propfind(textUri, 0);
log.info(textPropfind);
// author lock the file
String lockToken = conn.lock(textUri, UUID.randomUUID().toString());
Assert.assertNotNull(lockToken);
// check vfs lock
Roles adminRoles = new Roles(true, false, false, false, false, false, false);
boolean lockedForMe = lockManager.isLockedForMe(item, user, adminRoles);
Assert.assertTrue(lockedForMe);
LockInfo lock = lockManager.getLock(item);
Assert.assertNotNull(lock);
Assert.assertNotNull(lock.getScope());
Assert.assertNotNull(lock.getType());
Assert.assertNotNull(lock.getOwner());
Assert.assertTrue(lock.getOwner().length() > 0);
Assert.assertFalse(lock.isVfsLock());
Assert.assertTrue(lock.isWebDAVLock());
Assert.assertEquals(user.getKey(), lock.getLockedBy());
Assert.assertEquals(1, lock.getTokensSize());
// try to unlock which should not be possible
boolean unlocked = lockManager.unlock(item, user, adminRoles);
Assert.assertFalse(unlocked);
// check that nothing changed
LockInfo lockAfterUnlock = lockManager.getLock(item);
Assert.assertNotNull(lockAfterUnlock);
Assert.assertNotNull(lockAfterUnlock.getScope());
Assert.assertNotNull(lockAfterUnlock.getType());
Assert.assertNotNull(lockAfterUnlock.getOwner());
Assert.assertTrue(lockAfterUnlock.getOwner().length() > 0);
Assert.assertFalse(lockAfterUnlock.isVfsLock());
Assert.assertTrue(lockAfterUnlock.isWebDAVLock());
Assert.assertEquals(user.getKey(), lockAfterUnlock.getLockedBy());
Assert.assertEquals(1, lock.getTokensSize());
IOUtils.closeQuietly(conn);
}
use of org.olat.core.util.vfs.lock.LockInfo in project OpenOLAT by OpenOLAT.
the class WebdavStatus method doUnlock.
/**
* UNLOCK Method.
*/
protected void doUnlock(HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (isLocked(req)) {
resp.sendError(WebdavStatus.SC_LOCKED);
return;
}
final String path = getRelativePath(req);
final WebResourceRoot resources = getResources(req);
final WebResource resource = resources.getResource(path);
String lockTokenHeader = req.getHeader("Lock-Token");
if (lockTokenHeader == null) {
lockTokenHeader = "";
} else if (lockTokenHeader != null && lockTokenHeader.startsWith("<opaquelocktoken") && !lockTokenHeader.endsWith(">")) {
lockTokenHeader += ">";
}
// Checking resource locks
if (log.isDebug()) {
log.debug("Unlock the ressource: " + path);
}
LockInfo lock = lockManager.getResourceLock(resource);
if (lock != null) {
// At least one of the tokens of the locks must have been given
Iterator<String> tokenList = lock.tokens();
while (tokenList.hasNext()) {
String token = tokenList.next();
if (lockTokenHeader.indexOf(token) != -1) {
lock.removeToken(token);
}
}
if (lock.getTokensSize() == 0) {
lockManager.removeResourceLock(resource);
// Removing any lock-null resource which would be present
lockManager.removeLockNullResource(resource);
}
}
// Checking inheritable collection locks
Iterator<LockInfo> collectionLocksList = lockManager.getCollectionLocks();
while (collectionLocksList.hasNext()) {
lock = collectionLocksList.next();
if (path.equals(lock.getWebPath())) {
Iterator<String> tokenList = lock.tokens();
while (tokenList.hasNext()) {
String token = tokenList.next();
if (lockTokenHeader.indexOf(token) != -1) {
lock.removeToken(token);
break;
}
}
if (lock.getTokensSize() == 0) {
lockManager.removeCollectionLock(lock);
// Removing any lock-null resource which would be present
lockManager.removeLockNullResource(resource);
}
}
}
resp.setStatus(WebdavStatus.SC_NO_CONTENT);
}
use of org.olat.core.util.vfs.lock.LockInfo in project OpenOLAT by OpenOLAT.
the class WebdavStatus method generateLockDiscovery.
/**
* Print the lock discovery information associated with a path.
*
* @param path Path
* @param generatedXML XML data to which the locks info will be appended
* @return true if at least one lock was displayed
*/
private boolean generateLockDiscovery(final WebResource resource, final String path, XMLWriter generatedXML) {
LockInfo resourceLock = lockManager.getResourceLock(resource);
Iterator<LockInfo> collectionLocksList = lockManager.getCollectionLocks();
boolean wroteStart = false;
if (resourceLock != null) {
wroteStart = true;
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
resourceLock.toXML(generatedXML);
} else {
LockInfo ooLock = lockManager.getVFSLock(resource);
if (ooLock != null) {
wroteStart = true;
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
ooLock.toXML(generatedXML);
}
}
while (collectionLocksList.hasNext()) {
LockInfo currentLock = collectionLocksList.next();
if (path.startsWith(currentLock.getWebPath())) {
if (!wroteStart) {
wroteStart = true;
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
}
currentLock.toXML(generatedXML);
}
}
if (wroteStart) {
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.CLOSING);
} else {
return false;
}
return true;
}
Aggregations