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