public boolean testCase2()

in java/src/org/apache/qetest/xalanj2/SmoketestOuttakes.java [243:341]


    public boolean testCase2()
    {
        reporter.testCaseInit("Recreate ExamplesTest.exampleContentHandlerToContentHandler");

        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_18.out";

        try
        {

            TransformerFactory tfactory = TransformerFactory.newInstance();

            // Make sure the transformer factory we obtained supports both
            // DOM and SAX.
            if (!(tfactory.getFeature(SAXSource.FEATURE)
                && tfactory.getFeature(DOMSource.FEATURE)))
            {
                reporter.logErrorMsg("exampleContentHandler2DOM:Processor does not support SAX/DOM");
                return true;
            }
              // We can now safely cast to a SAXTransformerFactory.
              SAXTransformerFactory sfactory = (SAXTransformerFactory) tfactory;
              
              // Create an Document node as the root for the output.
              DocumentBuilderFactory dfactory 
                = DocumentBuilderFactory.newInstance();
              DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
              org.w3c.dom.Document outNode = docBuilder.newDocument();
              
              // Create a ContentHandler that can liston to SAX events 
              // and transform the output to DOM nodes.
              reporter.logTraceMsg("newTransformerHandler(new StreamSource(" + QetestUtils.filenameToURL(xslID));
              TransformerHandler handler 
                = sfactory.newTransformerHandler(new StreamSource(QetestUtils.filenameToURL(xslID)));
              handler.setResult(new DOMResult(outNode));
              
              // Create a reader and set it's ContentHandler to be the 
              // transformer.
              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);
              reader.setProperty("http://xml.org/sax/properties/lexical-handler",
                                 handler);
              
              // Send the SAX events from the parser to the transformer,
              // and thus to the DOM tree.
              reporter.logTraceMsg("reader.parse(" + QetestUtils.filenameToURL(sourceID));
              reader.parse(QetestUtils.filenameToURL(sourceID));
              
              // Serialize the node for diagnosis.
              //    This serializes to outNames.nextName()
              exampleSerializeNode(outNode);

            fileChecker.check(reporter, new File(outNames.currentName()),
                              new File(goldName),                
                              "exampleContentHandler2DOM fileChecker of:" + outNames.currentName());

        }
        catch (Throwable t)
        {
            reporter.checkFail("Problem with testCase2:");
            reporter.logThrowable(reporter.ERRORMSG, t, "Problem with testCase2");
        }
        reporter.testCaseClose();
        return true;
    }