Example usage for org.apache.commons.digester Digester setCustomContentHandler

List of usage examples for org.apache.commons.digester Digester setCustomContentHandler

Introduction

In this page you can find the example usage for org.apache.commons.digester Digester setCustomContentHandler.

Prototype

public void setCustomContentHandler(ContentHandler handler) 

Source Link

Document

Redirects (or cancels redirecting) of SAX ContentHandler events to an external object.

Usage

From source file:org.xchain.framework.digester.SerializationRule.java

public void begin(String namespaceUri, String name, Attributes attributes) throws Exception {
    // get the digester.
    Digester digester = getDigester();

    // store the old content handlers.
    oldCustomContentHandler = digester.getCustomContentHandler();
    if (digester instanceof ExtendedDigester) {
        oldCustomLexicalHandler = ((ExtendedDigester) digester).getCustomLexicalHandler();
    }/* w  ww  .ja  v a  2s  .  c  om*/

    // create the handler.
    handler = new RuleSerializationHandler();

    // set up the handlers that will do the serialization.
    handler.setWrappedHandler(newHandler());

    // set the new handlers.
    digester.setCustomContentHandler(handler);
    if (digester instanceof ExtendedDigester) {
        ((ExtendedDigester) digester).setCustomLexicalHandler(handler);
    }

    // push the buffer onto the stack.
    digester.push(buffer);

    // start the document.
    handler.startDocument();

    // set all of the namespaces that are defined on the digester.
    Iterator currentNamespaceIterator = digester.getCurrentNamespaces().entrySet().iterator();
    while (currentNamespaceIterator.hasNext()) {
        Map.Entry currentNamespace = (Map.Entry) currentNamespaceIterator.next();
        handler.startPrefixMapping((String) currentNamespace.getKey(), (String) currentNamespace.getValue());
    }

    // send the current element to the handler.
    if (digester.getNamespaceAware()) {
        handler.startElement(namespaceUri, name, digester.getCurrentElementName(), attributes);
    } else {
        handler.startElement(namespaceUri, name, name, attributes);
    }
}