Search in sources :

Example 1 with ElementIterator

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

the class ResourceConfig method parseNamespacesEntry.

private void parseNamespacesEntry(Element parent) {
    Element namespaces = DomUtil.getChildElement(parent, "namespaces", null);
    if (namespaces != null) {
        List<String> l = new ArrayList<String>();
        // retrieve prefix child elements
        ElementIterator it = DomUtil.getChildren(namespaces, "prefix", null);
        while (it.hasNext()) {
            Element e = it.nextElement();
            l.add(DomUtil.getText(e));
        }
        String[] prefixes = l.toArray(new String[l.size()]);
        l.clear();
        // retrieve uri child elements
        it = DomUtil.getChildren(namespaces, "uri", null);
        while (it.hasNext()) {
            Element e = it.nextElement();
            l.add(DomUtil.getText(e));
        }
        String[] uris = l.toArray(new String[l.size()]);
        itemFilter.setFilteredPrefixes(prefixes);
        itemFilter.setFilteredURIs(uris);
    }
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 2 with ElementIterator

use of org.apache.jackrabbit.webdav.xml.ElementIterator 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 3 with ElementIterator

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

the class ExpandPropertyReport method getResponse.

/**
 * Builds a <code>MultiStatusResponse</code> for the given resource respecting
 * the properties specified. Any property that represents a {@link HrefProperty}
 * is expanded: It's name equals the name of a valid {@link HrefProperty}.
 * However the value of that given property (consisting of one or multiple DAV:href elements)
 * is replaced by the Xml representation of a separate
 * {@link MultiStatusResponse multistatus responses} for the
 * resource referenced by the given DAV:href elements. The responses may
 * themselves have properties, which are defined by the separate list.
 *
 * @param res
 * @param propertyElements
 * @return <code>MultiStatusResponse</code> for the given resource.
 * @see ExpandProperty
 */
private MultiStatusResponse getResponse(DavResource res, Iterator<Element> propertyElements) {
    MultiStatusResponse resp = new MultiStatusResponse(res.getHref(), null);
    while (propertyElements.hasNext()) {
        Element propertyElem = propertyElements.next();
        // retrieve the localName present in the "name" attribute
        String nameAttr = propertyElem.getAttribute(ATTR_NAME);
        if (nameAttr == null || "".equals(nameAttr)) {
            // NOTE: this is not valid according to the DTD
            continue;
        }
        // retrieve the namespace present in the "namespace" attribute
        // NOTE: if this attribute is missing the DAV: namespace represents the default.
        String namespaceAttr = propertyElem.getAttribute(ATTR_NAMESPACE);
        Namespace namespace = (namespaceAttr != null) ? Namespace.getNamespace(namespaceAttr) : NAMESPACE;
        DavPropertyName propName = DavPropertyName.create(nameAttr, namespace);
        DavProperty<?> p = res.getProperty(propName);
        if (p != null) {
            if (p instanceof HrefProperty && res instanceof DeltaVResource) {
                ElementIterator it = DomUtil.getChildren(propertyElem, XML_PROPERTY, NAMESPACE);
                resp.add(new ExpandProperty((DeltaVResource) res, (HrefProperty) p, it));
            } else {
                resp.add(p);
            }
        } else {
            resp.add(propName, DavServletResponse.SC_NOT_FOUND);
        }
    }
    return resp;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DeltaVResource(org.apache.jackrabbit.webdav.version.DeltaVResource) Namespace(org.apache.jackrabbit.webdav.xml.Namespace) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 4 with ElementIterator

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

the class LocateByHistoryReport method setInfo.

/**
 * Set the <code>ReportInfo</code>
 *
 * @param info
 * @throws DavException if the given <code>ReportInfo</code>
 * does not contain a DAV:version-tree element.
 */
private void setInfo(ReportInfo info) throws DavException {
    if (info == null || !getType().isRequestedReportType(info)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:locate-by-history element expected.");
    }
    Element versionHistorySet = info.getContentElement(XML_VERSION_HISTORY_SET, NAMESPACE);
    if (versionHistorySet == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "The DAV:locate-by-history element must contain a DAV:version-history-set child.");
    }
    ElementIterator it = DomUtil.getChildren(versionHistorySet, DavConstants.XML_HREF, DavConstants.NAMESPACE);
    while (it.hasNext()) {
        String href = DomUtil.getText(it.nextElement());
        if (href != null) {
            vhHrefSet.add(href);
        }
    }
    this.info = info;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Example 5 with ElementIterator

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

the class OptionsResponse method createFromXml.

/**
 * Build a new <code>OptionsResponse</code> object from the given xml element.
 *
 * @param orElem
 * @return a new <code>OptionsResponse</code> object
 * @throws IllegalArgumentException if the specified element is <code>null</code>
 * or if its name is other than 'DAV:options-response'.
 */
public static OptionsResponse createFromXml(Element orElem) {
    if (!DomUtil.matches(orElem, XML_OPTIONS_RESPONSE, NAMESPACE)) {
        throw new IllegalArgumentException("DAV:options-response element expected");
    }
    OptionsResponse oResponse = new OptionsResponse();
    ElementIterator it = DomUtil.getChildren(orElem);
    while (it.hasNext()) {
        Element el = it.nextElement();
        List<String> hrefs = new ArrayList<String>();
        ElementIterator hrefIt = DomUtil.getChildren(el, DavConstants.XML_HREF, DavConstants.NAMESPACE);
        while (hrefIt.hasNext()) {
            hrefs.add(DomUtil.getTextTrim(hrefIt.nextElement()));
        }
        oResponse.addEntry(el.getLocalName(), DomUtil.getNamespace(el), hrefs.toArray(new String[hrefs.size()]));
    }
    return oResponse;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) 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