Java Code Examples for org.apache.jackrabbit.webdav.WebdavRequest#matchesIfHeader()

The following examples show how to use org.apache.jackrabbit.webdav.WebdavRequest#matchesIfHeader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected boolean isPreconditionValid(WebdavRequest request, DavResource resource) {
	if (resource.getDisplayName().toLowerCase().equals("thumbs.db"))
		return false;

	return !resource.exists() || request.matchesIfHeader(resource);
}
 
Example 2
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Validate the given destination resource and return the proper status
 * code: Any return value greater/equal than
 * {@link DavServletResponse#SC_NO_CONTENT} indicates an error.
 * 
 * @param destResource destination resource to be validated.
 * @param request the HTTP request
 * 
 * @return status code indicating whether the destination is valid.
 */
private int validateDestination(DavResource destResource, WebdavRequest request) throws DavException {

	String destHeader = request.getHeader(HEADER_DESTINATION);
	if (destHeader == null || "".equals(destHeader)) {
		return DavServletResponse.SC_BAD_REQUEST;
	}
	if (destResource.getLocator().equals(request.getRequestLocator())) {
		return DavServletResponse.SC_FORBIDDEN;
	}

	int status;
	if (destResource.exists()) {
		if (request.isOverwrite()) {
			// matching if-header required for existing resources
			if (!request.matchesIfHeader(destResource)) {
				return DavServletResponse.SC_PRECONDITION_FAILED;
			} else {
				// overwrite existing resource
				destResource.getCollection().removeMember(destResource);
				status = DavServletResponse.SC_NO_CONTENT;
			}
		} else {
			// cannot copy/move to an existing item, if overwrite is not
			// forced
			return DavServletResponse.SC_PRECONDITION_FAILED;
		}
	} else {
		// destination does not exist >> copy/move can be performed
		status = DavServletResponse.SC_CREATED;
	}
	return status;
}