|
package test.saxon.streaming.transformerhandler;
|
|
|
|
import org.xml.sax.*;
|
|
import org.xml.sax.helpers.AttributesImpl;
|
|
import org.xml.sax.helpers.XMLFilterImpl;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class RowXMLReader extends XMLFilterImpl
|
|
{
|
|
private final int numRows;
|
|
|
|
private ContentHandler contentHandler;
|
|
|
|
public RowXMLReader(int numRows)
|
|
{
|
|
this.numRows = numRows;
|
|
}
|
|
|
|
@Override
|
|
public void setContentHandler(ContentHandler handler)
|
|
{
|
|
this.contentHandler = handler;
|
|
}
|
|
@Override
|
|
public ContentHandler getContentHandler()
|
|
{
|
|
return contentHandler;
|
|
}
|
|
|
|
private final AttributesImpl attrList = new AttributesImpl();
|
|
private void generateRows() throws SAXException
|
|
{
|
|
contentHandler.startDocument();
|
|
contentHandler.startElement("","rows","rows",attrList);
|
|
for(int i = 0; i < numRows; i++)
|
|
{
|
|
contentHandler.startElement("","row","row",attrList);
|
|
appendTextOnlyElement("name","name" + i);
|
|
appendTextOnlyElement("id",Integer.toString(i*10));
|
|
contentHandler.endElement("","row","row");
|
|
}
|
|
contentHandler.endElement("","rows","rows");
|
|
contentHandler.endDocument();
|
|
|
|
}
|
|
|
|
private void appendTextOnlyElement(String localName, String elementText) throws SAXException
|
|
{
|
|
contentHandler.startElement("",localName,localName, attrList);
|
|
char[] chars = elementText.toCharArray();
|
|
contentHandler.characters(chars, 0, chars.length);
|
|
contentHandler.endElement("",localName,localName);
|
|
}
|
|
|
|
@Override
|
|
public void parse(InputSource input) throws SAXException, IOException
|
|
{
|
|
generateRows();
|
|
}
|
|
|
|
@Override
|
|
public void parse(String systemId) throws SAXException, IOException
|
|
{
|
|
generateRows();
|
|
}
|
|
|
|
@Override
|
|
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException
|
|
{
|
|
|
|
}
|
|
}
|