public static void writeXdmValue(Processor proc, Vector<XdmValue> values, Destination destination, URI baseURI) throws SaxonApiException { try { Configuration config = proc.getUnderlyingConfiguration(); PipelineConfiguration pipeConfig = config.makePipelineConfiguration(); Receiver out = destination.getReceiver(config); TreeReceiver tree = new TreeReceiver(out); tree.setPipelineConfiguration(pipeConfig); if (baseURI != null) { tree.setSystemId(baseURI.toASCIIString()); } tree.open(); tree.startDocument(0); for (XdmValue value : values) { for (XdmItem item : (Iterable<XdmItem>) value) { tree.append((Item) item.getUnderlyingValue(), VoidLocation.instance(), NodeInfo.ALL_NAMESPACES); } } tree.endDocument(); tree.close(); } catch (XPathException err) { throw new SaxonApiException(err); } }
/** * Notify a namespace. Namespaces are notified <b>after</b> 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 namespaceCode an integer: the top half is a prefix code, the bottom half a URI code. * These may be translated into an actual prefix and URI using the name pool. A prefix code of * zero represents the empty prefix (that is, the default namespace). A URI code of zero represents * a URI of "", that is, a namespace undeclaration. * @throws IllegalStateException: attempt to output a namespace when there is no open element * start tag */ public void namespace(int namespaceCode, int properties) throws XPathException { if (contentStarted) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, getNamePool().getPrefixFromNamespaceCode(namespaceCode), getPipelineConfiguration().getHostLanguage(), true, getPipelineConfiguration().isSerializing()); } nextReceiver.namespace(namespaceCode, properties); previousAtomic = false; }
/** * Processing Instruction */ public void processingInstruction(String target, CharSequence data, Location locationId, int properties) throws XPathException { if (inStartTag) { startContent(); } nextReceiver.processingInstruction(target, data, locationId, properties); previousAtomic = false; }
/** * Serialize a sequence to a given result * @param iterator the sequence to be serialized * @param config the Saxon Configuration * @param result the destination to receive the output * @param outputProperties the serialization properties to be used. The requested properties are * not validated. * @throws XPathException * @since 9.0 */ public static void serializeSequence( SequenceIterator iterator, Configuration config, Result result, Properties outputProperties) throws XPathException { SerializerFactory sf = config.getSerializerFactory(); PipelineConfiguration pipe = config.makePipelineConfiguration(); Receiver receiver = sf.getReceiver(result, pipe, outputProperties); TreeReceiver tr = new TreeReceiver(receiver); tr.open(); while (true) { Item item = iterator.next(); if (item == null) { break; } tr.append(item, 0, NodeInfo.ALL_NAMESPACES); } tr.close(); }
/** * Append an arbitrary item (node or atomic value) to the output */ public void append(Item item, int locationId, int copyNamespaces) throws XPathException { if (item instanceof AtomicValue) { if (previousAtomic) { characters(" ", locationId, 0); } characters(item.getStringValueCS(), locationId, 0); previousAtomic = true; } else if (((NodeInfo)item).getNodeKind() == Type.DOCUMENT) { startDocument(0); // needed to ensure that illegal namespaces or attributes in the content are caught SequenceIterator iter = ((NodeInfo)item).iterateAxis(Axis.CHILD); while (true) { Item it = iter.next(); if (it == null) break; append(it, locationId, copyNamespaces); } previousAtomic = false; endDocument(); } else { ((NodeInfo)item).copy(this, copyNamespaces, true, locationId); previousAtomic = false; } }
Receiver out = destination.getReceiver(config.makePipelineConfiguration(), config.obtainDefaultSerializationProperties()); out = new NamespaceReducer(out); TreeReceiver tree = new TreeReceiver(out); tree.open(); tree.startDocument(0); for (XdmItem item : value) { tree.append(item.getUnderlyingValue(), ExplicitLocation.UNKNOWN_LOCATION, ReceiverOptions.ALL_NAMESPACES); tree.endDocument(); tree.close(); destination.closeAndNotify();
public TeeOutputter(Receiver seq1, Receiver seq2) { if (seq1 instanceof SequenceReceiver) { this.seq1 = (SequenceReceiver)seq1; } else { this.seq1 = new TreeReceiver(seq1); } if (seq2 instanceof SequenceReceiver) { this.seq2 = (SequenceReceiver)seq2; } else { this.seq2 = new TreeReceiver(seq2); } }
c2.setTemporaryReceiver(ini); } else { TreeReceiver tr = new TreeReceiver(validator); tr.setPipelineConfiguration(seq.getPipelineConfiguration()); c2.setReceiver(tr); ini = tr;
/** * Create a TreeReceiver * @param nextInChain the receiver to which events will be directed, after * expanding append events into more primitive tree-based events */ public TreeReceiver(Receiver nextInChain) { nextReceiver = nextInChain; previousAtomic = false; setPipelineConfiguration(nextInChain.getPipelineConfiguration()); }
/** * Append an arbitrary item (node or atomic value) to the output */ public void append(Item item, int locationId, int copyNamespaces) throws XPathException { if (item instanceof AtomicValue) { if (previousAtomic) { characters(" ", locationId, 0); } characters(item.getStringValueCS(), locationId, 0); previousAtomic = true; } else if (((NodeInfo)item).getNodeKind() == Type.DOCUMENT) { SequenceIterator iter = ((NodeInfo)item).iterateAxis(Axis.CHILD); while (true) { Item it = iter.next(); if (it == null) break; append(it, locationId, copyNamespaces); } previousAtomic = false; } else { ((NodeInfo)item).copy(this, copyNamespaces, true, locationId); previousAtomic = false; } }
/** * 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 the location of the node in the source, or of the instruction that created it * @param properties Bit significant value. The following bits are defined: * <dl> * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * </dl> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(NodeName nameCode, SimpleType typeCode, CharSequence value, Location locationId, int properties) throws XPathException { boolean documentLevel = level == 0 || isDocumentLevel[level - 1]; if (documentLevel || !inStartTag) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.ATTRIBUTE, nameCode.getDisplayName(), getPipelineConfiguration().getHostLanguage(), documentLevel, ExplicitLocation.UNKNOWN_LOCATION); } nextReceiver.attribute(nameCode, typeCode, value, locationId, properties); previousAtomic = false; }
Receiver out = destination.getReceiver(config.makePipelineConfiguration(), config.obtainDefaultSerializationProperties()); out = new NamespaceReducer(out); TreeReceiver tree = new TreeReceiver(out); tree.open(); tree.startDocument(0); for (XdmItem item : value) { tree.append(item.getUnderlyingValue(), ExplicitLocation.UNKNOWN_LOCATION, ReceiverOptions.ALL_NAMESPACES); tree.endDocument(); tree.close(); destination.closeAndNotify();
public TeeOutputter(Receiver seq1, Receiver seq2) { if (seq1 instanceof SequenceReceiver) { this.seq1 = (SequenceReceiver)seq1; } else { this.seq1 = new TreeReceiver(seq1); } if (seq2 instanceof SequenceReceiver) { this.seq2 = (SequenceReceiver)seq2; } else { this.seq2 = new TreeReceiver(seq2); } }
TreeReceiver tr = new TreeReceiver(receiver); tr.open(); while (true) { Item item = iterator.next(); break; tr.append(item, 0, NodeInfo.ALL_NAMESPACES); tr.close();
c2.setTemporaryReceiver(ini); } else { TreeReceiver tr = new TreeReceiver(validator); tr.setPipelineConfiguration(seq.getPipelineConfiguration()); c2.setReceiver(tr); ini = tr;
/** * Create a TreeReceiver * @param nextInChain the receiver to which events will be directed, after * expanding append events into more primitive tree-based events */ public TreeReceiver(Receiver nextInChain) { nextReceiver = nextInChain; previousAtomic = false; setPipelineConfiguration(nextInChain.getPipelineConfiguration()); }
/** * Notify a namespace. Namespaces are notified <b>after</b> 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 { boolean documentLevel = level == 0 || isDocumentLevel[level - 1]; if (documentLevel || !inStartTag) { //noinspection LoopStatementThatDoesntLoop for (NamespaceBinding ns : namespaceBindings) { // Throw an exception if there is an least one namespace binding in the set throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, ns.getPrefix(), getPipelineConfiguration().getHostLanguage(), documentLevel, ExplicitLocation.UNKNOWN_LOCATION); } } nextReceiver.namespace(namespaceBindings, properties); previousAtomic = false; }
public static void writeXdmValue(XProcRuntime runtime, XdmItem node, Destination destination, URI baseURI) throws SaxonApiException { try { Processor proc = runtime.getProcessor(); Configuration config = proc.getUnderlyingConfiguration(); PipelineConfiguration pipeConfig = config.makePipelineConfiguration(); Receiver out = destination.getReceiver(config); TreeReceiver tree = new TreeReceiver(out); tree.setPipelineConfiguration(pipeConfig); if (baseURI != null) { tree.setSystemId(baseURI.toASCIIString()); } tree.open(); tree.startDocument(0); tree.append((Item) node.getUnderlyingValue(), VoidLocation.instance(), NodeInfo.ALL_NAMESPACES); tree.endDocument(); tree.close(); } catch (XPathException err) { throw new SaxonApiException(err); } }
public SequenceReceiver makeSequenceNormalizer(Receiver receiver, Properties properties) { String method = properties.getProperty(OutputKeys.METHOD); if ("json".equals(method) || "adaptive".equals(method)) { return receiver instanceof SequenceReceiver ? (SequenceReceiver)receiver : new TreeReceiver(receiver); } else { PipelineConfiguration pipe = receiver.getPipelineConfiguration(); SequenceReceiver result; String separator = properties.getProperty(SaxonOutputKeys.ITEM_SEPARATOR); if (separator == null || "#absent".equals(separator)) { result = new SequenceNormalizerWithSpaceSeparator(receiver); } else { result = new SequenceNormalizerWithItemSeparator(receiver, separator); } result.setPipelineConfiguration(pipe); return result; } }
context.setReceiver(ini); } else { TreeReceiver tr = new TreeReceiver(validator); tr.setPipelineConfiguration(seq.getPipelineConfiguration()); context.setReceiver(tr); ini = tr;