示例#1
0
  public DAVLock getLock(DAVResource resource) throws DAVException {
    if (resource.getResourceURI().getPath() == null) {
      return null;
    }

    if (DAVHandlerFactory.METHOD_LOCK.equals(myOwner.getRequestMethod())) {
      return null;
    }

    // TODO: add authz check here later

    DAVLock davLock = null;
    FSLock lock = null;
    try {
      lock = (FSLock) resource.getLock();
    } catch (SVNException svne) {
      throw DAVException.convertError(
          svne.getErrorMessage(),
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Failed to check path for a lock.",
          null);
    }

    if (lock != null) {
      davLock = convertSVNLockToDAVLock(lock, myIsBreakLock, resource.exists());
      myOwner.setResponseHeader(
          HTTPHeader.CREATION_DATE_HEADER, SVNDate.formatDate(lock.getCreationDate()));
      myOwner.setResponseHeader(HTTPHeader.LOCK_OWNER_HEADER, lock.getOwner());
    }
    return davLock;
  }
示例#2
0
  public DAVLock findLock(DAVResource resource, String lockToken) throws DAVException {
    // TODO: add here authz check later

    DAVLock davLock = null;
    FSLock lock = null;
    try {
      lock = (FSLock) resource.getLock();
    } catch (SVNException svne) {
      throw DAVException.convertError(
          svne.getErrorMessage(),
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Failed to look up lock by path.",
          null);
    }

    if (lock != null) {
      if (!lockToken.equals(lock.getID())) {
        throw new DAVException(
            "Incoming token doesn't match existing lock.",
            HttpServletResponse.SC_BAD_REQUEST,
            DAVErrorCode.LOCK_SAVE_LOCK);
      }
      davLock = convertSVNLockToDAVLock(lock, false, resource.exists());
      myOwner.setResponseHeader(
          HTTPHeader.CREATION_DATE_HEADER, SVNDate.formatDate(lock.getCreationDate()));
      myOwner.setResponseHeader(HTTPHeader.LOCK_OWNER_HEADER, lock.getOwner());
    }
    return davLock;
  }
示例#3
0
  public void removeLock(DAVResource resource, String lockToken) throws DAVException {
    DAVResourceURI resourceURI = resource.getResourceURI();
    if (resourceURI.getPath() == null) {
      return;
    }

    if (isKeepLocks()) {
      return;
    }

    // TODO: add here authz check later
    String token = null;
    SVNLock lock = null;
    if (lockToken == null) {
      try {
        lock = resource.getLock();
      } catch (SVNException svne) {
        throw DAVException.convertError(
            svne.getErrorMessage(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Failed to check path for a lock.",
            null);
      }
      if (lock != null) {
        token = lock.getID();
      }
    } else {
      token = lockToken;
    }

    if (token != null) {
      try {
        resource.unlock(token, isBreakLock());
      } catch (SVNException svne) {
        if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.FS_NO_USER) {
          throw new DAVException(
              "Anonymous lock removal is not allowed.",
              HttpServletResponse.SC_UNAUTHORIZED,
              DAVErrorCode.LOCK_SAVE_LOCK);
        }
        throw DAVException.convertError(
            svne.getErrorMessage(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Failed to remove a lock.",
            null);
      }
      // TODO: add logging here
    }
  }
示例#4
0
  public boolean hasLocks(DAVResource resource) throws DAVException {
    if (resource.getResourceURI().getPath() == null) {
      return false;
    }

    if (DAVHandlerFactory.METHOD_LOCK.equals(myOwner.getRequestMethod())) {
      return false;
    }

    // TODO: add authz check here later
    SVNLock lock = null;
    try {
      lock = resource.getLock();
    } catch (SVNException svne) {
      throw DAVException.convertError(
          svne.getErrorMessage(),
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Failed to check path for a lock.",
          null);
    }
    return lock != null;
  }