1 39 40 package parser.dom; 41 42 import com.sun.japex.JapexDriverBase; 43 import com.sun.japex.TestCase; 44 import com.sun.xml.fastinfoset.sax.SAXDocumentParser; 45 import com.sun.xml.fastinfoset.sax.SAXDocumentSerializer; 46 import java.io.File ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.FileInputStream ; 50 51 import javax.xml.parsers.SAXParserFactory ; 52 import javax.xml.parsers.SAXParser ; 53 import javax.xml.transform.Transformer ; 54 import javax.xml.transform.TransformerFactory ; 55 import javax.xml.transform.dom.DOMResult ; 56 57 import org.jvnet.fastinfoset.FastInfosetSource; 58 59 public class FIJAXPSAXDOMDriver extends JapexDriverBase { 60 ByteArrayInputStream _inputStream; 61 62 SAXDocumentParser _fidp; 63 Transformer _transformer; 64 FastInfosetSource _source; 65 DOMResult _result; 66 67 public void initializeDriver() { 68 try { 69 _transformer = TransformerFactory.newInstance().newTransformer(); 70 } catch (Exception e) { 71 e.printStackTrace(); 72 } 73 } 74 75 76 public void prepare(TestCase testCase) { 77 String xmlFile = testCase.getParam("xmlfile"); 78 if (xmlFile == null) { 79 throw new RuntimeException ("xmlfile not specified"); 80 } 81 82 try { 84 SAXParserFactory spf = SAXParserFactory.newInstance(); 85 spf.setNamespaceAware(true); 86 SAXParser parser = spf.newSAXParser(); 87 88 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 89 SAXDocumentSerializer ds = new SAXDocumentSerializer(); 90 91 ds.setOutputStream(baos); 92 93 FileInputStream fis = new FileInputStream (new File (xmlFile)); 95 parser.parse(fis, ds); 96 fis.close(); 97 98 _inputStream = new ByteArrayInputStream (baos.toByteArray()); 99 _source = new FastInfosetSource(_inputStream); 100 } 101 catch (Exception e) { 102 e.printStackTrace(); 103 } 104 } 105 106 public void warmup(TestCase testCase) { 107 try { 108 DOMResult result = new DOMResult (); 109 _inputStream.reset(); 110 _transformer.transform(_source, result); 111 } 112 catch (Exception e) { 113 e.printStackTrace(); 114 } 115 } 116 117 public void run(TestCase testCase) { 118 try { 119 DOMResult result = new DOMResult (); 120 _inputStream.reset(); 121 _transformer.transform(_source, result); 122 } 123 catch (Exception e) { 124 e.printStackTrace(); 125 } 126 } 127 128 public void finish(TestCase testCase) { 129 } 130 131 public void terminateDriver() { 132 } 133 } 134 | Popular Tags |