public void addLock(DAVLock lock, DAVResource resource) throws DAVException { DAVDepth depth = lock.getDepth(); if (!resource.isCollection()) { depth = DAVDepth.DEPTH_ZERO; } appendLock(resource, lock); if (depth != DAVDepth.DEPTH_ZERO) { DAVResourceWalker walker = new DAVResourceWalker(); DAVLockWalker lockHandler = new DAVLockWalker(resource, lock); DAVResponse response = walker.walk( this, resource, null, 0, null, DAVResourceWalker.DAV_WALKTYPE_NORMAL | DAVResourceWalker.DAV_WALKTYPE_AUTH, lockHandler, DAVDepth.DEPTH_INFINITY); if (response != null) { throw new DAVException( "Error(s) occurred on resources during the addition of a depth lock.", ServletDAVHandler.SC_MULTISTATUS, 0, response); } } }
public static String getActiveLockXML(DAVLock lock) { StringBuffer buffer = new StringBuffer(); if (lock == null) { return ""; } if (lock.getRecType() == DAVLockRecType.INDIRECT_PARTIAL) { // TODO: add debugging message here? } SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.ACTIVE_LOCK.getName(), SVNXMLUtil.XML_STYLE_NORMAL, null, buffer); SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_TYPE.getName(), SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer); if (lock.getType() == DAVLockType.WRITE) { SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.WRITE.getName(), SVNXMLUtil.XML_STYLE_SELF_CLOSING | SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer); } else { // TODO: internal error. log something? } SVNXMLUtil.closeXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_TYPE.getName(), buffer); SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_SCOPE.getName(), SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer); if (lock.getScope() == DAVLockScope.EXCLUSIVE) { SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.EXCLUSIVE.getName(), SVNXMLUtil.XML_STYLE_SELF_CLOSING | SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer); } else if (lock.getScope() == DAVLockScope.SHARED) { SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.SHARED.getName(), SVNXMLUtil.XML_STYLE_SELF_CLOSING | SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer); } else { // TODO: internal error. log something? } SVNXMLUtil.closeXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_SCOPE.getName(), buffer); SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.DEPTH.getName(), SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer); buffer.append( lock.getDepth() == DAVDepth.DEPTH_INFINITY ? DAVDepth.DEPTH_INFINITY.toString() : DAVDepth.DEPTH_ZERO.toString()); SVNXMLUtil.closeXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.DEPTH.getName(), buffer); if (lock.getOwner() != null) { buffer.append(lock.getOwner()); } SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_TIMEOUT.getName(), SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer); if (lock.getTimeOutDate() == null) { buffer.append("Infinite"); } else { Date timeOutDate = lock.getTimeOutDate(); long now = System.currentTimeMillis(); long diff = timeOutDate.getTime() - now; buffer.append("Second-"); // TODO: I'm not sure if I clearly understand what we must send here, // have to test and review this later buffer.append(diff); } SVNXMLUtil.closeXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_TIMEOUT.getName(), buffer); SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_TOKEN.getName(), SVNXMLUtil.XML_STYLE_NORMAL, null, buffer); SVNXMLUtil.openXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.HREF.getName(), SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer); buffer.append(lock.getLockToken()); SVNXMLUtil.closeXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.HREF.getName(), buffer); SVNXMLUtil.closeXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_TOKEN.getName(), buffer); SVNXMLUtil.closeXMLTag( SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.ACTIVE_LOCK.getName(), buffer); return buffer.toString(); }