public class ERXPropertyListSerialization extends Object
The string representation can be in XML or the ASCII plist format. To distinguish between the two formats, the parser that converts strings to property lists finds out whether the string starts with <?xml
. A discussion of the ASCII plist format,
A Primer on ASCII Property Lists, is available in the Mac OS X section of the Apple Developer Connection website. A discussion of XML property lists, Property List Services, is also available in the same area of the Apple Developer Connection website.
Some methods do not support XML property list representations, specifically booleanForString
and intForString
. Also note that XML property lists de-serialize 'integer' value types to java.math.BigInteger and 'real' value types ot java.math.BigDecimal.
The ERXPropertyListSerialization class cannot be instantiated. There is an alternative Binary plist format.
NSDictionary dict<String,Object> = new NSDictionary<>(new String[] { "one", "two" }, new Object[] {Integer.valueOf(1), Integer.valueOf(2)});
String jsonString = ERXPropertyListSerialization.jsonStringFromPropertyList(dict);
NSDictionary<String, Object> result = ERXPropertyListSerialization.<String, Object> dictionaryForJSONString(jsonString);
If you know that you are receiving a JSON array, you can use the convenience API:
NSArray result = ERXPropertyListSerialization.arrayForJSONString(jsonString);
try {
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
NSDictionary plist = ERXPropertyListSerialization.dictionaryForBinaryStream(is);
} catch (RuntimeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
File tempFile = File.createTempFile("myPlist", "plist");
try (FileOutputStream out = new FileOutputStream(tempFile)) {
ERXPropertyListSerialization.propertyListWriteToStream(plist, out, ERXPropertyListSerialization.PListFormat.NSPropertyListXMLFormat_v1_0);
} catch (Exception e) {
e.printStackTrace();
}
Modifier and Type | Class and Description |
---|---|
static class |
ERXPropertyListSerialization._ApplePList |
static class |
ERXPropertyListSerialization._BinaryPListParser
Description of the binary plist format derived from http://cvs.opendarwin.org/cgi-bin/cvsweb.cgi/~checkout~/src/CoreFoundation/Parsing.subproj/CFBinaryPList.c?rev=1.1.1.3&content-type=text/plain EBNF description of the file format:
|
static class |
ERXPropertyListSerialization._JSONPList |
static class |
ERXPropertyListSerialization._PListParser
This class is intentionally undocumented
|
static class |
ERXPropertyListSerialization._XML
This class is intentionally undocumented
|
static class |
ERXPropertyListSerialization.PListFormat
Types of property lists (as specified in CoreFoundation)
|
static class |
ERXPropertyListSerialization.PListType
Data types found in property lists (as specified in CoreFoundation)
|
Modifier and Type | Field and Description |
---|---|
static Class<?> |
_CLASS |
protected static String |
DefaultSimpleDateFormatPattern
yyyy-MM-dd'T'HH:mm:ss'Z'
|
static boolean |
ForceXML
Convenience for methods to convert to xml plist.
|
static boolean |
Indents
Convenience for methods to convert to plist.
|
protected static double |
kCFAbsoluteTimeIntervalSince1970 |
static boolean |
NoIndents
Convenience for methods to convert to plist.
|
static String |
NULL
Null value
|
Modifier | Constructor and Description |
---|---|
protected |
ERXPropertyListSerialization() |
Modifier and Type | Method and Description |
---|---|
static NSArray<?> |
arrayForBinaryStream(InputStream is) |
static <E> NSArray<E> |
arrayForJSONString(String value)
Parses the JSON formatted
string and returns the resulting property list as an NSArray. |
static <E> NSArray<E> |
arrayForString(String value)
Parses the property list representation
string and returns the resulting property list as an NSArray. |
static <E> NSArray<E> |
arrayForString(String value,
boolean forceXML)
Parses the property list representation
string and returns the resulting property list as an NSArray. |
static <E> NSArray<E> |
arrayWithPathURL(URL url)
Converts a java.net.URL into a property list and returns the resulting property list as an NSArray.
|
static <E> NSArray<E> |
arrayWithPathURL(URL url,
boolean forceXML)
Converts a java.net.URL into a property list and returns the resulting property list as an NSArray.
|
static boolean |
booleanForString(String value)
Parses a given string for boolean value according to the table below.
|
static com.webobjects.foundation.NSData |
dataFromPropertyList(Object plist,
ERXPropertyListSerialization.PListFormat type,
String encoding)
For a specified property list format, create an NSData from an object.
|
static com.webobjects.foundation.NSData |
dataFromPropertyList(Object plist,
String encoding)
Converts the property list
object into a string using a character encoding and returns it as an NSData object. |
static <K,V> NSDictionary<K,V> |
dictionaryForJSONString(String value)
Parses the JSON formatted
string and returns the resulting property list as an NSDictionary. |
static <K,V> NSDictionary<K,V> |
dictionaryForString(String value)
Parses the property list representation
string and returns the resulting property list as an NSDictionary. |
static <K,V> NSDictionary<K,V> |
dictionaryForString(String value,
boolean forceXML)
Parses the property list representation
string and returns the resulting property list as an NSDictionary. |
static <K,V> NSDictionary<K,V> |
dictionaryWithBinaryPropertyListPathURL(URL url)
Return NSDictionary for a valid plist.
|
static <K,V> NSDictionary<K,V> |
dictionaryWithBinaryStream(InputStream is)
Return NSDictionary for a valid plist when passed a binary plist stream.
|
static <K,V> NSDictionary<K,V> |
dictionaryWithInputStream(InputStream is,
String encoding)
Read a plist from an InputStream and return NSDictionary of values.
|
static <K,V> NSDictionary<K,V> |
dictionaryWithPathURL(URL url)
Converts a java.net.URL into a property list and returns the resulting property list as an NSDictionary.
|
static <K,V> NSDictionary<K,V> |
dictionaryWithPathURL(URL url,
boolean forceXML)
Converts a java.net.URL into a property list and returns the resulting property list as an NSDictionary.
|
static Document |
documentWithBinaryPropertyListURL(URL url)
Parse binary plist to XML Document
|
static int |
intForString(String value)
Parses a given string and returns the corresponding integer value.
|
static String |
jsonStringFromPropertyList(Object plist)
Converts the property list
object into a JSON formatted string. |
static String |
jsonStringFromPropertyList(Object plist,
boolean suppressWhiteSpace)
Converts the property list
object into a JSON formatted string. |
static Object |
propertyListFromData(com.webobjects.foundation.NSData data,
ERXPropertyListSerialization.PListFormat type,
String encoding)
Converts an NSData into a property list and returns it.
|
static Object |
propertyListFromData(com.webobjects.foundation.NSData data,
String encoding)
Converts an NSData into a property list using a character encoding and returns it.
|
static Object |
propertyListFromJSONString(String string)
Convert JSON formatted string to a property list
|
static Object |
propertyListFromString(String string)
Converts a string into a property list and returns it.
|
static Object |
propertyListFromString(String string,
boolean forceXML)
Converts a string into a property list and returns it.
|
static Object |
propertyListWithData(com.webobjects.foundation.NSData data,
ERXPropertyListSerialization.PListFormat type,
String encoding)
Reads a plist from the given NSData using the specified format.
|
static Object |
propertyListWithPathURL(URL url)
Converts a java.net.URL into a property list and returns it.
|
static Object |
propertyListWithPathURL(URL url,
boolean forceXML)
Converts a java.net.URL into a property list and returns it.
|
static Object |
propertyListWithStream(InputStream is,
ERXPropertyListSerialization.PListFormat type,
String encoding)
Reads a plist from the given inputstream using the specified format.
|
static Object |
propertyListWithURL(URL url,
ERXPropertyListSerialization.PListFormat type,
String encoding)
Reads a plist from the given URL using the specified format.
|
static String |
stringFromPropertyList(Object plist)
Converts a property list object into a string (old style plist) and returns it.
|
static String |
stringFromPropertyList(Object plist,
boolean indents)
Converts a property list object into a string (old style plist) and returns it.
|
static void |
writePropertyListToStream(Object plist,
OutputStream out,
ERXPropertyListSerialization.PListFormat type,
String encoding)
For a specified property list format, write a plist to the provided outputstream.
|
static String |
xmlStringFromPropertyList(Object plist)
Converts a property list object into an XML string and returns it.
|
static String |
xmlStringFromPropertyList(Object plist,
boolean indents)
Converts a property list object into an XML string and returns it.
|
static String |
xmlStringWithBinaryPropertyListURL(URL url)
Parse binary plist to XML Document
|
public static final Class<?> _CLASS
public static final boolean Indents
public static final boolean NoIndents
public static final boolean ForceXML
public static final String NULL
protected static final String DefaultSimpleDateFormatPattern
protected static final double kCFAbsoluteTimeIntervalSince1970
public static String stringFromPropertyList(Object plist)
plist
- the property list to convertplist
as a stringpropertyListFromString(String)
public static String stringFromPropertyList(Object plist, boolean indents)
plist
- the property list to convertindents
- if true the resulting plist is indented (tabs and CR) if false no tabs anc CR are inserted in the resultplist
as a stringpropertyListFromString(String, boolean)
public static String xmlStringFromPropertyList(Object plist)
plist
- the property list to convertplist
as a stringpropertyListFromString(String)
public static String xmlStringFromPropertyList(Object plist, boolean indents)
plist
- the property list to convertindents
- if true the resulting plist is indented (tabs and CR) if false no tabs anc CR are inserted in the resultplist
as a stringpropertyListFromString(String, boolean)
public static Object propertyListFromString(String string)
string
- the string to convert to a property liststring
as a property liststringFromPropertyList(Object)
public static Object propertyListFromString(String string, boolean forceXML)
string
- the string to convert to a property listforceXML
- force xml decodingstring
as a property liststringFromPropertyList(Object, boolean)
public static Object propertyListWithPathURL(URL url)
url
- the java.net.URL to convert to a property listurl
as a property liststringFromPropertyList(Object)
public static Object propertyListWithPathURL(URL url, boolean forceXML)
url
- the java.net.URL to convert to a property listforceXML
- force xml decodingurl
as a property list(Object, boolean)
public static Object propertyListFromJSONString(String string)
string
- public static String jsonStringFromPropertyList(Object plist)
object
into a JSON formatted string. By default, it will not append whitespace to JSON string.plist
- public static String jsonStringFromPropertyList(Object plist, boolean suppressWhiteSpace)
object
into a JSON formatted string.plist
- suppressWhiteSpace
- - will not format string with whitespacepublic static com.webobjects.foundation.NSData dataFromPropertyList(Object plist, String encoding)
object
into a string using a character encoding and returns it as an NSData object.plist
- the property list object to convertencoding
- encoding used to convert the characters in the result string to byteobject
converted to an NSDatapropertyListFromData(NSData, java.lang.String)
public static com.webobjects.foundation.NSData dataFromPropertyList(Object plist, ERXPropertyListSerialization.PListFormat type, String encoding)
plist
- the object to writetype
- type of plist to generateencoding
- the string encoding of the bytes in the stream (ignored for binary plist format)ERXPropertyListSerialization.PListFormat.NSPropertyListJsonFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListBinaryFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListXMLFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListOpenStepFormat
public static Object propertyListFromData(com.webobjects.foundation.NSData data, String encoding)
data
- the byte array to be converted to a property listencoding
- encoding to use to convert the bytes in the data byte array to characters in a string representationdata
as a property listdataFromPropertyList(Object, java.lang.String)
public static Object propertyListFromData(com.webobjects.foundation.NSData data, ERXPropertyListSerialization.PListFormat type, String encoding)
data
- the byte array to be converted to a property listtype
- type of plist to generateencoding
- the string encoding of the bytes in the stream (ignored for binary plist format)data
as a property listERXPropertyListSerialization.PListFormat.NSPropertyListJsonFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListBinaryFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListXMLFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListOpenStepFormat
public static boolean booleanForString(String value)
String | Result | |
---|---|---|
"YES" |
true |
|
"true" |
true |
|
any other value | false |
The tests for "YES" and "true" are case insensitive.
value
- the string to be parsed for boolean valuepublic static int intForString(String value)
value
- the string to be parsed for integer valuestring
; 0
if it is null
public static <E> NSArray<E> arrayWithPathURL(URL url)
E
- url
- the java.net.URL to convert to a property liststringFromPropertyList
public static <E> NSArray<E> arrayWithPathURL(URL url, boolean forceXML)
E
- url
- the java.net.URL to convert to a property listforceXML
- force xml decodingstringFromPropertyList
public static <E> NSArray<E> arrayForString(String value)
string
and returns the resulting property list as an NSArray.E
- value
- input property list representation stringdictionaryForString(String)
public static <E> NSArray<E> arrayForString(String value, boolean forceXML)
string
and returns the resulting property list as an NSArray.E
- value
- input property list representation stringforceXML
- force xml decodingdictionaryForString(String)
public static <E> NSArray<E> arrayForJSONString(String value)
string
and returns the resulting property list as an NSArray. NOTE: any JSON 'null' values will be tranlated to a String placeholder value (See ERXPropertyListSerialization.NULL).E
- value
- input property list representation stringNULL
,
dictionaryForJSONString(String)
public static <K,V> NSDictionary<K,V> dictionaryWithPathURL(URL url)
K
- V
- url
- the java.net.URL to convert to a property liststring
as an NSDictionary(Object)
public static <K,V> NSDictionary<K,V> dictionaryWithPathURL(URL url, boolean forceXML)
K
- V
- url
- the java.net.URL to convert to a property listforceXML
- force xml decodingstring
as an NSDictionary(Object, boolean)
public static <K,V> NSDictionary<K,V> dictionaryForString(String value)
string
and returns the resulting property list as an NSDictionary.K
- V
- value
- property list represented as a stringstring
as an NSDictionaryarrayForString(String)
public static <K,V> NSDictionary<K,V> dictionaryWithBinaryPropertyListPathURL(URL url)
K
- V
- url
- public static <K,V> NSDictionary<K,V> dictionaryWithBinaryStream(InputStream is)
K
- V
- is
- public static Document documentWithBinaryPropertyListURL(URL url)
url
- the url to read fromDocument
public static NSArray<?> arrayForBinaryStream(InputStream is)
is
- public static String xmlStringWithBinaryPropertyListURL(URL url)
url
- the url to read fromDocument
public static Object propertyListWithURL(URL url, ERXPropertyListSerialization.PListFormat type, String encoding)
url
- the URL to read fromtype
- type of plist to generateencoding
- the string encoding of the bytes in the stream (ignored for binary plist format)ERXPropertyListSerialization.PListFormat.NSPropertyListJsonFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListBinaryFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListXMLFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListOpenStepFormat
public static Object propertyListWithStream(InputStream is, ERXPropertyListSerialization.PListFormat type, String encoding)
is
- the InputStream to read fromtype
- type of plist to generateencoding
- the string encoding of the bytes in the stream (ignored for binary plist format)ERXPropertyListSerialization.PListFormat.NSPropertyListJsonFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListBinaryFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListXMLFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListOpenStepFormat
public static Object propertyListWithData(com.webobjects.foundation.NSData data, ERXPropertyListSerialization.PListFormat type, String encoding)
data
- the NSData to read fromtype
- type of plist to generateencoding
- the string encoding of the bytes in the stream (ignored for binary plist format)ERXPropertyListSerialization.PListFormat.NSPropertyListJsonFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListBinaryFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListXMLFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListOpenStepFormat
public static void writePropertyListToStream(Object plist, OutputStream out, ERXPropertyListSerialization.PListFormat type, String encoding)
plist
- the object to writeout
- output stream for plisttype
- type of plist to generateencoding
- the string encoding of the bytes in the stream (ignored for binary plist format)ERXPropertyListSerialization.PListFormat.NSPropertyListJsonFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListBinaryFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListXMLFormat_v1_0
,
ERXPropertyListSerialization.PListFormat.NSPropertyListOpenStepFormat
public static <K,V> NSDictionary<K,V> dictionaryWithInputStream(InputStream is, String encoding)
K
- V
- is
- the input stream to read fromencoding
- the string encoding of the bytes in the stream (ignored for binary plist format)public static <K,V> NSDictionary<K,V> dictionaryForString(String value, boolean forceXML)
string
and returns the resulting property list as an NSDictionary.K
- V
- value
- property list represented as a stringforceXML
- force xml decodingstring
as an NSDictionaryarrayForString(String)
public static <K,V> NSDictionary<K,V> dictionaryForJSONString(String value)
string
and returns the resulting property list as an NSDictionary. NOTE: any JSON 'null' values will be tranlated to a String placeholder value (See ERXPropertyListSerialization.NULL).K
- V
- value
- property list represented as a stringstring
as an NSDictionaryNULL
,
arrayForJSONString(String)
Copyright © 2002 – 2020 Project Wonder.