Search in sources :

Example 51 with DavException

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

the class OptionsInfo method createFromXml.

/**
     * Build an <code>OptionsInfo</code> object from the root element present
     * in the request body.
     *
     * @param optionsElement
     * @return
     * @throws DavException if the optionsElement is <code>null</code>
     * or not a DAV:options element.
     */
public static OptionsInfo createFromXml(Element optionsElement) throws DavException {
    if (!DomUtil.matches(optionsElement, DeltaVConstants.XML_OPTIONS, DeltaVConstants.NAMESPACE)) {
        log.warn("DAV:options element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    OptionsInfo oInfo = new OptionsInfo();
    ElementIterator it = DomUtil.getChildren(optionsElement);
    while (it.hasNext()) {
        // todo: not correct since assuming its the deltaV-namespace
        oInfo.entriesLocalNames.add(it.nextElement().getLocalName());
    }
    return oInfo;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException)

Example 52 with DavException

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

the class PrincipalSearchReport method init.

/**
     * @see Report#init(DavResource, ReportInfo)
     */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    super.init(resource, info);
    // make sure the request body contains all mandatory elements
    if (!info.containsContentElement(XML_PROPERTY_SEARCH, SecurityConstants.NAMESPACE)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Request body must contain at least a single DAV:property-search element.");
    }
    List<Element> psElements = info.getContentElements(XML_PROPERTY_SEARCH, SecurityConstants.NAMESPACE);
    searchArguments = new SearchArgument[psElements.size()];
    int i = 0;
    for (Element psElement : psElements) {
        searchArguments[i++] = new SearchArgument(psElement);
    }
    if (info.containsContentElement(XML_APPLY_TO_PRINCIPAL_COLLECTION_SET, SecurityConstants.NAMESPACE)) {
        HrefProperty p = new HrefProperty(resource.getProperty(SecurityConstants.PRINCIPAL_COLLECTION_SET));
        searchRoots = p.getHrefs().toArray(new String[0]);
    } else {
        searchRoots = new String[] { resource.getHref() };
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Example 53 with DavException

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

the class AbstractWebdavServlet method doAcl.

/**
     * The ACL method
     *
     * @param request
     * @param response
     * @param resource
     * @throws DavException
     * @throws IOException
     */
protected void doAcl(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException {
    if (!(resource instanceof AclResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    Document doc = request.getRequestDocument();
    if (doc == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body.");
    }
    AclProperty acl = AclProperty.createFromXml(doc.getDocumentElement());
    ((AclResource) resource).alterAcl(acl);
}
Also used : AclProperty(org.apache.jackrabbit.webdav.security.AclProperty) AclResource(org.apache.jackrabbit.webdav.security.AclResource) DavException(org.apache.jackrabbit.webdav.DavException) Document(org.w3c.dom.Document)

Example 54 with DavException

use of org.apache.jackrabbit.webdav.DavException 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 55 with DavException

use of org.apache.jackrabbit.webdav.DavException 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)

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