KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > output > TEXTEmitter


1 package com.icl.saxon.output;
2 import com.icl.saxon.charcode.UnicodeCharacterSet;
3 import java.io.IOException JavaDoc;
4 import org.xml.sax.Attributes JavaDoc;
5 import javax.xml.transform.OutputKeys JavaDoc;
6 import javax.xml.transform.TransformerException JavaDoc;
7
8 /**
9   * This class generates TEXT output
10   * @author <A HREF="mailto:mhkay@iclway.co.uk>Michael H. Kay</A>
11   */

12
13 public class TEXTEmitter extends XMLEmitter {
14
15     // This class is no longer used for
16
// output to attribute, comment, or processing-instruction nodes:
17
// these use StringEmitter instead.
18

19     private String JavaDoc mediaType = "text/plain";
20
21     /**
22     * Start of the document.
23     */

24     
25     public void startDocument () throws TransformerException JavaDoc
26     {
27         String JavaDoc mime = outputProperties.getProperty(OutputKeys.MEDIA_TYPE);
28         if (mime!=null) {
29             mediaType = mime;
30         }
31
32         if (characterSet==null) {
33             characterSet = UnicodeCharacterSet.getInstance();
34         }
35         empty = true;
36     }
37
38     /**
39     * Produce output using the current Writer. <BR>
40     * Special characters are not escaped.
41     * @param ch Character array to be output
42     * @param start start position of characters to be output
43     * @param length number of characters to be output
44     * @exception TransformerException for any failure
45     */

46
47     public void characters(char ch[], int start, int length) throws TransformerException JavaDoc {
48         for (int i=start; i<start+length; i++) {
49             if (!characterSet.inCharset(ch[i])) {
50                 throw new TransformerException JavaDoc("Output character not available in this encoding (decimal " + (int)ch[i] + ")");
51             }
52         }
53         try {
54             writer.write(ch, start, length);
55         } catch (java.io.IOException JavaDoc err) {
56             throw new TransformerException JavaDoc(err);
57         }
58     }
59
60     /**
61     * Output an element start tag. <br>
62     * Does nothing with this output method.
63     * @param name The element name (tag)
64     */

65
66     public void startElement(int nameCode, Attributes JavaDoc attributes,
67                               int[] namespaces, int nscount) throws TransformerException JavaDoc {
68         // no-op
69
}
70
71     
72     /**
73     * Output an element end tag. <br>
74     * Does nothing with this output method.
75     * @param name The element name (tag)
76     */

77
78     public void endElement(int nameCode) throws TransformerException JavaDoc {
79         // no-op
80
}
81
82     /**
83     * Output a processing instruction. <br>
84     * Does nothing with this output method.
85     */

86
87     public void processingInstruction(String JavaDoc name, String JavaDoc value) throws TransformerException JavaDoc {}
88
89     /**
90     * Output a comment. <br>
91     * Does nothing with this output method.
92     */

93
94     public void comment(char ch[], int start, int length) throws TransformerException JavaDoc {}
95
96 }
97
98 //
99
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
100
// you may not use this file except in compliance with the License. You may obtain a copy of the
101
// License at http://www.mozilla.org/MPL/
102
//
103
// Software distributed under the License is distributed on an "AS IS" basis,
104
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
105
// See the License for the specific language governing rights and limitations under the License.
106
//
107
// The Original Code is: all this file.
108
//
109
// The Initial Developer of the Original Code is
110
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
111
//
112
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
113
//
114
// Contributor(s): none.
115
//
116
Popular Tags