//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 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.jaxp; import net.sf.saxon.event.PipelineConfiguration; import net.sf.saxon.event.Receiver; import net.sf.saxon.event.ReceiverWithOutputProperties; import net.sf.saxon.event.SequenceNormalizer; import net.sf.saxon.lib.SaxonOutputKeys; import net.sf.saxon.s9api.AbstractDestination; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.serialize.SerializationProperties; /** * An implementation of {@code Destination} that simply wraps a supplied {@code Receiver} *
The supplied {@code Receiver} will be wrapped in a sequence normalizer unless requested * otherwise. Specifically, it is wrapped unless the method {@link #acceptsRawOutput()} * returns true.
*/ public class ReceivingDestination extends AbstractDestination { private Receiver outputTarget; /** * Create a {@code ReceivingDestination} that wraps a supplied {@code Receiver} * @param target the supplied {@code Receiver}. This must accept a regular event sequence * as defined in {@link net.sf.saxon.event.RegularSequenceChecker} */ public ReceivingDestination(Receiver target) { this.outputTarget = target; } /** * Get a {@code Receiver} to which events may be sent. For this implementation, this * will be the wrapped {@code Receiver}. * @param pipe The Saxon configuration. Not used in this implementation. * @param properties The required serialization properties (not used) * @return the wrapped {@code Receiver} */ public Receiver getReceiver(PipelineConfiguration pipe, SerializationProperties properties) { if (acceptsRawOutput()) { return outputTarget; } else { return properties.makeSequenceNormalizer(outputTarget); } } /** * Ask whether this receiver accepts raw output, that is, an arbitrary sequence of items * not necessarily forming an XML document or element tree. May be overridden in a subclass. * @return false unless one of the following conditions is true: *