Search in sources :

Example 1 with PropertyManager

use of org.apache.jackrabbit.server.io.PropertyManager 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)

Aggregations

IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 CopyMoveHandler (org.apache.jackrabbit.server.io.CopyMoveHandler)1 CopyMoveManager (org.apache.jackrabbit.server.io.CopyMoveManager)1 DefaultIOManager (org.apache.jackrabbit.server.io.DefaultIOManager)1 IOHandler (org.apache.jackrabbit.server.io.IOHandler)1 IOManager (org.apache.jackrabbit.server.io.IOManager)1 PropertyHandler (org.apache.jackrabbit.server.io.PropertyHandler)1 PropertyManager (org.apache.jackrabbit.server.io.PropertyManager)1 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1