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.


Field Summary
static int ATTLIST_CONTEXT
          The ATTLIST context.
protected  char attrDelimiter
          The last attribute delimiter encountered.
static int ATTRIBUTE_VALUE_CONTEXT
          The attribute value context.
protected  char[] buffer
          The recording buffer.
protected static java.lang.String BUNDLE_CLASSNAME
          The default resource bundle base name.
static int CDATA_SECTION_CONTEXT
          The CDATA section context.
protected  boolean cdataEndRead
          A CDATA section end is the next token
static int CONTENT_CONTEXT
          The content context.
protected  int context
          The current scanning context.
protected  int current
          The current char.
protected  int depth
          The depth in the xml tree.
static int DOCTYPE_CONTEXT
          The doctype context.
static int DOCUMENT_START_CONTEXT
          The document start context.
static int DTD_DECLARATIONS_CONTEXT
          The DTD declarations context.
static int ELEMENT_DECLARATION_CONTEXT
          The element declaration context.
protected  int end
          The end offset of the last lexical unit.
static int END_TAG_CONTEXT
          The end tag context.
static int ENTITY_CONTEXT
          The entity context.
static int ENTITY_VALUE_CONTEXT
          The entity value context.
static int ENUMERATION_CONTEXT
          The enumeration context.
protected  boolean inDTD
          The scanner is in the internal DTD.
protected  LocalizableSupport localizableSupport
          The localizable support.
static int NOTATION_CONTEXT
          The notation context.
static int NOTATION_TYPE_CONTEXT
          The notation type context.
static int PI_CONTEXT
          The processing instruction context.
protected  boolean piEndRead
          A PI end has been previously read.
protected  int position
          The current position in the buffer.
protected  NormalizingReader reader
          The reader.
protected  int start
          The start offset of the last lexical unit.
static int START_TAG_CONTEXT
          The start tag context.
static int TOP_LEVEL_CONTEXT
          The top level context.
protected  int type
          The type of the current lexical unit.
static int XML_DECL_CONTEXT
          The XML declaration context.
 
Constructor Summary
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
 void clearBuffer()
          Clears the buffer.
protected  XMLException createXMLException(java.lang.String message)
          Returns an XMLException initialized with the given message key.
 java.lang.String formatMessage(java.lang.String key, java.lang.Object[] args)
          Implements Localizable.formatMessage(String,Object[]).
 char[] getBuffer()
          Returns the buffer used to store the chars.
 int getColumn()
          Returns the current column.
 int getContext()
          Returns the current context.
 int getDepth()
          Returns the current depth in the XML tree.
 int getEnd()
          Returns the end offset of the last lexical unit.
 int getEndOffset()
          Returns the end offset of the current lexical unit.
 int getLine()
          Returns the current line.
 java.util.Locale getLocale()
          Implements Localizable.getLocale().
 int getStart()
          Returns the start offset of the last lexical unit.
 int getStartOffset()
          Returns the start offset of the current lexical unit.
 char getStringDelimiter()
          Returns the last encountered string delimiter.
 int getType()
          The current lexical unit type like defined in LexicalUnits.
 int next()
          Advances to the next lexical unit.
 int next(int ctx)
          Advances to the next lexical unit.
protected  int nextChar()
          Sets the value of the current char to the next character or -1 if the end of stream has been reached.
protected  int nextInAttList()
          Returns the next lexical unit in the context of an attribute list.
protected  int nextInAttributeValue()
          Returns the next lexical unit in the context of an attribute value.
protected  int nextInCDATASection()
          Returns the next lexical unit in the context of a CDATA section.
protected  int nextInContent()
          Returns the next lexical unit in the context of an element content.
protected  int nextInDoctype()
          Returns the next lexical unit in the context of a doctype.
protected  int nextInDocumentStart()
          Reads the first token in the stream.
protected  int nextInDTDDeclarations()
          Returns the next lexical unit in the context dtd declarations.
protected  int nextInElementDeclaration()
          Returns the next lexical unit in the context of a element declaration.
protected  int nextInEndTag()
          Returns the next lexical unit in the context of a end tag.
protected  int nextInEntity()
          Returns the next lexical unit in the context of an entity.
protected  int nextInEntityValue()
          Returns the next lexical unit in the context of an entity value.
protected  int nextInEnumeration()
          Returns the next lexical unit in the context of an enumeration.
protected  int nextInNotation()
          Returns the next lexical unit in the context of a notation.
protected  int nextInNotationType()
          Returns the next lexical unit in the context of a notation type.
protected  int nextInPI()
          Returns the next lexical unit in the context of a processing instruction.
protected  int nextInStartTag()
          Returns the next lexical unit in the context of a start tag.
protected  int nextInTopLevel()
          Advances to the next lexical unit in the top level context.
protected  int nextInXMLDecl()
          Returns the next lexical unit in the context of an XML declaration.
protected  int readComment()
          Reads a comment.
protected  int readIdentifier(java.lang.String s, int type, int ntype)
          Reads the given identifier.
protected  int readName(int type)
          Reads a name.
protected  int readNmtoken()
          Reads a Nmtoken.
protected  int readPEReference()
          Reads a parameter entity reference.
protected  int readPIStart()
          Reads a processing instruction start.
protected  int readReference()
          Reads an entity or character reference.
protected  int readString()
          Reads a simple string, like the ones used for version, encoding, public/system identifiers...
 void setContext(int c)
          Sets the current context.
 void setDepth(int i)
          Sets the current depth in the XML tree.
 void setLocale(java.util.Locale l)
          Implements Localizable.setLocale(Locale).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOCUMENT_START_CONTEXT

public static final int DOCUMENT_START_CONTEXT
The document start context.

TOP_LEVEL_CONTEXT

public static final int TOP_LEVEL_CONTEXT
The top level context.

PI_CONTEXT

public static final int PI_CONTEXT
The processing instruction context.

XML_DECL_CONTEXT

public static final int XML_DECL_CONTEXT
The XML declaration context.

DOCTYPE_CONTEXT

public static final int DOCTYPE_CONTEXT
The doctype context.

START_TAG_CONTEXT

public static final int START_TAG_CONTEXT
The start tag context.

CONTENT_CONTEXT

public static final int CONTENT_CONTEXT
The content context.

DTD_DECLARATIONS_CONTEXT

public static final int DTD_DECLARATIONS_CONTEXT
The DTD declarations context.

CDATA_SECTION_CONTEXT

public static final int CDATA_SECTION_CONTEXT
The CDATA section context.

END_TAG_CONTEXT

public static final int END_TAG_CONTEXT
The end tag context.

ATTRIBUTE_VALUE_CONTEXT

public static final int ATTRIBUTE_VALUE_CONTEXT
The attribute value context.

ATTLIST_CONTEXT

public static final int ATTLIST_CONTEXT
The ATTLIST context.

ELEMENT_DECLARATION_CONTEXT

public static final int ELEMENT_DECLARATION_CONTEXT
The element declaration context.

ENTITY_CONTEXT

public static final int ENTITY_CONTEXT
The entity context.

NOTATION_CONTEXT

public static final int NOTATION_CONTEXT
The notation context.

NOTATION_TYPE_CONTEXT

public static final int NOTATION_TYPE_CONTEXT
The notation type context.

ENUMERATION_CONTEXT

public static final int ENUMERATION_CONTEXT
The enumeration context.

ENTITY_VALUE_CONTEXT

public static final int ENTITY_VALUE_CONTEXT
The entity value context.

BUNDLE_CLASSNAME

protected static final java.lang.String BUNDLE_CLASSNAME
The default resource bundle base name.

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 XMLException
Creates a new XML scanner.
Parameters:
r - The reader to scan.

XMLScanner

public XMLScanner(java.io.InputStream is,
                  java.lang.String enc)
           throws XMLException
Creates a new XML scanner.
Parameters:
r - The input stream to scan.
enc - The character encoding to use.

XMLScanner

public XMLScanner(java.lang.String s)
           throws XMLException
Creates a new XML scanner.
Parameters:
s - The string to parse.
Method Detail

setLocale

public void setLocale(java.util.Locale l)
Implements Localizable.setLocale(Locale).
Specified by:
setLocale in interface Localizable
Following copied from interface: org.apache.batik.i18n.Localizable
Parameters:
l - The locale to set.

getLocale

public java.util.Locale getLocale()
Implements Localizable.getLocale().
Specified by:
getLocale in interface Localizable

formatMessage

public java.lang.String formatMessage(java.lang.String key,
                                      java.lang.Object[] args)
                               throws java.util.MissingResourceException
Implements Localizable.formatMessage(String,Object[]).
Specified by:
formatMessage in interface Localizable
Following copied from interface: org.apache.batik.i18n.Localizable
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 XMLException
Advances to the next lexical unit.
Returns:
The type of the lexical unit like defined in LexicalUnits.

next

public int next(int ctx)
         throws XMLException
Advances to the next lexical unit.
Parameters:
ctx - The context to use for scanning.
Returns:
The type of the lexical unit like defined in LexicalUnits.

nextInDocumentStart

protected int nextInDocumentStart()
                           throws java.io.IOException,
                                  XMLException
Reads the first token in the stream.

nextInTopLevel

protected int nextInTopLevel()
                      throws java.io.IOException,
                             XMLException
Advances to the next lexical unit in the top level context.
Returns:
The type of the lexical unit like defined in LexicalUnits.

nextInPI

protected int nextInPI()
                throws java.io.IOException,
                       XMLException
Returns the next lexical unit in the context of a processing instruction.

nextInStartTag

protected int nextInStartTag()
                      throws java.io.IOException,
                             XMLException
Returns the next lexical unit in the context of a start tag.

nextInAttributeValue

protected int nextInAttributeValue()
                            throws java.io.IOException,
                                   XMLException
Returns the next lexical unit in the context of an attribute value.

nextInContent

protected int nextInContent()
                     throws java.io.IOException,
                            XMLException
Returns the next lexical unit in the context of an element content.

nextInEndTag

protected int nextInEndTag()
                    throws java.io.IOException,
                           XMLException
Returns the next lexical unit in the context of a end tag.

nextInCDATASection

protected int nextInCDATASection()
                          throws java.io.IOException,
                                 XMLException
Returns the next lexical unit in the context of a CDATA section.

nextInXMLDecl

protected int nextInXMLDecl()
                     throws java.io.IOException,
                            XMLException
Returns the next lexical unit in the context of an XML declaration.

nextInDoctype

protected int nextInDoctype()
                     throws java.io.IOException,
                            XMLException
Returns the next lexical unit in the context of a doctype.

nextInDTDDeclarations

protected int nextInDTDDeclarations()
                             throws java.io.IOException,
                                    XMLException
Returns the next lexical unit in the context dtd declarations.

readString

protected int readString()
                  throws java.io.IOException,
                         XMLException
Reads a simple string, like the ones used for version, encoding, public/system identifiers... The current character must be the string delimiter.
Returns:
type.

readComment

protected int readComment()
                   throws java.io.IOException,
                          XMLException
Reads a comment. '<!-' must have been read.

readIdentifier

protected int readIdentifier(java.lang.String s,
                             int type,
                             int ntype)
                      throws java.io.IOException,
                             XMLException
Reads 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.

readName

protected int readName(int type)
                throws java.io.IOException,
                       XMLException
Reads a name. The current character must be the first character.
Parameters:
type - The lexical unit type to set.
Returns:
type.

readPIStart

protected int readPIStart()
                   throws java.io.IOException,
                          XMLException
Reads a processing instruction start.
Returns:
type.

nextInElementDeclaration

protected int nextInElementDeclaration()
                                throws java.io.IOException,
                                       XMLException
Returns the next lexical unit in the context of a element declaration.

nextInAttList

protected int nextInAttList()
                     throws java.io.IOException,
                            XMLException
Returns the next lexical unit in the context of an attribute list.

nextInNotation

protected int nextInNotation()
                      throws java.io.IOException,
                             XMLException
Returns the next lexical unit in the context of a notation.

nextInEntity

protected int nextInEntity()
                    throws java.io.IOException,
                           XMLException
Returns the next lexical unit in the context of an entity.

nextInEntityValue

protected int nextInEntityValue()
                         throws java.io.IOException,
                                XMLException
Returns the next lexical unit in the context of an entity value.

nextInNotationType

protected int nextInNotationType()
                          throws java.io.IOException,
                                 XMLException
Returns the next lexical unit in the context of a notation type.

nextInEnumeration

protected int nextInEnumeration()
                         throws java.io.IOException,
                                XMLException
Returns the next lexical unit in the context of an enumeration.

readReference

protected int readReference()
                     throws java.io.IOException,
                            XMLException
Reads an entity or character reference. The current character must be '&'.
Returns:
type.

readPEReference

protected int readPEReference()
                       throws java.io.IOException,
                              XMLException
Reads a parameter entity reference. The current character must be '%'.
Returns:
type.

readNmtoken

protected int readNmtoken()
                   throws java.io.IOException,
                          XMLException
Reads a Nmtoken. The current character must be the first character.
Returns:
LexicalUnits.NMTOKEN.

nextChar

protected int nextChar()
                throws java.io.IOException
Sets the value of the current char to the next character or -1 if the end of stream has been reached.

createXMLException

protected XMLException createXMLException(java.lang.String message)
Returns an XMLException initialized with the given message key.


Copyright © 2002 Apache Software Foundation. All Rights Reserved.