Package org.tmatesoft.svn.core.internal.server.dav

Examples of org.tmatesoft.svn.core.internal.server.dav.DAVResource


                    }
                }
            }
        }
       
        DAVResource resource = getRequestedDAVResource(true, applyToVSN);
        if (!resource.exists()) {
            throw new DAVException(DAVServlet.getStatusLine(HttpServletResponse.SC_NOT_FOUND), null, HttpServletResponse.SC_NOT_FOUND, null,
                    SVNLogType.NETWORK, Level.FINE, null, null, null, 0, null);
        }
       
        if (resource.getResourceURI().getType() != DAVResourceType.REGULAR &&
                resource.getResourceURI().getType() != DAVResourceType.VERSION) {
            response("Cannot checkout this type of resource.", DAVServlet.getStatusLine(HttpServletResponse.SC_CONFLICT),
                    HttpServletResponse.SC_CONFLICT);
        }
       
        if (!resource.isVersioned()) {
            response("Cannot checkout unversioned resource.", DAVServlet.getStatusLine(HttpServletResponse.SC_CONFLICT),
                    HttpServletResponse.SC_CONFLICT);
        }
       
        if (resource.isWorking()) {
            response("The resource is already checked out to the workspace.", DAVServlet.getStatusLine(HttpServletResponse.SC_CONFLICT),
                    HttpServletResponse.SC_CONFLICT);
        }

        DAVResource workingResource = null;
        try {
            workingResource = checkOut(resource, false, isUnreserved, createActivity, activities);
        } catch (DAVException dave) {
            throw new DAVException("Could not CHECKOUT resource {0}.", new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) },
                    HttpServletResponse.SC_CONFLICT, null, SVNLogType.NETWORK, Level.FINE, dave, null, null, 0, null);
        }
       
        setResponseHeader(CACHE_CONTROL_HEADER, CACHE_CONTROL_VALUE);
       
        if (workingResource == null) {
            setResponseHeader(HTTPHeader.CONTENT_LENGTH_HEADER, "0");
            return;
        }
           
        handleDAVCreated(workingResource.getResourceURI().getRequestURI(), "Checked-out resource", false);
    }
View Full Code Here


        }
       
        DAVLockInfoProvider lockProvider = null;


        DAVResource resource = getRequestedDAVResource(false, false);
       
        try {
            lockProvider = DAVLockInfoProvider.createLockInfoProvider(this, false);
        } catch (SVNException svne) {
            throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, null);
        }
           
        boolean isNewLockRequest = false;
        DAVLock lock = null;

        if (readLength > 0) {
            lock = getLockRequest().parseLockInfo(this, resource, getNamespaces());
            isNewLockRequest = true;
        }
           
        DAVResourceState resourceState = getResourceState(resource);
        try {
            int flags = resourceState == DAVResourceState.NULL ? DAV_VALIDATE_PARENT : DAV_VALIDATE_RESOURCE;
            flags |= DAV_VALIDATE_ADD_LD;
            validateRequest(resource, depth, flags, isNewLockRequest ? lock.getScope() : null, null, lockProvider);
        } catch (DAVException dave) {
            DAVException next = new DAVException("Could not LOCK {0} due to a failed precondition (e.g. other locks).",
                    new Object[] { SVNEncodingUtil.xmlEncodeCDATA(resource.getResourceURI().getRequestURI(), true) }, dave.getResponseCode(), dave, 0);
            throw next;
        }
           
        if (!isNewLockRequest) {
            List lockTokens = null;
            try {
                lockTokens = getLockTokensList();
            } catch (DAVException dave) {
                DAVException next = new DAVException("The lock refresh for {0} failed because no lock tokens were specified in an \"If:\" header.",
                        new Object[] { SVNEncodingUtil.xmlEncodeCDATA(resource.getResourceURI().getRequestURI(), true) }, dave.getResponseCode(), dave, 0);
                throw next;
            }
               
            String lockToken = (String) lockTokens.get(0);
            lock = lockProvider.refreshLock(resource, lockToken, getTimeout());
View Full Code Here

    public DAVGetHandler(DAVRepositoryManager connector, HttpServletRequest request, HttpServletResponse response) {
        super(connector, request, response);
    }

    public void execute() throws SVNException {
        DAVResource resource = getRequestedDAVResource(true, false);

        if (!resource.exists()) {
            SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_DAV_PATH_NOT_FOUND, "Path ''{0}'' you requested not found", resource.getResourceURI().getPath()), SVNLogType.NETWORK);
        }

        if (resource.getResourceURI().getType() != DAVResourceType.REGULAR && resource.getResourceURI().getType() != DAVResourceType.VERSION
                && resource.getResourceURI().getType() != DAVResourceType.WORKING) {
            SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_DAV_MALFORMED_DATA, "Cannot GET this type of resource."), SVNLogType.NETWORK);
        }

        setDefaultResponseHeaders();
        setResponseHeaders(resource);

        try {
            checkPreconditions(resource.getETag(), resource.getLastModified());
        } catch (SVNException e) {
            //Nothing to do, there are no enough conditions
        }

        if (resource.isCollection()) {
            StringBuffer body = new StringBuffer();
            generateResponseBody(resource, body);
            String responseBody = body.toString();

            try {
                setResponseContentLength(responseBody.getBytes(UTF8_ENCODING).length);
            } catch (UnsupportedEncodingException e) {
                setResponseContentLength(responseBody.getBytes().length);
            }

            try {
                getResponseWriter().write(responseBody);
            } catch (IOException e) {
                SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED, e), e, SVNLogType.NETWORK);
            }
        } else if (resource.getDeltaBase() != null) {
            //Here we should send SVN delta (for old clients)
        } else {
            resource.writeTo(getResponseOutputStream());
        }
    }
View Full Code Here

    protected DAVPropPatchHandler(DAVRepositoryManager connector, HttpServletRequest request, HttpServletResponse response) {
        super(connector, request, response);
    }

    public void execute() throws SVNException {
        DAVResource resource = getRequestedDAVResource(false, false);
        if (!resource.exists()) {
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        long readLength = readInput(false);
        if (readLength <= 0) {
            getPropPatchRequest().invalidXMLRoot();
        }
       
        validateRequest(resource, DAVDepth.DEPTH_ZERO, DAV_VALIDATE_RESOURCE, null, null, null);
        DAVAutoVersionInfo avInfo = autoCheckOut(resource, false);
       
        DAVPropertiesProvider propsProvider = null;
        try {
            propsProvider = DAVPropertiesProvider.createPropertiesProvider(resource, this);
        } catch (DAVException dave) {
            autoCheckIn(resource, true, false, avInfo);
            throw new DAVException("Could not open the property database for {0}.", new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) },
                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 0);
        }
       
        boolean isFailure = false;
        List properties = new LinkedList();
        DAVPropPatchRequest requestXMLObject = getPropPatchRequest()
        DAVElementProperty rootElement = requestXMLObject.getRoot();
        List childrenElements = rootElement.getChildren();
        for (Iterator childrenIter = childrenElements.iterator(); childrenIter.hasNext();) {
            DAVElementProperty childElement = (DAVElementProperty) childrenIter.next();
            DAVElement childElementName = childElement.getName();
            if (!DAVElement.DAV_NAMESPACE.equals(childElementName.getNamespace()) || (childElementName != DAVPropPatchRequest.REMOVE &&
                    childElementName != DAVPropPatchRequest.SET)) {
                continue;
            }

            DAVElementProperty propChildrenElement = childElement.getChild(DAVElement.PROP);
            if (propChildrenElement == null) {
                autoCheckIn(resource, true, false, avInfo);
                SVNDebugLog.getDefaultLog().logError(SVNLogType.NETWORK, "A \"prop\" element is missing inside the propertyupdate command.");
                setResponseStatus(HttpServletResponse.SC_BAD_REQUEST);
                return;
            }
           
            boolean isRemove = childElementName == DAVPropPatchRequest.REMOVE;
            List propChildren = propChildrenElement.getChildren();
            for (Iterator propsIter = propChildren.iterator(); propsIter.hasNext();) {
                DAVElementProperty property = (DAVElementProperty) propsIter.next();
                DAVElement propertyName = property.getName();
                PropertyChangeContext propContext = new PropertyChangeContext();
                propContext.myIsSet = !isRemove;
                propContext.myProperty = property;
                properties.add(propContext);
                validateProp(propertyName, propsProvider, propContext);
                if (propContext.myError != null && propContext.myError.getResponseCode() >= 300) {
                    isFailure = true;
                }
            }
        }
       
        String propStatText = null;
        DAVPropertyExecuteHandler executeHandler = new DAVPropertyExecuteHandler(propsProvider);
        if (!isFailure && processPropertyContextList(executeHandler, properties, true, false)) {
            isFailure = true;
        }
       
        if (isFailure) {
            DAVPropertyRollBackHandler rollBackHandler = new DAVPropertyRollBackHandler(propsProvider);
            processPropertyContextList(rollBackHandler, properties, false, true);
            propStatText = getFailureMessage(properties);
        } else {
            propStatText = getSuccessMessage(properties);
        }
       
        autoCheckIn(resource, isFailure, false, avInfo);
        //TODO: log propCtxt.error here later
        DAVPropsResult propResult = new DAVPropsResult();
        propResult.addPropStatsText(propStatText);
        DAVResponse response = new DAVResponse(null, resource.getResourceURI().getRequestURI(), null, propResult, 0);
        try {
            DAVXMLUtil.sendMultiStatus(response, getHttpServletResponse(), SC_MULTISTATUS, getNamespaces());
        } catch (IOException ioe) {
            throw new DAVException(ioe.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, SVNErrorCode.IO_ERROR.getCode());
        }
View Full Code Here

        super(connector, request, response);
        myIsMove = isMove;
    }

    public void execute() throws SVNException {
        DAVResource resource = getRequestedDAVResource(!myIsMove, false);
        if (!resource.exists()) {
            sendError(HttpServletResponse.SC_NOT_FOUND, null);
            return;
        }
       
        if (resource.getType() != DAVResourceType.REGULAR) {
            String body = "Cannot COPY/MOVE resource " + SVNEncodingUtil.xmlEncodeCDATA(getURI()) + ".";
            response(body, DAVServlet.getStatusLine(HttpServletResponse.SC_METHOD_NOT_ALLOWED), HttpServletResponse.SC_METHOD_NOT_ALLOWED);
            return;
        }
       
        String destination = getRequestHeader(HTTPHeader.DESTINATION_HEADER);
        if (destination == null) {
            String netScapeHost = getRequestHeader(HTTPHeader.HOST_HEADER);
            String netScapeNewURI = getRequestHeader(HTTPHeader.NEW_URI_HEADER);
            if (netScapeHost != null && netScapeNewURI != null) {
                String path = SVNPathUtil.append(netScapeHost, netScapeNewURI);
                if (path.startsWith("/")) {
                    path = path.substring(1);
                }
                destination = "http://" + path;
            }
        }
       
        if (destination == null) {
            SVNDebugLog.getDefaultLog().logFine(SVNLogType.NETWORK, "The request is missing a Destination header.");
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        URI uri = null;
        try {
            uri = DAVServletUtil.lookUpURI(destination, getRequest(), true);
        } catch (DAVException dave) {
            if (dave.getResponseCode() == HttpServletResponse.SC_BAD_REQUEST) {
                throw dave;
            }
            response(dave.getMessage(), DAVServlet.getStatusLine(dave.getResponseCode()), dave.getResponseCode());
        }
       
        String path = uri.getPath();
        DAVRepositoryManager manager = getRepositoryManager();
        String resourceContext = manager.getResourceContext();
       
        if (!path.startsWith(resourceContext)) {
            throw new DAVException("Destination url starts with a wrong context", HttpServletResponse.SC_BAD_REQUEST, 0);
        }
       
        path = path.substring(resourceContext.length());
        DAVResource newResource = getRequestedDAVResource(false, false, path);
        int overwrite = getOverwrite();
        if (overwrite < 0) {
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        if (newResource.exists() && overwrite == 0) {
            response("Destination is not empty and Overwrite is not \"T\"", DAVServlet.getStatusLine(HttpServletResponse.SC_PRECONDITION_FAILED),
                    HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
       
        if (resource.equals(newResource)) {
            response("Source and Destination URIs are the same.", DAVServlet.getStatusLine(HttpServletResponse.SC_FORBIDDEN),
                    HttpServletResponse.SC_FORBIDDEN);
            return;
        }
       
        boolean isDir = resource.isCollection();
        DAVDepth depth = null;
        try {
            depth = getRequestDepth(DAVDepth.DEPTH_INFINITY);
        } catch (SVNException svne) {
            throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_BAD_REQUEST, null, null);
        }
       
        if (depth == DAVDepth.DEPTH_ONE) {
            //add logging here later
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        if (myIsMove && isDir && depth != DAVDepth.DEPTH_INFINITY) {
            //add logging here later
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        if (myIsMove) {
            try {
                validateRequest(resource, depth, DAV_VALIDATE_PARENT | DAV_VALIDATE_USE_424, null, null, null);
            } catch (DAVException dave) {
                throw new DAVException("Could not MOVE {0} due to a failed precondition on the source (e.g. locks).",
                        new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) }, dave.getResponseCode(), null, SVNLogType.NETWORK,
                        Level.FINE, dave, null, null, 0, dave.getResponse());
            }
        }
       
        try {
            validateRequest(newResource, DAVDepth.DEPTH_INFINITY, DAV_VALIDATE_PARENT | DAV_VALIDATE_USE_424, null, null, null);
        } catch (DAVException dave) {
            throw new DAVException("Could not MOVE/COPY {0} due to a failed precondition on the destination (e.g. locks).",
                    new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) }, dave.getResponseCode(), null, SVNLogType.NETWORK, Level.FINE,
                    dave, null, null, 0, dave.getResponse());
        }
       
        if (isDir && depth == DAVDepth.DEPTH_INFINITY && resource.isParentResource(newResource)) {
            response("Source collection contains the Destination.", DAVServlet.getStatusLine(HttpServletResponse.SC_FORBIDDEN), HttpServletResponse.SC_FORBIDDEN);
            return;
        }
       
        if (isDir && newResource.isParentResource(newResource)) {
            response("Destination collection contains the Source and Overwrite has been specified.", DAVServlet.getStatusLine(HttpServletResponse.SC_FORBIDDEN),
                    HttpServletResponse.SC_FORBIDDEN);
            return;
        }
       
        readInput(true);
        DAVLockInfoProvider lockProvider = null;
        try {
            lockProvider = DAVLockInfoProvider.createLockInfoProvider(this, false);
        } catch (SVNException svne) {
            throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, null);
        }
       
        if (myIsMove) {
            unlock(resource, null);
        }
       
        DAVAutoVersionInfo srcAVInfo = null;
        if (myIsMove) {
            srcAVInfo = autoCheckOut(resource, true);
           
        }
       
        boolean replaceDestination = false;
        DAVResourceState resNewState = getResourceState(newResource);
        if (newResource.exists()) {
            if (myIsMove || !newResource.isVersioned()) {
                replaceDestination = true;
            } else if (resource.getType() != newResource.getType()) {
                replaceDestination = true;
            } else if (resource.isCollection() != newResource.isCollection()) {
                replaceDestination = true;
            }
        }
       
        DAVAutoVersionInfo dstAVInfo = null;
        if (!newResource.exists() || replaceDestination) {
            try {
                 dstAVInfo = autoCheckOut(newResource, true);
            } catch (DAVException dave) {
                if (myIsMove) {
                    autoCheckIn(null, true, false, srcAVInfo);
                }
                throw dave;
            }
        }
       
        if (srcAVInfo != null && srcAVInfo.getParentResource() != null && dstAVInfo != null &&
                dstAVInfo.getParentResource() != null) {
            DAVResource srcParentResource = srcAVInfo.getParentResource();
            DAVResource dstParentResource = dstAVInfo.getParentResource();
            if (srcParentResource.equals(dstParentResource)) {
                dstAVInfo.setParentResource(srcAVInfo.getParentResource());
            }
        }
       
View Full Code Here

        SVNDebugLog.getDefaultLog().logFine(SVNLogType.DEFAULT, "in execute() of DAVOptiondsHandler");
       
        readInput(false);
        SVNDebugLog.getDefaultLog().logFine(SVNLogType.DEFAULT, "read input");
       
        DAVResource resource = getRequestedDAVResource(false, false);
        SVNDebugLog.getDefaultLog().logFine(SVNLogType.DEFAULT, "got resource");

        Collection supportedMethods = getSupportedMethods(resource);
        SVNDebugLog.getDefaultLog().logFine(SVNLogType.DEFAULT, "got supported methods");
View Full Code Here

        if (status != HttpServletResponse.SC_OK) {
            sendError(status, null);
            return;
        }
       
        DAVResource resource = getRequestedDAVResource(false, false);
        if (resource.exists()) {
            sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, null);
            return;
        }
       
        DAVResourceState resourceState = getResourceState(resource);
        validateRequest(resource, DAVDepth.DEPTH_ZERO, resourceState == DAVResourceState.NULL ? DAV_VALIDATE_PARENT : DAV_VALIDATE_RESOURCE,
                null, null, null);
       
        DAVException err1 = null;
        DAVException err2 = null;
        DAVAutoVersionInfo avInfo = autoCheckOut(resource, true);
        resource.setCollection(true);
        try {
            createdCollection(resource);
        } catch (DAVException dave) {
            err1 = dave;
        }
View Full Code Here

    public void execute() throws SVNException {
        myCommonReportHandler.checkSVNNamespace(null);

        setDAVResource(getRequestedDAVResource(false, false));
       
        DAVResource resource = getDAVResource();
        DAVGetLocationsRequest request = getGetLocationsRequest();
        String path = request.getPath();
        long pegRevision = request.getPegRevision();
       
        if (path == null || !SVNRevision.isValidRevisionNumber(pegRevision)) {
            throw new DAVException("Not all parameters passed.", HttpServletResponse.SC_BAD_REQUEST, SVNLogType.NETWORK,
                    DAVXMLUtil.SVN_DAV_ERROR_TAG, DAVElement.SVN_DAV_ERROR_NAMESPACE);
        }
       
        if (!path.startsWith("/")) {
            path = SVNPathUtil.append(resource.getResourceURI().getPath(), path);   
        }
       
        SVNRepository repository = resource.getRepository();
        Collection locations = repository.getLocations(path, (Collection)null, pegRevision, request.getRevisions());

        Map attrs = new SVNHashMap();
        writeXMLHeader(GET_LOCATIONS_REPORT);
        for (Iterator locationsIter = locations.iterator(); locationsIter.hasNext();) {
View Full Code Here

        }
        return convertSVNLockToDAVLock(svnLock, false, resource.exists());
    }
   
    public void inheritLocks(DAVResource resource, boolean useParent) throws DAVException {
        DAVResource whichResource = resource;
        if (useParent) {
            DAVResource parentResource = DAVResourceHelper.createParentResource(resource);
            if (parentResource == null) {
                throw new DAVException("Could not fetch parent resource. Unable to inherit locks from the parent and apply them to this resource.",
                        HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 0);
            }
            whichResource = parentResource;
View Full Code Here

    }

    public void execute() throws SVNException {
        readInput(false);

        DAVResource resource = getRequestedDAVResource(false, false);
        if (!resource.exists()) {
            sendError(HttpServletResponse.SC_NOT_FOUND, null);
            return;
        }
       
        DAVDepth depth = getRequestDepth(DAVDepth.DEPTH_INFINITY);
        if (resource.isCollection() && depth != DAVDepth.DEPTH_INFINITY) {
            SVNDebugLog.getDefaultLog().logError(SVNLogType.NETWORK, "Depth must be \"infinity\" for DELETE of a collection.");
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        if (!resource.isCollection() && depth == DAVDepth.DEPTH_ONE) {
            SVNDebugLog.getDefaultLog().logError(SVNLogType.NETWORK, "Depth of \"1\" is not allowed for DELETE.");
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
View Full Code Here

TOP

Related Classes of org.tmatesoft.svn.core.internal.server.dav.DAVResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.