Debian Codegraph @

net/sf/saxon/event/ProxyReceiver.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.event;
9
10 import net.sf.saxon.expr.parser.Location;
11 import net.sf.saxon.om.Item;
12 import net.sf.saxon.om.NamePool;
13 import net.sf.saxon.om.NamespaceBindingSet;
14 import net.sf.saxon.om.NodeName;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.type.SchemaType;
17 import net.sf.saxon.type.SimpleType;
18
19 /**
20 * A ProxyReceiver is an Receiver that filters data before passing it to another
21 * underlying Receiver.
22 */
23
24 public class ProxyReceiver extends SequenceReceiver {
25
26 /*@NotNull*/
27 protected Receiver nextReceiver;
28
29 public ProxyReceiver(/*@NotNull*/ Receiver nextReceiver) {
30 super(nextReceiver.getPipelineConfiguration());
31 setUnderlyingReceiver(nextReceiver);
32 setPipelineConfiguration(nextReceiver.getPipelineConfiguration());
33 }
34
35 public void setSystemId(String systemId) {
36 //noinspection StringEquality
37 if (systemId != this.systemId) {
38 // use of == rather than equals() is deliberate, since this is only an optimization
39 this.systemId = systemId;
40 nextReceiver.setSystemId(systemId);
41 }
42 }
43
44 /**
45 * Set the underlying receiver. This call is mandatory before using the Receiver.
46 *
47 * @param receiver the underlying receiver, the one that is to receive events after processing
48 * by this filter.
49 */
50
51 public void setUnderlyingReceiver(/*@NotNull*/ Receiver receiver) {
52 nextReceiver = receiver;
53 }
54
55 /**
56 * Get the next Receiver in the pipeline
57 *
58 * @return the next Receiver in the pipeline
59 */
60
61 public Receiver getNextReceiver() {
62 return nextReceiver;
63 }
64
65
66 public void setPipelineConfiguration(/*@NotNull*/ PipelineConfiguration pipe) {
67 if (pipelineConfiguration != pipe) {
68 pipelineConfiguration = pipe;
69 if (nextReceiver.getPipelineConfiguration() != pipe) {
70 nextReceiver.setPipelineConfiguration(pipe);
71 }
72 }
73 }
74
75 /**
76 * Get the namepool for this configuration
77 */
78
79 public NamePool getNamePool() {
80 return pipelineConfiguration.getConfiguration().getNamePool();
81 }
82
83 /**
84 * Start of event stream
85 */
86
87 public void open() throws XPathException {
88 nextReceiver.open();
89 }
90
91 /**
92 * End of output. Note that closing this receiver also closes the rest of the
93 * pipeline.
94 */
95
96 public void close() throws XPathException {
97 // Note: It's wrong to assume that because we've finished writing to this
98 // receiver, then we've also finished writing to other receivers in the pipe.
99 // In the case where the rest of the pipe is to stay open, the caller should
100 // either avoid doing the close(), or should first set the underlying receiver
101 // to null.
102 nextReceiver.close();
103 }
104
105 /**
106 * Start of a document node.
107 */
108
109 public void startDocument(int properties) throws XPathException {
110 nextReceiver.startDocument(properties);
111 }
112
113 /**
114 * Notify the end of a document node
115 */
116
117 public void endDocument() throws XPathException {
118 nextReceiver.endDocument();
119 }
120
121 /**
122 * Notify the start of an element
123 *
124 * @param elemName integer code identifying the name of the element within the name pool.
125 * @param type the element's type annotation.
126 * @param location a location associated with the event (typically either a location in the
127 * source document or the stylesheet)
128 * @param properties properties of the element node
129 */
130
131 public void startElement(NodeName elemName, SchemaType type, Location location, int properties) throws XPathException {
132 nextReceiver.startElement(elemName, type, location, properties);
133 }
134
135 /**
136 * Notify a namespace. Namespaces are notified <b>after</b> the startElement event, and before
137 * any children for the element. The namespaces that are reported are only required
138 * to include those that are different from the parent element; however, duplicates may be reported.
139 * A namespace must not conflict with any namespaces already used for element or attribute names.
140 *
141 * @param namespaceBindings the prefix/uri pair representing the namespace binding
142 * @param properties any special properties to be passed on this call
143 */
144
145 public void namespace(NamespaceBindingSet namespaceBindings, int properties) throws XPathException {
146 nextReceiver.namespace(namespaceBindings, properties);
147 }
148
149 /**
150 * Notify an attribute. Attributes are notified after the startElement event, and before any
151 * children. Namespaces and attributes may be intermingled.
152 *
153 * @param nameCode The name of the attribute
154 * @param typeCode The type of the attribute
155 * @param locationId The location of the node
156 * @param properties Bit significant value. The following bits are defined:
157 * <dl>
158 * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt>
159 * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt>
160 * </dl>
161 */
162
163 public void attribute(NodeName nameCode, SimpleType typeCode, CharSequence value, Location locationId, int properties)
164 throws XPathException {
165 nextReceiver.attribute(nameCode, typeCode, value, locationId, properties);
166 }
167
168 /**
169 * Notify the start of the content, that is, the completion of all attributes and namespaces.
170 * Note that the initial receiver of output from XSLT instructions will not receive this event,
171 * it has to detect it itself. Note that this event is reported for every element even if it has
172 * no attributes, no namespaces, and no content.
173 */
174
175
176 public void startContent() throws XPathException {
177 nextReceiver.startContent();
178 }
179
180 /**
181 * End of element
182 */
183
184 public void endElement() throws XPathException {
185 nextReceiver.endElement();
186 }
187
188 /**
189 * Character data
190 */
191
192 public void characters(CharSequence chars, Location locationId, int properties) throws XPathException {
193 nextReceiver.characters(chars, locationId, properties);
194 }
195
196
197 /**
198 * Processing Instruction
199 */
200
201 public void processingInstruction(String target, CharSequence data, Location locationId, int properties) throws XPathException {
202 nextReceiver.processingInstruction(target, data, locationId, properties);
203 }
204
205 /**
206 * Output a comment
207 */
208
209 public void comment(CharSequence chars, Location locationId, int properties) throws XPathException {
210 nextReceiver.comment(chars, locationId, properties);
211 }
212
213
214 /**
215 * Set the URI for an unparsed entity in the document.
216 */
217
218 public void setUnparsedEntity(String name, String uri, String publicId) throws XPathException {
219 nextReceiver.setUnparsedEntity(name, uri, publicId);
220 }
221
222 /**
223 * Append an arbitrary item (node or atomic value) to the output
224 *
225 * @param item the item to be appended
226 * @param locationId the location of the calling instruction, for diagnostics
227 * @param properties if the item is an element node, this indicates whether its namespaces
228 * need to be copied. Values are {@link ReceiverOptions#ALL_NAMESPACES},
229 * {@link ReceiverOptions#LOCAL_NAMESPACES}; the default (0) means
230 * no namespaces
231 */
232
233 public void append(Item item, Location locationId, int properties) throws XPathException {
234 nextReceiver.append(item, locationId, properties);
235 }
236
237 /**
238 * Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations
239 * supplied on element and attribute events
240 *
241 * @return true if the Receiver makes any use of this information. If false, the caller
242 * may supply untyped nodes instead of supplying the type annotation
243 */
244
245 public boolean usesTypeAnnotations() {
246 return nextReceiver.usesTypeAnnotations();
247 }
248 }
249