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