megamek.common
Class XMLStreamParser

java.lang.Object
  extended by megamek.common.XMLStreamParser
All Implemented Interfaces:
gd.xml.XMLResponder

public class XMLStreamParser
extends java.lang.Object
implements gd.xml.XMLResponder

This class parses an XML input stream. If the stream is well formed, no Exception will be thrown. If the stream adheres to the format described by the file, "xml-spec.txt", then this class can return entities. If unexpected entities are encountered while parsing a well-formed stream, a warning message will be available.

Version:
$Revision: 7430 $
Author:
Suvarov454@sourceforge.net (James A. Damour )

Field Summary
static java.lang.String ADVS
           
static java.lang.String AEROCRIT
           
static java.lang.String ARMOR
           
static java.lang.String ARTILLERY
           
static java.lang.String AUTOEJECT
           
static java.lang.String AVIONICS
           
static java.lang.String CAT_PORTRAIT
           
static java.lang.String CHASSIS
          The names of the attributes recognized by this parser.
static java.lang.String CIC
           
static java.lang.String COMMANDB
           
static java.lang.String COMMANDER
           
static java.lang.String DEAD
          Special values recognized by this parser.
static java.lang.String DESTROYED
           
static java.lang.String DIRECTION
           
static java.lang.String EJECTED
           
static java.lang.String EMPTY
           
static java.lang.String ENGINE
           
static java.lang.String ENTITY
           
static java.lang.String EXT_ID
           
static java.lang.String FCS
           
static java.lang.String FILE_PORTRAIT
           
static java.lang.String FLUFF
           
static java.lang.String FRONT
           
static java.lang.String FUEL
           
static java.lang.String GEAR
           
static java.lang.String GUNNERY
           
static java.lang.String GUNNERYB
           
static java.lang.String GUNNERYL
           
static java.lang.String GUNNERYM
           
static java.lang.String HEAT
           
static java.lang.String HITS
           
static java.lang.String IMPLANTS
           
static java.lang.String INDEX
           
static java.lang.String INITB
           
static java.lang.String INTEGRITY
           
static java.lang.String INTERNAL
           
static java.lang.String IS_DESTROYED
           
static java.lang.String IS_HIT
           
static java.lang.String IS_REAR
           
static java.lang.String IS_REPAIRABLE
           
static java.lang.String KF
           
static java.lang.String LEFT
           
static java.lang.String LEFT_THRUST
           
static java.lang.String LIFE_SUPPORT
           
static java.lang.String LOCATION
           
static java.lang.String MODEL
           
static java.lang.String MOVEMENT
           
static java.lang.String MUNITION
           
static java.lang.String NA
           
static java.lang.String NAME
           
static java.lang.String NICK
           
static java.lang.String PILOT
           
static java.lang.String PILOTING
           
static java.lang.String POINTS
           
static java.lang.String QUIRKS
           
static java.lang.String REAR
           
static java.lang.String RIGHT_THRUST
           
static java.lang.String SAIL
           
static java.lang.String SENSORS
           
static java.lang.String SHOTS
           
static java.lang.String SI
           
static java.lang.String SINK
           
static java.lang.String SLOT
           
static java.lang.String SPEED
           
static java.lang.String SYSTEM
           
static java.lang.String TEMPLATE
           
static java.lang.String TOUGH
           
static java.lang.String TURRETLOCK
           
static java.lang.String TYPE
           
static java.lang.String UNIT
          The names of the various elements recognized by this parser.
 
Constructor Summary
XMLStreamParser()
          No Entitys or warning message are available if the default constructor is used.
XMLStreamParser(java.io.InputStream input)
          Construct an object and parse the XML stream.
 
Method Summary
 java.io.InputStream getDocumentStream()
          This method is always called exactly once, before all other callbacks.
 java.util.Vector<Entity> getEntities()
          Get any Entitys parsed from the last input stream.
 java.util.Vector<Pilot> getPilots()
           
 java.lang.String getWarningMessage()
          Get the warning message from the last parse.
 boolean hasWarningMessage()
          Determine if unexpected XML entities were encountered during parsing.
 void parse(java.io.InputStream input)
          Parse the indicated XML stream.
 void recordAttlistDeclaration(java.lang.String element, java.lang.String attr, boolean notation, java.lang.String type, java.lang.String defmod, java.lang.String def)
          This method is called when an attribute definition is parsed from an attlist tag in a DTD.
 void recordCharData(java.lang.String charData)
          This method is called to return character data to the application.
 void recordComment(java.lang.String comment)
          This method is called to return comments to the application.
 void recordDocEnd()
          This method is called to indicate that the document stream has been successfully closed.
 void recordDocStart()
          This method is called to indicate that the document stream has been opened successfully.
 void recordDoctypeDeclaration(java.lang.String name, java.lang.String pubID, java.lang.String sysID)
          This method is called after all the DTD related information is has been passed back.
 void recordElementDeclaration(java.lang.String name, java.lang.String content)
          This method is called when an element declaration is met in a DTD.
 void recordElementEnd(java.lang.String name)
          This method is called to indicate the closure of an element (tag).
 void recordElementStart(java.lang.String name, java.util.Hashtable attr)
          This method is called to indicate the start of an element (tag).
 void recordEntityDeclaration(java.lang.String name, java.lang.String value, java.lang.String pubID, java.lang.String sysID, java.lang.String notation)
          This method is called whenever an general entity declaration is parsed from a DTD.
 void recordNotationDeclaration(java.lang.String name, java.lang.String pubID, java.lang.String sysID)
          This method is called whenever a notation is parsed from a DTD.
 void recordPI(java.lang.String name, java.lang.String pValue)
          This method is called to passback program instructions to the application.
 java.io.InputStream resolveDTDEntity(java.lang.String name, java.lang.String pubID, java.lang.String sysID)
          This method is called to obtain an external DTD.
 java.io.InputStream resolveExternalEntity(java.lang.String name, java.lang.String pubID, java.lang.String sysID)
          This method is called when an external entity must be resolved for insertion into the document its DTD.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIT

public static final java.lang.String UNIT
The names of the various elements recognized by this parser.

See Also:
Constant Field Values

TEMPLATE

public static final java.lang.String TEMPLATE
See Also:
Constant Field Values

ENTITY

public static final java.lang.String ENTITY
See Also:
Constant Field Values

FLUFF

public static final java.lang.String FLUFF
See Also:
Constant Field Values

PILOT

public static final java.lang.String PILOT
See Also:
Constant Field Values

LOCATION

public static final java.lang.String LOCATION
See Also:
Constant Field Values

ARMOR

public static final java.lang.String ARMOR
See Also:
Constant Field Values

SLOT

public static final java.lang.String SLOT
See Also:
Constant Field Values

MOVEMENT

public static final java.lang.String MOVEMENT
See Also:
Constant Field Values

TURRETLOCK

public static final java.lang.String TURRETLOCK
See Also:
Constant Field Values

SI

public static final java.lang.String SI
See Also:
Constant Field Values

HEAT

public static final java.lang.String HEAT
See Also:
Constant Field Values

FUEL

public static final java.lang.String FUEL
See Also:
Constant Field Values

KF

public static final java.lang.String KF
See Also:
Constant Field Values

SAIL

public static final java.lang.String SAIL
See Also:
Constant Field Values

AEROCRIT

public static final java.lang.String AEROCRIT
See Also:
Constant Field Values

CHASSIS

public static final java.lang.String CHASSIS
The names of the attributes recognized by this parser. Not every attribute is valid for every element.

See Also:
Constant Field Values

MODEL

public static final java.lang.String MODEL
See Also:
Constant Field Values

NAME

public static final java.lang.String NAME
See Also:
Constant Field Values

EXT_ID

public static final java.lang.String EXT_ID
See Also:
Constant Field Values

NICK

public static final java.lang.String NICK
See Also:
Constant Field Values

CAT_PORTRAIT

public static final java.lang.String CAT_PORTRAIT
See Also:
Constant Field Values

FILE_PORTRAIT

public static final java.lang.String FILE_PORTRAIT
See Also:
Constant Field Values

GUNNERY

public static final java.lang.String GUNNERY
See Also:
Constant Field Values

GUNNERYL

public static final java.lang.String GUNNERYL
See Also:
Constant Field Values

GUNNERYM

public static final java.lang.String GUNNERYM
See Also:
Constant Field Values

GUNNERYB

public static final java.lang.String GUNNERYB
See Also:
Constant Field Values

PILOTING

public static final java.lang.String PILOTING
See Also:
Constant Field Values

ARTILLERY

public static final java.lang.String ARTILLERY
See Also:
Constant Field Values

TOUGH

public static final java.lang.String TOUGH
See Also:
Constant Field Values

INITB

public static final java.lang.String INITB
See Also:
Constant Field Values

COMMANDB

public static final java.lang.String COMMANDB
See Also:
Constant Field Values

HITS

public static final java.lang.String HITS
See Also:
Constant Field Values

ADVS

public static final java.lang.String ADVS
See Also:
Constant Field Values

IMPLANTS

public static final java.lang.String IMPLANTS
See Also:
Constant Field Values

QUIRKS

public static final java.lang.String QUIRKS
See Also:
Constant Field Values

COMMANDER

public static final java.lang.String COMMANDER
See Also:
Constant Field Values

AUTOEJECT

public static final java.lang.String AUTOEJECT
See Also:
Constant Field Values

EJECTED

public static final java.lang.String EJECTED
See Also:
Constant Field Values

INDEX

public static final java.lang.String INDEX
See Also:
Constant Field Values

IS_DESTROYED

public static final java.lang.String IS_DESTROYED
See Also:
Constant Field Values

IS_REPAIRABLE

public static final java.lang.String IS_REPAIRABLE
See Also:
Constant Field Values

POINTS

public static final java.lang.String POINTS
See Also:
Constant Field Values

TYPE

public static final java.lang.String TYPE
See Also:
Constant Field Values

IS_REAR

public static final java.lang.String IS_REAR
See Also:
Constant Field Values

SHOTS

public static final java.lang.String SHOTS
See Also:
Constant Field Values

IS_HIT

public static final java.lang.String IS_HIT
See Also:
Constant Field Values

MUNITION

public static final java.lang.String MUNITION
See Also:
Constant Field Values

SPEED

public static final java.lang.String SPEED
See Also:
Constant Field Values

DIRECTION

public static final java.lang.String DIRECTION
See Also:
Constant Field Values

INTEGRITY

public static final java.lang.String INTEGRITY
See Also:
Constant Field Values

SINK

public static final java.lang.String SINK
See Also:
Constant Field Values

LEFT

public static final java.lang.String LEFT
See Also:
Constant Field Values

AVIONICS

public static final java.lang.String AVIONICS
See Also:
Constant Field Values

SENSORS

public static final java.lang.String SENSORS
See Also:
Constant Field Values

ENGINE

public static final java.lang.String ENGINE
See Also:
Constant Field Values

FCS

public static final java.lang.String FCS
See Also:
Constant Field Values

CIC

public static final java.lang.String CIC
See Also:
Constant Field Values

LEFT_THRUST

public static final java.lang.String LEFT_THRUST
See Also:
Constant Field Values

RIGHT_THRUST

public static final java.lang.String RIGHT_THRUST
See Also:
Constant Field Values

LIFE_SUPPORT

public static final java.lang.String LIFE_SUPPORT
See Also:
Constant Field Values

GEAR

public static final java.lang.String GEAR
See Also:
Constant Field Values

DEAD

public static final java.lang.String DEAD
Special values recognized by this parser.

See Also:
Constant Field Values

NA

public static final java.lang.String NA
See Also:
Constant Field Values

DESTROYED

public static final java.lang.String DESTROYED
See Also:
Constant Field Values

FRONT

public static final java.lang.String FRONT
See Also:
Constant Field Values

REAR

public static final java.lang.String REAR
See Also:
Constant Field Values

INTERNAL

public static final java.lang.String INTERNAL
See Also:
Constant Field Values

EMPTY

public static final java.lang.String EMPTY
See Also:
Constant Field Values

SYSTEM

public static final java.lang.String SYSTEM
See Also:
Constant Field Values
Constructor Detail

XMLStreamParser

public XMLStreamParser()
No Entitys or warning message are available if the default constructor is used.


XMLStreamParser

public XMLStreamParser(java.io.InputStream input)
                throws gd.xml.ParseException
Construct an object and parse the XML stream. Any warning message or Entitys from a previously parsed stream will be discarded.

Parameters:
input - - the InputStream to be parsed.
Throws:
gd.xml.ParseException - is thrown if a fatal warning occurs during parsing. Typically, this only occurs when the XML is not well-formed.
Method Detail

parse

public void parse(java.io.InputStream input)
           throws gd.xml.ParseException
Parse the indicated XML stream. Any warning message or Entitys from a previously parsed stream will be discarded.

Parameters:
input - - the InputStream to be parsed.
Throws:
gd.xml.ParseException - is thrown if a fatal error occurs during parsing. Typically, this only occurs when the XML is not well-formed.

hasWarningMessage

public boolean hasWarningMessage()
Determine if unexpected XML entities were encountered during parsing.

Returns:
true if a non-fatal warning occured.

getWarningMessage

public java.lang.String getWarningMessage()
Get the warning message from the last parse.

Returns:
The String warning message from the last parse. If there is no warning message, then an null value is returned.

getEntities

public java.util.Vector<Entity> getEntities()
Get any Entitys parsed from the last input stream. Entities may have been parsed out of the stream, even if errors were encountered.

Returns:
A Vector containing Entitys parsed from the stream. This Vector may be empty, but it will never be null.

getPilots

public java.util.Vector<Pilot> getPilots()

recordNotationDeclaration

public void recordNotationDeclaration(java.lang.String name,
                                      java.lang.String pubID,
                                      java.lang.String sysID)
                               throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called whenever a notation is parsed from a DTD.

Specified by:
recordNotationDeclaration in interface gd.xml.XMLResponder
Parameters:
name - the name of the notation
pubID - the public ID of the notation if it was specified or null otherwise
sysID - the system ID (typically filename) of the notation (or null if unspecified)
Throws:
gd.xml.ParseException

recordEntityDeclaration

public void recordEntityDeclaration(java.lang.String name,
                                    java.lang.String value,
                                    java.lang.String pubID,
                                    java.lang.String sysID,
                                    java.lang.String notation)
                             throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called whenever an general entity declaration is parsed from a DTD. Most applications will have no use for this information.

Specified by:
recordEntityDeclaration in interface gd.xml.XMLResponder
Parameters:
name - the name assigned to this entity
value - the replacement text of this entity
pubID - the public ID of the entities replacement text (or null if unspecified)
sysID - the system ID of the entities replacement text (or null if unspecified)
notation - specifies the notation associated with this entity (null if entity to be parsed as XML)
Throws:
gd.xml.ParseException

recordElementDeclaration

public void recordElementDeclaration(java.lang.String name,
                                     java.lang.String content)
                              throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called when an element declaration is met in a DTD. Most applications will have no use for this information.

Specified by:
recordElementDeclaration in interface gd.xml.XMLResponder
Parameters:
name - the tag name given to this element
content - a regexp-like expression which specifies which elements and character data may appear within this element
Throws:
gd.xml.ParseException

recordAttlistDeclaration

public void recordAttlistDeclaration(java.lang.String element,
                                     java.lang.String attr,
                                     boolean notation,
                                     java.lang.String type,
                                     java.lang.String defmod,
                                     java.lang.String def)
                              throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called when an attribute definition is parsed from an attlist tag in a DTD. Applications may wish to record these definitions to apply default values to element tags.

Specified by:
recordAttlistDeclaration in interface gd.xml.XMLResponder
Parameters:
element - the element to which this attribute applies
attr - the name of the attribute being described by this declaration
notation - the notation (if any) which applies to this attribute
type - the type of value defined by this attribute
defmod - describes the nature of this attributes default value (one of 'FIXED', 'REQUIRED', 'IMPLIED' - as per XML spec - or 'DEFAULT' indicating a 'basic' default value)
def - the default value of this attribute (may be null, indicating no default specified)
Throws:
gd.xml.ParseException

recordDoctypeDeclaration

public void recordDoctypeDeclaration(java.lang.String name,
                                     java.lang.String pubID,
                                     java.lang.String sysID)
                              throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called after all the DTD related information is has been passed back. It supplies information about the document type applied to the document.

Specified by:
recordDoctypeDeclaration in interface gd.xml.XMLResponder
Parameters:
name - the name of the document type
pubID - the public ID of the document type (may be null)
sysID - the system ID of the document type (null if no external DTD is specified)
Throws:
gd.xml.ParseException

recordDocStart

public void recordDocStart()
Description copied from interface: gd.xml.XMLResponder
This method is called to indicate that the document stream has been opened successfully.

Specified by:
recordDocStart in interface gd.xml.XMLResponder

recordDocEnd

public void recordDocEnd()
Description copied from interface: gd.xml.XMLResponder
This method is called to indicate that the document stream has been successfully closed.

Specified by:
recordDocEnd in interface gd.xml.XMLResponder

recordElementStart

public void recordElementStart(java.lang.String name,
                               java.util.Hashtable attr)
                        throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called to indicate the start of an element (tag).

Specified by:
recordElementStart in interface gd.xml.XMLResponder
Parameters:
name - the name of the element (tag name)
attr - a hashtable containing the explicitly supplied attributes (as strings)
Throws:
gd.xml.ParseException

recordElementEnd

public void recordElementEnd(java.lang.String name)
                      throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called to indicate the closure of an element (tag).

Specified by:
recordElementEnd in interface gd.xml.XMLResponder
Parameters:
name - the name of the element (tag) being closed
Throws:
gd.xml.ParseException

recordPI

public void recordPI(java.lang.String name,
                     java.lang.String pValue)
Description copied from interface: gd.xml.XMLResponder
This method is called to passback program instructions to the application.

Specified by:
recordPI in interface gd.xml.XMLResponder
Parameters:
name - the name of the program instruction
pValue - the data associated with this program instruction

recordCharData

public void recordCharData(java.lang.String charData)
Description copied from interface: gd.xml.XMLResponder
This method is called to return character data to the application. As per the XML specification, newlines on all platforms are converted to single 0x0A's. Contiguous character data may be returned with successive calls to this method.

Specified by:
recordCharData in interface gd.xml.XMLResponder
Parameters:
charData - character data from the document.

recordComment

public void recordComment(java.lang.String comment)
Description copied from interface: gd.xml.XMLResponder
This method is called to return comments to the application. Most applications will have no use for this information. param comment the contents of the comment tag

Specified by:
recordComment in interface gd.xml.XMLResponder

getDocumentStream

public java.io.InputStream getDocumentStream()
                                      throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is always called exactly once, before all other callbacks. It is used to retrieve an inputstream from which the XML document will be parsed. This method may not return null.

Specified by:
getDocumentStream in interface gd.xml.XMLResponder
Returns:
an InputStream which supplies the document text.
Throws:
gd.xml.ParseException

resolveExternalEntity

public java.io.InputStream resolveExternalEntity(java.lang.String name,
                                                 java.lang.String pubID,
                                                 java.lang.String sysID)
                                          throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called when an external entity must be resolved for insertion into the document its DTD. This method may return null as an indication that the application declines to retrieve the entity.

Specified by:
resolveExternalEntity in interface gd.xml.XMLResponder
Parameters:
name - the name of the entity to be retrieved.
pubID - the public ID of the entity (may be null)
sysID - the system ID of the entity
Returns:
an InputStream which supplies the entity's replacement text
Throws:
gd.xml.ParseException

resolveDTDEntity

public java.io.InputStream resolveDTDEntity(java.lang.String name,
                                            java.lang.String pubID,
                                            java.lang.String sysID)
                                     throws gd.xml.ParseException
Description copied from interface: gd.xml.XMLResponder
This method is called to obtain an external DTD. Most applications will simply refer this call to the resolveExternalEntity method. This separate callback method is made available, should the application need to resolve the ID's differently.

Specified by:
resolveDTDEntity in interface gd.xml.XMLResponder
Parameters:
name - the name of the DTD
pubID - its public ID (may be null)
sysID - its system ID
Returns:
an InputStream which supplies the DTD for this document
Throws:
gd.xml.ParseException