KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > event > TEXTEmitter


1 package net.sf.saxon.event;
2 import net.sf.saxon.charcode.UnicodeCharacterSet;
3 import net.sf.saxon.trans.DynamicError;
4 import net.sf.saxon.trans.XPathException;
5
6 import javax.xml.transform.OutputKeys JavaDoc;
7
8 /**
9   * This class generates TEXT output
10   * @author Michael H. Kay
11   */

12
13 public class TEXTEmitter extends XMLEmitter {
14
15     /**
16     * Start of the document.
17     */

18
19     public void open () throws XPathException
20     {
21         // Prevent output of XML declaration
22
declarationIsWritten = true;
23
24         empty = true;
25
26         // Write a BOM if requested
27
String JavaDoc byteOrderMark = outputProperties.getProperty(SaxonOutputKeys.BYTE_ORDER_MARK);
28
29         if ("yes".equals(byteOrderMark) &&
30                     "UTF-8".equalsIgnoreCase(outputProperties.getProperty(OutputKeys.ENCODING))) {
31             try {
32                 openDocument();
33                 writer.write('\uFEFF');
34                 empty = false;
35             } catch (java.io.IOException JavaDoc err) {
36                 // Might be an encoding exception; just ignore it
37
}
38         }
39
40         if (characterSet==null) {
41             characterSet = UnicodeCharacterSet.getInstance();
42         }
43     }
44
45     /**
46     * Produce output using the current Writer. <BR>
47     * Special characters are not escaped.
48     * @param chars Character sequence to be output
49     * @param properties bit fields holding special properties of the characters
50     * @exception XPathException for any failure
51     */

52
53     public void characters(CharSequence JavaDoc chars, int locationId, int properties) throws XPathException {
54         if (empty) {
55             openDocument();
56         }
57         if ((properties & ReceiverOptions.NO_SPECIAL_CHARS) == 0) {
58             int badchar = testCharacters(chars);
59             if (badchar != 0) {
60                 throw new DynamicError(
61                         "Output character not available in this encoding (decimal " + badchar + ")");
62             }
63         }
64         try {
65             writer.write(chars.toString());
66         } catch (java.io.IOException JavaDoc err) {
67             throw new DynamicError(err);
68         }
69     }
70
71     /**
72     * Output an element start tag. <br>
73     * Does nothing with this output method.
74     * @param nameCode The element name (tag)
75      * @param typeCode The type annotation
76      * @param properties Bit fields holding any special properties of the element
77     */

78
79     public void startElement(int nameCode, int typeCode, int locationId, int properties) {
80         // no-op
81
}
82
83     public void namespace(int namespaceCode, int properties) {}
84
85     public void attribute(int nameCode, int typeCode, CharSequence JavaDoc value, int locationId, int properties) {}
86
87
88     /**
89     * Output an element end tag. <br>
90     * Does nothing with this output method.
91     */

92
93     public void endElement() {
94         // no-op
95
}
96
97     /**
98     * Output a processing instruction. <br>
99     * Does nothing with this output method.
100     */

101
102     public void processingInstruction(String JavaDoc name, CharSequence JavaDoc value, int locationId, int properties) throws XPathException {}
103
104     /**
105     * Output a comment. <br>
106     * Does nothing with this output method.
107     */

108
109     public void comment(CharSequence JavaDoc chars, int locationId, int properties) throws XPathException {}
110
111 }
112
113 //
114
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
115
// you may not use this file except in compliance with the License. You may obtain a copy of the
116
// License at http://www.mozilla.org/MPL/
117
//
118
// Software distributed under the License is distributed on an "AS IS" basis,
119
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
120
// See the License for the specific language governing rights and limitations under the License.
121
//
122
// The Original Code is: all this file.
123
//
124
// The Initial Developer of the Original Code is Michael H. Kay.
125
//
126
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
127
//
128
// Contributor(s): none.
129
//
130
Popular Tags