jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting" <jukka.zitt...@gmail.com>
Subject Re: Session.importXml - how to monitor progress
Date Wed, 29 Aug 2007 18:43:28 GMT
Hi,

On 8/29/07, Amir Mistric <amistric@nemours.org> wrote:
> Is there an example of this "decoration" anywhere?
> I assume SAX does not come with ability to just add decorator handlers does it?

Using the helper base class given below, you could do something like this:

    ContentHandler handler = new ContentHandlerDecorator(
            session.getImportContentHandler(...)) {
        private int elements = 0;
        void endElement(String uri, String local, String name)
                throws SAXException {
            super.endElement(uri, local, name);
            if (++elements % 100 == 0) {
                System.out.println(elements + " XML elements processed.");
            }
        }
    }

BR,

Jukka Zitting

----

import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

public class ContentHandlerDecorator implements ContentHandler {

    private final ContentHandler handler;

    public ContentHandlerDecorator(ContentHandler handler) {
        this.handler = handler;
    }

    public void characters(char[] ch, int start, int length)
            throws SAXException {
        handler.characters(ch, start, length);
    }

    public void endDocument() throws SAXException {
        handler.endDocument();
    }

    public void endElement(String uri, String localName, String name)
            throws SAXException {
        handler.endElement(uri, localName, name);
    }

    public void endPrefixMapping(String prefix) throws SAXException {
        handler.endPrefixMapping(prefix);
    }

    public void ignorableWhitespace(char[] ch, int start, int length)
            throws SAXException {
        handler.ignorableWhitespace(ch, start, length);
    }

    public void processingInstruction(String target, String data)
            throws SAXException {
        handler.processingInstruction(target, data);
    }

    public void setDocumentLocator(Locator locator) {
        handler.setDocumentLocator(locator);
    }

    public void skippedEntity(String name) throws SAXException {
        handler.skippedEntity(name);
    }

    public void startDocument() throws SAXException {
        handler.startDocument();
    }

    public void startElement(String uri, String localName, String name,
            Attributes atts) throws SAXException {
        handler.startElement(uri, localName, name, atts);
    }

    public void startPrefixMapping(String prefix, String uri)
            throws SAXException {
        handler.startPrefixMapping(prefix, uri);
    }

}

Mime
View raw message