Search in sources :

Example 11 with ElementIterator

use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.

the class UnbindInfo method createFromXml.

/**
 * Build an <code>UnbindInfo</code> object from the root element present
 * in the request body.
 *
 * @param root the root element of the request body
 * @return a UnbindInfo object containing a segment identifier
 * @throws org.apache.jackrabbit.webdav.DavException if the UNBIND request is malformed
 */
public static UnbindInfo createFromXml(Element root) throws DavException {
    if (!DomUtil.matches(root, BindConstants.XML_UNBIND, BindConstants.NAMESPACE)) {
        log.warn("DAV:unbind element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    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 {
            log.warn("unexpected element " + elt.getLocalName());
            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 UnbindInfo(segment);
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Example 12 with ElementIterator

use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.

the class RebindInfo method createFromXml.

/**
 * Build an <code>RebindInfo</code> object from the root element present
 * in the request body.
 *
 * @param root the root element of the request body
 * @return a RebindInfo object containing segment and href
 * @throws org.apache.jackrabbit.webdav.DavException if the REBIND request is malformed
 */
public static RebindInfo createFromXml(Element root) throws DavException {
    if (!DomUtil.matches(root, BindConstants.XML_REBIND, BindConstants.NAMESPACE)) {
        log.warn("DAV:rebind 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 RebindInfo(href, segment);
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Example 13 with ElementIterator

use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.

the class WebdavRequestImpl method parsePropFindRequest.

/**
 * Parse the propfind request body in order to determine the type of the propfind
 * and the set of requested property.
 * NOTE: An empty 'propfind' request body will be treated as request for all
 * property according to the specification.
 */
private void parsePropFindRequest() throws DavException {
    propfindProps = new DavPropertyNameSet();
    Document requestDocument = getRequestDocument();
    // propfind httpRequest with empty body >> retrieve all property
    if (requestDocument == null) {
        return;
    }
    // propfind httpRequest with invalid body
    Element root = requestDocument.getDocumentElement();
    if (!XML_PROPFIND.equals(root.getLocalName())) {
        log.info("PropFind-Request has no <propfind> tag.");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "PropFind-Request has no <propfind> tag.");
    }
    DavPropertyNameSet include = null;
    ElementIterator it = DomUtil.getChildren(root);
    int propfindTypeFound = 0;
    while (it.hasNext()) {
        Element child = it.nextElement();
        String nodeName = child.getLocalName();
        if (NAMESPACE.getURI().equals(child.getNamespaceURI())) {
            if (XML_PROP.equals(nodeName)) {
                propfindType = PROPFIND_BY_PROPERTY;
                propfindProps = new DavPropertyNameSet(child);
                propfindTypeFound += 1;
            } else if (XML_PROPNAME.equals(nodeName)) {
                propfindType = PROPFIND_PROPERTY_NAMES;
                propfindTypeFound += 1;
            } else if (XML_ALLPROP.equals(nodeName)) {
                propfindType = PROPFIND_ALL_PROP;
                propfindTypeFound += 1;
            } else if (XML_INCLUDE.equals(nodeName)) {
                include = new DavPropertyNameSet();
                ElementIterator pit = DomUtil.getChildren(child);
                while (pit.hasNext()) {
                    include.add(DavPropertyName.createFromXml(pit.nextElement()));
                }
            }
        }
    }
    if (propfindTypeFound > 1) {
        log.info("Multiple top-level propfind instructions");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Multiple top-level propfind instructions");
    }
    if (include != null) {
        if (propfindType == PROPFIND_ALL_PROP) {
            // special case: allprop with include extension
            propfindType = PROPFIND_ALL_PROP_INCLUDE;
            propfindProps = include;
        } else {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "<include> goes only with <allprop>");
        }
    }
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) Element(org.w3c.dom.Element) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) Document(org.w3c.dom.Document)

Example 14 with ElementIterator

use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.

the class MultiStatusResponse method createFromXml.

/**
 * Build a new response object from the given xml element.
 *
 * @param responseElement
 * @return new <code>MultiStatusResponse</code> instance
 * @throws IllegalArgumentException if the specified element is
 * <code>null</code> or not a DAV:response element or if the mandatory
 * DAV:href child is missing.
 */
public static MultiStatusResponse createFromXml(Element responseElement) {
    if (!DomUtil.matches(responseElement, XML_RESPONSE, NAMESPACE)) {
        throw new IllegalArgumentException("DAV:response element required.");
    }
    String href = DomUtil.getChildTextTrim(responseElement, XML_HREF, NAMESPACE);
    if (href == null) {
        throw new IllegalArgumentException("DAV:response element must contain a DAV:href element expected.");
    }
    String statusLine = DomUtil.getChildText(responseElement, XML_STATUS, NAMESPACE);
    String responseDescription = DomUtil.getChildText(responseElement, XML_RESPONSEDESCRIPTION, NAMESPACE);
    MultiStatusResponse response;
    if (statusLine != null) {
        Status status = Status.parse(statusLine);
        response = new MultiStatusResponse(href, status, responseDescription);
    } else {
        response = new MultiStatusResponse(href, responseDescription, TYPE_PROPSTAT);
        // read propstat elements
        ElementIterator it = DomUtil.getChildren(responseElement, XML_PROPSTAT, NAMESPACE);
        while (it.hasNext()) {
            Element propstat = it.nextElement();
            String propstatus = DomUtil.getChildText(propstat, XML_STATUS, NAMESPACE);
            Element prop = DomUtil.getChildElement(propstat, XML_PROP, NAMESPACE);
            if (propstatus != null && prop != null) {
                int statusCode = Status.parse(propstatus).getStatusCode();
                ElementIterator propIt = DomUtil.getChildren(prop);
                while (propIt.hasNext()) {
                    Element el = propIt.nextElement();
                    /*
                        always build dav property from the given element, since
                        distinction between prop-names and properties not having
                        a value is not possible.
                        retrieval of the set of 'property names' is possible from
                        the given prop-set by calling DavPropertySet#getPropertyNameSet()
                        */
                    DavProperty<?> property = DefaultDavProperty.createFromXml(el);
                    response.add(property, statusCode);
                }
            }
        }
    }
    return response;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) Element(org.w3c.dom.Element)

Example 15 with ElementIterator

use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.

the class AclProperty method createFromXml.

/**
 * Build a new <code>AclProperty</code> object from the request body of the
 * ACL method call.
 *
 * @param aclElement
 * @return new <code>AclProperty</code>
 * @throws DavException
 */
public static AclProperty createFromXml(Element aclElement) throws DavException {
    if (!DomUtil.matches(aclElement, SecurityConstants.ACL.getName(), SecurityConstants.ACL.getNamespace())) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body.");
    }
    List<Ace> aces = new ArrayList<Ace>();
    ElementIterator it = DomUtil.getChildren(aclElement, Ace.XML_ACE, SecurityConstants.NAMESPACE);
    while (it.hasNext()) {
        Element aceElem = it.nextElement();
        aces.add(Ace.createFromXml(aceElem));
    }
    return new AclProperty(aces);
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Aggregations

ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)36 Element (org.w3c.dom.Element)34 ArrayList (java.util.ArrayList)17 DavException (org.apache.jackrabbit.webdav.DavException)13 RepositoryException (javax.jcr.RepositoryException)9 Document (org.w3c.dom.Document)7 IOException (java.io.IOException)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 HttpResponse (org.apache.http.HttpResponse)4 SAXException (org.xml.sax.SAXException)4 Name (org.apache.jackrabbit.spi.Name)3 QValue (org.apache.jackrabbit.spi.QValue)3 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)3 HashMap (java.util.HashMap)2 Event (org.apache.jackrabbit.spi.Event)2 EventBundleImpl (org.apache.jackrabbit.spi.commons.EventBundleImpl)2 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1