org.apache.jackrabbit.webdav.DavServletResponse Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.DavServletResponse. 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 PROPPATCH method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 */
@SuppressWarnings("rawtypes")
protected void doPropPatch(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doPropPatch");

	List changeList = request.getPropPatchChangeList();
	if (changeList.isEmpty()) {
		response.sendError(DavServletResponse.SC_BAD_REQUEST);
		return;
	}

	MultiStatus ms = new MultiStatus();
	MultiStatusResponse msr = resource.alterProperties(changeList);
	ms.addResponse(msr);
	response.sendMultiStatus(ms);
}
 
Example #2
Source File: DavResourceFactoryImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
	try {
		DavResource resource = getFromCache(session, locator.getResourcePath());
		if (resource != null)
			return resource;

		Resource res = resourceService.getResource(locator.getResourcePath(), session);
		resource = createResource(locator, session, res);

		putInCache(session, resource);
		return resource;
	} catch (Throwable e) {
		log.error(e.getMessage(), e);
		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
	}
}
 
Example #3
Source File: DavResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Adds a new member to this resource.
 * 
 * @see DavResource#addMember(DavResource,
 *      org.apache.jackrabbit.webdav.io.InputContext)
 */
public void addMember(DavResource member, InputContext inputContext) throws DavException {
	if (!exists()) {
		throw new DavException(DavServletResponse.SC_CONFLICT);
	}
	if (isLocked(this) || isLocked(member)) {
		throw new DavException(DavServletResponse.SC_LOCKED);
	}

	try {
		String memberName = Text.getName(member.getLocator().getResourcePath());

		ImportContext ctx = getImportContext(inputContext, memberName);

		if (!config.getIOManager().importContent(ctx, member)) {
			// any changes should have been reverted in the importer
			throw new DavException(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
		}
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
}
 
Example #4
Source File: DeltaVResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public DavResource[] getReferenceResources(DavPropertyName hrefPropertyName) throws DavException {
	DavProperty prop = getProperty(hrefPropertyName);
	List resources = new ArrayList();
	if (prop != null && prop instanceof HrefProperty) {
		HrefProperty hp = (HrefProperty) prop;
		// process list of hrefs
		List hrefs = hp.getHrefs();
		for (Iterator iter = hrefs.iterator(); iter.hasNext();) {
			String href = (String) iter.next();
			DavResourceLocator locator = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(),
					href);
			resources.add(createResourceFromLocator(locator));
		}
	} else {
		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
	}
	return (DavResource[]) resources.toArray(new DavResource[0]);
}
 
Example #5
Source File: ArchivaDavResource.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public ActiveLock refreshLock( LockInfo lockInfo, String lockToken )
    throws DavException
{
    if ( !exists() )
    {
        throw new DavException( DavServletResponse.SC_NOT_FOUND );
    }
    ActiveLock lock = getLock( lockInfo.getType(), lockInfo.getScope() );
    if ( lock == null )
    {
        throw new DavException( DavServletResponse.SC_PRECONDITION_FAILED,
                                "No lock with the given type/scope present on resource " + getResourcePath() );
    }

    lock = lockManager.refreshLock( lockInfo, lockToken, this );

    return lock;
}
 
Example #6
Source File: DeltaVResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Report getReport(ReportInfo reportInfo) throws DavException {
	if (reportInfo == null) {
		throw new DavException(DavServletResponse.SC_BAD_REQUEST,
				"A REPORT request must provide a valid XML request body.");
	}
	if (!exists()) {
		throw new DavException(DavServletResponse.SC_NOT_FOUND);
	}

	if (supportedReports.isSupportedReport(reportInfo)) {
		Report report = ReportType.getType(reportInfo).createReport(this, reportInfo);
		return report;
	} else {
		throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Unkown report "
				+ reportInfo.getReportName() + "requested.");
	}
}
 
Example #7
Source File: ArchivaDavResource.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public void unlock( String lockToken )
    throws DavException
{
    ActiveLock lock = getLock( Type.WRITE, Scope.EXCLUSIVE );
    if ( lock == null )
    {
        throw new DavException( HttpServletResponse.SC_PRECONDITION_FAILED );
    }
    else if ( lock.isLockedByToken( lockToken ) )
    {
        lockManager.releaseLock( lockToken, this );
    }
    else
    {
        throw new DavException( DavServletResponse.SC_LOCKED );
    }
}
 
Example #8
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 #9
Source File: DavResourceTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteNonExistantResourceShould404()
    throws Exception
{
    Path dir = baseDir.resolve( "testdir" );
    try
    {
        DavResource directoryResource = getDavResource( "/testdir", dir );
        directoryResource.getCollection().removeMember( directoryResource );
        fail( "Did not throw DavException" );
    }
    catch ( DavException e )
    {
        assertEquals( DavServletResponse.SC_NOT_FOUND, e.getErrorCode() );
    }
}
 
Example #10
Source File: VersionControlledResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Modify the labels present with the versions of this resource.
 * 
 * @param labelInfo details of the label
 * 
 * @throws org.apache.jackrabbit.webdav.DavException error in the DAV communication
 * @see VersionControlledResource#label(LabelInfo)
 * @see javax.jcr.version.VersionHistory#addVersionLabel(String, String,
 *      boolean)
 * @see javax.jcr.version.VersionHistory#removeVersionLabel(String)
 */
public void label(LabelInfo labelInfo) throws DavException {
	if (labelInfo == null) {
		throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid label request body required.");
	}
	if (!exists()) {
		throw new DavException(DavServletResponse.SC_NOT_FOUND);
	}

	try {
		if (!isVersionControlled()) {
			throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED,
					"A LABEL request may only be applied to a version-controlled, checked-in resource.");
		}
		DavResource[] resArr = this.getReferenceResources(CHECKED_IN);
		if (resArr.length == 1 && resArr[0] instanceof VersionResource) {
			((VersionResource) resArr[0]).label(labelInfo);
		} else {
			throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:checked-in property on '"
					+ getHref() + "' did not point to a single VersionResource.");
		}
	} catch (Exception e) {

	}
}
 
Example #11
Source File: DavResourceTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Test
public void testRefreshLockThrowsExceptionIfNoLockIsPresent()
    throws Exception
{
    LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false );

    assertEquals( 0, resource.getLocks().length );

    try
    {
        lockManager.refreshLock( info, "notoken", resource );
        fail( "Did not throw dav exception" );
    }
    catch ( DavException e )
    {
        assertEquals( DavServletResponse.SC_PRECONDITION_FAILED, e.getErrorCode() );
    }

    assertEquals( 0, resource.getLocks().length );
}
 
Example #12
Source File: DavResourceTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnlockThrowsDavExceptionIfNotLocked()
    throws Exception
{
    LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false );

    assertEquals( 0, resource.getLocks().length );

    lockManager.createLock( info, resource );

    assertEquals( 1, resource.getLocks().length );

    try
    {
        lockManager.releaseLock( "BLAH", resource );
        fail( "Did not throw DavException" );
    }
    catch ( DavException e )
    {
        assertEquals( DavServletResponse.SC_LOCKED, e.getErrorCode() );
    }

    assertEquals( 1, resource.getLocks().length );
}
 
Example #13
Source File: DavResourceTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnlockThrowsDavExceptionIfResourceNotLocked()
    throws Exception
{
    assertEquals( 0, resource.getLocks().length );

    try
    {
        lockManager.releaseLock( "BLAH", resource );
        fail( "Did not throw DavException" );
    }
    catch ( DavException e )
    {
        assertEquals( DavServletResponse.SC_PRECONDITION_FAILED, e.getErrorCode() );
    }

    assertEquals( 0, resource.getLocks().length );
}
 
Example #14
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The REPORT 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 doReport(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doReport");

	ReportInfo info = request.getReportInfo();
	Report report;
	if (resource instanceof DeltaVResource) {
		report = ((DeltaVResource) resource).getReport(info);
	} else if (resource instanceof AclResource) {
		report = ((AclResource) resource).getReport(info);
	} else {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}

	int statusCode = (report.isMultiStatusReport()) ? DavServletResponse.SC_MULTI_STATUS : DavServletResponse.SC_OK;
	response.sendXmlResponse(report, statusCode);
}
 
Example #15
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The OPTION method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 */
protected void doOptions(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doOptions");

	response.addHeader(DavConstants.HEADER_DAV, resource.getComplianceClass());
	response.addHeader("Allow", resource.getSupportedMethods());
	response.addHeader("MS-Author-Via", DavConstants.HEADER_DAV);
	if (resource instanceof SearchResource) {
		String[] langs = ((SearchResource) resource).getQueryGrammerSet().getQueryLanguages();
		for (int i = 0; i < langs.length; i++) {
			response.addHeader(SearchConstants.HEADER_DASL, "<" + langs[i] + ">");
		}
	}
	// with DeltaV the OPTIONS request may contain a Xml body.
	OptionsResponse oR = null;
	OptionsInfo oInfo = request.getOptionsInfo();
	if (oInfo != null && resource instanceof DeltaVResource) {
		oR = ((DeltaVResource) resource).getOptionResponse(oInfo);
	}
	if (oR == null) {
		response.setStatus(DavServletResponse.SC_OK);
	} else {
		response.sendXmlResponse(oR, DavServletResponse.SC_OK);
	}
}
 
Example #16
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 #17
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The DELETE 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 doDelete(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {

	log.debug("doDelete");
	try {
		if (log.isDebugEnabled())
			log.debug("[DELETE] {} {}", (resource.isCollection() ? " FOLDER" : " DOCUMENT"),
					resource.getDisplayName());

		DavResource parent = resource.getCollection();
		if (parent != null) {
			parent.removeMember(resource);
			response.setStatus(DavServletResponse.SC_NO_CONTENT);
		} else {
			response.sendError(DavServletResponse.SC_FORBIDDEN, "Cannot remove the root resource.");
		}
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
}
 
Example #18
Source File: ArchivaDavResource.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public void copy( DavResource destination, boolean shallow )
    throws DavException
{
    if ( !exists() )
    {
        throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist." );
    }

    if ( shallow && isCollection() )
    {
        throw new DavException( DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy for collection" );
    }

    try
    {
        ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( destination );
        if ( isCollection() )
        {
            repositoryStorage.copyAsset( asset, destination.getResourcePath() );

            triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.COPY_DIRECTORY );
        }
        else
        {
            repositoryStorage.copyAsset( asset, destination.getResourcePath() );

            triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.COPY_FILE );
        }

        log.debug( "{}{}' copied to '{}' (current user '{}')", ( isCollection() ? "Directory '" : "File '" ),
                   asset.getPath(), destination, this.principal );

    }
    catch ( IOException e )
    {
        throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
    }
}
 
Example #19
Source File: ArchivaDavResourceFactory.java    From archiva with Apache License 2.0 5 votes vote down vote up
private void setHeaders( DavServletResponse response, DavResourceLocator locator, DavResource resource,
                         boolean group )
{
    // [MRM-503] - Metadata file need Pragma:no-cache response
    // header.
    if ( locator.getResourcePath().endsWith( "/maven-metadata.xml" ) || ( resource instanceof ArchivaDavResource
        && ( ArchivaDavResource.class.cast( resource ).getAsset().isContainer() ) ) )
    {
        response.setHeader( "Pragma", "no-cache" );
        response.setHeader( "Cache-Control", "no-cache" );
        response.setDateHeader( "Last-Modified", new Date().getTime() );
    }
    // if the resource is a directory don't cache it as new groupId deployed will be available
    // without need of refreshing browser
    else if ( locator.getResourcePath().endsWith( "/maven-metadata.xml" ) || (
        resource instanceof ArchivaVirtualDavResource && ( Files.isDirectory(Paths.get(
            ArchivaVirtualDavResource.class.cast( resource ).getLogicalResource() )) ) ) )
    {
        response.setHeader( "Pragma", "no-cache" );
        response.setHeader( "Cache-Control", "no-cache" );
        response.setDateHeader( "Last-Modified", new Date().getTime() );
    }
    else if ( group )
    {
        if ( resource instanceof ArchivaVirtualDavResource )
        {
            //MRM-1854 here we have a directory so force "Last-Modified"
            response.setDateHeader( "Last-Modified", new Date().getTime() );
        }
    }
    else
    {
        // We need to specify this so connecting wagons can work correctly
        response.setDateHeader( "Last-Modified", resource.getModificationTime() );
    }
    // TODO: [MRM-524] determine http caching options for other types of files (artifacts, sha1, md5, snapshots)
}
 
Example #20
Source File: SimpleReport.java    From cosmo with Apache License 2.0 5 votes vote down vote up
protected void output(DavServletResponse response)
    throws CosmoDavException {
    try {
        response.setStatus(DavServletResponse.SC_OK);
        response.setContentType(contentType);
        response.setCharacterEncoding(encoding);
        FileCopyUtils.copy(stream, response.getOutputStream());
        response.flushBuffer();
    } catch (Exception e) {
        throw new CosmoDavException(e);
    }
}
 
Example #21
Source File: MultiStatusReport.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Generates and writes the multistatus response.
 */
protected void output(DavServletResponse response) throws CosmoDavException {
    try {
        buildMultistatus();
        response.sendXmlResponse(multistatus, 207);
    } catch (Exception e) {
        throw new CosmoDavException(e);
    }
}
 
Example #22
Source File: ReportBase.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the report and writes the output to the response.
 * Calls {@link runQuery())} to execute the report and
 * {@link #output(DavServletResponse)} to write the result.
 */
public void run(DavServletResponse response)
        throws CosmoDavException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Running report {} against {} ", getType().getReportName(), resource.getResourcePath());
    }
    runQuery();
    output(response);
}
 
Example #23
Source File: PrincipalSearchPropertySetReport.java    From cosmo with Apache License 2.0 5 votes vote down vote up
protected void output(DavServletResponse response)
    throws CosmoDavException {
    try {
        response.sendXmlResponse(new PrincipalSearchPropertySet(), 200);
    } catch (Exception e) {
        throw new CosmoDavException(e);
    }
}
 
Example #24
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testWellKnown() throws IOException {
    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
    davPropertyNameSet.add(DavPropertyName.create("current-user-principal", Namespace.getNamespace("DAV:")));
    davPropertyNameSet.add(DavPropertyName.create("principal-URL", Namespace.getNamespace("DAV:")));
    davPropertyNameSet.add(DavPropertyName.create("resourcetype", Namespace.getNamespace("DAV:")));
    HttpPropfind method = new HttpPropfind("/.well-known/caldav", davPropertyNameSet, 0) {
        @Override
        public boolean succeeded(HttpResponse response) {
            return response.getStatusLine().getStatusCode() == DavServletResponse.SC_MOVED_PERMANENTLY;
        }
    };
    httpClient.executeDavRequest(method);
}
 
Example #25
Source File: ResourceServiceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Resource move(Resource source, Resource destination, DavSession session) throws DavException {
	String sid = (String) session.getObject("sid");
	if (source.isWorkspace()) {
		throw new DavException(DavServletResponse.SC_FORBIDDEN, "Cannot move a workspace");
	} else if (source.isFolder()) {
		return folderRenameOrMove(source, destination, session, sid);
	} else {
		return fileRenameOrMove(source, destination, session, sid);
	}
}
 
Example #26
Source File: DavResourceFactoryImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavSession session)
		throws DavException {

	try {
		String resourcePath = locator.getResourcePath();
		Matcher matcher = versionRequestPattern.matcher(locator.getResourcePath());

		String version = null;
		if (matcher.matches() == true) {
			version = matcher.group(1);
			resourcePath = resourcePath.replaceFirst("/vstore/" + version, "");
		}

		DavResource resource;

		Resource repositoryResource = resourceService.getResource(resourcePath, session);

		if (repositoryResource == null) {
			boolean isCollection = DavMethods.isCreateCollectionRequest(request);
			resource = createNullResource(locator, session, isCollection);
		} else {
			repositoryResource.setVersionLabel(version);
			repositoryResource.setRequestedPerson(Long.parseLong(session.getObject("id").toString()));
			resource = new VersionControlledResourceImpl(locator, this, session, resourceConfig, repositoryResource);
		}

		putInCache(session, resource);
		return resource;
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
	}
}
 
Example #27
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The EVENT_UNCHECKOUT 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 doUncheckout(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doUncheckout(" + resource.getDisplayName() + ")");
	if (!(resource instanceof VersionControlledResource)) {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}
	((VersionControlledResource) resource).uncheckout();
	response.setStatus(DavServletResponse.SC_OK);
}
 
Example #28
Source File: DavResourceTest.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public DavResource createResource( DavResourceLocator locator, DavServletRequest request,
                                   DavServletResponse response )
    throws DavException
{
    throw new UnsupportedOperationException( "Not supported yet." );
}
 
Example #29
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void doVersionControl(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doVersionControl");
	if (!(resource instanceof VersionableResource)) {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}
	((VersionableResource) resource).addVersionControl();
}
 
Example #30
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;
}