Project

Profile

Help

Support #3237 » PseudoXMLReader.java

Aniruddha Joag, 2017-06-01 16:53

 
package test.saxon.streaming.transformerhandler;

import org.xml.sax.*;
import org.xml.sax.helpers.XMLFilterImpl;

import java.io.IOException;
import java.util.Objects;
import java.util.function.Consumer;

public class PseudoXMLReader extends XMLFilterImpl
{
private final Consumer<ContentHandler> runMainTransform;
public PseudoXMLReader(Consumer<ContentHandler> runMainTransform)
{
this.runMainTransform = runMainTransform;
}

private ContentHandler contentHandler;
@Override
public ContentHandler getContentHandler()
{
return contentHandler;
}

@Override
public void setContentHandler(ContentHandler handler)
{
System.out.println("PseudoXMLReader -> setContentHandler. handler = " + handler.getClass().getName());
contentHandler = handler;
}

@Override
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException
{
// super.setFeature(name, value);
}

@Override
public void parse(InputSource input) throws SAXException, IOException
{
parseImpl();
}

@Override
public void parse(String systemId) throws SAXException, IOException
{
parseImpl();
}

private void parseImpl()
{
System.out.println("PseudoXMLReader -> parseImpl(). The (next chained) transformer has called parse. Will call main transform : runMainTransform");
runMainTransform.accept(contentHandler);
}
}
(10-10/15)