Search in sources :

Example 21 with ElementIterator

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

the class ResourceConfig method parse.

/**
 * Parses the given input stream into the xml configuration file.
 * The xml must match the following structure:<br>
 * <pre>
 * &lt;!ELEMENT config (iomanager, propertymanager, (collection | noncollection)?, filter?, mimetypeproperties?) &gt;
 * &lt;!ELEMENT iomanager (class, iohandler*) &gt;
 * &lt;!ELEMENT iohandler (class) &gt;
 * &lt;!ELEMENT propertymanager (class, propertyhandler*) &gt;
 * &lt;!ELEMENT propertyhandler (class) &gt;
 * &lt;!ELEMENT collection (nodetypes) &gt;
 * &lt;!ELEMENT noncollection (nodetypes) &gt;
 * &lt;!ELEMENT filter (class, namespaces?, nodetypes?) &gt;
 * &lt;!ELEMENT class &gt;
 *    &lt;!ATTLIST class
 *      name  CDATA #REQUIRED
 *    &gt;
 * &lt;!ELEMENT namespaces (prefix|uri)* &gt;
 * &lt;!ELEMENT prefix (CDATA) &gt;
 * &lt;!ELEMENT uri (CDATA) &gt;
 * &lt;!ELEMENT nodetypes (nodetype)* &gt;
 * &lt;!ELEMENT nodetype (CDATA) &gt;
 * &lt;!ELEMENT mimetypeproperties (mimemapping*, defaultmimetype) &gt;
 * &lt;!ELEMENT mimemapping &gt;
 *    &lt;!ATTLIST mimemapping
 *      extension  CDATA #REQUIRED
 *      mimetype  CDATA #REQUIRED
 *    &gt;
 * &lt;!ELEMENT defaultmimetype (CDATA) &gt;
 * </pre>
 * <p>
 * The &lt;mimetypeproperties/&gt; settings have been deprecated and will
 * be ignored with a warning. Instead you can use the
 * {@link SimpleWebdavServlet#INIT_PARAM_MIME_INFO mime-info}
 * servlet initialization parameter to customize the media type settings.
 *
 * @param stream
 */
public void parse(InputStream stream) {
    try {
        Element config = DomUtil.parseDocument(stream).getDocumentElement();
        if (config == null) {
            log.warn("Mandatory 'config' element is missing.");
            return;
        }
        // iomanager config entry
        Element el = DomUtil.getChildElement(config, ELEMENT_IOMANAGER, null);
        if (el != null) {
            Object inst = buildClassFromConfig(el);
            if (inst != null && inst instanceof IOManager) {
                ioManager = (IOManager) inst;
                ioManager.setDetector(detector);
                // get optional 'iohandler' child elements and populate the
                // ioManager with the instances
                ElementIterator iohElements = DomUtil.getChildren(el, ELEMENT_IOHANDLER, null);
                while (iohElements.hasNext()) {
                    Element iohEl = iohElements.nextElement();
                    inst = buildClassFromConfig(iohEl);
                    if (inst != null && inst instanceof IOHandler) {
                        IOHandler handler = (IOHandler) inst;
                        setParameters(handler, iohEl);
                        ioManager.addIOHandler(handler);
                    } else {
                        log.warn("Not a valid IOHandler : " + getClassName(iohEl));
                    }
                }
            } else {
                log.warn("'iomanager' element does not define a valid IOManager.");
            }
        } else {
            log.warn("'iomanager' element is missing.");
        }
        // propertymanager config entry
        el = DomUtil.getChildElement(config, ELEMENT_PROPERTYMANAGER, null);
        if (el != null) {
            Object inst = buildClassFromConfig(el);
            if (inst != null && inst instanceof PropertyManager) {
                propManager = (PropertyManager) inst;
                // get optional 'iohandler' child elements and populate the
                // ioManager with the instances
                ElementIterator iohElements = DomUtil.getChildren(el, ELEMENT_PROPERTYHANDLER, null);
                while (iohElements.hasNext()) {
                    Element iohEl = iohElements.nextElement();
                    inst = buildClassFromConfig(iohEl);
                    if (inst != null && inst instanceof PropertyHandler) {
                        PropertyHandler handler = (PropertyHandler) inst;
                        setParameters(handler, iohEl);
                        propManager.addPropertyHandler(handler);
                    } else {
                        log.warn("Not a valid PropertyHandler : " + getClassName(iohEl));
                    }
                }
            } else {
                log.warn("'propertymanager' element does not define a valid PropertyManager.");
            }
        } else {
            log.debug("'propertymanager' element is missing.");
        }
        // copymovemanager config entry
        el = DomUtil.getChildElement(config, ELEMENT_COPYMOVEMANAGER, null);
        if (el != null) {
            Object inst = buildClassFromConfig(el);
            if (inst != null && inst instanceof CopyMoveManager) {
                cmManager = (CopyMoveManager) inst;
                // get optional 'copymovehandler' child elements and populate
                // the copy move manager with the instances
                ElementIterator iohElements = DomUtil.getChildren(el, ELEMENT_COPYMOVEHANDLER, null);
                while (iohElements.hasNext()) {
                    Element iohEl = iohElements.nextElement();
                    inst = buildClassFromConfig(iohEl);
                    if (inst != null && inst instanceof CopyMoveHandler) {
                        CopyMoveHandler handler = (CopyMoveHandler) inst;
                        setParameters(handler, iohEl);
                        cmManager.addCopyMoveHandler(handler);
                    } else {
                        log.warn("Not a valid CopyMoveHandler : " + getClassName(iohEl));
                    }
                }
            } else {
                log.warn("'copymovemanager' element does not define a valid CopyMoveManager.");
            }
        } else {
            log.debug("'copymovemanager' element is missing.");
        }
        // collection/non-collection config entry
        el = DomUtil.getChildElement(config, "collection", null);
        if (el != null) {
            nodetypeNames = parseNodeTypesEntry(el);
            collectionNames = true;
        } else if ((el = DomUtil.getChildElement(config, "noncollection", null)) != null) {
            nodetypeNames = parseNodeTypesEntry(el);
            collectionNames = false;
        }
        // todo: should check if both 'noncollection' and 'collection' are present and write a warning
        // filter config entry
        el = DomUtil.getChildElement(config, "filter", null);
        if (el != null) {
            Object inst = buildClassFromConfig(el);
            if (inst != null && inst instanceof ItemFilter) {
                itemFilter = (ItemFilter) inst;
            }
            if (itemFilter != null) {
                itemFilter.setFilteredNodetypes(parseNodeTypesEntry(el));
                parseNamespacesEntry(el);
            }
        } else {
            log.debug("No 'filter' element specified.");
        }
        el = DomUtil.getChildElement(config, "mimetypeproperties", null);
        if (el != null) {
            log.warn("Ignoring deprecated mimetypeproperties settings");
        }
    } catch (IOException e) {
        log.debug("Invalid resource configuration: " + e.getMessage());
    } catch (ParserConfigurationException e) {
        log.warn("Failed to parse resource configuration: " + e.getMessage());
    } catch (SAXException e) {
        log.warn("Failed to parse resource configuration: " + e.getMessage());
    }
}
Also used : IOHandler(org.apache.jackrabbit.server.io.IOHandler) ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) CopyMoveManager(org.apache.jackrabbit.server.io.CopyMoveManager) DefaultIOManager(org.apache.jackrabbit.server.io.DefaultIOManager) IOManager(org.apache.jackrabbit.server.io.IOManager) PropertyManager(org.apache.jackrabbit.server.io.PropertyManager) Element(org.w3c.dom.Element) IOException(java.io.IOException) CopyMoveHandler(org.apache.jackrabbit.server.io.CopyMoveHandler) SAXException(org.xml.sax.SAXException) PropertyHandler(org.apache.jackrabbit.server.io.PropertyHandler) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 22 with ElementIterator

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

the class ResourceConfig method parseNodeTypesEntry.

private static String[] parseNodeTypesEntry(Element parent) {
    String[] ntNames;
    Element nodetypes = DomUtil.getChildElement(parent, "nodetypes", null);
    if (nodetypes != null) {
        List<String> l = new ArrayList<String>();
        ElementIterator it = DomUtil.getChildren(nodetypes, "nodetype", null);
        while (it.hasNext()) {
            Element e = it.nextElement();
            l.add(DomUtil.getText(e));
        }
        ntNames = l.toArray(new String[l.size()]);
    } else {
        ntNames = new String[0];
    }
    return ntNames;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 23 with ElementIterator

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

the class EventImpl method getEventInfo.

private static Map<Name, QValue> getEventInfo(Element infoElement, NamePathResolver resolver, QValueFactory qvFactory) {
    if (infoElement == null) {
        return Collections.emptyMap();
    }
    Map<Name, QValue> info = new HashMap<Name, QValue>();
    ElementIterator it = DomUtil.getChildren(infoElement);
    while (it.hasNext()) {
        Element el = it.nextElement();
        String uri = el.getNamespaceURI();
        if (uri == null) {
            uri = Namespace.EMPTY_NAMESPACE.getURI();
        }
        String localName = el.getLocalName();
        String value = DomUtil.getTextTrim(el);
        try {
            Name n = N_FACTORY.create(uri, localName);
            QValue qv = null;
            if (value != null) {
                qv = ValueFormat.getQValue(value, PropertyType.PATH, resolver, qvFactory);
            }
            info.put(n, qv);
        } catch (RepositoryException e) {
            log.error("Internal Error: {}", e.getMessage());
        }
    }
    return info;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) QValue(org.apache.jackrabbit.spi.QValue) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 24 with ElementIterator

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

the class DefinitionUtil method createQNodeTypeDefinition.

static QNodeTypeDefinition createQNodeTypeDefinition(Element ntdElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
    QNodeTypeDefinitionBuilder builder = new QNodeTypeDefinitionBuilder();
    // NOTE: the server should send the namespace-mappings as addition ns-defininitions
    try {
        if (ntdElement.hasAttribute(NAME_ATTRIBUTE)) {
            builder.setName(resolver.getQName(ntdElement.getAttribute(NAME_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(PRIMARYITEMNAME_ATTRIBUTE)) {
            builder.setPrimaryItemName(resolver.getQName(ntdElement.getAttribute(PRIMARYITEMNAME_ATTRIBUTE)));
        }
        Element child = DomUtil.getChildElement(ntdElement, SUPERTYPES_ELEMENT, null);
        if (child != null) {
            ElementIterator stIter = DomUtil.getChildren(child, SUPERTYPE_ELEMENT, null);
            List<Name> qNames = new ArrayList<Name>();
            while (stIter.hasNext()) {
                Name st = resolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
                qNames.add(st);
            }
            builder.setSupertypes(qNames.toArray(new Name[qNames.size()]));
        }
        if (ntdElement.hasAttribute(ISMIXIN_ATTRIBUTE)) {
            builder.setMixin(Boolean.valueOf(ntdElement.getAttribute(ISMIXIN_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)) {
            builder.setOrderableChildNodes(Boolean.valueOf(ntdElement.getAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(ISABSTRACT_ATTRIBUTE)) {
            builder.setAbstract(Boolean.valueOf(ntdElement.getAttribute(ISABSTRACT_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(ISQUERYABLE_ATTRIBUTE)) {
            builder.setQueryable(Boolean.valueOf(ntdElement.getAttribute(ISQUERYABLE_ATTRIBUTE)));
        }
        // nodeDefinitions
        ElementIterator it = DomUtil.getChildren(ntdElement, CHILDNODEDEFINITION_ELEMENT, null);
        List<QNodeDefinition> nds = new ArrayList<QNodeDefinition>();
        while (it.hasNext()) {
            nds.add(createQNodeDefinition(builder.getName(), it.nextElement(), resolver));
        }
        builder.setChildNodeDefs(nds.toArray(new QNodeDefinition[nds.size()]));
        // propertyDefinitions
        it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
        List<QPropertyDefinition> pds = new ArrayList<QPropertyDefinition>();
        while (it.hasNext()) {
            pds.add(createQPropertyDefinition(builder.getName(), it.nextElement(), resolver, qValueFactory));
        }
        builder.setPropertyDefs(pds.toArray(new QPropertyDefinition[pds.size()]));
    } catch (NameException e) {
        log.error(e.getMessage());
        throw new RepositoryException(e);
    }
    return builder.build();
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Element(org.w3c.dom.Element) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder) Name(org.apache.jackrabbit.spi.Name)

Example 25 with ElementIterator

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

the class DefinitionUtil method createQNodeDefinition.

/**
 * @param declaringNodeType
 * @param ndefElement
 * @param resolver
 * @return
 * @throws RepositoryException
 */
static QNodeDefinition createQNodeDefinition(Name declaringNodeType, Element ndefElement, NamePathResolver resolver) throws RepositoryException {
    QNodeDefinitionBuilder builder = new QNodeDefinitionBuilder();
    buildQItemDefinition(declaringNodeType, ndefElement, resolver, builder);
    // NOTE: the server should send the namespace-mappings as addition ns-defininitions
    try {
        if (ndefElement.hasAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE)) {
            Name defaultPrimaryType = resolver.getQName(ndefElement.getAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE));
            builder.setDefaultPrimaryType(defaultPrimaryType);
        }
        Element reqPrimaryTypes = DomUtil.getChildElement(ndefElement, REQUIREDPRIMARYTYPES_ELEMENT, null);
        if (reqPrimaryTypes != null) {
            ElementIterator it = DomUtil.getChildren(reqPrimaryTypes, REQUIREDPRIMARYTYPE_ELEMENT, null);
            while (it.hasNext()) {
                builder.addRequiredPrimaryType(resolver.getQName(DomUtil.getTextTrim(it.nextElement())));
            }
        } else {
            builder.addRequiredPrimaryType(NameConstants.NT_BASE);
        }
        if (ndefElement.hasAttribute(SAMENAMESIBLINGS_ATTRIBUTE)) {
            builder.setAllowsSameNameSiblings(Boolean.valueOf(ndefElement.getAttribute(SAMENAMESIBLINGS_ATTRIBUTE)));
        }
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
    return builder.build();
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

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