in java/src/org/apache/qetest/xalanj2/SmoketestOuttakes.java [134:234]
public boolean testCase1()
{
reporter.testCaseInit("Recreate ExamplesTest.exampleContentHandlerToContentHandler");
try
{
String xslID = inputDir
+ File.separator
+ "trax"
+ File.separator
+ "xsl"
+ File.separator
+ "foo.xsl";
String sourceID = inputDir
+ File.separator
+ "trax"
+ File.separator
+ "xml"
+ File.separator
+ "foo.xml";
String goldName = goldDir
+ File.separator
+ "trax"
+ File.separator
+ "ExamplesTest_7.out";
reporter.logTraceMsg("NOTE! This file is very sensitive to pathing issues!");
TransformerFactory tfactory = TransformerFactory.newInstance();
// Does this factory support SAX features?
if (!tfactory.getFeature(SAXSource.FEATURE))
{
reporter.logErrorMsg("exampleContentHandlerToContentHandler:Processor does not support SAX");
return true;
}
// If so, we can safely cast.
SAXTransformerFactory stfactory = ((SAXTransformerFactory) tfactory);
// A TransformerHandler is a ContentHandler that will listen for
// SAX events, and transform them to the result.
reporter.logTraceMsg("newTransformerHandler(new StreamSource(" + QetestUtils.filenameToURL(xslID));
TransformerHandler handler
= stfactory.newTransformerHandler(new StreamSource(QetestUtils.filenameToURL(xslID)));
// Set the result handling to be a serialization to the file output stream.
Serializer serializer = SerializerFactory.getSerializer
(OutputPropertiesFactory.getDefaultMethodProperties("xml"));
FileOutputStream fos = new FileOutputStream(outNames.nextName());
serializer.setOutputStream(fos);
reporter.logStatusMsg("Test-output-to: new FileOutputStream(" + outNames.currentName());
Result result = new SAXResult(serializer.asContentHandler());
handler.setResult(result);
// Create a reader, and set it's content handler to be the TransformerHandler.
XMLReader reader=null;
// Use JAXP1.1 ( if possible )
try {
javax.xml.parsers.SAXParserFactory factory=
javax.xml.parsers.SAXParserFactory.newInstance();
factory.setNamespaceAware( true );
javax.xml.parsers.SAXParser jaxpParser=
factory.newSAXParser();
reader=jaxpParser.getXMLReader();
} catch( javax.xml.parsers.ParserConfigurationException ex ) {
throw new org.xml.sax.SAXException( ex );
} catch( javax.xml.parsers.FactoryConfigurationError ex1 ) {
throw new org.xml.sax.SAXException( ex1.toString() );
} catch( NoSuchMethodError ex2 ) {
}
if( reader==null ) reader = getJAXPXMLReader();
reader.setContentHandler(handler);
// It's a good idea for the parser to send lexical events.
// The TransformerHandler is also a LexicalHandler.
reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
// Parse the source XML, and send the parse events to the TransformerHandler.
reporter.logTraceMsg("reader.parse(" + QetestUtils.filenameToURL(sourceID));
reader.parse(QetestUtils.filenameToURL(sourceID));
fos.close();
reporter.logTraceMsg("Note: See SPR SCUU4RZT78 for discussion as to why this output is different than XMLReader/XMLFilter");
fileChecker.check(reporter, new File(outNames.currentName()),
new File(goldName),
"exampleContentHandlerToContentHandler fileChecker of:" + outNames.currentName());
}
catch (Throwable t)
{
reporter.checkFail("Problem with testCase1:");
reporter.logThrowable(reporter.ERRORMSG, t, "Problem with testCase1");
}
reporter.testCaseClose();
return true;
}