xmlwise
Class Plist

java.lang.Object
  extended by xmlwise.Plist

public final class Plist
extends java.lang.Object

Plist xml handling (serialization and deserialization)

The xml plist dtd can be found at http://www.apple.com/DTDs/PropertyList-1.0.dtd

The plist spec handles 8 types of objects: booleans, real, integers, dates, binary data, strings, arrays (lists) and dictionaries (maps).

The java Plist lib handles converting xml plists to a nested Map<String, Object> that can be trivially read from java. It also provides a simple way to convert a nested Map<String, Object> into an xml plist representation.

The following mapping will be done when converting from plist to Map:

 true/false -> Boolean
 real -> Double
 integer -> Integer/Long (depends on size, values exceeding an int will be rendered as longs)
 data -> byte[]
 string -> String
 array -> List
 dict -> Map
 

When converting from Map -> plist the conversion is as follows:

 Boolean -> true/false
 Float/Double -> real
 Byte/Short/Integer/Long -> integer
 byte[] -> data
 List -> array
 Map -> dict
 

Author:
Christoffer Lerno

Method Summary
static java.util.Map<java.lang.String,java.lang.Object> fromXml(java.lang.String xml)
          Create a nested map<String, Object> from a plist xml string using the default mapping.
static java.util.Map<java.lang.String,java.lang.Object> fromXmlElement(XmlElement element)
          Create a nested map<String, Object> from an XmlElement using the default mapping.
static java.util.Map<java.lang.String,java.lang.Object> load(java.io.File file)
          Create a nested map<String, Object> from a plist xml file using the default mapping.
static java.util.Map<java.lang.String,java.lang.Object> load(java.lang.String filename)
          Create a nested map<String, Object> from a plist xml file using the default mapping.
static java.lang.Object loadObject(java.io.File file)
          Create an object from a plist xml file using the default mapping.
static java.lang.Object loadObject(java.lang.String filename)
          Create an object from a plist xml file using the default mapping.
static java.lang.Object objectFromXml(java.lang.String xml)
          Create an object from a plist xml string using the default mapping.
static java.lang.Object objectFromXmlElement(XmlElement element)
          Create an object from an XmlElement using the default mapping.
static void store(java.util.Map<java.lang.String,java.lang.Object> data, java.io.File file)
          Store a nested map<String, Object> as a plist using the default mapping.
static void store(java.util.Map<java.lang.String,java.lang.Object> data, java.lang.String filename)
          Store a nested map<String, Object> as a plist using the default mapping.
static void storeObject(java.lang.Object data, java.io.File file)
          Store an object as a plist using the default mapping.
static void storeObject(java.lang.Object object, java.lang.String filename)
          Store an object as a plist using the default mapping.
static java.lang.String toPlist(java.lang.Object o)
          Convert an object to a plist xml string using the default mapping.
static java.lang.String toXml(java.util.Map<java.lang.String,java.lang.Object> data)
          Convert a nested map<String, Object> as a plist xml string using the default mapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toXml

public static java.lang.String toXml(java.util.Map<java.lang.String,java.lang.Object> data)
Convert a nested map<String, Object> as a plist xml string using the default mapping.

Parameters:
data - the nested data to store as a plist.
Returns:
the resulting xml as a string.

toPlist

public static java.lang.String toPlist(java.lang.Object o)
Convert an object to a plist xml string using the default mapping.

Parameters:
o - the nested object to store as a plist.
Returns:
the resulting xml as a string.

store

public static void store(java.util.Map<java.lang.String,java.lang.Object> data,
                         java.lang.String filename)
                  throws java.io.IOException
Store a nested map<String, Object> as a plist using the default mapping.

Parameters:
data - the nested data to store as a plist.
filename - the destination file to store the data to.
Throws:
java.io.IOException - if there was an IO error saving the file.

storeObject

public static void storeObject(java.lang.Object object,
                               java.lang.String filename)
                        throws java.io.IOException
Store an object as a plist using the default mapping.

Parameters:
object - the object to store as a plist.
filename - the destination file to store the data to.
Throws:
java.io.IOException - if there was an IO error saving the file.

store

public static void store(java.util.Map<java.lang.String,java.lang.Object> data,
                         java.io.File file)
                  throws java.io.IOException
Store a nested map<String, Object> as a plist using the default mapping.

Parameters:
data - the nested data to store as a plist.
file - the destination File to store the data to.
Throws:
java.io.IOException - if there was an IO error saving the file.

storeObject

public static void storeObject(java.lang.Object data,
                               java.io.File file)
                        throws java.io.IOException
Store an object as a plist using the default mapping.

Parameters:
data - the nested data to store as a plist.
file - the destination File to store the data to.
Throws:
java.io.IOException - if there was an IO error saving the file.

fromXml

public static java.util.Map<java.lang.String,java.lang.Object> fromXml(java.lang.String xml)
                                                                throws XmlParseException
Create a nested map<String, Object> from a plist xml string using the default mapping.

Parameters:
xml - the plist xml data as a string.
Returns:
the resulting map as read from the plist data.
Throws:
XmlParseException - if the plist could not be properly parsed.

fromXmlElement

public static java.util.Map<java.lang.String,java.lang.Object> fromXmlElement(XmlElement element)
                                                                       throws XmlParseException
Create a nested map<String, Object> from an XmlElement using the default mapping.

Parameters:
element - the plist xml data as a string.
Returns:
the resulting map as read from the plist data.
Throws:
XmlParseException - if the plist could not be properly parsed.

objectFromXmlElement

public static java.lang.Object objectFromXmlElement(XmlElement element)
                                             throws XmlParseException
Create an object from an XmlElement using the default mapping.

Parameters:
element - the element that represents the plist.
Returns:
the resulting map as read from the plist data.
Throws:
XmlParseException - if the plist could not be properly parsed.

objectFromXml

public static java.lang.Object objectFromXml(java.lang.String xml)
                                      throws XmlParseException
Create an object from a plist xml string using the default mapping.

Parameters:
xml - the plist xml data as a string.
Returns:
the resulting map as read from the plist data.
Throws:
XmlParseException - if the plist could not be properly parsed.

load

public static java.util.Map<java.lang.String,java.lang.Object> load(java.io.File file)
                                                             throws XmlParseException,
                                                                    java.io.IOException
Create a nested map<String, Object> from a plist xml file using the default mapping.

Parameters:
file - the File containing the the plist xml.
Returns:
the resulting map as read from the plist data.
Throws:
XmlParseException - if the plist could not be properly parsed.
java.io.IOException - if there was an issue reading the plist file.

loadObject

public static java.lang.Object loadObject(java.io.File file)
                                   throws XmlParseException,
                                          java.io.IOException
Create an object from a plist xml file using the default mapping.

Parameters:
file - the File containing the the plist xml.
Returns:
the resulting object as read from the plist data.
Throws:
XmlParseException - if the plist could not be properly parsed.
java.io.IOException - if there was an issue reading the plist file.

load

public static java.util.Map<java.lang.String,java.lang.Object> load(java.lang.String filename)
                                                             throws XmlParseException,
                                                                    java.io.IOException
Create a nested map<String, Object> from a plist xml file using the default mapping.

Parameters:
filename - the file containing the the plist xml.
Returns:
the resulting map as read from the plist data.
Throws:
XmlParseException - if the plist could not be properly parsed.
java.io.IOException - if there was an issue reading the plist file.

loadObject

public static java.lang.Object loadObject(java.lang.String filename)
                                   throws XmlParseException,
                                          java.io.IOException
Create an object from a plist xml file using the default mapping.

Parameters:
filename - the file containing the the plist xml.
Returns:
the resulting object as read from the plist data.
Throws:
XmlParseException - if the plist could not be properly parsed.
java.io.IOException - if there was an issue reading the plist file.