public class PlistProperties extends Object
Title: PlistReader PlistProperties
Description: Package to read and write PLIST files on OsX
Copyright: 2007, Gie Spaepen
Company: University of Antwerp
When you read a PLIST
file you'll work afterwards with
this class. This object holds all the data structured as key - value pairs.
Some functions show similarity with the java.util.Properties
class but this class doesn't inherit from that class for the simple reason
that a Properties class extends a java.util.Hashtable
and
that's not flexible enough.
The keys are always strings and the values can be instance of the following classes (all non-primitive):
All of these classes are translations of the XML code:
Scroll on to the functions for the usage
Modifier and Type | Field and Description |
---|---|
private Vector |
internalKeys
Stores all the key values
|
private Vector |
internalValues
Stores all the values of the keys
|
private String |
key
Stores the key of this object itselves
|
static Class |
TYPE_ARRAY
Class object for a Vector (follows
PLIST syntax) |
static Class |
TYPE_BOOLEAN
Class object for a Boolean
|
static Class |
TYPE_DATA
Class object for a Byte[]
|
static Class |
TYPE_DATE
Class object for a Date
|
static Class |
TYPE_DICTIONARY
Alias for a
TYPE_PLISTPROPERTIES (follows PLIST syntax) |
static Class |
TYPE_DOUBLE
Class object for a Double
|
static Class |
TYPE_INTEGER
Class object for an Integer
|
static Class |
TYPE_PLISTPROPERTIES
Class object for a PlistProperties
|
static Class |
TYPE_STRING
Class object for a String
|
static Class |
TYPE_VECTOR
Alias for a
TYPE_ARRAY |
Constructor and Description |
---|
PlistProperties()
Empty constructor
|
PlistProperties(String _key)
Construct a
PlistProperties object with a specific key |
Modifier and Type | Method and Description |
---|---|
void |
changeProperty(String _key,
Object _value)
Change the value of a given key
_key to a value _value . |
static PlistProperties |
convertToPlistProperties(Properties _props) |
Properties |
convertToProperties()
This function converts a
PlistPropertiesObject to a
regular java.util.Properties object. |
static Properties |
convertToProperties(PlistProperties _props) |
int |
getKeyIndex(String _key)
Get the index of a key.
|
Vector |
getKeys()
Get the
Vector of all the kyes |
String |
getPropertiesKey()
Get the key of this object
|
Object |
getProperty(String _key)
Search a property value for a given key.
|
Object |
getProperty(String _key,
Object _default)
Get the value of a given key and return the
_default
object if nothing is found. |
Object |
getPropertyRecursive(String _key)
Search a property value for a given key.
|
Vector |
getValues()
Get the
Vector of all the values |
void |
list(PrintStream _out)
This function prints the contents of this object to a Printstream
_out . |
void |
list(PrintStream _out,
int _tabIndex)
This function prints the contents of this object to a Printstream
_out . |
void |
list(PrintWriter _out)
This function prints the contents of this object to a Printstream
_out . |
void |
list(PrintWriter _out,
int _tabIndex)
This function prints the contents of this object to a PrintWriter
_out . |
private void |
printContent(Object _out,
int _tabIndex)
This function handles the actions described in the various
list()
functions in this document. |
int |
propertyTypeCount(Class _type)
Get the number of properties belonging to a certain type.
|
int |
propertyTypeCount(Class _type,
int _baseCount)
Get the number of properties belonging to a certain type.
|
void |
setPropertiesKey(String _key)
Set the key of this object
|
void |
setProperty(String _key,
Object _value)
Set the value of a given key
_key to a value _value . |
private Vector internalKeys
private Vector internalValues
private String key
public static final Class TYPE_STRING
public static final Class TYPE_INTEGER
public static final Class TYPE_DOUBLE
public static final Class TYPE_DATE
public static final Class TYPE_DATA
public static final Class TYPE_BOOLEAN
public static final Class TYPE_ARRAY
PLIST
syntax)public static final Class TYPE_VECTOR
TYPE_ARRAY
TYPE_VECTOR
public static final Class TYPE_PLISTPROPERTIES
public static final Class TYPE_DICTIONARY
TYPE_PLISTPROPERTIES
(follows PLIST
syntax)TYPE_PLISTPROPERTIES
public PlistProperties()
public PlistProperties(String _key)
PlistProperties
object with a specific key_key
- Stringpublic Object getProperty(String _key) throws PlistReaderException
_key
- StringPlistReaderException
public int getKeyIndex(String _key)
_key
- Stringpublic Object getPropertyRecursive(String _key) throws PlistReaderException
_key
- StringPlistReaderException
public void setPropertiesKey(String _key)
_key
- Stringpublic String getPropertiesKey()
public Object getProperty(String _key, Object _default)
_default
object if nothing is found. This function is not recursive._key
- String_default
- Objectpublic void setProperty(String _key, Object _value) throws PlistReaderException
_key
to a value _value
.
This function generates an error if the wrong key is given. If the key exists
its value is changed. Otherwise a new element is added._key
- String_value
- ObjectPlistReaderException
public void changeProperty(String _key, Object _value) throws PlistReaderException
_key
to a value _value
.
The difference with the setProperty
function is the fact that
this function throws an exception when no key is found instead of adding
a new node._key
- String_value
- ObjectPlistReaderException
public int propertyTypeCount(Class _type)
PlistProperties
object of the type String (equals to a <string>
tag you
can call this function. As parameter _type
you can use the
static fields of this class:
_type
- Classpublic int propertyTypeCount(Class _type, int _baseCount)
propertyTypeCount(Class _type)
for more information. The only
difference with that previous function is the fact that the counting
doesn't start from 0 but from _baseCount
._type
- Class_baseCount
- intpublic Properties convertToProperties()
PlistPropertiesObject
to a
regular java.util.Properties
object. Only the first-level
childs of the root dict
node are converted to
String-String
key-value pairs. Nested arrays or dictionaries
are not added to the Properties
object.public static Properties convertToProperties(PlistProperties _props)
public static PlistProperties convertToPlistProperties(Properties _props)
public void list(PrintStream _out)
_out
. An '-' means an element of this object and '+' refers to
elements of an array._out
- PrintStreamlist(PrintStream _out, int _tabIndex)
public void list(PrintWriter _out)
_out
. An '-' means an element of this object and '+' refers to
elements of an array._out
- PrintStreamlist(PrintStream _out, int _tabIndex)
public void list(PrintStream _out, int _tabIndex)
_out
. An '-' means an element of this object and '+' refers to
elements of an array. With the integer _tabIndex
you can d
define the indentation of the text._out
- PrintStream_tabIndex
- int - the left indentationlist(PrintStream _out)
public void list(PrintWriter _out, int _tabIndex)
_out
. An '-' means an element of this object and '+' refers to
elements of an array. With the integer _tabIndex
you can d
define the indentation of the text._out
- PrintStream_tabIndex
- int - the left indentationlist(PrintWriter _out)
private void printContent(Object _out, int _tabIndex) throws PlistReaderException
list()
functions in this document. Because printWriter
and PrintStream
have for the list()
functions
the same method syntax these methods are blended to this function using
some aspects of java.lang.reflect
to print it to the resp.
streams._out
- Object_tabIndex
- intPlistReaderException
public Vector getKeys()
Vector
of all the kyespublic Vector getValues()
Vector
of all the values