Examples of ViolatedPrecondition


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

                }
                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_CONTENT,
                                                    WebdavStatus.SC_FORBIDDEN);
                }
                if ( E_LOCKED_CHECKOUT.equals(autoVersion) &&
                        ( !versioningHelper.isWriteLocked(stoken, revisionDescriptors) ) ) {
                    return new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION_CONTROLLED_CONTENT,
                                                    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

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

     */
    public void init(String resourcePath, Element locateByHistoryElm) throws PreconditionViolationException {
        List childrenList = locateByHistoryElm.getChildren();
        if (childrenList.size() != 2) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("invalid-locate-by-history",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "DAV:locate-by-history element must have 2 children: DAV:version-history-set and DAV:prop"),
                resourcePath
            );
        }
       
        Element versionHistorySetElm = null;
        Element propElm = null;
        if ( E_VERSION_HISTORY_SET.equals(((Element)childrenList.get(0)).getName()) &&
            E_PROP.equals(((Element)childrenList.get(1)).getName()) ) {
            versionHistorySetElm = (Element)childrenList.get(0);
            propElm = (Element)childrenList.get(1);
        }
        else if ( E_PROP.equals(((Element)childrenList.get(0)).getName()) &&
                 E_VERSION_HISTORY_SET.equals(((Element)childrenList.get(1)).getName()) ) {
            propElm = (Element)childrenList.get(0);
            versionHistorySetElm = (Element)childrenList.get(1);
        }
        else {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("invalid-locate-by-history",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "DAV:locate-by-history element must have 2 children: DAV:version-history-set and DAV:prop"),
                resourcePath
            );
        }
       
        // <locate-by-history> report can only be applied to collection
        if ( ! WebdavUtils.isCollection(token, slideToken, resourcePath) ) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("must-be-collection",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "the request-URI must specify a collection"),
                resourcePath
            );
        }
       
        this.versionHistorySet =
            new XMLValue(versionHistorySetElm.getChildren(E_HREF, DNSP));
       
        // check DAV:must-be-version-history
        UriHandler uriHandler = null;
        String href = null;
        boolean isVersionHistory = false;
        Iterator iterator = versionHistorySet.getHrefStrings().iterator();
        while (iterator.hasNext()) {
            href = (String)iterator.next();
            uriHandler = UriHandler.getUriHandler(WebdavUtils.getSlidePath(href, contextPath));
            isVersionHistory = uriHandler.isHistoryUri();
            if (!isVersionHistory) {
                break;
            }
        }
        if (!isVersionHistory) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition(C_MUST_BE_VERSION_HISTORY,
                                         WebdavStatus.SC_CONFLICT),
                resourcePath
            );
        }
       
        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

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

     * @throws     SlideException
     * @throws     PreconditionViolationException  if any precondition has been violated.
     */
    private void checkPreconditions(String updateSourcePath, String updateLabelName, String resourcePath) throws SlideException, PreconditionViolationException {

        ViolatedPrecondition violatedPrecondition = getPreconditionViolation(updateSourcePath,
                                                                             updateLabelName,
                                                                             resourcePath);
        if (violatedPrecondition != null) {
            throw new PreconditionViolationException(violatedPrecondition, resourcePath);
        }
View Full Code Here

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

     */
    protected ViolatedPrecondition getPreconditionViolation(String updateSourcePath, String updateSourceLabel, String resourcePath) throws SlideException {
        // use a non-blocking slide token.
        SlideToken stoken = readonlySlideToken();

        ViolatedPrecondition violatedPrecondition = null;

        NodeRevisionDescriptors revisionDescriptors =
            content.retrieve(stoken, resourcePath);
        NodeRevisionDescriptor revisionDescriptor =
            content.retrieve(stoken, revisionDescriptors);
        ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token,
                                                                               revisionDescriptors,
                                                                               revisionDescriptor);
        if ( ! (resourceKind instanceof CheckedInVersionControlled) ) {
            return new ViolatedPrecondition(DeltavConstants.C_MUST_BE_CHECKED_IN_VERSION_CONTROLLED_RESOURCE,
                                            WebdavStatus.SC_CONFLICT);
        }

        if (updateSourceLabel != null) {
            try {
                updateSourcePath = versioningHelper.getLabeledResourceUri(resourcePath, updateLabelName);
            }
            catch (LabeledRevisionNotFoundException e) {
                return new ViolatedPrecondition(DeltavConstants.C_MUST_SELECT_VERSION_IN_HISTORY,
                                                WebdavStatus.SC_CONFLICT);
            }
        }

        String associatedVrUri = versioningHelper.getUriOfAssociatedVR(resourcePath);
        String vcrHistoryUri = UriHandler.getUriHandler(associatedVrUri).getAssociatedHistoryUri();
        UriHandler vrUriHandler = UriHandler.getUriHandler(updateSourcePath);
        boolean isVersionOfVcrHistory = false;
        if (vrUriHandler.isVersionUri() &&
            vcrHistoryUri.equals(vrUriHandler.getAssociatedHistoryUri()) ) {

            NodeRevisionDescriptors vrDescriptors =
                content.retrieve(stoken, updateSourcePath);
            try {
                NodeRevisionDescriptor vrDescriptor =
                    content.retrieve(stoken, vrDescriptors);
                isVersionOfVcrHistory = true;
            }
            catch (RevisionDescriptorNotFoundException e) {
            }
        }

        if ( ! isVersionOfVcrHistory ) {
            return new ViolatedPrecondition(DeltavConstants.C_MUST_SELECT_VERSION_IN_HISTORY,
                                            WebdavStatus.SC_CONFLICT);
        }

        return violatedPrecondition;
    }
View Full Code Here

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

        }
        catch (SlideException e) {} // ignore silently

        if (collectionNode == null || !isCollection(collectionUri)) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition(C_REBIND_INTO_COLLECTION, WebdavStatus.SC_CONFLICT), collectionUri);
        }
        if (!MethodUtil.isValidSegment(segment)) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition(C_NAME_ALLOWED, WebdavStatus.SC_FORBIDDEN), segment);
        }
        if (sourceNode == null) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition(C_REBIND_SOURCE_EXISTS, WebdavStatus.SC_CONFLICT), sourceUri);
        }
        if (collectionNode.hasBinding(segment)) {
            if (overwrite) {
                resp.setStatus( WebdavStatus.SC_NO_CONTENT );
            }
            else {
                throw new PreconditionViolationException(
                    new ViolatedPrecondition(C_CAN_OVERWRITE, WebdavStatus.SC_FORBIDDEN), segment);
            }
        }
        if (isCollection(sourceUri)) {
            if (isDescendant(collectionNode, sourceNode)) {
                throw new PreconditionViolationException(
                    new ViolatedPrecondition(C_CYCLE_ALLOWED, WebdavStatus.SC_FORBIDDEN), sourceUri);
            }
        }
    }
View Full Code Here

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

            structure.removeBinding( slideToken, sourceParentNode, sourceSegment );
        }
        catch (CrossServerBindingException e) {
            sendPreconditionViolation(
                new PreconditionViolationException(
                                         new ViolatedPrecondition(C_CROSS_SERVER_BINDING, WebdavStatus.SC_FORBIDDEN),
                                         collectionNode.getUri()
                                     )
            );
        }
        catch (ObjectLockedException e) {
            ViolatedPrecondition violatedPrecondition;
            if (collectionUri.equals(e.getObjectUri())) {
                violatedPrecondition =
                    new ViolatedPrecondition(C_LOCKED_UPDATE_ALLOWED, WebdavStatus.SC_LOCKED);
            }
            else if (sourceParentUri.equals(e.getObjectUri())) {
                violatedPrecondition =
                    new ViolatedPrecondition(C_LOCKED_SOURCE_COLLECTION_UPDATE_ALLOWED, WebdavStatus.SC_CONFLICT);
            }
            else if (sourceUri.equals(e.getObjectUri())) {
                violatedPrecondition =
                    new ViolatedPrecondition(C_PROTECTED_SOURCE_URL_DELETION_ALLOWED, WebdavStatus.SC_CONFLICT);
            }
            else {
                violatedPrecondition =
                    new ViolatedPrecondition(C_PROTECTED_URL_MODIFICATION_ALLOWED, WebdavStatus.SC_CONFLICT);
            }
            sendPreconditionViolation(
                new PreconditionViolationException(violatedPrecondition, collectionNode.getUri())
            );
        }
View Full Code Here

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

        if (childrenList.size() == 0) {
            return;
        }
        else if (childrenList.size() > 1) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("at-most-one-prop-element",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         "the DAV:version-tree element must contain at most one DAV:prop element"),
                resourcePath
            );
        }
       
        Element propElm = (Element)childrenList.get(0);
        try {
            requestedProperties = new RequestedPropertiesImpl(propElm);
        }
        catch (PropertyParseException e) {
            throw new PreconditionViolationException(
                new ViolatedPrecondition("invalid-prop-element",
                                         WebdavStatus.SC_BAD_REQUEST,
                                         e.getMessage()),
                resourcePath
            );
        }
View Full Code Here

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

     * @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

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

     * @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

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

                ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, resourcePath, revisionDescriptor);
               
                versioningHelper.isWriteLocked(slideToken, revisionDescriptors);
               
                // check preconditions
                ViolatedPrecondition violatedPrecondition = getPreconditionViolation(revisionDescriptors, revisionDescriptor, resourceKind);
                if (violatedPrecondition != null) {
                    throw new PreconditionViolationException(violatedPrecondition, resourcePath);
                }
               
                // Changed for DeltaV --start--
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.