/** * Create a DOMSender that will send events representing the nodes in a tree * to a nominated receiver * * @param startNode the root node of the tree to be send. Usually a document or element node. * @param receiver the object to be notified of the resulting events. The supplied Receiver must * be initialized with a PipelineConfiguration. The caller is responsible for opening * and closing the Receiver. */ public DOMSender(Node startNode, Receiver receiver) { if (startNode == null) { throw new NullPointerException("startNode"); } if (receiver == null) { throw new NullPointerException("receiver"); } this.root = startNode; this.receiver = new NamespaceReducer(receiver); }
/** * Create a DOMSender that will send events representing the nodes in a tree * to a nominated receiver * * @param startNode the root node of the tree to be send. Usually a document or element node. * @param receiver the object to be notified of the resulting events. The supplied Receiver must * be initialized with a PipelineConfiguration. The caller is responsible for opening * and closing the Receiver. */ public DOMSender(Node startNode, Receiver receiver) { if (startNode == null) { throw new NullPointerException("startNode"); } if (receiver == null) { throw new NullPointerException("receiver"); } this.root = startNode; this.receiver = new NamespaceReducer(receiver); }
/** * This method constructs a step in the output pipeline to perform namespace-related * tasks for HTML5 serialization. The default implementation adds a NamespaceReducer * and an XHTMLPrefixRemover * * @param target the Receiver that receives the output of this step * @param outputProperties the serialization properties * @return a new Receiver to perform HTML5-related namespace manipulation */ public Receiver addHtml5Component(Receiver target, Properties outputProperties) { target = new NamespaceReducer(target); target = new XHTMLPrefixRemover(target); return target; }
/** * This method constructs a step in the output pipeline to perform namespace-related * tasks for HTML5 serialization. The default implementation adds a NamespaceReducer * and an XHTMLPrefixRemover * * @param target the Receiver that receives the output of this step * @param outputProperties the serialization properties * @return a new Receiver to perform HTML5-related namespace manipulation */ public Receiver addHtml5Component(Receiver target, Properties outputProperties) { target = new NamespaceReducer(target); target = new XHTMLPrefixRemover(target); return target; }
/** * Create a serializer with given output properties, and return * an XMLStreamWriter that can be used to feed events to the serializer. * * @param result the destination of the serialized output (wraps a Writer, an OutputStream, or a File) * @param properties the serialization properties to be used * @return a serializer in the form of an XMLStreamWriter * @throws net.sf.saxon.trans.XPathException * if any error occurs */ public StreamWriterToReceiver getXMLStreamWriter( StreamResult result, Properties properties) throws XPathException { Receiver r = getReceiver(result, new SerializationProperties(properties)); r = new NamespaceReducer(r); return new StreamWriterToReceiver(r); }
/** * Create a serializer with given output properties, and return * an XMLStreamWriter that can be used to feed events to the serializer. * * @param result the destination of the serialized output (wraps a Writer, an OutputStream, or a File) * @param properties the serialization properties to be used * @return a serializer in the form of an XMLStreamWriter * @throws net.sf.saxon.trans.XPathException * if any error occurs */ public StreamWriterToReceiver getXMLStreamWriter( StreamResult result, Properties properties) throws XPathException { Receiver r = getReceiver(result, new SerializationProperties(properties)); r = new NamespaceReducer(r); return new StreamWriterToReceiver(r); }
public static XMLStreamWritable<XdmNode> nodeWriter(Configuration configuration) throws SaxonApiException, XPathException { XdmDestination destination = new XdmDestination(); Receiver receiver = new NamespaceReducer(destination.getReceiver(configuration)); receiver.open(); BaseURIAwareXMLStreamWriter writer = new BaseURIAwareStreamWriterToReceiver(receiver); return new XMLStreamWritable<XdmNode>() { public BaseURIAwareXMLStreamWriter getWriter() { return writer; } public XdmNode doneWriting() throws TransformerException { try { receiver.close(); return destination.getXdmNode(); } catch (XPathException e) { throw new TransformerException(e); } } }; }
/** * Get an XMLStreamWriter that can be used for writing application-generated XML * to be output via this serializer. * * @return a newly constructed XMLStreamWriter that pipes events into this Serializer * @throws SaxonApiException if any other failure occurs * @since 9.3 */ public StreamWriterToReceiver getXMLStreamWriter() throws SaxonApiException { PipelineConfiguration pipe = processor.getUnderlyingConfiguration().makePipelineConfiguration(); Receiver r = getReceiver(pipe, getSerializationProperties()); r = new NamespaceReducer(r); return new StreamWriterToReceiver(r); }
/** * Get an XMLStreamWriter that can be used for writing application-generated XML * to be output via this serializer. * * @return a newly constructed XMLStreamWriter that pipes events into this Serializer * @throws SaxonApiException if any other failure occurs * @since 9.3 */ public StreamWriterToReceiver getXMLStreamWriter() throws SaxonApiException { PipelineConfiguration pipe = processor.getUnderlyingConfiguration().makePipelineConfiguration(); Receiver r = getReceiver(pipe, getSerializationProperties()); r = new NamespaceReducer(r); return new StreamWriterToReceiver(r); }
/** * Get an {@link javax.xml.stream.XMLStreamWriter} that may be used to build the document programmatically. * * @return a newly constructed {@link BuildingStreamWriter}, which implements the <code>XMLStreamWriter</code> * interface. If schema validation has been requested for this <code>DocumentBuilder</code>, then the document constructed * using the <code>XMLStreamWriter</code> will be validated as it is written. * <p>If the stream of events supplied to the <code>XMLStreamWriter</code> does not constitute * a well formed (and namespace-well-formed) document, the effect is undefined; Saxon may fail * to detect the error, and construct an unusable tree. </p> * @throws SaxonApiException if any failure occurs * @since 9.3 */ public BuildingStreamWriterImpl newBuildingStreamWriter() throws SaxonApiException { PipelineConfiguration pipe = config.makePipelineConfiguration(); Builder builder = treeModel.makeBuilder(pipe); builder.setLineNumbering(lineNumbering); Receiver r = builder; r = new NamespaceReducer(r); r = injectValidator(r, builder); return new BuildingStreamWriterImpl(r, builder); }
/** * Make the handler to construct the XML tree representation for JSON * * @param context the context in which the result tree is to be built * @param staticBaseUri the static base URI, used for the base URI of the constructed tree * @param flags flags indicating the chosen options * @throws XPathException if initialization fails, for example because of problems loading the schema */ public JsonHandlerXML(XPathContext context, String staticBaseUri, int flags) throws XPathException { init(context, flags); builder = context.getController().makeBuilder(); builder.setSystemId(staticBaseUri); builder.setTiming(false); out = new NamespaceReducer(builder); out.open(); out.startDocument(0); }
/** * Make the handler to construct the XML tree representation for JSON * * @param context the context in which the result tree is to be built * @param staticBaseUri the static base URI, used for the base URI of the constructed tree * @param flags flags indicating the chosen options * @throws XPathException if initialization fails, for example because of problems loading the schema */ public JsonHandlerXML(XPathContext context, String staticBaseUri, int flags) throws XPathException { init(context, flags); builder = context.getController().makeBuilder(); builder.setSystemId(staticBaseUri); builder.setTiming(false); out = new NamespaceReducer(builder); out.open(); out.startDocument(0); }
/** * Take the results of a query (or any other SequenceIterator) and create * an XML document containing copies of all items in the sequence, each item wrapped in a containing * element that identifies its type * * @param iterator The values to be wrapped * @param config The Saxon configuration used to evaluate the query * @return the document containing the wrapped results * @throws XPathException if any failure occurs * @since 8.8 */ /*@Nullable*/ public static DocumentInfo wrap(SequenceIterator iterator, /*@NotNull*/ Configuration config) throws XPathException { PipelineConfiguration pipe = config.makePipelineConfiguration(); TinyBuilder builder = new TinyBuilder(pipe); builder.setStatistics(Statistics.SOURCE_DOCUMENT_STATISTICS); NamespaceReducer reducer = new NamespaceReducer(builder); ComplexContentOutputter outputter = new ComplexContentOutputter(reducer); sendWrappedSequence(iterator, outputter); return new DocumentInfo(builder.getCurrentRoot()); }
/** * Get a ContentHandler that can be used to direct the output of a SAX parser (or other * source of SAX events) to this serializer. * * @return a newly constructed ContentHandler that pipes events into this Serializer * @throws SaxonApiException if any other failure occurs * @since 9.7 */ public org.xml.sax.ContentHandler getContentHandler() throws SaxonApiException { PipelineConfiguration pipe = processor.getUnderlyingConfiguration().makePipelineConfiguration(); Receiver r = getReceiver(pipe, getSerializationProperties()); //r = new SequenceNormalizerWithSpaceSeparator(r); r = new NamespaceReducer(r); ReceivingContentHandler rch = new ReceivingContentHandler(); rch.setReceiver(r); rch.setPipelineConfiguration(r.getPipelineConfiguration()); return rch; }
/** * Get a ContentHandler that can be used to direct the output of a SAX parser (or other * source of SAX events) to this serializer. * * @return a newly constructed ContentHandler that pipes events into this Serializer * @throws SaxonApiException if any other failure occurs * @since 9.7 */ public org.xml.sax.ContentHandler getContentHandler() throws SaxonApiException { PipelineConfiguration pipe = processor.getUnderlyingConfiguration().makePipelineConfiguration(); Receiver r = getReceiver(pipe, getSerializationProperties()); //r = new SequenceNormalizerWithSpaceSeparator(r); r = new NamespaceReducer(r); ReceivingContentHandler rch = new ReceivingContentHandler(); rch.setReceiver(r); rch.setPipelineConfiguration(r.getPipelineConfiguration()); return rch; }
/** * Take the results of a query (or any other SequenceIterator) and create * an XML document containing copies of all items in the sequence, each item wrapped in a containing * element that identifies its type * * @param iterator The values to be wrapped * @param config The Saxon configuration used to evaluate the query * @return the document containing the wrapped results * @throws XPathException if any failure occurs * @since 8.8 */ /*@Nullable*/ public static DocumentInfo wrap(SequenceIterator iterator, /*@NotNull*/ Configuration config) throws XPathException { PipelineConfiguration pipe = config.makePipelineConfiguration(); TinyBuilder builder = new TinyBuilder(pipe); builder.setStatistics(config.getTreeStatistics().SOURCE_DOCUMENT_STATISTICS); NamespaceReducer reducer = new NamespaceReducer(builder); ComplexContentOutputter outputter = new ComplexContentOutputter(reducer); sendWrappedSequence(iterator, outputter); return new DocumentInfo(builder.getCurrentRoot()); }
NamespaceReducer ne = new NamespaceReducer(receiver); ne.setSystemId(receiver.getSystemId()); receiver = ne;
/** * Take the results of a query (or any other SequenceIterator) and create * an XML document containing copies of all items in the sequence, each item wrapped in a containing * element that identifies its type * @param iterator The values to be wrapped * @param config The Saxon configuration used to evaluate the query * @return the document containing the wrapped results * @throws XPathException * @since 8.8 */ public static DocumentInfo wrap(SequenceIterator iterator, Configuration config) throws XPathException { PipelineConfiguration pipe = config.makePipelineConfiguration(); TinyBuilder builder = new TinyBuilder(); builder.setPipelineConfiguration(pipe); NamespaceReducer reducer = new NamespaceReducer(); reducer.setUnderlyingReceiver(builder); reducer.setPipelineConfiguration(pipe); ComplexContentOutputter outputter = new ComplexContentOutputter(); outputter.setPipelineConfiguration(pipe); outputter.setReceiver(reducer); sendWrappedSequence(iterator, outputter); return (DocumentInfo)builder.getCurrentRoot(); }
/** * Create a TinyTree to hold a document or element node. * @throws net.sf.saxon.trans.XPathException */ private void createTree() throws XPathException { builder = new TinyBuilder(); builder.setPipelineConfiguration(getPipelineConfiguration()); builder.setSystemId(getSystemId()); NamespaceReducer reducer = new NamespaceReducer(); reducer.setUnderlyingReceiver(builder); reducer.setPipelineConfiguration(getPipelineConfiguration()); ComplexContentOutputter cco = new ComplexContentOutputter(); cco.setHostLanguage(getPipelineConfiguration().getHostLanguage()); cco.setPipelineConfiguration(getPipelineConfiguration()); cco.setReceiver(reducer); outputter = cco; outputter.setSystemId(systemId); outputter.setPipelineConfiguration(getPipelineConfiguration()); outputter.open(); }
/** * Create a TinyTree to hold a document or element node. * @throws net.sf.saxon.trans.XPathException */ private void createTree() throws XPathException { PipelineConfiguration pipe = getPipelineConfiguration(); builder = pipe.getController().makeBuilder(); builder.setPipelineConfiguration(pipe); builder.setSystemId(getSystemId()); builder.setTiming(false); NamespaceReducer reducer = new NamespaceReducer(); reducer.setUnderlyingReceiver(builder); reducer.setPipelineConfiguration(getPipelineConfiguration()); ComplexContentOutputter cco = new ComplexContentOutputter(); cco.setHostLanguage(getPipelineConfiguration().getHostLanguage()); cco.setPipelineConfiguration(getPipelineConfiguration()); cco.setReceiver(reducer); outputter = cco; outputter.setSystemId(systemId); outputter.setPipelineConfiguration(getPipelineConfiguration()); outputter.open(); }