1 39 40 package serializer.dom; 41 42 43 import java.io.File ; 44 import java.io.OutputStream ; 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 48 import javax.xml.transform.Transformer ; 49 import javax.xml.transform.TransformerFactory ; 50 import javax.xml.transform.sax.SAXResult ; 51 import javax.xml.transform.dom.DOMSource ; 52 import com.sun.xml.fastinfoset.sax.SAXDocumentSerializer; 53 54 import com.sun.japex.*; 55 import com.sun.xml.fastinfoset.vocab.SerializerVocabulary; 56 57 58 public class FISAXNoIndexedContentDriver extends JapexDriverBase { 59 String _xmlFile; 60 ByteArrayInputStream _inputStream; 61 Transformer _transformer; 62 DOMSource _source = null; 63 SAXResult _result = null; 64 SerializerVocabulary _vocabulary; 65 ByteArrayOutputStream _baos; 66 67 public FISAXNoIndexedContentDriver() { 68 } 69 70 public void initializeDriver() { 71 try { 72 _transformer = TransformerFactory.newInstance().newTransformer(); 73 } catch (Exception e) { 74 e.printStackTrace(); 75 } 76 } 77 78 public void prepare(TestCase testCase) { 79 _xmlFile = testCase.getParam("xmlfile"); 80 if (_xmlFile == null) { 81 throw new RuntimeException ("xmlfile not specified"); 82 } 83 84 Util util = new Util(Util.STAX_SERIALIZER_SJSXP); 85 _source = util.getDOMSource(new File (_xmlFile)); 86 _baos = new ByteArrayOutputStream (); 87 getSAXResult(_baos); 88 } 89 90 private void getSAXResult(OutputStream output) { 91 try { 92 _vocabulary = new SerializerVocabulary(); 93 _vocabulary.attributeValueSizeConstraint = _vocabulary.characterContentChunkSizeContraint = 0; 94 SAXDocumentSerializer serializer = new SAXDocumentSerializer(); 95 serializer.setVocabulary(_vocabulary); 96 serializer.setOutputStream(output); 97 98 _result = new SAXResult (); 99 _result.setHandler(serializer); 100 _result.setLexicalHandler(serializer); 101 102 } 103 catch (Exception e) { 104 e.printStackTrace(); 105 } 106 } 107 108 public void warmup(TestCase testCase) { 109 try { 110 _baos.reset(); 111 _vocabulary.clear(); 112 _transformer.transform(_source, _result); 113 } 114 catch (Exception e) { 115 e.printStackTrace(); 116 } 117 } 118 119 public void run(TestCase testCase) { 120 try { 121 _baos.reset(); 122 _vocabulary.clear(); 123 _transformer.transform(_source, _result); 124 } 125 catch (Exception e) { 126 e.printStackTrace(); 127 } 128 } 129 130 public void finish(TestCase testCase) { 131 } 132 133 public void terminateDriver() { 134 } 135 } 136 | Popular Tags |