Java Code Examples for org.apache.jackrabbit.webdav.DavServletResponse#SC_NO_CONTENT

The following examples show how to use org.apache.jackrabbit.webdav.DavServletResponse#SC_NO_CONTENT . 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: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The COPY method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doCopy(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doCopy");
	// only depth 0 and infinity is allowed
	int depth = request.getDepth(DEPTH_INFINITY);
	if (!(depth == DEPTH_0 || depth == DEPTH_INFINITY)) {
		response.sendError(DavServletResponse.SC_BAD_REQUEST);
		return;
	}

	DavResource destResource = null;
	try {
		destResource = getResourceFactory().createResource(request.getDestinationLocator(), request);
	} catch (Throwable e) {
		destResource = resource.getCollection();
	}
	int status = validateDestination(destResource, request);
	if (status > DavServletResponse.SC_NO_CONTENT) {
		response.sendError(status);
		return;
	}

	resource.copy(destResource, depth == DEPTH_0);
	response.setStatus(status);
}
 
Example 2
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The PUT method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doPut(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("************doPut*****************");
	if (log.isDebugEnabled())
		log.debug("[ADD] Document {}", resource.getDisplayName());

	try {
		DavResource parentResource = resource.getCollection();
		if (parentResource == null || !parentResource.exists()) {
			// parent does not exist
			response.sendError(DavServletResponse.SC_CONFLICT);
			return;
		}

		int status;
		// test if resource already exists
		if (resource.exists()) {
			status = DavServletResponse.SC_NO_CONTENT;
		} else {
			status = DavServletResponse.SC_CREATED;
		}

		parentResource.addMember(resource, getInputContext(request, request.getInputStream()));

		getResourceFactory().putInCache((com.logicaldoc.webdav.session.DavSession) parentResource.getSession(),
				parentResource);

		response.setStatus(status);
	} catch (Exception e) {
	}
}
 
Example 3
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;
}