Interface XMLEventListener
-
- All Superinterfaces:
XMLEventListenerStates
- All Known Subinterfaces:
StatefulXMLEventListener
- All Known Implementing Classes:
XMLOutputter
public interface XMLEventListener extends XMLEventListenerStates
Interface for XML event listeners.State transitions
XML event sources must obey a state model when callingXMLEventListeners. However, anXMLEventListeneris not required to check that this state model is actually respected. If it does, then it will throw anIllegalStateExceptionif the state model is violated.Stateful
XMLEventListenerimplementations should implement theStatefulXMLEventListenerinterface instead of implementingXMLEventListenerdirectly.Initially the state of an uninitialized
XMLEventListenerisUNINITIALIZED.The following table defines how the state changes when a certain method is called in a certain state. Horizontally are the current states, vertically the notification methods. The cells self contain the new state.
S0 S1 S2 S3 S4 S5 S6 declaration()S1 ISE ISE ISE ISE ISE ISE dtd(String,String,String)S2 S2 ISE ISE ISE ISE ISE startTag(String)S3 S3 S3 S3 S3 ISE ISE attribute(String,String)ISE ISE ISE S3 ISE ISE ISE endTag()ISE ISE ISE S4/S5 S4/S5 ISE ISE pcdata(String)ISE ISE ISE S4 S4 ISE ISE pcdata(char[],int,int)ISE ISE ISE S4 S4 ISE ISE cdata(String)ISE ISE ISE S4 S4 ISE ISE whitespace(String)S1 S1 S4 S4 S4 S5 ISE whitespace(char[],int,int)S1 S1 S4 S4 S4 S5 ISE comment(String)S1 S1 S4 S4 S4 S5 ISE pi(String,String)S1 S1 S4 S4 S4 S5 ISE endDocument()ISE ISE ISE S6 S6 S6 ISE List of states as used in the table:
- S0:
BEFORE_XML_DECLARATION - S1:
BEFORE_DTD_DECLARATION - S2:
BEFORE_ROOT_ELEMENT - S3:
START_TAG_OPEN - S4:
WITHIN_ELEMENT - S5:
AFTER_ROOT_ELEMENT - S6:
DOCUMENT_ENDED
- Since:
- xmlenc 0.30
- Version:
- $Revision: 1.9 $ $Date: 2005/09/12 08:40:02 $
- Author:
- Ernst de Haan (wfe.dehaan@gmail.com)
-
-
Field Summary
-
Fields inherited from interface org.znerd.xmlenc.XMLEventListenerStates
AFTER_ROOT_ELEMENT, BEFORE_DTD_DECLARATION, BEFORE_ROOT_ELEMENT, BEFORE_XML_DECLARATION, DOCUMENT_ENDED, ERROR_STATE, START_TAG_OPEN, UNINITIALIZED, WITHIN_ELEMENT
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidattribute(java.lang.String name, java.lang.String value)Adds an attribute to the current element.voidcdata(java.lang.String text)Notification of a CDATA section.voidcomment(java.lang.String text)Notification of a comment.voiddeclaration()Notification of an XML declaration.voiddtd(java.lang.String name, java.lang.String publicID, java.lang.String systemID)Notification of a document type declaration.voidendDocument()Notification of the end of the document.voidendTag()Notification of an element end tag.XMLEventListenerStategetState()Returns the current state of this outputter.voidpcdata(char[] ch, int start, int length)Notification of a PCDATA section (as achararray).voidpcdata(java.lang.String text)Notification of a PCDATA section (as aString).voidpi(java.lang.String target, java.lang.String instruction)Notification of a processing instruction.voidreset()Resets this XML event listener.voidsetState(XMLEventListenerState newState, java.lang.String[] newElementStack)Sets the state of this XML event listener.voidstartTag(java.lang.String type)Notification of an element start tag.voidwhitespace(char[] ch, int start, int length)Notification of ignorable whitespace (as aString).voidwhitespace(java.lang.String whitespace)Notification of ignorable whitespace (as aString).
-
-
-
Method Detail
-
reset
void reset()
Resets this XML event listener. The state will be set toUNINITIALIZED.
-
getState
XMLEventListenerState getState() throws java.lang.UnsupportedOperationException
Returns the current state of this outputter.- Returns:
- the current state, cannot be
null. - Throws:
java.lang.UnsupportedOperationException- if this is not a stateful XML event listener.
-
setState
void setState(XMLEventListenerState newState, java.lang.String[] newElementStack) throws java.lang.IllegalArgumentException
Sets the state of this XML event listener. Normally, it is not necessary to call this method and it should be used with great care.Calling this method with
UNINITIALIZEDas the state is equivalent to callingreset().- Parameters:
newState- the new state, notnull.newElementStack- the new element stack, ifnewState ==then it should be non-START_TAG_OPEN|| newState ==WITHIN_ELEMENTnulland containing nonullelements, otherwise it must benull.- Throws:
java.lang.IllegalArgumentException- ifnewState == null || (newState ==(whereSTART_TAG_OPEN&& newElementStack == null) || (newState ==WITHIN_ELEMENT&& newElementStack == null) || (newState !=START_TAG_OPEN&& newState !=WITHIN_ELEMENT&& newElementStack != null) || newElementStack[n] == null0 <= n < newElementStack.length).
-
declaration
void declaration() throws java.lang.IllegalStateException, java.io.IOExceptionNotification of an XML declaration. No encoding is explicitly specified.- Throws:
java.lang.IllegalStateException- ifgetState() != BEFORE_XML_DECLARATION.java.io.IOException- if an I/O error occurs; this will set the state toERROR_STATE.
-
dtd
void dtd(java.lang.String name, java.lang.String publicID, java.lang.String systemID) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionNotification of a document type declaration.An external subset can be specified using either a system identifier (alone), or using both a public identifier and a system identifier. It can never be specified using a public identifier alone.
For example, for XHTML 1.0 the public identifier is:
-//W3C//DTD XHTML 1.0 Transitional//ENwhile the system identifier is:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdThe output is typically similar to this:
or alternatively, if only the system identifier is specified:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">- Parameters:
name- the name of the document type, notnull.publicID- the public identifier, can benull.systemID- the system identifier, can benull, but otherwise it should be a properly formatted URL, see section 4.2.2 External Entities in the XML 1.0 Specification.- Throws:
java.lang.IllegalStateException- ifgetState() !=.BEFORE_XML_DECLARATION&& getState() !=BEFORE_DTD_DECLARATIONjava.lang.IllegalArgumentException- ifname == null || (publicID != null && systemID == null).java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.InvalidXMLException
-
startTag
void startTag(java.lang.String type) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionNotification of an element start tag.- Parameters:
type- the type of the tag to start, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=.BEFORE_XML_DECLARATION&& getState() !=BEFORE_DTD_DECLARATION&& getState() !=BEFORE_ROOT_ELEMENT&& getState() !=START_TAG_OPEN&& getState() !=WITHIN_ELEMENTjava.lang.IllegalArgumentException- iftype == null.java.io.IOException- if an I/O error occurs; this will set the state toERROR_STATE.InvalidXMLException
-
attribute
void attribute(java.lang.String name, java.lang.String value) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionAdds an attribute to the current element. There must currently be an open element.The attribute value is surrounded by single quotes.
- Parameters:
name- the name of the attribute, notnull.value- the value of the attribute, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.START_TAG_OPENjava.lang.IllegalArgumentException- ifname == null || value == null.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.InvalidXMLException
-
endTag
void endTag() throws java.lang.IllegalStateException, java.io.IOExceptionNotification of an element end tag.- Throws:
java.lang.IllegalStateException- ifgetState() != START_TAG_OPEN && getState() != WITHIN_ELEMENTjava.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
pcdata
void pcdata(java.lang.String text) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionNotification of a PCDATA section (as aString).- Parameters:
text- the PCDATA section contents, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() != START_TAG_OPEN && getState() != WITHIN_ELEMENTjava.lang.IllegalArgumentException- iftext == null.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
pcdata
void pcdata(char[] ch, int start, int length) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException, InvalidXMLException, java.io.IOExceptionNotification of a PCDATA section (as achararray).- Parameters:
ch- the character array containing the PCDATA section contents, notnull.start- the start index in the array, must be >= 0 and it must be <ch.length.length- the number of characters to read from the array, must be > 0.- Throws:
java.lang.IllegalStateException- ifgetState() != START_TAG_OPEN && getState() != WITHIN_ELEMENTjava.lang.IllegalArgumentException- ifch == null || start < 0 || start >= ch.length || length < 0.java.lang.IndexOutOfBoundsException- ifstart + length > ch.length.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
cdata
void cdata(java.lang.String text) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionNotification of a CDATA section.A CDATA section can contain any string, except
"]]>". This will, however, not be checked by this method.Left angle brackets and ampersands will be output in their literal form; they need not (and cannot) be escaped using
"<"and"&".If the specified string is empty (i.e.
"".equals(text), then nothing will be output.If the specified string contains characters that cannot be printed in this encoding, then the result is undefined.
- Parameters:
text- the contents of the CDATA section, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() != START_TAG_OPEN && getState() != WITHIN_ELEMENTjava.lang.IllegalArgumentException- iftext == null.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
whitespace
void whitespace(java.lang.String whitespace) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionNotification of ignorable whitespace (as aString). Ignorable whitespace can be found anywhere in an XML document, except above the XML declaration.This method does not check if the string actually contains whitespace.
If the state equals
XMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set toXMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise if the state isXMLEventListenerStates.START_TAG_OPENthen it will be set toXMLEventListenerStates.WITHIN_ELEMENT, otherwise the state will not be changed.- Parameters:
whitespace- the ignorable whitespace to be written, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() == ERROR_STATE.java.lang.IllegalArgumentException- ifwhitespace == null.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
whitespace
void whitespace(char[] ch, int start, int length) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException, InvalidXMLException, java.io.IOExceptionNotification of ignorable whitespace (as aString). Ignorable whitespace can be found anywhere in an XML document, except above the XML declaration.This method does not check if the string actually contains whitespace.
If the state equals
XMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set toXMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise if the state isXMLEventListenerStates.START_TAG_OPENthen it will be set toXMLEventListenerStates.WITHIN_ELEMENT, otherwise the state will not be changed.- Parameters:
ch- the character array containing the text to be written, notnull.start- the start index in the array, must be >= 0 and it must be <ch.length.length- the number of characters to read from the array, must be > 0.- Throws:
java.lang.IllegalStateException- ifgetState() == ERROR_STATE.java.lang.IllegalArgumentException- ifch == null || start < 0 || start >= ch.length || length < 0.java.lang.IndexOutOfBoundsException- ifstart + length > ch.length.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
comment
void comment(java.lang.String text) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionNotification of a comment. The comment should not contain the string"--".If the state equals
XMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set toXMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise if the state isXMLEventListenerStates.START_TAG_OPENthen it will be set toXMLEventListenerStates.WITHIN_ELEMENT, otherwise the state will not be changed.- Parameters:
text- the text for the comment be written, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() == ERROR_STATE.java.lang.IllegalArgumentException- iftext == null.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
pi
void pi(java.lang.String target, java.lang.String instruction) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionNotification of a processing instruction. A target and an optional instruction should be specified.A processing instruction can appear above and below the root element, and between elements. It cannot appear inside an element start or end tag, nor inside a comment. Processing instructions cannot be nested.
If the state equals
XMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set toXMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise the state will not be changed.- Parameters:
target- an identification of the application at which the instruction is targeted, notnull.instruction- the instruction, can benull, which is equivalent to an empty string.- Throws:
java.lang.IllegalStateException- ifgetState() == ERROR_STATE.java.lang.IllegalArgumentException- iftarget == null.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
endDocument
void endDocument() throws java.lang.IllegalStateException, java.io.IOExceptionNotification of the end of the document. After calling this method, none of the other notification methods can be called untilreset()is called.- Throws:
java.lang.IllegalStateException- ifgetState() == UNINITIALIZED || getState() == DOCUMENT_ENDED.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
-