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