Class PListParser
java.lang.Object
com.github.markusbernhardt.proxy.util.PListParser
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Small helper class representing a tree node.private static enum
All element types possible for a plist.static class
Exception is used for XML parse problems. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char[]
private static final String
private final DateFormat
private final Map
<Class<?>, PListParser.ElementType> private static final PListParser
Singleton instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static byte[]
base64decode
(String base64) Converts a string to a byte array assuming the string uses base64-encoding.(package private) static String
base64encode
(byte[] bytes) Encode an array of bytes to a string using base64 encoding.private String
Parses a string value from a node.static PListParser.Dict
Create a nestedmap<String, Object>
from a plist xml file using the default mapping.(package private) PListParser.Dict
Parses a plist top element into a map dictionary containing all the data in the plist.private static PListParser.Dict
parse
(InputSource input) Reads from the given input stream and parses it to a Dict.parseArray
(NodeList elements) Parse a list of xml elements as a plist array.private PListParser.Dict
Parse a list of xml elements as a plist dict.private Object
parseElement
(Node element) Parses a (non-top) xml element.private Object
parseElementRaw
(Node element) Parses a (non-top) xml element.private Number
Parses a string into a Long or Integer depending on size.(package private) static void
silentlyClose
(Closeable closeable) Utility method to close a closeable.
-
Field Details
-
PLIST
Singleton instance. -
BASE64_STRING
- See Also:
-
BASE64_CHARS
private static final char[] BASE64_CHARS -
m_dateFormat
-
m_simpleTypes
-
-
Constructor Details
-
PListParser
PListParser()Create a plist handler.
-
-
Method Details
-
silentlyClose
Utility method to close a closeable.- Parameters:
closeable
- or null.
-
parse
Reads from the given input stream and parses it to a Dict.- Parameters:
input
- the input stream to read from.- Returns:
- the parsed dictionary.
- Throws:
PListParser.XmlParseException
- on parsing error.
-
load
Create a nestedmap<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:
PListParser.XmlParseException
- if the plist could not be properly parsed.IOException
- if there was an issue reading the plist file.
-
parse
Parses a plist top element into a map dictionary containing all the data in the plist.- Parameters:
element
- the top plist element.- Returns:
- the resulting data tree structure.
- Throws:
PListParser.XmlParseException
- if there was any error parsing the xml.
-
parseElement
Parses a (non-top) xml element.- Parameters:
element
- the element to parse.- Returns:
- the resulting object.
- Throws:
PListParser.XmlParseException
- if there was some error in the xml.
-
parseElementRaw
Parses a (non-top) xml element.- Parameters:
element
- the element to parse.- Returns:
- the resulting object.
- Throws:
ParseException
- if there was some error parsing the xml.
-
getValue
Parses a string value from a node.- Parameters:
n
- the node to extract the value from.- Returns:
- the content of the node
-
parseInt
Parses a string into a Long or Integer depending on size.- Parameters:
value
- the value as a string.- Returns:
- the long value of this string is the value doesn't fit in an integer, otherwise the int value of the string.
-
parseDict
Parse a list of xml elements as a plist dict.- Parameters:
elements
- the elements to parse.- Returns:
- the dict deserialized as a map.
- Throws:
ParseException
- if there are any problems deserializing the map.
-
parseArray
Parse a list of xml elements as a plist array.- Parameters:
elements
- the elements to parse.- Returns:
- the array deserialized as a list.
- Throws:
ParseException
- if there are any problems deserializing the list.
-
base64encode
Encode an array of bytes to a string using base64 encoding.- Parameters:
bytes
- the bytes to convert.- Returns:
- the base64 representation of the bytes.
-
base64decode
Converts a string to a byte array assuming the string uses base64-encoding.- Parameters:
base64
- the string to convert.- Returns:
- the resulting byte array.
-