Package org.apache.batik.xml
Class XMLScanner
- java.lang.Object
-
- org.apache.batik.xml.XMLScanner
-
- All Implemented Interfaces:
Localizable
public class XMLScanner extends java.lang.Object implements Localizable
This class represents a scanner for XML documents.- Version:
- $Id: XMLScanner.java 1802297 2017-07-18 13:58:12Z ssteiner $
-
-
Field Summary
Fields Modifier and Type Field Description static intATTLIST_CONTEXTThe ATTLIST context.protected charattrDelimiterThe last attribute delimiter encountered.static intATTRIBUTE_VALUE_CONTEXTThe attribute value context.protected char[]bufferThe recording buffer.protected static java.lang.StringBUNDLE_CLASSNAMEThe default resource bundle base name.static intCDATA_SECTION_CONTEXTThe CDATA section context.protected booleancdataEndReadA CDATA section end is the next tokenstatic intCONTENT_CONTEXTThe content context.protected intcontextThe current scanning context.protected intcurrentThe current char.protected intdepthThe depth in the xml tree.static intDOCTYPE_CONTEXTThe doctype context.static intDOCUMENT_START_CONTEXTThe document start context.static intDTD_DECLARATIONS_CONTEXTThe DTD declarations context.static intELEMENT_DECLARATION_CONTEXTThe element declaration context.protected intendThe end offset of the last lexical unit.static intEND_TAG_CONTEXTThe end tag context.static intENTITY_CONTEXTThe entity context.static intENTITY_VALUE_CONTEXTThe entity value context.static intENUMERATION_CONTEXTThe enumeration context.protected booleaninDTDThe scanner is in the internal DTD.protected LocalizableSupportlocalizableSupportThe localizable support.static intNOTATION_CONTEXTThe notation context.static intNOTATION_TYPE_CONTEXTThe notation type context.static intPI_CONTEXTThe processing instruction context.protected booleanpiEndReadA PI end has been previously read.protected intpositionThe current position in the buffer.protected NormalizingReaderreaderThe reader.protected intstartThe start offset of the last lexical unit.static intSTART_TAG_CONTEXTThe start tag context.static intTOP_LEVEL_CONTEXTThe top level context.protected inttypeThe type of the current lexical unit.static intXML_DECL_CONTEXTThe XML declaration context.
-
Constructor Summary
Constructors Constructor Description XMLScanner(java.io.InputStream is, java.lang.String enc)Creates a new XML scanner.XMLScanner(java.io.Reader r)Creates a new XML scanner.XMLScanner(java.lang.String s)Creates a new XML scanner.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearBuffer()Clears the buffer.protected XMLExceptioncreateXMLException(java.lang.String message)Returns an XMLException initialized with the given message key.java.lang.StringformatMessage(java.lang.String key, java.lang.Object[] args)ImplementsLocalizable.formatMessage(String,Object[]).char[]getBuffer()Returns the buffer used to store the chars.intgetColumn()Returns the current column.intgetContext()Returns the current context.intgetDepth()Returns the current depth in the XML tree.intgetEnd()Returns the end offset of the last lexical unit.intgetEndOffset()Returns the end offset of the current lexical unit.intgetLine()Returns the current line.java.util.LocalegetLocale()ImplementsLocalizable.getLocale().intgetStart()Returns the start offset of the last lexical unit.intgetStartOffset()Returns the start offset of the current lexical unit.chargetStringDelimiter()Returns the last encountered string delimiter.intgetType()The current lexical unit type like defined in LexicalUnits.intnext()Advances to the next lexical unit.intnext(int ctx)Advances to the next lexical unit.protected intnextChar()Sets the value of the current char to the next character or -1 if the end of stream has been reached.protected intnextInAttList()Returns the next lexical unit in the context of an attribute list.protected intnextInAttributeValue()Returns the next lexical unit in the context of an attribute value.protected intnextInCDATASection()Returns the next lexical unit in the context of a CDATA section.protected intnextInContent()Returns the next lexical unit in the context of an element content.protected intnextInDoctype()Returns the next lexical unit in the context of a doctype.protected intnextInDocumentStart()Reads the first token in the stream.protected intnextInDTDDeclarations()Returns the next lexical unit in the context dtd declarations.protected intnextInElementDeclaration()Returns the next lexical unit in the context of a element declaration.protected intnextInEndTag()Returns the next lexical unit in the context of a end tag.protected intnextInEntity()Returns the next lexical unit in the context of an entity.protected intnextInEntityValue()Returns the next lexical unit in the context of an entity value.protected intnextInEnumeration()Returns the next lexical unit in the context of an enumeration.protected intnextInNotation()Returns the next lexical unit in the context of a notation.protected intnextInNotationType()Returns the next lexical unit in the context of a notation type.protected intnextInPI()Returns the next lexical unit in the context of a processing instruction.protected intnextInStartTag()Returns the next lexical unit in the context of a start tag.protected intnextInTopLevel()Advances to the next lexical unit in the top level context.protected intnextInXMLDecl()Returns the next lexical unit in the context of an XML declaration.protected intreadComment()Reads a comment.protected intreadIdentifier(java.lang.String s, int type, int ntype)Reads the given identifier.protected intreadName(int type)Reads a name.protected intreadNmtoken()Reads a Nmtoken.protected intreadPEReference()Reads a parameter entity reference.protected intreadPIStart()Reads a processing instruction start.protected intreadReference()Reads an entity or character reference.protected intreadString()Reads a simple string, like the ones used for version, encoding, public/system identifiers...voidsetContext(int c)Sets the current context.voidsetDepth(int i)Sets the current depth in the XML tree.voidsetLocale(java.util.Locale l)ImplementsLocalizable.setLocale(Locale).
-
-
-
Field Detail
-
DOCUMENT_START_CONTEXT
public static final int DOCUMENT_START_CONTEXT
The document start context.- See Also:
- Constant Field Values
-
TOP_LEVEL_CONTEXT
public static final int TOP_LEVEL_CONTEXT
The top level context.- See Also:
- Constant Field Values
-
PI_CONTEXT
public static final int PI_CONTEXT
The processing instruction context.- See Also:
- Constant Field Values
-
XML_DECL_CONTEXT
public static final int XML_DECL_CONTEXT
The XML declaration context.- See Also:
- Constant Field Values
-
DOCTYPE_CONTEXT
public static final int DOCTYPE_CONTEXT
The doctype context.- See Also:
- Constant Field Values
-
START_TAG_CONTEXT
public static final int START_TAG_CONTEXT
The start tag context.- See Also:
- Constant Field Values
-
CONTENT_CONTEXT
public static final int CONTENT_CONTEXT
The content context.- See Also:
- Constant Field Values
-
DTD_DECLARATIONS_CONTEXT
public static final int DTD_DECLARATIONS_CONTEXT
The DTD declarations context.- See Also:
- Constant Field Values
-
CDATA_SECTION_CONTEXT
public static final int CDATA_SECTION_CONTEXT
The CDATA section context.- See Also:
- Constant Field Values
-
END_TAG_CONTEXT
public static final int END_TAG_CONTEXT
The end tag context.- See Also:
- Constant Field Values
-
ATTRIBUTE_VALUE_CONTEXT
public static final int ATTRIBUTE_VALUE_CONTEXT
The attribute value context.- See Also:
- Constant Field Values
-
ATTLIST_CONTEXT
public static final int ATTLIST_CONTEXT
The ATTLIST context.- See Also:
- Constant Field Values
-
ELEMENT_DECLARATION_CONTEXT
public static final int ELEMENT_DECLARATION_CONTEXT
The element declaration context.- See Also:
- Constant Field Values
-
ENTITY_CONTEXT
public static final int ENTITY_CONTEXT
The entity context.- See Also:
- Constant Field Values
-
NOTATION_CONTEXT
public static final int NOTATION_CONTEXT
The notation context.- See Also:
- Constant Field Values
-
NOTATION_TYPE_CONTEXT
public static final int NOTATION_TYPE_CONTEXT
The notation type context.- See Also:
- Constant Field Values
-
ENUMERATION_CONTEXT
public static final int ENUMERATION_CONTEXT
The enumeration context.- See Also:
- Constant Field Values
-
ENTITY_VALUE_CONTEXT
public static final int ENTITY_VALUE_CONTEXT
The entity value context.- See Also:
- Constant Field Values
-
BUNDLE_CLASSNAME
protected static final java.lang.String BUNDLE_CLASSNAME
The default resource bundle base name.- See Also:
- Constant Field Values
-
localizableSupport
protected LocalizableSupport localizableSupport
The localizable support.
-
reader
protected NormalizingReader reader
The reader.
-
current
protected int current
The current char.
-
type
protected int type
The type of the current lexical unit.
-
buffer
protected char[] buffer
The recording buffer.
-
position
protected int position
The current position in the buffer.
-
start
protected int start
The start offset of the last lexical unit.
-
end
protected int end
The end offset of the last lexical unit.
-
context
protected int context
The current scanning context.
-
depth
protected int depth
The depth in the xml tree.
-
piEndRead
protected boolean piEndRead
A PI end has been previously read.
-
inDTD
protected boolean inDTD
The scanner is in the internal DTD.
-
attrDelimiter
protected char attrDelimiter
The last attribute delimiter encountered.
-
cdataEndRead
protected boolean cdataEndRead
A CDATA section end is the next token
-
-
Constructor Detail
-
XMLScanner
public XMLScanner(java.io.Reader r) throws XMLExceptionCreates a new XML scanner.- Parameters:
r- The reader to scan.- Throws:
XMLException
-
XMLScanner
public XMLScanner(java.io.InputStream is, java.lang.String enc) throws XMLExceptionCreates a new XML scanner.- Parameters:
is- The input stream to scan.enc- The character encoding to use.- Throws:
XMLException
-
XMLScanner
public XMLScanner(java.lang.String s) throws XMLExceptionCreates a new XML scanner.- Parameters:
s- The string to parse.- Throws:
XMLException
-
-
Method Detail
-
setLocale
public void setLocale(java.util.Locale l)
ImplementsLocalizable.setLocale(Locale).- Specified by:
setLocalein interfaceLocalizable- Parameters:
l- The locale to set.
-
getLocale
public java.util.Locale getLocale()
ImplementsLocalizable.getLocale().- Specified by:
getLocalein interfaceLocalizable
-
formatMessage
public java.lang.String formatMessage(java.lang.String key, java.lang.Object[] args) throws java.util.MissingResourceExceptionImplementsLocalizable.formatMessage(String,Object[]).- Specified by:
formatMessagein interfaceLocalizable- Parameters:
key- The key used to retreive the message from the resource bundle.args- The objects that compose the message.- Throws:
java.util.MissingResourceException- if the key is not in the bundle.
-
setDepth
public void setDepth(int i)
Sets the current depth in the XML tree.
-
getDepth
public int getDepth()
Returns the current depth in the XML tree.
-
setContext
public void setContext(int c)
Sets the current context.
-
getContext
public int getContext()
Returns the current context.
-
getType
public int getType()
The current lexical unit type like defined in LexicalUnits.
-
getLine
public int getLine()
Returns the current line.
-
getColumn
public int getColumn()
Returns the current column.
-
getBuffer
public char[] getBuffer()
Returns the buffer used to store the chars.
-
getStart
public int getStart()
Returns the start offset of the last lexical unit.
-
getEnd
public int getEnd()
Returns the end offset of the last lexical unit.
-
getStringDelimiter
public char getStringDelimiter()
Returns the last encountered string delimiter.
-
getStartOffset
public int getStartOffset()
Returns the start offset of the current lexical unit.
-
getEndOffset
public int getEndOffset()
Returns the end offset of the current lexical unit.
-
clearBuffer
public void clearBuffer()
Clears the buffer.
-
next
public int next() throws XMLExceptionAdvances to the next lexical unit.- Returns:
- The type of the lexical unit like defined in LexicalUnits.
- Throws:
XMLException
-
next
public int next(int ctx) throws XMLExceptionAdvances to the next lexical unit.- Parameters:
ctx- The context to use for scanning.- Returns:
- The type of the lexical unit like defined in LexicalUnits.
- Throws:
XMLException
-
nextInDocumentStart
protected int nextInDocumentStart() throws java.io.IOException, XMLExceptionReads the first token in the stream.- Throws:
java.io.IOExceptionXMLException
-
nextInTopLevel
protected int nextInTopLevel() throws java.io.IOException, XMLExceptionAdvances to the next lexical unit in the top level context.- Returns:
- The type of the lexical unit like defined in LexicalUnits.
- Throws:
java.io.IOExceptionXMLException
-
nextInPI
protected int nextInPI() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of a processing instruction.- Throws:
java.io.IOExceptionXMLException
-
nextInStartTag
protected int nextInStartTag() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of a start tag.- Throws:
java.io.IOExceptionXMLException
-
nextInAttributeValue
protected int nextInAttributeValue() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of an attribute value.- Throws:
java.io.IOExceptionXMLException
-
nextInContent
protected int nextInContent() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of an element content.- Throws:
java.io.IOExceptionXMLException
-
nextInEndTag
protected int nextInEndTag() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of a end tag.- Throws:
java.io.IOExceptionXMLException
-
nextInCDATASection
protected int nextInCDATASection() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of a CDATA section.- Throws:
java.io.IOExceptionXMLException
-
nextInXMLDecl
protected int nextInXMLDecl() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of an XML declaration.- Throws:
java.io.IOExceptionXMLException
-
nextInDoctype
protected int nextInDoctype() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of a doctype.- Throws:
java.io.IOExceptionXMLException
-
nextInDTDDeclarations
protected int nextInDTDDeclarations() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context dtd declarations.- Throws:
java.io.IOExceptionXMLException
-
readString
protected int readString() throws java.io.IOException, XMLExceptionReads a simple string, like the ones used for version, encoding, public/system identifiers... The current character must be the string delimiter.- Returns:
- type.
- Throws:
java.io.IOExceptionXMLException
-
readComment
protected int readComment() throws java.io.IOException, XMLExceptionReads a comment. '<!-' must have been read.- Throws:
java.io.IOExceptionXMLException
-
readIdentifier
protected int readIdentifier(java.lang.String s, int type, int ntype) throws java.io.IOException, XMLExceptionReads the given identifier.- Parameters:
s- The portion of the identifier to read.type- The lexical unit type of the identifier.ntype- The lexical unit type to set if the identifier do not match or -1 if an error must be signaled.- Throws:
java.io.IOExceptionXMLException
-
readName
protected int readName(int type) throws java.io.IOException, XMLExceptionReads a name. The current character must be the first character.- Parameters:
type- The lexical unit type to set.- Returns:
- type.
- Throws:
java.io.IOExceptionXMLException
-
readPIStart
protected int readPIStart() throws java.io.IOException, XMLExceptionReads a processing instruction start.- Returns:
- type.
- Throws:
java.io.IOExceptionXMLException
-
nextInElementDeclaration
protected int nextInElementDeclaration() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of a element declaration.- Throws:
java.io.IOExceptionXMLException
-
nextInAttList
protected int nextInAttList() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of an attribute list.- Throws:
java.io.IOExceptionXMLException
-
nextInNotation
protected int nextInNotation() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of a notation.- Throws:
java.io.IOExceptionXMLException
-
nextInEntity
protected int nextInEntity() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of an entity.- Throws:
java.io.IOExceptionXMLException
-
nextInEntityValue
protected int nextInEntityValue() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of an entity value.- Throws:
java.io.IOExceptionXMLException
-
nextInNotationType
protected int nextInNotationType() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of a notation type.- Throws:
java.io.IOExceptionXMLException
-
nextInEnumeration
protected int nextInEnumeration() throws java.io.IOException, XMLExceptionReturns the next lexical unit in the context of an enumeration.- Throws:
java.io.IOExceptionXMLException
-
readReference
protected int readReference() throws java.io.IOException, XMLExceptionReads an entity or character reference. The current character must be '&'.- Returns:
- type.
- Throws:
java.io.IOExceptionXMLException
-
readPEReference
protected int readPEReference() throws java.io.IOException, XMLExceptionReads a parameter entity reference. The current character must be '%'.- Returns:
- type.
- Throws:
java.io.IOExceptionXMLException
-
readNmtoken
protected int readNmtoken() throws java.io.IOException, XMLExceptionReads a Nmtoken. The current character must be the first character.- Returns:
- LexicalUnits.NMTOKEN.
- Throws:
java.io.IOExceptionXMLException
-
nextChar
protected int nextChar() throws java.io.IOExceptionSets the value of the current char to the next character or -1 if the end of stream has been reached.- Throws:
java.io.IOException
-
createXMLException
protected XMLException createXMLException(java.lang.String message)
Returns an XMLException initialized with the given message key.
-
-