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

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

Introduction

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

Prototype

public ContentHandler getCustomContentHandler() 

Source Link

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();
    }/*  ww  w  .j av a2 s .  c o m*/

    // 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);
    }
}