Class ReceivingContentHandler
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,LexicalHandler
- Direct Known Subclasses:
IdentityTransformerHandler
,StreamingTransformerImpl.StreamingTransformerHandler
,TemplatesHandlerImpl
,TransformerHandlerImpl
If the input stream contains the processing instructions assigned by JAXP to switch disable-output-escaping on or off, these will be reflected in properties set in the corresponding characters events. In this case adjacent text nodes will not be combined.
The ReceivingContentHandler
is written on the assumption that it is receiving events
from a parser configured with http://xml.org/sax/features/namespaces
set to true
and http://xml.org/sax/features/namespace-prefixes
set to false.
When running as a TransformerHandler
, we have no control over the feature settings
of the sender of the events, and if the events do not follow this pattern then the class may
fail in unpredictable ways.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
An implementation of the SaxonLocation
interface that wraps the SAX Locator information. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a ReceivingContentHandler and initialise variables -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) Report character data.void
comment
(char[] ch, int start, int length) Notify the existence of a comment.void
endCDATA()
void
Receive notification of the end of a documentvoid
endDTD()
Register the end of the DTD.void
endElement
(String uri, String localname, String rawname) Report the end of an element (the close tag)void
void
endPrefixMapping
(String prefix) Notify that a namespace binding is going out of scopeGet the Configuration objectGet the pipeline configurationGet the receiver to which events are passed.void
ignorableWhitespace
(char[] ch, int start, int length) Report character data classified as "Ignorable whitespace", that is, whitespace text nodes appearing as children of elements with an element-only content modelboolean
Determine whether "ignorable whitespace" is ignored.void
notationDecl
(String name, String publicId, String systemId) void
processingInstruction
(String name, String remainder) Notify the existence of a processing instructionvoid
reset()
Set the ReceivingContentHandler to its initial state, except for the local name cache, which is retainedvoid
setDocumentLocator
(Locator locator) Supply a locator that can be called to give information about location in the source document being parsed.void
setIgnoreIgnorableWhitespace
(boolean ignore) Set whether "ignorable whitespace" should be ignored.void
Set the pipeline configurationvoid
setReceiver
(Receiver receiver) Set the receiver to which events are passed.void
skippedEntity
(String name) Notify a skipped entity.void
void
Receive notification of the beginning of a document.void
Register the start of the DTD.void
startElement
(String uri, String localname, String rawname, Attributes atts) Receive notification of the beginning of an element.void
startEntity
(String name) void
startPrefixMapping
(String prefix, String uri) Notify a namespace prefix to URI bindingvoid
unparsedEntityDecl
(String name, String publicId, String systemId, String notationName) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
ReceivingContentHandler
public ReceivingContentHandler()Create a ReceivingContentHandler and initialise variables
-
-
Method Details
-
reset
public void reset()Set the ReceivingContentHandler to its initial state, except for the local name cache, which is retained -
setReceiver
Set the receiver to which events are passed. ReceivingContentHandler is essentially a translator that takes SAX events as input and produces Saxon Receiver events as output; these Receiver events are passed to the supplied Receiver- Parameters:
receiver
- the Receiver of events
-
getReceiver
Get the receiver to which events are passed.- Returns:
- the underlying Receiver
-
setPipelineConfiguration
Set the pipeline configuration- Parameters:
pipe
- the pipeline configuration. This holds a reference to the Saxon configuration, as well as information that can vary from one pipeline to another
-
getPipelineConfiguration
Get the pipeline configuration- Returns:
- the pipeline configuration as supplied to
setPipelineConfiguration(PipelineConfiguration)
-
getConfiguration
Get the Configuration object- Returns:
- the Saxon configuration
-
setIgnoreIgnorableWhitespace
public void setIgnoreIgnorableWhitespace(boolean ignore) Set whether "ignorable whitespace" should be ignored. This method is effective only if called after setPipelineConfiguration, since the default value is taken from the configuration.- Parameters:
ignore
- true if ignorable whitespace (whitespace in element content that is notified via theignorableWhitespace(char[], int, int)
method) should be ignored, false if it should be treated as ordinary text.
-
isIgnoringIgnorableWhitespace
public boolean isIgnoringIgnorableWhitespace()Determine whether "ignorable whitespace" is ignored. This returns the value that was set usingsetIgnoreIgnorableWhitespace(boolean)
if that has been called; otherwise the value from the configuration.- Returns:
- true if ignorable whitespace is being ignored
-
startDocument
Receive notification of the beginning of a document.- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
-
endDocument
Receive notification of the end of a document- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
-
setDocumentLocator
Supply a locator that can be called to give information about location in the source document being parsed.- Specified by:
setDocumentLocator
in interfaceContentHandler
-
startPrefixMapping
Notify a namespace prefix to URI binding- Specified by:
startPrefixMapping
in interfaceContentHandler
-
endPrefixMapping
Notify that a namespace binding is going out of scope- Specified by:
endPrefixMapping
in interfaceContentHandler
-
startElement
public void startElement(String uri, String localname, String rawname, Attributes atts) throws SAXException Receive notification of the beginning of an element.The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding
endElement
event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.This event allows up to three name components for each element:
- the Namespace URI;
- the local name; and
- the qualified (prefixed) name.
Saxon expects all three of these to be provided.
The attribute list provided should contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes should be omitted. The attribute list should not contain attributes used for Namespace declarations (xmlns* attributes); if it does, Saxon will ignore them, which may lead to unresolved namespace prefixes.
- Specified by:
startElement
in interfaceContentHandler
- Parameters:
uri
- the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performedlocalname
- the local name (without prefix), or the empty string if Namespace processing is not being performedrawname
- the qualified name (with prefix), or the empty string if qualified names are not availableatts
- the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined- Throws:
SAXException
- any SAX exception, possibly wrapping another exception- See Also:
-
endElement
Report the end of an element (the close tag)- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) Report character data. Note that contiguous character data may be reported as a sequence of calls on this method, with arbitrary boundaries- Specified by:
characters
in interfaceContentHandler
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) Report character data classified as "Ignorable whitespace", that is, whitespace text nodes appearing as children of elements with an element-only content model- Specified by:
ignorableWhitespace
in interfaceContentHandler
-
processingInstruction
Notify the existence of a processing instruction- Specified by:
processingInstruction
in interfaceContentHandler
- Throws:
SAXException
-
comment
Notify the existence of a comment. Note that in SAX this is part of LexicalHandler interface rather than the ContentHandler interface.- Specified by:
comment
in interfaceLexicalHandler
- Throws:
SAXException
-
skippedEntity
Notify a skipped entity. Saxon ignores this event- Specified by:
skippedEntity
in interfaceContentHandler
-
startDTD
Register the start of the DTD. Saxon ignores the DTD; however, it needs to know when the DTD starts and ends so that it can ignore comments in the DTD, which are reported like any other comment, but which are skipped because they are not part of the XPath data model- Specified by:
startDTD
in interfaceLexicalHandler
-
endDTD
public void endDTD()Register the end of the DTD. Comments in the DTD are skipped because they are not part of the XPath data model- Specified by:
endDTD
in interfaceLexicalHandler
-
startEntity
- Specified by:
startEntity
in interfaceLexicalHandler
-
endEntity
- Specified by:
endEntity
in interfaceLexicalHandler
-
startCDATA
public void startCDATA()- Specified by:
startCDATA
in interfaceLexicalHandler
-
endCDATA
public void endCDATA()- Specified by:
endCDATA
in interfaceLexicalHandler
-
notationDecl
- Specified by:
notationDecl
in interfaceDTDHandler
-
unparsedEntityDecl
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException - Specified by:
unparsedEntityDecl
in interfaceDTDHandler
- Throws:
SAXException
-