//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2018 Saxonica Limited. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// package net.sf.saxon.event; import net.sf.saxon.expr.parser.Location; import net.sf.saxon.om.*; import net.sf.saxon.trans.XPathException; import net.sf.saxon.type.SchemaType; import net.sf.saxon.type.SimpleType; /** * TeeOutputter: a SequenceReceiver that duplicates received events to two different destinations */ public class TeeOutputter extends SequenceReceiver { Receiver seq1; Receiver seq2; public TeeOutputter(Receiver seq1, Receiver seq2) { super(seq1.getPipelineConfiguration()); this.seq1 = seq1; this.seq2 = seq2; } /** * Set the first destination * * @param seq1 the first output destination */ protected void setFirstDestination(Receiver seq1) { this.seq1 = seq1; } /** * Set the second destination * * @param seq2 the second output destination */ protected void setSecondDestination(Receiver seq2) { this.seq2 = seq2; } /** * Get the first destination * * @return the first output destination */ protected Receiver getFirstDestination() { return seq1; } /** * Get the second destination * * @return the second output destination */ protected Receiver getSecondDestination() { return seq2; } /** * Pass on information about unparsed entities * @param name The name of the unparsed entity * @param systemID The system identifier of the unparsed entity * @param publicID The public identifier of the unparsed entity * @throws XPathException in the event of an error */ @Override public void setUnparsedEntity(String name, String systemID, String publicID) throws XPathException { seq1.setUnparsedEntity(name, systemID, publicID); seq2.setUnparsedEntity(name, systemID, publicID); } /** * Output an item (atomic value or node) to the sequence */ public void append(Item item, Location locationId, int properties) throws XPathException { seq1.append(item, locationId, properties); seq2.append(item, locationId, properties); } @Override public void open() throws XPathException { super.open(); seq1.open(); seq2.open(); } /** * Notify the start of a document node */ public void startDocument(int properties) throws XPathException { seq1.startDocument(properties); seq2.startDocument(properties); } /** * Notify the end of a document node */ public void endDocument() throws XPathException { seq1.endDocument(); seq2.endDocument(); } /** * Notify the start of an element * @param nameCode integer code identifying the name of the element within the name pool. * @param typeCode integer code identifying the element's type within the name pool. The value -1 * indicates the default type, xs:untyped. * @param location * @param properties bit-significant properties of the element node. If there are no revelant */ public void startElement(NodeName nameCode, SchemaType typeCode, Location location, int properties) throws XPathException { seq1.startElement(nameCode, typeCode, location, properties); seq2.startElement(nameCode, typeCode, location, properties); } /** * Notify a namespace. Namespaces are notified after the startElement event, and before * any children for the element. The namespaces that are reported are only required * to include those that are different from the parent element; however, duplicates may be reported. * A namespace must not conflict with any namespaces already used for element or attribute names. * * @param namespaceBindings the prefix/uri pair * @throws IllegalStateException: attempt to output a namespace when there is no open element * start tag */ public void namespace(NamespaceBindingSet namespaceBindings, int properties) throws XPathException { seq1.namespace(namespaceBindings, properties); seq2.namespace(namespaceBindings, properties); } /** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute * @param typeCode The type of the attribute * @param locationId an integer which can be interpreted using a LocationMap to return * information such as line number and system ID. If no location information is available, * the value zero is supplied. * @param properties Bit significant value. The following bits are defined: *