Search in sources :

Example 1 with IOHandler

use of org.apache.jackrabbit.server.io.IOHandler in project jackrabbit by apache.

the class ResourceConfigTest method testIOManagerConfig.

public void testIOManagerConfig() throws Exception {
    InputStream in = new ByteArrayInputStream(CONFIG_1.getBytes("UTF-8"));
    ResourceConfig config = new ResourceConfig(null);
    config.parse(in);
    IOManager ioMgr = config.getIOManager();
    assertNotNull(ioMgr);
    assertEquals("org.apache.jackrabbit.server.io.IOManagerImpl", ioMgr.getClass().getName());
    IOHandler[] handlers = ioMgr.getIOHandlers();
    assertNotNull(handlers);
    assertEquals(1, handlers.length);
    assertEquals("org.apache.jackrabbit.server.io.DefaultHandler", handlers[0].getName());
}
Also used : IOHandler(org.apache.jackrabbit.server.io.IOHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) IOManager(org.apache.jackrabbit.server.io.IOManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 2 with IOHandler

use of org.apache.jackrabbit.server.io.IOHandler in project jackrabbit by apache.

the class ResourceConfigTest method testIOManagerConfigWithParam.

public void testIOManagerConfigWithParam() throws Exception {
    InputStream in = new ByteArrayInputStream(CONFIG_2.getBytes("UTF-8"));
    ResourceConfig config = new ResourceConfig(null);
    config.parse(in);
    IOManager ioMgr = config.getIOManager();
    assertNotNull(ioMgr);
    assertEquals("org.apache.jackrabbit.server.io.IOManagerImpl", ioMgr.getClass().getName());
    IOHandler[] handlers = ioMgr.getIOHandlers();
    assertNotNull(handlers);
    assertEquals(1, handlers.length);
    assertEquals("org.apache.jackrabbit.server.io.DefaultHandler", handlers[0].getName());
    DefaultHandler dh = (DefaultHandler) handlers[0];
    assertEquals("nt:unstructured", dh.getCollectionNodeType());
    assertEquals("nt:unstructured", dh.getNodeType());
    assertEquals("nt:resource", dh.getContentNodeType());
}
Also used : IOHandler(org.apache.jackrabbit.server.io.IOHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) IOManager(org.apache.jackrabbit.server.io.IOManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultHandler(org.apache.jackrabbit.server.io.DefaultHandler)

Example 3 with IOHandler

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

IOHandler (org.apache.jackrabbit.server.io.IOHandler)3 IOManager (org.apache.jackrabbit.server.io.IOManager)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 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 DefaultHandler (org.apache.jackrabbit.server.io.DefaultHandler)1 DefaultIOManager (org.apache.jackrabbit.server.io.DefaultIOManager)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