Project

Profile

Help

Support #3237 » ContentHandlerForwarder.java

Aniruddha Joag, 2017-05-25 17:44

 
package test.saxon.streaming.transformerhandler;

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

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;

public class ContentHandlerForwarder implements ContentHandler
{
private ContentHandler contentHandlerToForwardTo;
public ContentHandlerForwarder(Transformer transformer, StreamResult result) throws TransformerException
{
PseudoXMLReader pseudoXMLReader = new PseudoXMLReader();
SAXSource saxSource = new SAXSource(pseudoXMLReader, null);
System.out.println("ContentHandlerForwarder -> transform");
transformer.transform(saxSource, result);
contentHandlerToForwardTo = pseudoXMLReader.getContentHandler();
}

@Override
public void setDocumentLocator(Locator locator)
{
contentHandlerToForwardTo.setDocumentLocator(locator);
}

@Override
public void startDocument() throws SAXException
{
System.out.println("startDocument()");
contentHandlerToForwardTo.startDocument();
}

@Override
public void endDocument() throws SAXException
{
System.out.println("endDocument()");
contentHandlerToForwardTo.endDocument();
}

@Override
public void startPrefixMapping(String prefix, String uri) throws SAXException
{
contentHandlerToForwardTo.startPrefixMapping(prefix, uri);
}

@Override
public void endPrefixMapping(String prefix) throws SAXException
{
contentHandlerToForwardTo.endPrefixMapping(prefix);
}

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
{
System.out.println("startElement()");
contentHandlerToForwardTo.startElement(uri, localName, qName, atts);
}

@Override
public void endElement(String uri, String localName, String qName) throws SAXException
{
System.out.println("endElement()");
contentHandlerToForwardTo.endElement(uri, localName, qName);
}

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

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

@Override
public void processingInstruction(String target, String data) throws SAXException
{
contentHandlerToForwardTo.processingInstruction(target, data);
}

@Override
public void skippedEntity(String name) throws SAXException
{
contentHandlerToForwardTo.skippedEntity(name);
}
}
(1-1/15)