Debian Codegraph @

net/sf/saxon/event/ComplexContentOutputter.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.Configuration;
11 import net.sf.saxon.expr.parser.ExplicitLocation;
12 import net.sf.saxon.expr.parser.Location;
13 import net.sf.saxon.lib.NamespaceConstant;
14 import net.sf.saxon.lib.ParseOptions;
15 import net.sf.saxon.lib.Validation;
16 import net.sf.saxon.om.*;
17 import net.sf.saxon.trans.Err;
18 import net.sf.saxon.trans.XPathException;
19 import net.sf.saxon.tree.tiny.TinyBuilder;
20 import net.sf.saxon.tree.tiny.TinyElementImpl;
21 import net.sf.saxon.type.BuiltInAtomicType;
22 import net.sf.saxon.type.SchemaType;
23 import net.sf.saxon.type.SimpleType;
24 import net.sf.saxon.type.Type;
25
26 import java.util.Arrays;
27
28 import static net.sf.saxon.event.RegularSequenceChecker.State.*;
29
30 /**
31 * This class is used for generating complex content, that is, the content of an
32 * element or document node. It enforces the rules on the order of events within
33 * complex content (attributes and namespaces must come first), and it implements
34 * part of the namespace fixup rules, in particular, it ensures that there is a
35 * namespace node for the namespace used in the element name and in each attribute
36 * name.
37 * <p>
38 * The same ComplexContentOutputter may be used for generating an entire XML
39 * document; it is not necessary to create a new outputter for each element node.
40 * <p>
41 * From Saxon 9.9, the ComplexContentOutputter does not combine top-level events.
42 * Unless nested within a startDocument/endDocument or startElement/endElement pair,
43 * items such as atomic values, text nodes, attribute nodes, maps and arrays are
44 * passed through unchanged to the output. It is typically the responsibility
45 * of the Destination object to decide how to combine top-level events (whether
46 * to build a single document, whether to insert item separators, etc).
47 *
48 *
49 */
50
51 public final class ComplexContentOutputter extends SequenceReceiver {
52
53 private Receiver nextReceiver;
54 // the next receiver in the output pipeline
55
56 private NodeName pendingStartTag = null;
57 private int level = -1;
58 // records the number of startDocument or startElement events
59 // that have not yet been closed. Note that startDocument and startElement
60 // events may be arbitrarily nested; startDocument and endDocument
61 // are ignored unless they occur at the outermost level, except that they
62 // still change the level number
63 private boolean[] currentLevelIsDocument = new boolean[20];
64 private InScopeNamespaces[] copyNamespacesStack = new InScopeNamespaces[20];
65 private Boolean elementIsInNullNamespace;
66 private NodeName[] pendingAttCode = new NodeName[20];
67 private SimpleType[] pendingAttType = new SimpleType[20];
68 private String[] pendingAttValue = new String[20];
69 private Location[] pendingAttLocation = new Location[20];
70 private int[] pendingAttProp = new int[20];
71 private int pendingAttListSize = 0;
72
73 private NamespaceBinding[] pendingNSList = new NamespaceBinding[20];
74 private int pendingNSListSize = 0;
75
76 private SchemaType currentSimpleType = null; // any other value means we are currently writing an
77 // element of a particular simple type
78
79 private int startElementProperties;
80 private Location startElementLocationId = ExplicitLocation.UNKNOWN_LOCATION;
81 private boolean declaresDefaultNamespace;
82 private int hostLanguage = Configuration.XSLT;
83
84 private RegularSequenceChecker.State state = Initial;
85 /**
86 * Create a ComplexContentOutputter
87 * @param next the next receiver in the pipeline
88 */
89
90 public ComplexContentOutputter(Receiver next) {
91 super(next.getPipelineConfiguration());
92 setReceiver(next);
93 setHostLanguage(next.getPipelineConfiguration().getHostLanguage());
94 }
95
96 /**
97 * Static factory method to create an push pipeline containing a ComplexContentOutputter
98 * @param receiver the destination to which the constructed complex content will be written
99 * @param options options for validating the output stream; may be null
100 */
101
102 public static Receiver makeComplexContentReceiver(Receiver receiver, ParseOptions options) {
103 // System.err.println("CHANGE OUTPUT DESTINATION new=" + receiver);
104
105 String systemId = receiver.getSystemId();
106 boolean validate = options != null && options.getSchemaValidationMode() != Validation.PRESERVE;
107
108 if (receiver instanceof ComplexContentOutputter && !validate) {
109 return receiver;
110 }
111
112 // add a validator to the pipeline if required
113
114 if (validate) {
115 Configuration config = receiver.getPipelineConfiguration().getConfiguration();
116 receiver = config.getDocumentValidator(receiver, systemId, options, null);
117 }
118
119 // add a filter to remove duplicate namespaces
120 NamespaceReducer ne = new NamespaceReducer(receiver);
121 ne.setSystemId(receiver.getSystemId());
122 receiver = ne;
123
124 receiver = new ComplexContentOutputter(ne);
125
126 receiver.setSystemId(systemId);
127 return receiver;
128 }
129
130 public void setPipelineConfiguration(/*@NotNull*/ PipelineConfiguration pipe) {
131 if (pipelineConfiguration != pipe) {
132 pipelineConfiguration = pipe;
133 if (nextReceiver != null) {
134 nextReceiver.setPipelineConfiguration(pipe);
135 }
136 }
137 }
138
139 @Override
140 public void setSystemId(String systemId) {
141 super.setSystemId(systemId);
142 nextReceiver.setSystemId(systemId);
143 }
144
145 /**
146 * Set the host language
147 *
148 * @param language the host language, for example {@link Configuration#XQUERY}
149 */
150
151 public void setHostLanguage(int language) {
152 hostLanguage = language;
153 }
154
155
156 /**
157 * Set the receiver (to handle the next stage in the pipeline) directly
158 *
159 * @param receiver the receiver to handle the next stage in the pipeline
160 */
161
162 public void setReceiver(Receiver receiver) {
163 this.nextReceiver = receiver;
164 }
165
166 /**
167 * Get the next receiver in the processing pipeline
168 *
169 * @return the receiver which this ComplexContentOutputter writes to
170 */
171
172 public Receiver getReceiver() {
173 return nextReceiver;
174 }
175
176
177 /**
178 * Start the output process
179 */
180
181 public void open() throws XPathException {
182 nextReceiver.open();
183 previousAtomic = false;
184 state = Open;
185 }
186
187 /**
188 * Start of a document node.
189 */
190
191 public void startDocument(int properties) throws XPathException {
192 level++;
193 if (level == 0) {
194 nextReceiver.startDocument(properties);
195 } else if (state == StartTag) {
196 startContent();
197 }
198 previousAtomic = false;
199 if (currentLevelIsDocument.length < level + 1) {
200 currentLevelIsDocument = Arrays.copyOf(currentLevelIsDocument, level * 2);
201 }
202 currentLevelIsDocument[level] = true;
203 state = Content;
204 }
205
206 /**
207 * Notify the end of a document node
208 */
209
210 public void endDocument() throws XPathException {
211 if (level == 0) {
212 nextReceiver.endDocument();
213 }
214 previousAtomic = false;
215 level--;
216 state = level < 0 ? Open : Content;
217 }
218
219 /**
220 * Notify an unparsed entity URI.
221 *
222 * @param name The name of the unparsed entity
223 * @param systemID The system identifier of the unparsed entity
224 * @param publicID The public identifier of the unparsed entity
225 */
226 @Override
227 public void setUnparsedEntity(String name, String systemID, String publicID) throws XPathException {
228 nextReceiver.setUnparsedEntity(name, systemID, publicID);
229 }
230
231 /**
232 * Produce text content output. <BR>
233 * Special characters are escaped using XML/HTML conventions if the output format
234 * requires it.
235 *
236 * @param s The String to be output
237 * @param locationId the location of the node in the source, or of the instruction that created it
238 * @throws XPathException for any failure
239 */
240
241 public void characters(CharSequence s, Location locationId, int properties) throws XPathException {
242 if (level >= 0) {
243 previousAtomic = false;
244 if (s == null) {
245 return;
246 }
247 int len = s.length();
248 if (len == 0) {
249 return;
250 }
251 if (state == StartTag) {
252 startContent();
253 }
254 }
255 nextReceiver.characters(s, locationId, properties);
256 }
257
258 /**
259 * Output an element start tag. <br>
260 * The actual output of the tag is deferred until all attributes have been output
261 * using attribute().
262 *
263 * @param elemName The element name
264 * @param location the location of the element node (or the instruction that created it)
265 */
266
267 public void startElement(NodeName elemName, SchemaType typeCode, Location location, int properties) throws XPathException {
268 //System.err.println("CCO " + this + "StartElement " + nameCode);
269 level++;
270 if (state == StartTag) {
271 startContent();
272 }
273 startElementProperties = properties;
274 startElementLocationId = location.saveLocation();
275 pendingAttListSize = 0;
276 pendingNSListSize = 0;
277 pendingStartTag = elemName;
278 //pendingStartTagDepth = 1;
279 elementIsInNullNamespace = null; // meaning not yet computed
280 declaresDefaultNamespace = false;
281 currentSimpleType = typeCode;
282 previousAtomic = false;
283 if (currentLevelIsDocument.length < level + 1) {
284 currentLevelIsDocument = Arrays.copyOf(currentLevelIsDocument, level * 2);
285 }
286 if (copyNamespacesStack.length < level + 1) {
287 copyNamespacesStack = Arrays.copyOf(copyNamespacesStack, level * 2);
288 }
289 currentLevelIsDocument[level] = false;
290 state = StartTag;
291 }
292
293
294 /**
295 * Output one or more namespace declarations. <br>
296 * This is added to a list of pending namespaces for the current start tag.
297 * If there is already another declaration of the same prefix, this one is
298 * ignored, unless the REJECT_DUPLICATES flag is set, in which case this is an error.
299 * Note that unlike SAX2 startPrefixMapping(), this call is made AFTER writing the start tag.
300 *
301 * @param nsBindings The namespace bindings
302 * @throws XPathException if there is no start tag to write to (created using writeStartTag),
303 * or if character content has been written since the start tag was written.
304 */
305
306 public void namespace(NamespaceBindingSet nsBindings, int properties)
307 throws XPathException {
308 // Optimization for recursive shallow-copy added in 9.8 - see bug 3011.
309 if (nsBindings instanceof InScopeNamespaces) {
310 copyNamespacesStack[level] = (InScopeNamespaces)nsBindings;
311 if (level > 0 && copyNamespacesStack[level - 1] != null &&
312 copyNamespacesStack[level - 1].getElement().equals(((InScopeNamespaces)nsBindings).getElement())) {
313 // Ignore these namespaces if they are the same as the namespaces for the parent element
314 return;
315 }
316 }
317
318 // System.err.println("Write namespace prefix=" + (nscode>>16) + " uri=" + (nscode&0xffff));
319 for (NamespaceBinding ns : nsBindings) {
320 if (state != StartTag) {
321 throw NoOpenStartTagException.makeNoOpenStartTagException(
322 Type.NAMESPACE,
323 ns.getPrefix(),
324 hostLanguage,
325 currentLevelIsDocument[level],
326 startElementLocationId);
327 }
328
329 // elimination of namespaces already present on an outer element of the
330 // result tree is done by the NamespaceReducer.
331
332 // Handle declarations whose prefix is duplicated for this element.
333
334 boolean rejectDuplicates = (properties & ReceiverOptions.REJECT_DUPLICATES) != 0;
335
336 for (int i = 0; i < pendingNSListSize; i++) {
337 if (ns.getPrefix().equals(pendingNSList[i].getPrefix())) {
338 if (ns.getURI().equals(pendingNSList[i].getURI())) {
339 return; // duplicate namespace, no action needed
340 }
341 if (pendingNSList[i].isDefaultUndeclaration() || ns.isDefaultUndeclaration()) {
342 // xmlns="" overridden by xmlns="abc"
343 pendingNSList[i] = ns;
344 } else if (rejectDuplicates) {
345 String prefix = ns.getPrefix();
346 String uri1 = ns.getURI();
347 String uri2 = pendingNSList[i].getURI();
348 XPathException err = new XPathException("Cannot create two namespace nodes with the same prefix mapped to different URIs (prefix=" +
349 (prefix.isEmpty() ? "\"\"" : prefix) + ", URI=" +
350 (uri1.isEmpty() ? "\"\"" : uri1) + ", URI=" +
351 (uri2.isEmpty() ? "\"\"" : uri2) + ")");
352 err.setErrorCode(hostLanguage == Configuration.XSLT ? "XTDE0430" : "XQDY0102");
353 throw err;
354 } else {
355 // same prefix, do a quick exit
356 return;
357 }
358 }
359 }
360
361 // It is an error to output a namespace node for the default namespace if the element
362 // itself is in the null namespace, as the resulting element could not be serialized
363
364 if (ns.getPrefix().isEmpty() && !ns.getURI().isEmpty()) {
365 declaresDefaultNamespace = true;
366 if (elementIsInNullNamespace == null) {
367 elementIsInNullNamespace = pendingStartTag.hasURI("");
368 }
369 if (elementIsInNullNamespace) {
370 XPathException err = new XPathException("Cannot output a namespace node for the default namespace when the element is in no namespace");
371 err.setErrorCode(hostLanguage == Configuration.XSLT ? "XTDE0440" : "XQDY0102");
372 throw err;
373 }
374 }
375
376 // if it's not a duplicate namespace, add it to the list for this start tag
377
378 if (pendingNSListSize + 1 > pendingNSList.length) {
379 pendingNSList = Arrays.copyOf(pendingNSList, pendingNSListSize * 2);
380 }
381 pendingNSList[pendingNSListSize++] = ns;
382 previousAtomic = false;
383 }
384 }
385
386
387 /**
388 * Output an attribute value. <br>
389 * This is added to a list of pending attributes for the current start tag, overwriting
390 * any previous attribute with the same name. <br>
391 * This method should NOT be used to output namespace declarations.<br>
392 *
393 * @param attName The name of the attribute
394 * @param value The value of the attribute
395 * @param locationId the location of the node in the source, or of the instruction that created it
396 *@param properties Bit fields containing properties of the attribute to be written @throws XPathException if there is no start tag to write to (created using writeStartTag),
397 * or if character content has been written since the start tag was written.
398 */
399
400 public void attribute(NodeName attName, SimpleType typeCode, CharSequence value, Location locationId, int properties) throws XPathException {
401 //System.err.println("Write attribute " + attName + "=" + value + " to Outputter " + this);
402 if (level >= 0 && state != StartTag) {
403 // The complexity here is in identifying the right error message and error code
404
405 XPathException err = NoOpenStartTagException.makeNoOpenStartTagException(
406 Type.ATTRIBUTE,
407 attName.getDisplayName(),
408 hostLanguage,
409 currentLevelIsDocument[level],
410 startElementLocationId);
411 err.setLocator(locationId);
412 throw err;
413 }
414
415 // if this is a duplicate attribute, overwrite the original in XSLT; throw an error in XQuery.
416 // No check needed if the NOT_A_DUPLICATE property is set (typically, during a deep copy operation)
417
418 if (level >= 0 && ((properties & ReceiverOptions.NOT_A_DUPLICATE)==0)) {
419 for (int a = 0; a < pendingAttListSize; a++) {
420 if (pendingAttCode[a].equals(attName)) {
421 if (hostLanguage == Configuration.XSLT) {
422 pendingAttType[a] = typeCode;
423 pendingAttValue[a] = value.toString();
424 // we have to copy the CharSequence, because some kinds of CharSequence are mutable.
425 pendingAttLocation[a] = locationId;
426 pendingAttProp[a] = properties;
427 return;
428 } else {
429 XPathException err = new XPathException("Cannot create an element having two attributes with the same name: " +
430 Err.wrap(attName.getDisplayName(), Err.ATTRIBUTE));
431 err.setErrorCode("XQDY0025");
432 throw err;
433 }
434 }
435 }
436 }
437
438 // for top-level attributes (attributes whose parent element is not being copied),
439 // check that the type annotation is not namespace-sensitive (because the namespace context might
440 // be different, and we don't do namespace fixup for prefixes in content: see bug 4151
441
442 if (level == 0 && !typeCode.equals(BuiltInAtomicType.UNTYPED_ATOMIC) /**/ && currentLevelIsDocument[0] /**/) {
443 // commenting-out in line above done MHK 22 Jul 2011 to pass test Constr-cont-nsmode-8
444 // reverted 2011-07-27 to pass tests in qischema family
445 if (typeCode.isNamespaceSensitive()) {
446 XPathException err = new XPathException("Cannot copy attributes whose type is namespace-sensitive (QName or NOTATION): " +
447 Err.wrap(attName.getDisplayName(), Err.ATTRIBUTE));
448 err.setErrorCode(hostLanguage == Configuration.XSLT ? "XTTE0950" : "XQTY0086");
449 throw err;
450 }
451 }
452
453 // push top-level attribute nodes down the pipeline
454 if (level < 0) {
455 nextReceiver.attribute(attName, typeCode, value, locationId, properties);
456 }
457
458 // otherwise, add this one to the list
459
460 if (pendingAttListSize >= pendingAttCode.length) {
461 pendingAttCode = Arrays.copyOf(pendingAttCode, pendingAttListSize * 2);
462 pendingAttType = Arrays.copyOf(pendingAttType, pendingAttListSize * 2);
463 pendingAttValue = Arrays.copyOf(pendingAttValue, pendingAttListSize * 2);
464 pendingAttLocation = Arrays.copyOf(pendingAttLocation, pendingAttListSize * 2);
465 pendingAttProp = Arrays.copyOf(pendingAttProp, pendingAttListSize * 2);
466 }
467
468 pendingAttCode[pendingAttListSize] = attName;
469 pendingAttType[pendingAttListSize] = typeCode;
470 pendingAttValue[pendingAttListSize] = value.toString();
471 pendingAttLocation[pendingAttListSize] = locationId;
472 pendingAttProp[pendingAttListSize] = properties;
473 pendingAttListSize++;
474 previousAtomic = false;
475 }
476
477 /**
478 * Check that the prefix for an element or attribute is acceptable, allocating a substitute
479 * prefix if not. The prefix is acceptable unless a namespace declaration has been
480 * written that assignes this prefix to a different namespace URI. This method
481 * also checks that the element or attribute namespace has been declared, and declares it
482 * if not.
483 *
484 * @param nodeName the proposed name, including proposed prefix
485 * @param seq sequence number, used for generating a substitute prefix when necessary.
486 * The value 0 is used for element names; values greater than 0 are used
487 * for attribute names.
488 * @return a nameCode to use in place of the proposed nameCode (or the original nameCode
489 * if no change is needed)
490 * @throws net.sf.saxon.trans.XPathException
491 * if an error occurs writing the new
492 * namespace node
493 */
494
495 private NodeName checkProposedPrefix(NodeName nodeName, int seq) throws XPathException {
496 NamespaceBinding binding = nodeName.getNamespaceBinding();
497 String nsprefix = binding.getPrefix();
498
499 for (int i = 0; i < pendingNSListSize; i++) {
500 if (nsprefix.equals(pendingNSList[i].getPrefix())) {
501 // same prefix
502 if (binding.getURI().equals(pendingNSList[i].getURI())) {
503 // same URI
504 return nodeName; // all is well
505 } else {
506 String prefix = getSubstitutePrefix(binding, seq);
507 NodeName newName = new FingerprintedQName(prefix, nodeName.getURI(), nodeName.getLocalPart());
508 namespace(newName.getNamespaceBinding(), 0);
509 return newName;
510 }
511 }
512 }
513 // no declaration of this prefix: declare it now
514 if (seq > 0 && nsprefix.isEmpty()) {
515 // This is an attribute and the prefix is "" - need to invent a prefix
516 // See bug 3068 and unit test ParserTest/testXercesSchemaDefaultedAttributes
517 String prefix = getSubstitutePrefix(binding, seq);
518 NodeName newName = new FingerprintedQName(prefix, nodeName.getURI(), nodeName.getLocalPart());
519 namespace(newName.getNamespaceBinding(), 0);
520 return newName;
521 }
522 namespace(binding, 0);
523 return nodeName;
524 }
525
526 /**
527 * It is possible for a single output element to use the same prefix to refer to different
528 * namespaces. In this case we have to generate an alternative prefix for uniqueness. The
529 * one we generate is based on the sequential position of the element/attribute: this is
530 * designed to ensure both uniqueness (with a high probability) and repeatability
531 *
532 * @param nscode the proposed namespace code
533 * @param seq sequence number for use in the substitute prefix
534 * @return a prefix to use in place of the one originally proposed
535 */
536
537 private String getSubstitutePrefix(NamespaceBinding nscode, int seq) {
538 if (nscode.getURI().equals(NamespaceConstant.XML)) {
539 return "xml";
540 }
541 return nscode.getPrefix() + '_' + seq;
542 }
543
544 /**
545 * Output an element end tag.
546 */
547
548 public void endElement() throws XPathException {
549 //System.err.println("Write end tag " + this + " : " + name);
550 if (state == StartTag) {
551 startContent();
552 } else {
553 //pendingStartTagDepth = -2;
554 pendingStartTag = null;
555 }
556
557 // write the end tag
558
559 nextReceiver.endElement();
560 level--;
561 previousAtomic = false;
562 state = level < 0 ? Open : Content;
563 }
564
565 /**
566 * Write a comment
567 */
568
569 public void comment(CharSequence comment, Location locationId, int properties) throws XPathException {
570 if (level >= 0) {
571 if (state == StartTag) {
572 startContent();
573 }
574 previousAtomic = false;
575 }
576 nextReceiver.comment(comment, locationId, properties);
577 }
578
579 /**
580 * Write a processing instruction
581 */
582
583 public void processingInstruction(String target, CharSequence data, Location locationId, int properties) throws XPathException {
584 if (level >= 0) {
585 if (state == StartTag) {
586 startContent();
587 }
588 previousAtomic = false;
589 }
590 nextReceiver.processingInstruction(target, data, locationId, properties);
591 }
592
593 /**
594 * Append an arbitrary item (node or atomic value) to the output
595 *
596 * @param item the item to be appended
597 * @param locationId the location of the calling instruction, for diagnostics
598 * @param copyNamespaces if the item is an element node, this indicates whether its namespaces
599 * need to be copied. Values are {@link ReceiverOptions#ALL_NAMESPACES},
600 * {@link ReceiverOptions#LOCAL_NAMESPACES}; the default (0) means
601 * no namespaces
602 */
603
604 public void append(Item item, Location locationId, int copyNamespaces) throws XPathException {
605 // Decompose the item into a sequence of node events if we're within a start/end element/document
606 // pair. Otherwise, send the item down the pipeline unchanged: it's the job of the Destination
607 // to deal with it (inserting item separators if appropriate)
608 if (level >= 0) {
609 decompose(item, locationId, copyNamespaces);
610 } else {
611 nextReceiver.append(item, locationId, copyNamespaces);
612 }
613 }
614
615 /**
616 * Close the output
617 */
618
619 public void close() throws XPathException {
620 // System.err.println("Close " + this + " using emitter " + emitter.getClass());
621 nextReceiver.close();
622 previousAtomic = false;
623 state = Final;
624 }
625
626 /**
627 * Flush out a pending start tag
628 */
629
630 public void startContent() throws XPathException {
631
632 if (state != StartTag) {
633 // this can happen if the method is called from outside,
634 // e.g. from a SequenceOutputter earlier in the pipeline
635 return;
636 }
637
638 NodeName elcode = checkProposedPrefix(pendingStartTag, 0);
639 int props = startElementProperties | ReceiverOptions.NAMESPACE_OK;
640 nextReceiver.startElement(elcode, currentSimpleType, startElementLocationId, props);
641
642 for (int a = 0; a < pendingAttListSize; a++) {
643 NodeName attcode = pendingAttCode[a];
644 if (!attcode.hasURI("")) { // non-null prefix
645 attcode = checkProposedPrefix(attcode, a + 1);
646 pendingAttCode[a] = attcode;
647 }
648 }
649
650 for (int n = 0; n < pendingNSListSize; n++) {
651 nextReceiver.namespace(pendingNSList[n], 0);
652 }
653
654 for (int a = 0; a < pendingAttListSize; a++) {
655 nextReceiver.attribute(pendingAttCode[a],
656 pendingAttType[a],
657 pendingAttValue[a],
658 pendingAttLocation[a],
659 pendingAttProp[a]);
660 }
661
662 nextReceiver.startContent();
663
664 pendingAttListSize = 0;
665 pendingNSListSize = 0;
666 //pendingStartTagDepth = -1;
667 previousAtomic = false;
668 state = Content;
669 }
670
671 /**
672 * Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations
673 * supplied on element and attribute events
674 *
675 * @return true if the Receiver makes any use of this information. If false, the caller
676 * may supply untyped nodes instead of supplying the type annotation
677 */
678
679 public boolean usesTypeAnnotations() {
680 return nextReceiver.usesTypeAnnotations();
681 }
682
683 public boolean isReadyForGrafting() {
684 Receiver r2 = getReceiver();
685 if (r2 instanceof NamespaceReducer) {
686 if (!((NamespaceReducer) r2).isDisinheritingNamespaces()) {
687 Receiver r3 = ((NamespaceReducer) r2).getNextReceiver();
688 return r3 instanceof TinyBuilder &&
689 ((state == StartTag &&
690 (startElementProperties & ReceiverOptions.DISINHERIT_NAMESPACES) == 0)
691 || ((TinyBuilder) r3).isPositionedAtElement());
692 }
693 }
694 return false;
695 }
696
697 public void graftElementNode(TinyElementImpl elementNode, int copyOptions) throws XPathException {
698 NamespaceReducer r2 = (NamespaceReducer)getReceiver();
699 TinyBuilder target = (TinyBuilder)r2.getNextReceiver();
700 beforeBulkCopy();
701 boolean copyNamespaces = CopyOptions.includes(copyOptions, CopyOptions.ALL_NAMESPACES);
702 target.graft(elementNode, copyNamespaces);
703 afterBulkCopy();
704 }
705
706 public boolean isReadyForBulkCopy() {
707 Receiver r2 = getReceiver();
708 if (r2 instanceof NamespaceReducer) {
709 if (!((NamespaceReducer) r2).isDisinheritingNamespaces()) {
710 Receiver r3 = ((NamespaceReducer) r2).getNextReceiver();
711 return r3 instanceof TinyBuilder &&
712 ((state == StartTag &&
713 (startElementProperties & ReceiverOptions.DISINHERIT_NAMESPACES) == 0)
714 || ((TinyBuilder) r3).isPositionedAtElement());
715 }
716 }
717 return false;
718 }
719
720 public void bulkCopyElementNode(TinyElementImpl elementNode, int copyOptions) throws XPathException {
721 NamespaceReducer r2 = (NamespaceReducer) getReceiver();
722 TinyBuilder target = (TinyBuilder) r2.getNextReceiver();
723 beforeBulkCopy();
724 boolean copyNamespaces = CopyOptions.includes(copyOptions, CopyOptions.ALL_NAMESPACES);
725 target.bulkCopy(elementNode, copyNamespaces);
726 afterBulkCopy();
727 }
728
729 private void beforeBulkCopy() throws XPathException {
730 level++;
731 if (state == StartTag) {
732 startContent();
733 }
734 }
735
736 private void afterBulkCopy() {
737 level--;
738 previousAtomic = false;
739 }
740 }
741