public class SerializerFactory
extends java.lang.Object
Since Saxon 8.8 is is possible to write a subclass of SerializerFactory and register it with the Configuration, allowing customisation of the Serializer pipeline.
The class includes methods for instantiating each of the components used on the Serialization pipeline. This allows a customized SerializerFactory to replace any or all of these components by subclasses that refine the behaviour.
Constructor and Description |
---|
SerializerFactory(Configuration config)
Create a SerializerFactory
|
SerializerFactory(PipelineConfiguration pipe) |
Modifier and Type | Method and Description |
---|---|
Receiver |
addHtml5Component(Receiver target,
java.util.Properties outputProperties)
This method constructs a step in the output pipeline to perform namespace-related
tasks for HTML5 serialization.
|
Receiver |
addTextOutputFilter(Receiver next,
java.util.Properties properties)
Add a filter to the text output method pipeline.
|
protected void |
checkExtensions(java.lang.String key) |
protected static void |
checkListOfClarkNames(java.lang.String key,
java.lang.String value) |
protected static void |
checkListOfClarkNamesAllowingStar(java.lang.String key,
java.lang.String value) |
protected static void |
checkNonNegativeInteger(java.lang.String key,
java.lang.String value) |
java.lang.String |
checkOutputProperty(java.lang.String key,
java.lang.String value)
Check that a supplied output property is valid, and normalize the value (specifically in the case of boolean
values where yes|true|1 are normalized to "yes", and no|false|0 are normalized to "no").
|
protected static java.lang.String |
checkYesOrNo(java.lang.String key,
java.lang.String value) |
protected SequenceReceiver |
createHTMLSerializer(Emitter emitter,
SerializationProperties params,
PipelineConfiguration pipe)
Create a serialization pipeline to implement the HTML output method.
|
protected SequenceReceiver |
createSaxonSerializationMethod(java.lang.String method,
SerializationProperties params,
PipelineConfiguration pipe,
CharacterMapExpander characterMapExpander,
ProxyReceiver normalizer,
javax.xml.transform.stream.StreamResult result) |
protected SequenceReceiver |
createTextSerializer(Emitter emitter,
SerializationProperties params)
Create a serialization pipeline to implement the text output method.
|
protected SequenceReceiver |
createUserDefinedOutputMethod(java.lang.String method,
java.util.Properties props,
PipelineConfiguration pipe)
Create a serialization pipeline to implement a user-defined output method.
|
protected SequenceReceiver |
createXHTMLSerializer(Emitter emitter,
SerializationProperties params,
PipelineConfiguration pipe)
Create a serialization pipeline to implement the XHTML output method.
|
protected SequenceReceiver |
createXMLSerializer(XMLEmitter emitter,
SerializationProperties params)
Create a serialization pipeline to implement the XML output method.
|
protected SequenceReceiver |
customizeAdaptiveSerializer(AdaptiveEmitter emitter,
java.util.Properties props,
CharacterMapExpander characterMapExpander,
ProxyReceiver normalizer)
Create a serialization pipeline to implement the Adaptive output method.
|
protected SequenceReceiver |
customizeJSONSerializer(JSONSerializer emitter,
java.util.Properties props,
CharacterMapExpander characterMapExpander,
ProxyReceiver normalizer)
Create a serialization pipeline to implement the JSON output method.
|
Configuration |
getConfiguration() |
protected java.util.Comparator<AtomicValue> |
getPropertySorter(java.lang.String sortSpecification) |
Receiver |
getReceiver(javax.xml.transform.Result result)
Get a Receiver that wraps a given Result object.
|
Receiver |
getReceiver(javax.xml.transform.Result result,
PipelineConfiguration pipe,
java.util.Properties props)
Deprecated.
since Saxon 9.9: use one of the other
getReceiver methods |
Receiver |
getReceiver(javax.xml.transform.Result result,
SerializationProperties params)
Get a Receiver that wraps a given Result object.
|
Receiver |
getReceiver(javax.xml.transform.Result result,
SerializationProperties params,
PipelineConfiguration pipe)
Get a Receiver that wraps a given Result object.
|
StreamWriterToReceiver |
getXMLStreamWriter(javax.xml.transform.stream.StreamResult result,
java.util.Properties properties)
Create a serializer with given output properties, and return
an XMLStreamWriter that can be used to feed events to the serializer.
|
protected Receiver |
injectCharacterMapExpander(SerializationProperties params,
Receiver out,
boolean useNullMarkers) |
protected Receiver |
injectUnicodeNormalizer(SerializationProperties params,
Receiver out) |
SequenceReceiver |
makeSequenceNormalizer(Receiver receiver,
java.util.Properties properties) |
protected Receiver |
newAttributeSorter(Receiver next,
java.util.Properties outputProperties)
Create a new AttributeSorter, responsible for sorting of attributes into a specified order.
|
protected ProxyReceiver |
newCDATAFilter(Receiver next,
java.util.Properties outputProperties)
Create a new CDATA Filter, responsible for insertion of CDATA sections where required.
|
CharacterMapExpander |
newCharacterMapExpander(Receiver next)
Create a new CharacterMapExpander.
|
protected ContentHandlerProxy |
newContentHandlerProxy()
Create a ContentHandlerProxy.
|
protected Emitter |
newHTMLEmitter(java.util.Properties properties)
Create a new HTML Emitter.
|
protected ProxyReceiver |
newHTMLIndenter(Receiver next,
java.util.Properties outputProperties)
Create a new HTML Indenter.
|
protected MetaTagAdjuster |
newHTMLMetaTagAdjuster(Receiver next,
java.util.Properties outputProperties)
Create a new XHTML MetaTagAdjuster, responsible for insertion, removal, or replacement of meta
elements.
|
protected ProxyReceiver |
newHTMLURIEscaper(Receiver next,
java.util.Properties outputProperties)
Create a new HTML URI Escaper, responsible for percent-encoding of URIs in
HTML output documents.
|
protected Receiver |
newNamespaceSorter(Receiver next,
java.util.Properties outputProperties)
Create a new NamespaceSorter, responsible for sorting of namespaces into a specified order.
|
SequenceWrapper |
newSequenceWrapper(Receiver destination)
Get a SequenceWrapper, a class that serializes an XDM sequence with full annotation of item types, node kinds,
etc.
|
protected Emitter |
newTEXTEmitter()
Create a new Text Emitter.
|
protected UncommittedSerializer |
newUncommittedSerializer(javax.xml.transform.Result result,
Receiver next,
SerializationProperties params)
Create an UncommittedSerializer.
|
protected ProxyReceiver |
newUnicodeNormalizer(Receiver next,
java.util.Properties outputProperties)
Create a Unicode Normalizer.
|
protected Emitter |
newXHTMLEmitter(java.util.Properties properties)
Create a new XHTML Emitter.
|
protected ProxyReceiver |
newXHTMLIndenter(Receiver next,
java.util.Properties outputProperties)
Create a new XHTML Indenter.
|
protected MetaTagAdjuster |
newXHTMLMetaTagAdjuster(Receiver next,
java.util.Properties outputProperties)
Create a new XHTML MetaTagAdjuster, responsible for insertion, removal, or replacement of meta
elements.
|
protected ProxyReceiver |
newXHTMLURIEscaper(Receiver next,
java.util.Properties outputProperties)
Create a new XHTML URI Escaper, responsible for percent-encoding of URIs in
HTML output documents.
|
protected ProxyReceiver |
newXML10ContentChecker(Receiver next,
java.util.Properties outputProperties)
Create a new XML 1.0 content checker, responsible for checking that the output conforms to
XML 1.0 rules (this is used only if the Configuration supports XML 1.1 but the specific output
file requires XML 1.0).
|
protected Emitter |
newXMLEmitter(java.util.Properties properties)
Create a new XML Emitter.
|
protected ProxyReceiver |
newXMLIndenter(XMLEmitter next,
java.util.Properties outputProperties)
Create a new XML Indenter.
|
static java.lang.String |
parseListOfNodeNames(java.lang.String value,
NamespaceResolver nsResolver,
boolean useDefaultNS,
boolean prevalidated,
java.lang.String errorCode)
Process a serialization property whose value is a list of element names, for example cdata-section-elements
|
SequenceReceiver |
prepareNextStylesheet(PipelineConfiguration pipe,
java.lang.String href,
java.lang.String baseURI,
javax.xml.transform.Result result)
Prepare another stylesheet to handle the output of this one.
|
public SerializerFactory(Configuration config)
config
- the Saxon Configurationpublic SerializerFactory(PipelineConfiguration pipe)
public Configuration getConfiguration()
public StreamWriterToReceiver getXMLStreamWriter(javax.xml.transform.stream.StreamResult result, java.util.Properties properties) throws XPathException
result
- the destination of the serialized output (wraps a Writer, an OutputStream, or a File)properties
- the serialization properties to be usedXPathException
- if any error occurspublic Receiver getReceiver(javax.xml.transform.Result result, PipelineConfiguration pipe, java.util.Properties props) throws XPathException
getReceiver
methodsNote that this method ignores the SaxonOutputKeys.WRAP
output property. If
wrapped output is required, the user must create a SequenceWrapper
directly.
The effect of the method changes in Saxon 9.7 so that for serialization methods other than "json" and "adaptive", the returned Receiver performs the function of "sequence normalization" as defined in the Serialization specification. Previously the client code handled this by wrapping the result in a ComplexContentOutputter (usually as a side-effect of called XPathContext.changeOutputDestination()). Wrapping in a ComplexContentOutputter is no longer necessary, though it does no harm because the ComplexContentOutputter is idempotent.
Changed in 9.9 so that no character maps are used. Previously the character maps from the Executable associated with the Controller referenced from the PipelineConfiguration were used.
result
- The final destination of the serialized output. Usually a StreamResult,
but other kinds of Result are possible.pipe
- The PipelineConfiguration.props
- The serialization properties. If this includes the property SaxonOutputKeys.USE_CHARACTER_MAPS
then the PipelineConfiguration must contain a non-null Controller, and the Executable associated with this Controller
must have a CharacterMapIndex which is used to resolve the names of the character maps appearing in this property.XPathException
- if any failure occurspublic Receiver getReceiver(javax.xml.transform.Result result) throws XPathException
This version of the method calls getReceiver(Result, SerializationProperties, PipelineConfiguration)
supplying default output properties, and a PipelineConfiguration
newly constructed using
Configuration.makePipelineConfiguration()
.
result
- The final destination of the serialized output. Usually a StreamResult,
but other kinds of Result are possible.XPathException
- if a serializer cannot be createdpublic Receiver getReceiver(javax.xml.transform.Result result, SerializationProperties params) throws XPathException
This version of the method calls getReceiver(Result, SerializationProperties, PipelineConfiguration)
supplying a PipelineConfiguration
newly constructed using Configuration.makePipelineConfiguration()
.
result
- The final destination of the serialized output. Usually a StreamResult,
but other kinds of Result are possible.params
- The serialization properties, including character mapsXPathException
- if a serializer cannot be createdpublic Receiver getReceiver(javax.xml.transform.Result result, SerializationProperties params, PipelineConfiguration pipe) throws XPathException
Note that this method ignores the SaxonOutputKeys.WRAP
output property. If
wrapped output is required, the user must create a SequenceWrapper
directly.
The effect of the method changes in Saxon 9.7 so that for serialization methods other than "json" and "adaptive", the returned Receiver performs the function of "sequence normalization" as defined in the Serialization specification. Previously the client code handled this by wrapping the result in a ComplexContentOutputter (usually as a side-effect of called XPathContext.changeOutputDestination()). Wrapping in a ComplexContentOutputter is no longer necessary, though it does no harm because the ComplexContentOutputter is idempotent.
result
- The final destination of the serialized output. Usually a StreamResult,
but other kinds of Result are possible.params
- The serialization properties, including character mapspipe
- The PipelineConfiguration.XPathException
- if a serializer cannot be createdpublic SequenceReceiver makeSequenceNormalizer(Receiver receiver, java.util.Properties properties)
protected SequenceReceiver createHTMLSerializer(Emitter emitter, SerializationProperties params, PipelineConfiguration pipe) throws XPathException
emitter
- the emitter at the end of the pipeline (created using the method newHTMLEmitter(java.util.Properties)
params
- the serialization propertiespipe
- the pipeline configuration informationXPathException
- if a failure occursprotected SequenceReceiver createTextSerializer(Emitter emitter, SerializationProperties params) throws XPathException
emitter
- the emitter at the end of the pipeline (created using the method newTEXTEmitter()
params
- the serialization propertiesXPathException
- if a failure occursprotected SequenceReceiver customizeJSONSerializer(JSONSerializer emitter, java.util.Properties props, CharacterMapExpander characterMapExpander, ProxyReceiver normalizer) throws XPathException
emitter
- the emitter at the end of the pipeline (created using the method newTEXTEmitter()
props
- the serialization propertiescharacterMapExpander
- the filter to be used for expanding character maps defined in the stylesheetnormalizer
- the filter used for Unicode normalizationXPathException
protected SequenceReceiver customizeAdaptiveSerializer(AdaptiveEmitter emitter, java.util.Properties props, CharacterMapExpander characterMapExpander, ProxyReceiver normalizer)
emitter
- the emitter at the end of the pipelineprops
- the serialization propertiescharacterMapExpander
- the filter to be used for expanding character maps defined in the stylesheetnormalizer
- the filter used for Unicode normalizationprotected SequenceReceiver createXHTMLSerializer(Emitter emitter, SerializationProperties params, PipelineConfiguration pipe) throws XPathException
emitter
- the emitter at the end of the pipeline (created using the method newXHTMLEmitter(java.util.Properties)
params
- the serialization propertiespipe
- the pipeline configuration informationXPathException
- if a failure occurspublic Receiver addHtml5Component(Receiver target, java.util.Properties outputProperties)
target
- the Receiver that receives the output of this stepoutputProperties
- the serialization propertiesprotected SequenceReceiver createXMLSerializer(XMLEmitter emitter, SerializationProperties params) throws XPathException
emitter
- the emitter at the end of the pipeline (created using the method newXHTMLEmitter(java.util.Properties)
params
- the serialization propertiesXPathException
- if a failure occursprotected SequenceReceiver createSaxonSerializationMethod(java.lang.String method, SerializationProperties params, PipelineConfiguration pipe, CharacterMapExpander characterMapExpander, ProxyReceiver normalizer, javax.xml.transform.stream.StreamResult result) throws XPathException
XPathException
protected SequenceReceiver createUserDefinedOutputMethod(java.lang.String method, java.util.Properties props, PipelineConfiguration pipe) throws XPathException
method
- the name of the user-defined output method, as a QName in Clark format
(that is "{uri}local").props
- the serialization propertiespipe
- the pipeline configuration informationXPathException
- if a failure occursprotected Receiver injectCharacterMapExpander(SerializationProperties params, Receiver out, boolean useNullMarkers) throws XPathException
XPathException
protected Receiver injectUnicodeNormalizer(SerializationProperties params, Receiver out) throws XPathException
XPathException
protected ContentHandlerProxy newContentHandlerProxy()
protected UncommittedSerializer newUncommittedSerializer(javax.xml.transform.Result result, Receiver next, SerializationProperties params)
result
- the result destinationnext
- the next receiver in the pipelineparams
- the serialization parametersprotected Emitter newXMLEmitter(java.util.Properties properties)
properties
- the output propertiesprotected Emitter newHTMLEmitter(java.util.Properties properties)
properties
- the output propertiesprotected Emitter newXHTMLEmitter(java.util.Properties properties)
properties
- the output propertiespublic Receiver addTextOutputFilter(Receiver next, java.util.Properties properties) throws XPathException
next
- the next receiver (typically the TextEmitter)properties
- the output propertiesXPathException
- if the operation failsprotected Emitter newTEXTEmitter()
protected ProxyReceiver newXMLIndenter(XMLEmitter next, java.util.Properties outputProperties)
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersprotected ProxyReceiver newHTMLIndenter(Receiver next, java.util.Properties outputProperties)
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersprotected ProxyReceiver newXHTMLIndenter(Receiver next, java.util.Properties outputProperties)
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersprotected MetaTagAdjuster newXHTMLMetaTagAdjuster(Receiver next, java.util.Properties outputProperties)
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersprotected MetaTagAdjuster newHTMLMetaTagAdjuster(Receiver next, java.util.Properties outputProperties)
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersprotected ProxyReceiver newHTMLURIEscaper(Receiver next, java.util.Properties outputProperties)
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersprotected ProxyReceiver newXHTMLURIEscaper(Receiver next, java.util.Properties outputProperties)
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersprotected ProxyReceiver newCDATAFilter(Receiver next, java.util.Properties outputProperties) throws XPathException
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersXPathException
- if an error occursprotected Receiver newAttributeSorter(Receiver next, java.util.Properties outputProperties) throws XPathException
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersXPathException
protected Receiver newNamespaceSorter(Receiver next, java.util.Properties outputProperties) throws XPathException
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersXPathException
protected ProxyReceiver newXML10ContentChecker(Receiver next, java.util.Properties outputProperties)
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersprotected ProxyReceiver newUnicodeNormalizer(Receiver next, java.util.Properties outputProperties) throws XPathException
next
- the next receiver in the pipelineoutputProperties
- the serialization parametersXPathException
- if an error occurspublic CharacterMapExpander newCharacterMapExpander(Receiver next)
next
- the next receiver in the pipelinepublic SequenceReceiver prepareNextStylesheet(PipelineConfiguration pipe, java.lang.String href, java.lang.String baseURI, javax.xml.transform.Result result) throws XPathException
This method is intended for internal use, to support the
saxon:next-in-chain
extension.
pipe
- the current transformationhref
- URI of the next stylesheet to be appliedbaseURI
- base URI for resolving href if it's a relative
URIresult
- the output destination of the current stylesheetXPathException
- if any dynamic error occurspublic SequenceWrapper newSequenceWrapper(Receiver destination)
destination
- the place where the wrapped sequence will be sentpublic java.lang.String checkOutputProperty(java.lang.String key, java.lang.String value) throws XPathException
key
- the name of the property, in Clark formatvalue
- the value of the property. This may be set to null, in which case no validation takes place.
The value must be in JAXP format, that is, with lexical QNames expanded to Clark namesXPathException
- if the property name or value is invalidprotected static java.lang.String checkYesOrNo(java.lang.String key, java.lang.String value) throws XPathException
XPathException
protected static void checkNonNegativeInteger(java.lang.String key, java.lang.String value) throws XPathException
XPathException
protected static void checkListOfClarkNames(java.lang.String key, java.lang.String value) throws XPathException
XPathException
protected static void checkListOfClarkNamesAllowingStar(java.lang.String key, java.lang.String value) throws XPathException
XPathException
public static java.lang.String parseListOfNodeNames(java.lang.String value, NamespaceResolver nsResolver, boolean useDefaultNS, boolean prevalidated, java.lang.String errorCode) throws XPathException
value
- The value of the property as writtennsResolver
- The namespace resolver to use; may be null if prevalidated is set or if names are supplied
in Clark formatuseDefaultNS
- True if the namespace resolver should be used for unprefixed names; false if
unprefixed names should be considered to be in no namespaceprevalidated
- true if the property has already been validatederrorCode
- The error code to return in the event of problemsXPathException
- if any error is found in the list of element names, for example, an undeclared namespace prefixprotected void checkExtensions(java.lang.String key) throws XPathException
XPathException
protected java.util.Comparator<AtomicValue> getPropertySorter(java.lang.String sortSpecification) throws XPathException
XPathException
Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.