Java Code Examples for org.apache.jackrabbit.webdav.DavResource#exists()

The following examples show how to use org.apache.jackrabbit.webdav.DavResource#exists() . 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: DavResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see DavResource#removeMember(DavResource)
 */
public void removeMember(DavResource member) throws DavException {
	if (!exists() || !member.exists()) {
		throw new DavException(DavServletResponse.SC_NOT_FOUND);
	}
	if (isLocked(this) || isLocked(member)) {
		throw new DavException(DavServletResponse.SC_LOCKED);
	}

	try {
		Resource resource = resourceService.getResource(member.getLocator().getResourcePath(), session);
		// set the requesting person
		resource.setRequestedPerson(this.resource.getRequestedPerson());

		resourceService.deleteResource(resource, session);
	} catch (DavException de) {
		throw de;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 2
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 3
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * @param sendContent
 * 
 * @throws IOException generic I/O error
 */
private void spoolResource(WebdavRequest request, WebdavResponse response, DavResource resource,
		boolean sendContent) throws IOException {

	if (!resource.exists()) {
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return;
	}

	long modSince = request.getDateHeader("If-Modified-Since");
	if (modSince > UNDEFINED_TIME) {
		long modTime = resource.getModificationTime();
		// test if resource has been modified. note that formatted
		// modification
		// time lost the milli-second precision
		if (modTime != UNDEFINED_TIME && (modTime / 1000 * 1000) <= modSince) {
			// resource has not been modified since the time indicated in
			// the
			// 'If-Modified-Since' header.
			response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
			return;
		}
	}

	// spool resource properties and ev. resource content.
	OutputStream out = (sendContent) ? response.getOutputStream() : null;
	resource.spool(getOutputContext(response, out));
}
 
Example 4
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 5
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The MKCOL 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 doMkCol(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {

	log.debug("doMkCol");
	if (log.isDebugEnabled())
		log.debug("[ADD] Directory {}", resource.getDisplayName());
	try {
		DavResource parentResource = resource.getCollection();
		if (parentResource == null || !parentResource.exists() || !parentResource.isCollection()) {
			// parent does not exist or is not a collection
			response.sendError(DavServletResponse.SC_CONFLICT);
			return;
		}
		// shortcut: mkcol is only allowed on deleted/non-existing resources
		if (resource.exists()) {
			response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		}

		if (request.getContentLength() > 0 || request.getHeader("Transfer-Encoding") != null) {
			parentResource.addMember(resource, getInputContext(request, request.getInputStream()));
		} else {
			parentResource.addMember(resource, getInputContext(request, null));
		}
		response.setStatus(DavServletResponse.SC_CREATED);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 6
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;
}
 
Example 7
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * The PROPFIND method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 */
protected void doPropFind(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {

	log.debug("doPropFind");
	if (log.isDebugEnabled())
		log.debug("[READ] FINDING {} {}",
				(resource.isCollection() ? "DOCUMENTS WITHIN THE FOLDER" : "JUST THE DOCUMENT"),
				resource.getDisplayName());

	if (!resource.exists()) {
		log.warn("Resource not found: {}", resource.getResourcePath());
		response.sendError(DavServletResponse.SC_NOT_FOUND);
		return;
	}

	DavPropertyNameSet requestProperties = request.getPropFindProperties();

	if (log.isDebugEnabled()) {
		DavPropertyNameIterator iter = requestProperties.iterator();
		StringBuffer sb = new StringBuffer("Requested properties: ");
		while (iter.hasNext()) {
			sb.append(((DavPropertyName) iter.next()).getName());
			sb.append(",");
		}
		log.debug(sb.toString());
	}

	int propfindType = request.getPropFindType();

	int depth = Context.get().getProperties().getInt("webdav.depth", 1);
	String headerDepth = request.getHeader("Depth");
	if (StringUtils.isNotEmpty(headerDepth)) {
		if ("infinity".equals(headerDepth))
			depth = request.getDepth(DEPTH_INFINITY);
		else {
			depth = Integer.parseInt(headerDepth);
		}
	}

	MultiStatus mstatus = new MultiStatus();
	mstatus.addResourceProperties(resource, requestProperties, propfindType, depth);

	response.sendMultiStatus(mstatus);
}