KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.output;
2 import com.icl.saxon.*;
3 import com.icl.saxon.charcode.UnicodeCharacterSet;
4 import java.util.*;
5 import java.io.*;
6 import org.xml.sax.Attributes JavaDoc;
7 import javax.xml.transform.OutputKeys JavaDoc;
8 import javax.xml.transform.TransformerException JavaDoc;
9
10 /**
11   * This class outputs text content to a StringBuffer, and discards all other content.
12   * @author <A HREF="mailto:mhkay@iclway.co.uk>Michael H. Kay</A>
13   */

14
15 final class StringEmitter extends Emitter {
16
17     // element content is output for xsl:output method="text", but is suppressed for text
18
// output to attribute, comment, or processing-instruction nodes
19

20     private int ignoreElements = 0;
21     private StringBuffer JavaDoc buffer;
22     
23     protected StringEmitter(StringBuffer JavaDoc buffer) {
24         this.buffer = buffer;
25     }
26
27     /**
28     * Start of the document.
29     */

30     
31     public void startDocument () throws TransformerException JavaDoc {}
32
33     /**
34     * End of the document.
35     */

36     
37     public void endDocument () throws TransformerException JavaDoc {}
38
39     /**
40     * Produce output using the current Writer. <BR>
41     * Special characters are not escaped.
42     * @param ch Character array to be output
43     * @param start start position of characters to be output
44     * @param length number of characters to be output
45     * @exception TransformerException for any failure
46     */

47
48     public void characters(char ch[], int start, int length) throws TransformerException JavaDoc {
49         if (ignoreElements == 0) {
50             buffer.append(ch, start, length);
51         }
52     }
53
54     /**
55     * Output an element start tag. <br>
56     * Does nothing with this output method.
57     * @param name The element name (tag)
58     */

59
60     public void startElement(int nameCode, Attributes JavaDoc attributes,
61                               int[] namespaces, int nscount) throws TransformerException JavaDoc {
62         ignoreElements++;
63     }
64
65     
66     /**
67     * Output an element end tag. <br>
68     * Does nothing with this output method.
69     * @param name The element name (tag)
70     */

71
72     public void endElement(int nameCode) throws TransformerException JavaDoc {
73         ignoreElements--;
74     }
75
76     /**
77     * Output a processing instruction. <br>
78     * Does nothing with this output method.
79     */

80
81     public void processingInstruction(String JavaDoc name, String JavaDoc value) throws TransformerException JavaDoc {}
82
83     /**
84     * Output a comment. <br>
85     * Does nothing with this output method.
86     */

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