All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.saxon.jaxp.ReceivingDestination Maven / Gradle / Ivy

There is a newer version: 12.5
Show newest version
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2018-2023 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.*;
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 final 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} */ @Override 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: *
    *
  1. The {@code Receiver} is an instance of {@link SequenceNormalizer}
  2. *
  3. The {@code Receiver} implements {@link ReceiverWithOutputProperties}, * and a call on {@code getOutputProperties(SaxonOutputPropertes.REQUIRE_WELL_FORMED)} returns "no"
  4. *
  5. The method {#acceptRawOutput()} is implemented in a subclass of {@code ReceivingDestination}, * and returns false.
  6. *
*/ public boolean acceptsRawOutput() { if (outputTarget instanceof SequenceNormalizer) { return true; } if (outputTarget instanceof ReceiverWithOutputProperties) { return "no".equals(((ReceiverWithOutputProperties)outputTarget) .getOutputProperties().getProperty(SaxonOutputKeys.REQUIRE_WELL_FORMED)); } return false; } @Override public void close() throws SaxonApiException { // try { // outputTarget.close(); // } catch (XPathException e) { // throw new SaxonApiException(e); // } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy