1 39 40 package parser.dom; 41 42 import com.sun.japex.JapexDriverBase; 43 import com.sun.japex.TestCase; 44 import com.sun.org.apache.xml.internal.utils.DOMBuilder; 45 import com.sun.xml.fastinfoset.sax.Features; 46 import com.sun.xml.fastinfoset.sax.SAXDocumentParser; 47 import com.sun.xml.fastinfoset.sax.SAXDocumentSerializer; 48 import java.io.File ; 49 import java.io.ByteArrayInputStream ; 50 import java.io.ByteArrayOutputStream ; 51 import java.io.FileInputStream ; 52 import javax.xml.parsers.DocumentBuilder ; 53 import javax.xml.parsers.DocumentBuilderFactory ; 54 55 import javax.xml.parsers.SAXParserFactory ; 56 import javax.xml.parsers.SAXParser ; 57 58 59 60 public class FISAXXercesDOMBuilderDriver extends JapexDriverBase { 61 ByteArrayInputStream _inputStream; 62 63 SAXDocumentParser _fidp; 64 DocumentBuilder _db; 65 66 public void initializeDriver() { 67 } 68 69 70 public void prepare(TestCase testCase) { 71 String 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 _fidp = new SAXDocumentParser(); 94 _fidp.setFeature(Features.NAMESPACE_PREFIXES_FEATURE, true); 95 96 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 97 dbf.setNamespaceAware(true); 98 _db = dbf.newDocumentBuilder(); 99 } 100 catch (Exception e) { 101 } 102 } 103 104 public void warmup(TestCase testCase) { 105 try { 106 _inputStream.reset(); 107 _fidp.setInputStream(_inputStream); 108 DOMBuilder db = new DOMBuilder(_db.newDocument()); 109 _fidp.setContentHandler(db); 110 _fidp.setLexicalHandler(db); 111 _fidp.parse(); 112 } 113 catch (Exception e) { 114 e.printStackTrace(); 115 } 116 } 117 118 public void run(TestCase testCase) { 119 try { 120 _inputStream.reset(); 121 _fidp.setInputStream(_inputStream); 122 DOMBuilder db = new DOMBuilder(_db.newDocument()); 123 _fidp.setContentHandler(db); 124 _fidp.setLexicalHandler(db); 125 _fidp.parse(); 126 } 127 catch (Exception e) { 128 e.printStackTrace(); 129 } 130 } 131 132 public void finish(TestCase testCase) { 133 } 134 135 public void terminateDriver() { 136 } 137 } 138 | Popular Tags |