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

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


                    "Failed to look up lock by path.", null);
        }
       
        if (lock != null) {
            if (!lockToken.equals(lock.getID())) {
                throw new DAVException("Incoming token doesn't match existing lock.", HttpServletResponse.SC_BAD_REQUEST,
                        DAVErrorCode.LOCK_SAVE_LOCK);
            }
            davLock = convertSVNLockToDAVLock(lock, false, resource.exists());
            myOwner.setResponseHeader(HTTPHeader.CREATION_DATE_HEADER, SVNDate.formatDate(lock.getCreationDate()));
            myOwner.setResponseHeader(HTTPHeader.LOCK_OWNER_HEADER, lock.getOwner());
View Full Code Here


        if (token != null) {
            try {
                resource.unlock(token, isBreakLock());
            } catch (SVNException svne) {
                if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.FS_NO_USER) {
                    throw new DAVException("Anonymous lock removal is not allowed.", HttpServletResponse.SC_UNAUTHORIZED,
                            DAVErrorCode.LOCK_SAVE_LOCK);
                }
                throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "Failed to remove a lock.", null);
            }
View Full Code Here

        return buffer.toString();
    }
   
    public static FSLock convertDAVLockToSVNLock(DAVLock davLock, String path, boolean isSVNClient, SAXParserFactory saxParserFactory) throws DAVException {
        if (davLock.getType() != DAVLockType.WRITE) {
            throw new DAVException("Only 'write' locks are supported.", HttpServletResponse.SC_BAD_REQUEST, DAVErrorCode.LOCK_SAVE_LOCK);
        }
        if (davLock.getScope() != DAVLockScope.EXCLUSIVE) {
            throw new DAVException("Only exclusive locks are supported.", HttpServletResponse.SC_BAD_REQUEST, DAVErrorCode.LOCK_SAVE_LOCK);
        }
       
        boolean isDAVComment = false;
        String comment = null;
        if (davLock.getOwner() != null) {
            if (isSVNClient) {
                try {
                    SAXParser xmlParser = saxParserFactory.newSAXParser();
                    XMLReader reader = xmlParser.getXMLReader();
                    FetchXMLHandler handler = new FetchXMLHandler(DAVElement.LOCK_OWNER);
                    reader.setContentHandler(handler);
                    reader.setDTDHandler(handler);
                    reader.setErrorHandler(handler);
                    reader.setEntityResolver(handler);
                    String owner = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + davLock.getOwner();
                    reader.parse(new InputSource(new ByteArrayInputStream(owner.getBytes())));
                    comment = handler.getData();
                } catch (ParserConfigurationException e) {
                    throw new DAVException(e.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DAVErrorCode.LOCK_SAVE_LOCK);
                } catch (SAXException e) {
                    throw new DAVException(e.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DAVErrorCode.LOCK_SAVE_LOCK);
                } catch (IOException e) {
                    throw new DAVException(e.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DAVErrorCode.LOCK_SAVE_LOCK);
                }
            } else {
                isDAVComment = true;
                comment = davLock.getOwner();
            }
View Full Code Here

        }
       
        try {
            validateRequest(resource, depth, DAV_VALIDATE_PARENT | DAV_VALIDATE_USE_424, null, null, null);
        } catch (DAVException dave) {
            throw new DAVException("Could not DELETE {0} due to a failed precondition (e.g. locks).",
                    new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) }, dave.getResponseCode(), null, SVNLogType.NETWORK, Level.FINE,
                    dave, null, null, 0, dave.getResponse());
        }
       
        int respCode = unlock(resource, null);
        if (respCode != HttpServletResponse.SC_OK) {
            sendError(respCode, null);
            return;
        }
       
        DAVAutoVersionInfo avInfo = autoCheckOut(resource, true);
        try {
            removeResource(resource);
        } catch (DAVException dave) {
            autoCheckIn(null, true, false, avInfo);
            throw new DAVException("Could not DELETE {0}.", new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) }, dave.getResponseCode(),
                    dave, 0);
        }
       
        try {
            autoCheckIn(null, false, false, avInfo);
View Full Code Here

        FSRepository repos = (FSRepository) resource.getRepository();
        myFSFS = repos.getFSFS();
        readInput(true);
        if (resource.exists()) {
            throw new DAVException("<DAV:resource-must-be-null/>", HttpServletResponse.SC_CONFLICT, SVNLogType.NETWORK);
        }

        if (!resource.canBeActivity()) {
            throw new DAVException("<DAV:activity-location-ok/>", HttpServletResponse.SC_FORBIDDEN, SVNLogType.NETWORK);
        }
       
        try {
            makeActivity(resource);
        } catch (DAVException dave) {
            throw new DAVException("Could not create activity {0}.", new Object[] { SVNEncodingUtil.xmlEncodeCDATA(resource.getResourceURI().getURI()) },
                    dave.getResponseCode(), null, SVNLogType.NETWORK, Level.FINE, dave, null, null, 0, null);
        }

        setResponseHeader(CACHE_CONTROL_HEADER, CACHE_CONTROL_VALUE);
        handleDAVCreated(resource.getResourceURI().getURI(), "Activity", false);
View Full Code Here

        } catch (SVNException svne) {
            throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_BAD_REQUEST, null, null);
        }
       
        if (depth != DAVDepth.DEPTH_ONE && depth != DAVDepth.DEPTH_ZERO) {
            throw new DAVException("An invalid Depth header was specified.", HttpServletResponse.SC_BAD_REQUEST, 0);
        }
       
        Date timeout = handler.getTimeout();
        String lockToken = null;
       
        try {
            lockToken = FSRepositoryUtil.generateLockToken();
        } catch (SVNException e) {
            DAVException first = DAVException.convertError(e.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to generate a lock token.", null);
            DAVException next = new DAVException("Could not parse the lockinfo due to an internal problem creating a lock structure.", first.getResponseCode(), first, 0);
            throw next;
        }
       
        DAVElementProperty rootElement = null;
        try {
            rootElement = getRoot();
        } catch (SVNException e) {
            throw DAVException.convertError(e.getErrorMessage(), HttpServletResponse.SC_BAD_REQUEST,
                    "Could not parse the lockinfo, malformed xml request", null);
        }

        String owner = null;
        DAVLockScope lockScope = DAVLockScope.UNKNOWN;
        DAVLockType lockType = DAVLockType.UNKNOWN;
        for (Iterator childrenIter = rootElement.getChildren().iterator(); childrenIter.hasNext();) {
            DAVElementProperty childElement = (DAVElementProperty) childrenIter.next();
            DAVElement childElementName = childElement.getName();
            if (childElementName == DAVElement.LOCK_TYPE && childElement.getChildren() != null && lockType == DAVLockType.UNKNOWN) {
                DAVElementProperty writeChild = childElement.getChild(DAVElement.WRITE);
                if (writeChild != null) {
                    lockType = DAVLockType.WRITE;
                    continue;
                }
            }
            if (childElementName == DAVElement.LOCK_SCOPE && childElement.getChildren() != null && lockScope == DAVLockScope.UNKNOWN) {
                if (childElement.getChild(DAVElement.EXCLUSIVE) != null) {
                    lockScope = DAVLockScope.EXCLUSIVE;
                } else if (childElement.getChild(DAVElement.SHARED) != null) {
                    lockScope = DAVLockScope.SHARED;
                }
                if (lockScope != DAVLockScope.UNKNOWN) {
                    continue;
                }
            }
           
            if (childElementName == DAVElement.LOCK_OWNER) {
                //TODO: maybe make this recursive for all possible subelements  
                StringBuffer buffer = new StringBuffer();
                String namespace = childElementName.getNamespace();
                buffer.append("<");
                if (namespace == null || "".equals(namespace)) {
                    buffer.append(childElementName.getName());
                } else {
                    buffer.append(SVNXMLUtil.PREFIX_MAP.get(namespace));
                    buffer.append(":");
                    buffer.append(childElementName.getName());
                }
               
                Map attributes = childElement.getAttributes();
                if (attributes != null) {
                    for (Iterator attrsIter = attributes.keySet().iterator(); attrsIter.hasNext();) {
                        String attrName = (String) attrsIter.next();
                        String attrValue = (String) attributes.get(attrName);
                        buffer.append(" ");
                        buffer.append(attrName);
                        buffer.append("=\"");
                        buffer.append(attrValue);
                        buffer.append("\"");
                    }
                }
               
                for (Iterator namespacesIter = namespaces.iterator(); namespacesIter.hasNext();) {
                    String nextNamespace = (String) namespacesIter.next();
                    buffer.append(" xmlns:");
                    buffer.append(SVNXMLUtil.PREFIX_MAP.get(nextNamespace));
                    buffer.append("=\"");
                    buffer.append(nextNamespace);
                    buffer.append("\"");
                }
               
                if (childElement.isEmpty()) {
                    buffer.append(" />");
                } else {
                    buffer.append(">");
                    buffer.append(SVNEncodingUtil.xmlEncodeCDATA(childElement.getFirstValue(false), false));
                    buffer.append("</");
                    if (namespace == null || "".equals(namespace)) {
                        buffer.append(childElementName.getName());
                    } else {
                        buffer.append(SVNXMLUtil.PREFIX_MAP.get(namespace));
                        buffer.append(":");
                        buffer.append(childElementName.getName());
                    }
                    buffer.append(">");
                }
               
                owner = buffer.toString();
                continue;
            }
           
            throw new DAVException("The server cannot satisfy the LOCK request due to an unknown XML element (\"{0}\") within the DAV:lockinfo element.",
                    new Object[] { childElementName.getName() }, HttpServletResponse.SC_PRECONDITION_FAILED, 0);
        }
       
        return new DAVLock(resource.getUserName(), depth, resource.exists(), lockToken, owner, DAVLockRecType.DIRECT, lockScope, lockType, timeout);
View Full Code Here

        }
        return getRootElement();
    }

    protected void invalidXMLRoot() throws SVNException {
        throw new DAVException("The request body contains an unexpected XML root element.", null, HttpServletResponse.SC_BAD_REQUEST,
                null, SVNLogType.NETWORK, Level.FINE, null, null, null, 0, null);
    }
View Full Code Here

TOP

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

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.