KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.event;
2 import net.sf.saxon.om.Item;
3 import net.sf.saxon.om.NodeInfo;
4 import net.sf.saxon.trans.XPathException;
5
6 /**
7   * TeeOutputter: a SequenceReceiver that duplicates received events to two different destinations
8   */

9
10 public class TeeOutputter extends SequenceReceiver {
11     
12     SequenceReceiver seq1;
13     SequenceReceiver seq2;
14
15     public TeeOutputter(SequenceReceiver seq1, SequenceReceiver seq2) {
16         this.seq1 = seq1;
17         this.seq2 = seq2;
18     }
19
20     /**
21      * Output an item (atomic value or node) to the sequence
22      */

23
24     public void append(Item item, int locationId, int copyNamespaces) throws XPathException {
25         seq1.append(item, locationId, NodeInfo.ALL_NAMESPACES);
26         seq2.append(item, locationId, NodeInfo.ALL_NAMESPACES);
27     }
28
29     /**
30      * Notify the start of a document node
31      */

32
33     public void startDocument(int properties) throws XPathException {
34         seq1.startDocument(properties);
35         seq2.startDocument(properties);
36     }
37
38     /**
39      * Notify the end of a document node
40      */

41
42     public void endDocument() throws XPathException {
43         seq1.endDocument();
44         seq2.endDocument();
45     }
46
47     /**
48      * Notify the start of an element
49      *
50      * @param nameCode integer code identifying the name of the element within the name pool.
51      * @param typeCode integer code identifying the element's type within the name pool. The value -1
52      * indicates the default type, xdt:untyped.
53      * @param locationId an integer which can be interpreted using a LocationMap to return
54      * information such as line number and system ID. If no location information is available,
55      * the value zero is supplied.
56      * @param properties bit-significant properties of the element node. If there are no revelant
57      * properties, zero is supplied.
58      */

59
60     public void startElement(int nameCode, int typeCode, int locationId, int properties) throws XPathException {
61         seq1.startElement(nameCode, typeCode, locationId, properties);
62         seq2.startElement(nameCode, typeCode, locationId, properties);
63     }
64
65     /**
66      * Notify a namespace. Namespaces are notified <b>after</b> the startElement event, and before
67      * any children for the element. The namespaces that are reported are only required
68      * to include those that are different from the parent element; however, duplicates may be reported.
69      * A namespace must not conflict with any namespaces already used for element or attribute names.
70      *
71      * @param namespaceCode an integer: the top half is a prefix code, the bottom half a URI code.
72      * These may be translated into an actual prefix and URI using the name pool. A prefix code of
73      * zero represents the empty prefix (that is, the default namespace). A URI code of zero represents
74      * a URI of "", that is, a namespace undeclaration.
75      * @throws IllegalStateException: attempt to output a namespace when there is no open element
76      * start tag
77      */

78
79     public void namespace(int namespaceCode, int properties) throws XPathException {
80         seq1.namespace(namespaceCode, properties);
81         seq2.namespace(namespaceCode, properties);
82     }
83
84     /**
85      * Notify an attribute. Attributes are notified after the startElement event, and before any
86      * children. Namespaces and attributes may be intermingled.
87      *
88      * @param nameCode The name of the attribute, as held in the name pool
89      * @param typeCode The type of the attribute, as held in the name pool
90      * @param locationId an integer which can be interpreted using a LocationMap to return
91      * information such as line number and system ID. If no location information is available,
92      * the value zero is supplied.
93      * @param properties Bit significant value. The following bits are defined:
94      * <dt>DISABLE_ESCAPING</dt> <dd>Disable escaping for this attribute</dd>
95      * <dt>NO_SPECIAL_CHARACTERS</dt> <dd>Attribute value contains no special characters</dd>
96      * @throws IllegalStateException: attempt to output an attribute when there is no open element
97      * start tag
98      */

99
100     public void attribute(int nameCode, int typeCode, CharSequence JavaDoc value, int locationId, int properties) throws XPathException {
101         seq1.attribute(nameCode, typeCode, value, locationId, properties);
102         seq2.attribute(nameCode, typeCode, value, locationId, properties);
103     }
104
105     /**
106      * Notify the start of the content, that is, the completion of all attributes and namespaces.
107      * Note that the initial receiver of output from XSLT instructions will not receive this event,
108      * it has to detect it itself. Note that this event is reported for every element even if it has
109      * no attributes, no namespaces, and no content.
110      */

111
112     public void startContent() throws XPathException {
113         seq1.startContent();
114         seq2.startContent();
115     }
116
117     /**
118      * Notify the end of an element. The receiver must maintain a stack if it needs to know which
119      * element is ending.
120      */

121
122     public void endElement() throws XPathException {
123         seq1.endElement();
124         seq2.endElement();
125     }
126
127     /**
128      * Notify character data. Note that some receivers may require the character data to be
129      * sent in a single event, but in general this is not a requirement.
130      *
131      * @param chars The characters
132      * @param locationId an integer which can be interpreted using a LocationMap to return
133      * information such as line number and system ID. If no location information is available,
134      * the value zero is supplied.
135      * @param properties Bit significant value. The following bits are defined:
136      * <dt>DISABLE_ESCAPING</dt> <dd>Disable escaping for this text node</dd>
137      * <dt>USE_CDATA</dt> <dd>Output as a CDATA section</dd>
138      * <dt>NO_SPECIAL_CHARACTERS</dt> <dd>Value contains no special characters</dd>
139      * <dt>WHITESPACE</dt> <dd>Text is all whitespace</dd>
140      */

141
142     public void characters(CharSequence JavaDoc chars, int locationId, int properties) throws XPathException {
143         seq1.characters(chars, locationId, properties);
144         seq2.characters(chars, locationId, properties);
145     }
146
147     /**
148      * Output a processing instruction
149      *
150      * @param name The PI name. This must be a legal name (it will not be checked).
151      * @param data The data portion of the processing instruction
152      * @param locationId an integer which can be interpreted using a LocationMap to return
153      * information such as line number and system ID. If no location information is available,
154      * the value zero is supplied.
155      * @param properties Additional information about the PI. The following bits are
156      * defined:
157      * <dt>CHECKED</dt> <dd>Data is known to be legal (e.g. doesn't contain "?>")</dd>
158      * @throws IllegalArgumentException: the content is invalid for an XML processing instruction
159      */

160
161     public void processingInstruction(String JavaDoc name, CharSequence JavaDoc data, int locationId, int properties) throws XPathException {
162         seq1.processingInstruction(name, data, locationId, properties);
163         seq2.processingInstruction(name, data, locationId, properties);
164     }
165
166     /**
167      * Notify a comment. Comments are only notified if they are outside the DTD.
168      *
169      * @param content The content of the comment
170      * @param locationId an integer which can be interpreted using a LocationMap to return
171      * information such as line number and system ID. If no location information is available,
172      * the value zero is supplied.
173      * @param properties Additional information about the comment. The following bits are
174      * defined:
175      * <dt>CHECKED</dt> <dd>Comment is known to be legal (e.g. doesn't contain "--")</dd>
176      * @throws IllegalArgumentException: the content is invalid for an XML comment
177      */

178
179     public void comment(CharSequence JavaDoc content, int locationId, int properties) throws XPathException {
180         seq1.comment(content, locationId, properties);
181         seq2.comment(content, locationId, properties);
182     }
183
184     /**
185      * Notify the end of the event stream
186      */

187
188     public void close() throws XPathException {
189         seq1.close();
190         seq2.close();
191     }
192 }
193
194 //
195
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
196
// you may not use this file except in compliance with the License. You may obtain a copy of the
197
// License at http://www.mozilla.org/MPL/
198
//
199
// Software distributed under the License is distributed on an "AS IS" basis,
200
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
201
// See the License for the specific language governing rights and limitations under the License.
202
//
203
// The Original Code is: all this file.
204
//
205
// The Initial Developer of the Original Code is Michael H. Kay
206
//
207
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
208
//
209
// Contributor(s): none.
210
//
211
Popular Tags