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 FSLock convertDAVLockToSVNLock( DAVLock davLock, String path, boolean isSVNClient, SAXParserFactory saxParserFactory) throws DAVException { if (davLock.getType() != DAVLockType.WRITE) { throw new DAVException( "Only 'write' locks are supported.", HttpServletResponse.SC_BAD_REQUEST, DAVErrorCode.LOCK_SAVE_LOCK); } if (davLock.getScope() != DAVLockScope.EXCLUSIVE) { throw new DAVException( "Only exclusive locks are supported.", HttpServletResponse.SC_BAD_REQUEST, DAVErrorCode.LOCK_SAVE_LOCK); } boolean isDAVComment = false; String comment = null; if (davLock.getOwner() != null) { if (isSVNClient) { try { SAXParser xmlParser = saxParserFactory.newSAXParser(); XMLReader reader = xmlParser.getXMLReader(); FetchXMLHandler handler = new FetchXMLHandler(DAVElement.LOCK_OWNER); reader.setContentHandler(handler); reader.setDTDHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); String owner = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + davLock.getOwner(); reader.parse(new InputSource(new ByteArrayInputStream(owner.getBytes()))); comment = handler.getData(); } catch (ParserConfigurationException e) { throw new DAVException( e.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DAVErrorCode.LOCK_SAVE_LOCK); } catch (SAXException e) { throw new DAVException( e.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DAVErrorCode.LOCK_SAVE_LOCK); } catch (IOException e) { throw new DAVException( e.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DAVErrorCode.LOCK_SAVE_LOCK); } } else { isDAVComment = true; comment = davLock.getOwner(); } } return new FSLock( path, davLock.getLockToken(), davLock.getAuthUser(), comment, new Date(System.currentTimeMillis()), davLock.getTimeOutDate(), isDAVComment); }
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(); }