.getNamespaceConfig();
toLockSubject = getToLockSubject();
if (lockDate == null)
lockDate = new Date((new Date()).getTime()
+ ((long) lockDuration * 1000L));
NodeLock lockToken = new NodeLock(toLockSubject.getUri(),((SubjectNode)security.getPrincipal(slideToken)).getUri(),
namespaceConfig.getCreateObjectAction().getUri(), lockDate,
inheritance, NodeLock.LOCAL, lockInfo_lockOwner);
token.setTransactionTimeout(lockDuration * 1000);
Transaction transaction = token.getTransactionManager().suspend();
//String txId = lockToken.getLockId();
String fullTxId = "<" + S_LOCK_TOKEN + lockToken.getLockId() + ">";
ExternalTransactionContext.registerContext(fullTxId, transaction);
slideToken.setExternalTx();
resp.setHeader("Lock-Token", fullTxId);
showLockDiscoveryInfo(lockToken);
} catch (Exception e) {
int statusCode = getErrorCode(e);
sendError(statusCode, e);
throw new WebdavException(statusCode);
}
} else if (lockInfo_lockType.equals(E_WRITE)) {
try {
if (!checkIfHeaders()) {
return;
}
NamespaceConfig namespaceConfig = token
.getNamespaceConfig();
toLockSubject = getToLockSubject();
NodeLock lockToken = null;
inheritance = (depth != 0);
boolean exclusive = !(lockInfo_lockScope.equals(E_SHARED));
if (lockDate == null)
lockDate = new Date((new Date()).getTime()
+ ((long) lockDuration * 1000L));
lockToken = new NodeLock(toLockSubject,
(SubjectNode) security.getPrincipal(slideToken),
namespaceConfig.getCreateObjectAction(), lockDate,
inheritance, exclusive, lockInfo_lockOwner);
lock.lock(slideToken, lockToken);
// Set the lock-token header
// [RFC 2518, 9.5] " The Lock-Token response header is used
// with the LOCK method to indicate the lock token created
// as
// a result of a successful LOCK request to create a new
// lock."
resp.setHeader("Lock-Token", "<" + S_LOCK_TOKEN
+ lockToken.getLockId() + ">");
resp.setStatus(WebdavStatus.SC_OK);
// The lock token on which the DAV module will have the info
showLockDiscoveryInfo(lockToken);
} catch (ObjectIsAlreadyLockedException e) {
if (inheritance
&& generateMultiStatusResponse(isCollection, e,
requestUri)) {
// error is on the resource which we attempted to lock
String errorMessage = generateErrorMessage(e);
// Write it on the servlet writer
resp.setContentType(TEXT_XML_UTF_8);
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
try {
resp.getWriter().write(errorMessage);
} catch (IOException ex) {
// Critical error ... Servlet container is dead or
// something
int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
sendError(statusCode, e);
throw new WebdavException(statusCode);
}
} else {
// Returning 207 on non-collection requests is generally
// considered bad. So let's not do it, since this way
// makes clients generally behave better.
resp.setStatus(WebdavStatus.SC_LOCKED);
}
//
// make sure the transaction is aborted
// throw any WebDAV exception to indicate the transaction
// wants to be aborted
//
throw new WebdavException(WebdavStatus.SC_ACCEPTED, false);
} catch (Exception e) {
int statusCode = getErrorCode(e);
sendError(statusCode, e);
throw new WebdavException(statusCode);
}
}
break;
case LOCK_REFRESH:
try {
Enumeration lockTokens = lock.enumerateLocks(slideToken,
lockInfo_lockSubject, false);
NodeLock currentLockToken = null;
Date newExpirationDate = new Date((new Date()).getTime()
+ ((long) lockDuration * 1000L));
while (lockTokens.hasMoreElements()) {
currentLockToken = (NodeLock) lockTokens.nextElement();
lock.renew(slideToken, currentLockToken, newExpirationDate);