public class ReaderXMLHandler extends DefaultHandler implements EntityResolver
Title: PlistReader ReaderXMLHandler
Description: Package to read and write PLIST files on OsX
Copyright: 2007, Gie Spaepen
Company: University of Antwerp
THis class is used by the SAX Parser to, event based, handle the content
of the XML file and the DTD file. This class needs a PlistProperties
object as input parameter to construct a data tree.
Versions
PLIST
files.
date
tags and real
tags can now also be understood by the handler and will be stored as a Double
.
Modifier and Type | Field and Description |
---|---|
private boolean |
isDataLoaded
Flag to determine if a data tag just passed by
|
private boolean |
isDateLoaded
Flag to determine if a date tag just passed by
|
private boolean |
isIntegerLoaded
Flag to determine if an integer tag just passed by
|
private boolean |
isKeyLoaded
Flag to determine if a key tag just passed by
|
private boolean |
isRealLoaded
Flag to determine if a real tag just passed by
|
private boolean |
isStringLoaded
Flag to determine if a string tag just passed by
|
private PlistProperties |
rootObject
Main
PlistProperties object that acts
as a root object |
private Vector |
storageObjects
Vector to hold the different data nodes
|
private String |
tempKey
String to temporally hold a key
|
Constructor and Description |
---|
ReaderXMLHandler(PlistProperties _properties)
This constructor needs a valid
PlistProperties object. |
Modifier and Type | Method and Description |
---|---|
void |
characters(char[] _chars,
int _start,
int _len)
This function extends the
characters function of the
DefaultHandler class. |
private Date |
convertStringToDate(String value)
Little helper function to convert a string value to a date object.
|
void |
endElement(String _URI,
String _local,
String _raw)
This function extends the
endElement function of the
DefaultHandler class. |
private void |
levelDown(boolean _array)
When a closing array or dict tag is encountered this function is called
to close the current object, say to fold the last node, and add them
to the parent node.
|
private void |
levelUp(boolean _array)
When a a dict or array tag is encountered we have to create a new level
or node.
|
InputSource |
resolveEntity(String _pubId,
String _sysId)
Function to implement the
org.xml.sax.EntityResolver class. |
private void |
setProperty(String _key,
Object _value)
This function handles a key-value pair by adding them to the current and
active object: in other words the last open node in a manner of speaking.
|
void |
startElement(String _URI,
String _local,
String _raw,
Attributes atts)
This function extends the
startElement function of the
DefaultHandler class. |
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
private boolean isKeyLoaded
private boolean isStringLoaded
private boolean isIntegerLoaded
private boolean isRealLoaded
private boolean isDateLoaded
private boolean isDataLoaded
private PlistProperties rootObject
PlistProperties
object that acts
as a root objectprivate String tempKey
private Vector storageObjects
public ReaderXMLHandler(PlistProperties _properties)
PlistProperties
object. Don't use
the the following code as constructor:ReaderXMLHandler reader = new ReaderXMLHandler(new PlistProperties());
private
_properties
- PlistProperties - The object you want to use afterwards.public void startElement(String _URI, String _local, String _raw, Attributes atts)
startElement
function of the
DefaultHandler
class. It handles basically the tagnames of
opening tags.characters
function
knows what to do with the content. A boolean is immediately stored since
it is an empty tag. The dict or the array are handled by creating a new
level (say node) in the internal data storage object.startElement
in interface ContentHandler
startElement
in class DefaultHandler
_URI
- String - The namespace URI_local
- String - The tagname without prefixes (the one we need since all the Plist tags are 'simple' tags._raw
- String - The tagname with prefixesatts
- Attributes - The attributes attached to the elementpublic void characters(char[] _chars, int _start, int _len)
characters
function of the
DefaultHandler
class. It handles basically the tagnames of
opening tags.startElement
function
we only need to handle key, string, integer, data and data tags. A
key tag is temporally stored in a string and later on reused to match it's
value. The rest is passed to the setProperty
function and
converted to the resp. object.characters
in interface ContentHandler
characters
in class DefaultHandler
_chars
- char[]_start
- int_len
- intprivate Date convertStringToDate(String value)
value
- Stringpublic void endElement(String _URI, String _local, String _raw)
endElement
function of the
DefaultHandler
class. It handles basically the tagnames of
opening tags.startElement
function by 1) setting all the flags to false for a key, string,
integer, date or data tag and moving a level down (say node) when
encountering a dictionary or an array.endElement
in interface ContentHandler
endElement
in class DefaultHandler
_URI
- String - The namespace URI_local
- String - The tagname without prefix_raw
- String - The tagname with prefixstartElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public InputSource resolveEntity(String _pubId, String _sysId)
org.xml.sax.EntityResolver
class.
Since the PLIST files generally have a DOCTYPE
tag with
an URL in it the (stupid) SAX Parser want's to make an internet connection
and generates a fatal error if it can't. But, the correct DTD file is
located also in the JAR file of this library, so if we meet this tag
redirect the parser to the internal DTD file.resolveEntity
in interface EntityResolver
resolveEntity
in class DefaultHandler
_pubId
- String_sysId
- Stringprivate void setProperty(String _key, Object _value)
Vector
holding the array values, or to a _key
- String_value
- Objectprivate void levelUp(boolean _array)
Vector
is added to the data
storage and when it is a dict a PlistProperties
is added
and all the data content is added to those objects. Last: use the parameter
to the data storage. The added object will then act as current object
to say whether it is an array or not..._array
- boolean - new level is an array level (true) or a dict level (false)private void levelDown(boolean _array)
_array
- boolean - True for arrays and false for dictionaries.