Example usage for org.xml.sax ContentHandler ignorableWhitespace

List of usage examples for org.xml.sax ContentHandler ignorableWhitespace

Introduction

In this page you can find the example usage for org.xml.sax ContentHandler ignorableWhitespace.

Prototype

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

Source Link

Document

Receive notification of ignorable whitespace in element content.

Usage

From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.XSLTEntityHandler.java

public void parseToSAX(final String toRender, final ContentHandler ch) throws IOException, SAXException {
    /**/*from w w w .j av a2  s .  c om*/
     * create a proxy for the stream, filtering out the start element and
     * end element events
     */
    ContentHandler proxy = new ContentHandler() {
        public void setDocumentLocator(Locator arg0) {
            ch.setDocumentLocator(arg0);
        }

        public void startDocument() throws SAXException {
            // ignore
        }

        public void endDocument() throws SAXException {
            // ignore
        }

        public void startPrefixMapping(String arg0, String arg1) throws SAXException {
            ch.startPrefixMapping(arg0, arg1);
        }

        public void endPrefixMapping(String arg0) throws SAXException {
            ch.endPrefixMapping(arg0);
        }

        public void startElement(String arg0, String arg1, String arg2, Attributes arg3) throws SAXException {
            ch.startElement(arg0, arg1, arg2, arg3);
        }

        public void endElement(String arg0, String arg1, String arg2) throws SAXException {
            ch.endElement(arg0, arg1, arg2);
        }

        public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
            ch.characters(arg0, arg1, arg2);
        }

        public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException {
            ch.ignorableWhitespace(arg0, arg1, arg2);
        }

        public void processingInstruction(String arg0, String arg1) throws SAXException {
            ch.processingInstruction(arg0, arg1);
        }

        public void skippedEntity(String arg0) throws SAXException {
            ch.skippedEntity(arg0);
        }

    };
    InputSource ins = new InputSource(new StringReader(toRender));
    XMLReader xmlReader;
    try {
        SAXParser saxParser = saxParserFactory.newSAXParser();

        xmlReader = saxParser.getXMLReader();
    }

    catch (Exception e) {
        log.error("SAXException when creating XMLReader", e); //$NON-NLS-1$
        // rethrow!!
        throw new SAXException(e);
    }
    xmlReader.setContentHandler(proxy);
    xmlReader.parse(ins);
}