Package org.apache.slide.webdav.util

Examples of org.apache.slide.webdav.util.ViolatedPrecondition


        UriHandler sourceUriHandler = UriHandler.getUriHandler(sourceUri);
        isRequestSourceWorkspace = sourceUriHandler.isWorkspaceUri();

        try {
            // check preconditions
            ViolatedPrecondition violatedPrecondition = getPreconditionViolation(sourceUri, destinationUri);
            if (violatedPrecondition != null) {
                PreconditionViolationException e =
                    new PreconditionViolationException(violatedPrecondition, sourceUri);
                sendPreconditionViolation(e);
                throw e;
View Full Code Here


     *
     * @throws     SlideException
     */
    private ViolatedPrecondition getPreconditionViolation(String sourceUri, String destinationUri) throws SlideException {

        ViolatedPrecondition violatedPrecondition = null;
        if( Configuration.useVersionControl() ) {

            if (isRequestSourceWorkspace) {

                UriHandler destinationUriHandler = UriHandler.getUriHandler(destinationUri);
                NodeRevisionDescriptors destinationRevisionDescriptors = null;
                NodeRevisionDescriptor destinationRevisionDescriptor = null;
                try {
                    destinationRevisionDescriptors = content.retrieve( slideToken, destinationUri);
                    destinationRevisionDescriptor = content.retrieve( slideToken, destinationRevisionDescriptors);
                }
                catch( ObjectNotFoundException e ) {}; // can be ignored here!

                ResourceKind destinationResourceKind =
                    AbstractResourceKind.determineResourceKind( token, destinationUri, destinationRevisionDescriptor );

                if( !(destinationResourceKind instanceof DeltavCompliantUnmappedUrl) ) {
                    return new ViolatedPrecondition(C_RESOURCE_MUST_BE_NULL,
                                                    WebdavStatus.SC_CONFLICT);
                }
                if( !destinationUriHandler.isWorkspaceUri() ) {
                    return new ViolatedPrecondition(C_WORKSPACE_LOCATION_OK,
                                                    WebdavStatus.SC_CONFLICT);
                }
            }
        }
        if (isCollection(sourceUri)) {
            UriHandler destinationUriHandler = UriHandler.getUriHandler(destinationUri);
            ObjectNode destinationParentNode =
                structure.retrieve(slideToken, destinationUriHandler.getParentUriHandler().toString());
            ObjectNode sourceNode =
                structure.retrieve(slideToken, sourceUri);
            if (isDescendant(destinationParentNode, sourceNode)) {
                return new ViolatedPrecondition(C_CYCLE_ALLOWED, WebdavStatus.SC_FORBIDDEN);
            }
        }

        return violatedPrecondition;
    }
View Full Code Here

        if( Configuration.useVersionControl() ) {

            UriHandler uriHandler = UriHandler.getUriHandler(sourceUri);
            if (uriHandler.isVersionUri()) {
                throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_RENAME_VERSION,
                                                                                  WebdavStatus.SC_FORBIDDEN),
                                                         sourceUri);
            }
            if (uriHandler.isHistoryUri()) {
                throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_RENAME_HISTORY,
                                                                                  WebdavStatus.SC_FORBIDDEN),
                                                         sourceUri);
            }
            if (uriHandler.isWorkingresourceUri()) {
                throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_RENAME_WORKING_RESOURCE,
                                                                                  WebdavStatus.SC_FORBIDDEN),
                                                         sourceUri);
            }

            NodeRevisionDescriptors sourceRevisionDescriptors =
View Full Code Here

     * @throws   PreconditionViolationException
     */
    public void init(String resourcePath, Element principalPropertySearchElm) throws PreconditionViolationException {
        if (principalPropertySearchElm.getChildren().size() == 0) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("at-least-one-child-element",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "DAV:principal-property-search element must have at least one child"),
                resourcePath
            );
        }
        List propertySearchElmL = principalPropertySearchElm.getChildren(E_PROPERTY_SEARCH, DNSP);
        if (propertySearchElmL.size() == 0) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("at-least-one-property-search-element",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "DAV:principal-property-search element must contain at least one DAV:property-search element"),
                resourcePath
            );
        }
        Iterator ps = propertySearchElmL.iterator();
        this.conditionList = new ArrayList();
        while (ps.hasNext()) {
            Element propertySearchElm = (Element)ps.next();
            Element matchElm = propertySearchElm.getChild(E_MATCH, DNSP);
            if (matchElm == null) {
                continue;
            }
            Element propElm = propertySearchElm.getChild(E_PROP, DNSP);
            Iterator pElms = propElm.getChildren().iterator();
            while (pElms.hasNext()) {
                Element pElm = (Element)pElms.next();
                Element newpropElm = new Element(E_PROP, DNSP);
                newpropElm.addContent(new Element(pElm.getName(), pElm.getNamespace()));
                Element propcontainsElm = new Element("propcontains", Namespace.getNamespace("http://jakarta.apache.org/slide/"));
                Element literalElm = new Element(Literals.LITERAL, DNSP);
                literalElm.addContent(matchElm.getTextTrim());
                propcontainsElm.addContent(newpropElm);
                propcontainsElm.addContent(literalElm);
                conditionList.add(propcontainsElm);
            }
        }
        List propElmL = principalPropertySearchElm.getChildren(E_PROP, DNSP);
        if (propElmL.size() > 1) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("at-most-one-prop-element",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "DAV:principal-property-search element must have at most one DAV:prop child"),
                resourcePath
            );
        }
       
        if (propElmL.size() == 1) {
            Element propElm = (Element)propElmL.get(0);
            try {
                this.requestedProperties = new RequestedPropertiesImpl(propElm);
            }
            catch (PropertyParseException e) {
                throw new PreconditionViolationException(
                    new ViolatedPrecondition("invalid-prop",
                                             WebdavStatus.SC_BAD_REQUEST,
                                             e.getMessage()),
                    resourcePath
                );
            }
View Full Code Here

     * @throws   ServiceAccessException
     */
    public void checkPreconditions(String resourcePath, int depth) throws PreconditionViolationException, ServiceAccessException {
        if (depth != 0) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("depth-must-be-zero",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "This report is only defined for depth=0."),
                resourcePath
            );
        }
View Full Code Here

            }
           
            ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, resourcePath, revisionDescriptor);
           
            // check preconditions
            ViolatedPrecondition violatedPrecondition = getPreconditionViolation(revisionDescriptors, revisionDescriptor, resourceKind);
            if (violatedPrecondition != null) {
                throw new PreconditionViolationException(violatedPrecondition, resourcePath);
            }
           
            // Changed for DeltaV --start--
View Full Code Here

     * @param resourceKind  the kind of the resource to patch.
     */
    private boolean checkPropertyModification(PropPatchProperty property, NodeRevisionDescriptor rd, ResourceKind resourceKind) {
       
        boolean result = false;
        ViolatedPrecondition violatedPrecondition = getPropertySpecificPreconditionViolation(property);
        if (violatedPrecondition != null) {
            property.setViolatedPrecondition(violatedPrecondition);
        }
        else {
            NodeProperty originalProperty = rd.getProperty(property.getName(), property.getNamespace());
View Full Code Here

               
                if ( !E_CHECKOUT_CHECKIN.equals(autoVersion) &&
                    !E_CHECKOUT_UNLOCKED_CHECKIN.equals(autoVersion) &&
                    !E_CHECKOUT.equals(autoVersion) &&
                    !E_LOCKED_CHECKOUT.equals(autoVersion) ) {
                    return new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION_CONTROLLED_PROPERTY,
                                                    WebdavStatus.SC_FORBIDDEN);
                }
                if (E_LOCKED_CHECKOUT.equals(autoVersion)) {
                    if ( !versioningHelper.isWriteLocked(stoken, revisionDescriptors) ) {
                        return new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION_CONTROLLED_PROPERTY,
                                                        WebdavStatus.SC_FORBIDDEN);
                    }
                }
            }
           
            // check precondition DAV:cannot-modify-version
            UriHandler uriHandler = UriHandler.getUriHandler(resourcePath);
            if (uriHandler.isVersionUri()) {
                return new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION,
                                                WebdavStatus.SC_FORBIDDEN);
            }
        }
       
        return null;
View Full Code Here

    private ViolatedPrecondition getPropertySpecificPreconditionViolation(PropPatchProperty property) {
       
        // check precondition DAV:cannot-modify-protected-property
        if ( AbstractResourceKind.isProtectedProperty(property.getName()) &&
            DeltavConstants.DELTAV_PROPERTY_LIST.contains(property.getName()) ) {
            return new ViolatedPrecondition(C_CANNOT_MODIFY_PROTECTED_PROPERTY,
                                            WebdavStatus.SC_CONFLICT);
        }
       
        // check precondition DAV:supported-live-property
        // ...is there any property to check here yet ?
View Full Code Here

     * @throws   PreconditionViolationException
     */
    public void init(String resourcePath, Element principalMatchElm) throws PreconditionViolationException {
        if (principalMatchElm.getChildren().size() == 0) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("at-least-one-child-element",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "DAV:principal-match element must have at least one child"),
                resourcePath
            );
        }
        List principalPropertyElmL = principalMatchElm.getChildren(E_PRINCIPAL_PROPERTY, DNSP);
        List selfElmL = principalMatchElm.getChildren(E_SELF, DNSP);
        if (principalPropertyElmL.size()+selfElmL.size() != 1) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("either-one-principal-property-or-one-self-element",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "DAV:principal-match element must contain either a DAV:principal-property or a DAV:self element"),
                resourcePath
            );
        }
        if (principalPropertyElmL.size() == 1) {
            Element principalPropertyElm = (Element)principalPropertyElmL.get(0);
            if (principalPropertyElm.getChildren(E_OWNER, DNSP).size() > 0) {
                matchSubjectNode = SubjectNode.OWNER;
            }
            else {
                // TODO: support other properties
            }
        }
        else {
            matchSubjectNode = SubjectNode.SELF;
        }
        List propElmL = principalMatchElm.getChildren(E_PROP, DNSP);
        if (propElmL.size() > 1) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("at-most-one-prop-element",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "DAV:principal-match element must have at most one DAV:prop child"),
                resourcePath
            );
        }
       
        if (propElmL.size() == 1) {
            Element propElm = (Element)propElmL.get(0);
            try {
                this.requestedProperties = new RequestedPropertiesImpl(propElm);
            }
            catch (PropertyParseException e) {
                throw new PreconditionViolationException(
                    new ViolatedPrecondition("invalid-prop",
                                             WebdavStatus.SC_BAD_REQUEST,
                                             e.getMessage()),
                    resourcePath
                );
            }
View Full Code Here

TOP

Related Classes of org.apache.slide.webdav.util.ViolatedPrecondition

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.