Search in sources :

Example 61 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class SupportedPrivilege method getSupportedPrivilege.

/**
     * Factory method to create/retrieve a <code>SupportedPrivilege</code> from the given
     * DAV:privilege element.
     *
     * @param privilege
     * @return
     */
static SupportedPrivilege getSupportedPrivilege(Element supportedPrivilege) throws DavException {
    if (!DomUtil.matches(supportedPrivilege, XML_SUPPORTED_PRIVILEGE, SecurityConstants.NAMESPACE)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:supported-privilege element expected.");
    }
    boolean isAbstract = false;
    Privilege privilege = null;
    String description = null;
    String descriptionLanguage = null;
    List<SupportedPrivilege> sp = new ArrayList<SupportedPrivilege>();
    ElementIterator children = DomUtil.getChildren(supportedPrivilege);
    while (children.hasNext()) {
        Element child = children.next();
        if (child.getLocalName().equals(XML_ABSTRACT)) {
            isAbstract = true;
        } else if (child.getLocalName().equals(Privilege.XML_PRIVILEGE)) {
            privilege = Privilege.getPrivilege(child);
        } else if (child.getLocalName().equals(XML_DESCRIPTION)) {
            description = child.getLocalName();
            if (child.hasAttribute(descriptionLanguage)) {
                descriptionLanguage = child.getAttribute(descriptionLanguage);
            }
        } else if (child.getLocalName().equals(XML_SUPPORTED_PRIVILEGE)) {
            sp.add(getSupportedPrivilege(child));
        }
    }
    return new SupportedPrivilege(privilege, description, descriptionLanguage, isAbstract, sp.toArray(new SupportedPrivilege[sp.size()]));
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 62 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class BindInfo method createFromXml.

/**
     * Build an <code>BindInfo</code> object from the root element present
     * in the request body.
     *
     * @param root the root element of the request body
     * @return a BindInfo object containing segment and href
     * @throws org.apache.jackrabbit.webdav.DavException if the BIND request is malformed
     */
public static BindInfo createFromXml(Element root) throws DavException {
    if (!DomUtil.matches(root, BindConstants.XML_BIND, BindConstants.NAMESPACE)) {
        log.warn("DAV:bind element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    String href = null;
    String segment = null;
    ElementIterator it = DomUtil.getChildren(root);
    while (it.hasNext()) {
        Element elt = it.nextElement();
        if (DomUtil.matches(elt, BindConstants.XML_SEGMENT, BindConstants.NAMESPACE)) {
            if (segment == null) {
                segment = DomUtil.getText(elt);
            } else {
                log.warn("unexpected multiple occurrence of DAV:segment element");
                throw new DavException(DavServletResponse.SC_BAD_REQUEST);
            }
        } else if (DomUtil.matches(elt, BindConstants.XML_HREF, BindConstants.NAMESPACE)) {
            if (href == null) {
                href = DomUtil.getText(elt);
            } else {
                log.warn("unexpected multiple occurrence of DAV:href element");
                throw new DavException(DavServletResponse.SC_BAD_REQUEST);
            }
        } else {
            log.warn("unexpected element " + elt.getLocalName());
            throw new DavException(DavServletResponse.SC_BAD_REQUEST);
        }
    }
    if (href == null) {
        log.warn("DAV:href element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    if (segment == null) {
        log.warn("DAV:segment element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    return new BindInfo(href, segment);
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Example 63 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class SimpleLockManager method refreshLock.

/**
     *
     * @param lockInfo
     * @param lockToken
     * @param resource
     * @return
     * @throws DavException
     * @see DavResource#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, String)
     */
public ActiveLock refreshLock(LockInfo lockInfo, String lockToken, DavResource resource) throws DavException {
    ActiveLock lock = getLock(lockInfo.getType(), lockInfo.getScope(), resource);
    if (lock == null) {
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
    } else if (!lock.getToken().equals(lockToken)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    lock.setTimeout(lockInfo.getTimeout());
    return lock;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException)

Example 64 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class OrderPatch method createFromXml.

//------------------------------------------------------< static method >---
/**
     * Create a new <code>OrderPath</code> object.
     *
     * @param orderPatchElement
     * @throws IllegalArgumentException if the specified Xml element was not valid.
     */
public static OrderPatch createFromXml(Element orderPatchElement) throws DavException {
    if (!DomUtil.matches(orderPatchElement, XML_ORDERPATCH, NAMESPACE)) {
        log.warn("ORDERPATH request body must start with an 'orderpatch' element.");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    // retrieve the href of the orderingtype element
    String orderingType;
    Element otype = DomUtil.getChildElement(orderPatchElement, XML_ORDERING_TYPE, NAMESPACE);
    if (otype != null) {
        orderingType = DomUtil.getChildText(otype, DavConstants.XML_HREF, DavConstants.NAMESPACE);
    } else {
        log.warn("ORDERPATH request body must contain an 'ordering-type' child element.");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    // set build the list of ordering instructions
    List<Member> tmpList = new ArrayList<Member>();
    ElementIterator it = DomUtil.getChildren(orderPatchElement, XML_ORDER_MEMBER, NAMESPACE);
    while (it.hasNext()) {
        Element el = it.nextElement();
        try {
            // retrieve text 'DAV:segment' child of this DAV:order-member element
            String segment = DomUtil.getChildText(el, XML_SEGMENT, NAMESPACE);
            // retrieve the 'DAV:position' child element
            Position pos = Position.createFromXml(DomUtil.getChildElement(el, XML_POSITION, NAMESPACE));
            Member om = new Member(segment, pos);
            tmpList.add(om);
        } catch (IllegalArgumentException e) {
            log.warn("Invalid element in 'orderpatch' request body: " + e.getMessage());
            throw new DavException(DavServletResponse.SC_BAD_REQUEST);
        }
    }
    Member[] instructions = tmpList.toArray(new Member[tmpList.size()]);
    return new OrderPatch(orderingType, instructions);
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 65 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class WorkspaceResourceImpl method getCollection.

/**
     * Retrieve the collection that has all workspace collections
     * as internal members.
     *
     * @see org.apache.jackrabbit.webdav.DavResource#getCollection()
     */
@Override
public DavResource getCollection() {
    DavResource collection = null;
    // create location with 'null' values for workspace-path and resource-path
    DavResourceLocator parentLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), null, null, false);
    try {
        collection = createResourceFromLocator(parentLoc);
    } catch (DavException e) {
        log.error("Unexpected error while retrieving collection: " + e.getMessage());
    }
    return collection;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)129 RepositoryException (javax.jcr.RepositoryException)89 IOException (java.io.IOException)51 HttpResponse (org.apache.http.HttpResponse)47 Element (org.w3c.dom.Element)29 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)25 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)25 DavResource (org.apache.jackrabbit.webdav.DavResource)21 ArrayList (java.util.ArrayList)19 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)17 Node (javax.jcr.Node)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)13 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)12 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)12 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)8 Document (org.w3c.dom.Document)8 Session (javax.jcr.Session)7 Version (javax.jcr.version.Version)7