KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > serializer > dom > FISAXNoIndexedContentDriver


1 /*
2  * Japex ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * This Software is distributed under the following terms:
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, is permitted provided that the following conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistribution in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  *
18  * Neither the name of Sun Microsystems, Inc., 'Java', 'Java'-based names,
19  * nor the names of contributors may be used to endorse or promote products
20  * derived from this Software without specific prior written permission.
21  *
22  * The Software is provided "AS IS," without a warranty of any kind. ALL
23  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
24  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25  * PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS
26  * SHALL NOT BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE
27  * AS A RESULT OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE
28  * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE
29  * LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
30  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED
31  * AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
32  * INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGES.
34  *
35  * You acknowledge that the Software is not designed, licensed or intended
36  * for use in the design, construction, operation or maintenance of any
37  * nuclear facility.
38  */

39
40 package serializer.dom;
41
42
43 import java.io.File JavaDoc;
44 import java.io.OutputStream JavaDoc;
45 import java.io.ByteArrayInputStream JavaDoc;
46 import java.io.ByteArrayOutputStream JavaDoc;
47
48 import javax.xml.transform.Transformer JavaDoc;
49 import javax.xml.transform.TransformerFactory JavaDoc;
50 import javax.xml.transform.sax.SAXResult JavaDoc;
51 import javax.xml.transform.dom.DOMSource JavaDoc;
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 JavaDoc _xmlFile;
60     ByteArrayInputStream JavaDoc _inputStream;
61     Transformer JavaDoc _transformer;
62     DOMSource JavaDoc _source = null;
63     SAXResult JavaDoc _result = null;
64     SerializerVocabulary _vocabulary;
65     ByteArrayOutputStream JavaDoc _baos;
66     
67     public FISAXNoIndexedContentDriver() {
68     }
69     
70     public void initializeDriver() {
71         try {
72             _transformer = TransformerFactory.newInstance().newTransformer();
73         } catch (Exception JavaDoc 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 JavaDoc("xmlfile not specified");
82         }
83         
84         Util util = new Util(Util.STAX_SERIALIZER_SJSXP);
85         _source = util.getDOMSource(new File JavaDoc(_xmlFile));
86         _baos = new ByteArrayOutputStream JavaDoc();
87         getSAXResult(_baos);
88     }
89     
90     private void getSAXResult(OutputStream JavaDoc 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 JavaDoc();
99             _result.setHandler(serializer);
100             _result.setLexicalHandler(serializer);
101             
102         }
103         catch (Exception JavaDoc 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 JavaDoc 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 JavaDoc e) {
126             e.printStackTrace();
127         }
128     }
129     
130     public void finish(TestCase testCase) {
131     }
132     
133     public void terminateDriver() {
134     }
135 }
136
Popular Tags