Package com.dd.plist
Class ASCIIPropertyListParser
- java.lang.Object
-
- com.dd.plist.ASCIIPropertyListParser
-
public final class ASCIIPropertyListParser extends java.lang.ObjectParser for ASCII property lists. Supports Apple OS X/iOS and GnuStep/NeXTSTEP format. This parser is based on the recursive descent paradigm, but the underlying grammar is not explicitly defined.
Resources on ASCII property list format:
-
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description privateASCIIPropertyListParser(byte[] propertyListContent, java.lang.String encoding)Creates a new parser for the given property list content.privateASCIIPropertyListParser(char[] propertyListContent)Creates a new parser for the given property list content.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanaccept(char acceptableSymbol)Checks whether the given symbol can be accepted, that is, if the given symbols is found at the current parsing position.private booleanaccept(char... acceptableSymbols)Checks whether the given symbols can be accepted, that is, if one of the given symbols is found at the current parsing position.private booleanacceptSequence(char... sequence)Checks whether the given sequence of symbols can be accepted.private voidexpect(char expectedSymbol)Expects the input to have the given symbol at the current parsing position.private voidexpect(char... expectedSymbols)Expects the input to have one of the given symbols at the current parsing position.NSObjectparse()Parses the property list from the beginning and returns the root object of the property list.static NSObjectparse(byte[] bytes)Parses an ASCII property list from a byte array.static NSObjectparse(byte[] bytes, java.lang.String encoding)Parses an ASCII property list from a byte array.static NSObjectparse(java.io.File f)Parses an ASCII property list file.static NSObjectparse(java.io.File f, java.lang.String encoding)Parses an ASCII property list file.static NSObjectparse(java.io.InputStream in)Parses an ASCII property list from an input stream.static NSObjectparse(java.io.InputStream in, java.lang.String encoding)Parses an ASCII property list from an input stream.static NSObjectparse(java.io.Reader reader)Parses an ASCII property list from aReader.static NSObjectparse(java.lang.String plistData)Parses an ASCII property list from aStringstatic NSObjectparse(java.nio.file.Path path)Parses an ASCII property list file.static NSObjectparse(java.nio.file.Path path, java.lang.String encoding)Parses an ASCII property list file.private NSArrayparseArray()Parses an array from the current parsing position.private NSObjectparseData()Parses a data object from the current parsing position.private NSObjectparseDateString()Attempts to parse a plain string as a date if possible.private NSDictionaryparseDictionary()Parses a dictionary from the current parsing position.private static charparseEscapedSequence(java.text.StringCharacterIterator iterator)Unescapes an escaped character sequence, e.g.private NSObjectparseObject()Parses the NSObject found at the current position in the property list data stream.private java.lang.StringparseQuotedString()Parses a quoted string from the current parsing position.private static java.lang.StringparseQuotedString(java.lang.String s)Parses a string according to the format specified for ASCII property lists.private java.lang.StringparseString()Parses a plain string from the current parsing position.private voidread(char symbol)Reads an expected symbol.private java.lang.StringreadInputUntil(char symbol)Reads input until the given symbol is found.private java.lang.StringreadInputUntil(char... symbols)Reads input until one of the given symbols is found.private voidskip()Skips the current symbol.private voidskip(int numSymbols)Skips several symbolsprivate voidskipWhitespacesAndComments()Skips all whitespaces and comments from the current parsing position onward.
-
-
-
Field Detail
-
WHITESPACE_SPACE
public static final char WHITESPACE_SPACE
- See Also:
- Constant Field Values
-
WHITESPACE_TAB
public static final char WHITESPACE_TAB
- See Also:
- Constant Field Values
-
WHITESPACE_NEWLINE
public static final char WHITESPACE_NEWLINE
- See Also:
- Constant Field Values
-
WHITESPACE_CARRIAGE_RETURN
public static final char WHITESPACE_CARRIAGE_RETURN
- See Also:
- Constant Field Values
-
ARRAY_BEGIN_TOKEN
public static final char ARRAY_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
ARRAY_END_TOKEN
public static final char ARRAY_END_TOKEN
- See Also:
- Constant Field Values
-
ARRAY_ITEM_DELIMITER_TOKEN
public static final char ARRAY_ITEM_DELIMITER_TOKEN
- See Also:
- Constant Field Values
-
DICTIONARY_BEGIN_TOKEN
public static final char DICTIONARY_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
DICTIONARY_END_TOKEN
public static final char DICTIONARY_END_TOKEN
- See Also:
- Constant Field Values
-
DICTIONARY_ASSIGN_TOKEN
public static final char DICTIONARY_ASSIGN_TOKEN
- See Also:
- Constant Field Values
-
DICTIONARY_ITEM_DELIMITER_TOKEN
public static final char DICTIONARY_ITEM_DELIMITER_TOKEN
- See Also:
- Constant Field Values
-
QUOTEDSTRING_BEGIN_TOKEN
public static final char QUOTEDSTRING_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
QUOTEDSTRING_END_TOKEN
public static final char QUOTEDSTRING_END_TOKEN
- See Also:
- Constant Field Values
-
QUOTEDSTRING_ESCAPE_TOKEN
public static final char QUOTEDSTRING_ESCAPE_TOKEN
- See Also:
- Constant Field Values
-
DATA_BEGIN_TOKEN
public static final char DATA_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
DATA_END_TOKEN
public static final char DATA_END_TOKEN
- See Also:
- Constant Field Values
-
DATA_BASE64_BEGIN_TOKEN
public static final char DATA_BASE64_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
DATA_BASE64_END_TOKEN
public static final char DATA_BASE64_END_TOKEN
- See Also:
- Constant Field Values
-
DATA_GSOBJECT_BEGIN_TOKEN
public static final char DATA_GSOBJECT_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
DATA_GSDATE_BEGIN_TOKEN
public static final char DATA_GSDATE_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
DATA_GSBOOL_BEGIN_TOKEN
public static final char DATA_GSBOOL_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
DATA_GSBOOL_TRUE_TOKEN
public static final char DATA_GSBOOL_TRUE_TOKEN
- See Also:
- Constant Field Values
-
DATA_GSBOOL_FALSE_TOKEN
public static final char DATA_GSBOOL_FALSE_TOKEN
- See Also:
- Constant Field Values
-
DATA_GSINT_BEGIN_TOKEN
public static final char DATA_GSINT_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
DATA_GSREAL_BEGIN_TOKEN
public static final char DATA_GSREAL_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
DATE_DATE_FIELD_DELIMITER
public static final char DATE_DATE_FIELD_DELIMITER
- See Also:
- Constant Field Values
-
DATE_TIME_FIELD_DELIMITER
public static final char DATE_TIME_FIELD_DELIMITER
- See Also:
- Constant Field Values
-
DATE_GS_DATE_TIME_DELIMITER
public static final char DATE_GS_DATE_TIME_DELIMITER
- See Also:
- Constant Field Values
-
DATE_APPLE_DATE_TIME_DELIMITER
public static final char DATE_APPLE_DATE_TIME_DELIMITER
- See Also:
- Constant Field Values
-
DATE_APPLE_END_TOKEN
public static final char DATE_APPLE_END_TOKEN
- See Also:
- Constant Field Values
-
COMMENT_BEGIN_TOKEN
public static final char COMMENT_BEGIN_TOKEN
- See Also:
- Constant Field Values
-
MULTILINE_COMMENT_SECOND_TOKEN
public static final char MULTILINE_COMMENT_SECOND_TOKEN
- See Also:
- Constant Field Values
-
SINGLELINE_COMMENT_SECOND_TOKEN
public static final char SINGLELINE_COMMENT_SECOND_TOKEN
- See Also:
- Constant Field Values
-
MULTILINE_COMMENT_END_TOKEN
public static final char MULTILINE_COMMENT_END_TOKEN
- See Also:
- Constant Field Values
-
data
private final char[] data
Property list source data
-
index
private int index
Current parsing index
-
-
Constructor Detail
-
ASCIIPropertyListParser
private ASCIIPropertyListParser(byte[] propertyListContent, java.lang.String encoding) throws java.io.UnsupportedEncodingExceptionCreates a new parser for the given property list content.- Parameters:
propertyListContent- The content of the property list that is to be parsed.encoding- The name of a supportedcharsetto decode the property list.- Throws:
java.io.UnsupportedEncodingException- If no support for the named charset is available in this instance of the Java virtual machine.
-
ASCIIPropertyListParser
private ASCIIPropertyListParser(char[] propertyListContent)
Creates a new parser for the given property list content.- Parameters:
propertyListContent- The content of the property list that is to be parsed.
-
-
Method Detail
-
parse
public static NSObject parse(java.io.File f) throws java.io.IOException, java.text.ParseException
Parses an ASCII property list file.- Parameters:
f- The ASCII property list file.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.java.io.IOException- If an error occurs while reading from the input stream.
-
parse
public static NSObject parse(java.io.File f, java.lang.String encoding) throws java.io.IOException, java.text.ParseException
Parses an ASCII property list file.- Parameters:
f- The ASCII property list file.encoding- The name of a supportedcharsetto decode the property list.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.java.io.IOException- If an error occurs while reading from the input stream.java.io.UnsupportedEncodingException- If no support for the named charset is available in this instance of the Java virtual machine.
-
parse
public static NSObject parse(java.nio.file.Path path, java.lang.String encoding) throws java.io.IOException, java.text.ParseException
Parses an ASCII property list file.- Parameters:
path- The path to the ASCII property list file.encoding- The name of a supportedcharsetto decode the property list.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.java.io.IOException- If an error occurs while reading from the input stream.java.io.UnsupportedEncodingException- If no support for the named charset is available in this instance of the Java virtual machine.
-
parse
public static NSObject parse(java.nio.file.Path path) throws java.io.IOException, java.text.ParseException
Parses an ASCII property list file.- Parameters:
path- The path to the ASCII property list file.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.java.io.IOException- If an error occurs while reading from the input stream.
-
parse
public static NSObject parse(java.io.InputStream in) throws java.text.ParseException, java.io.IOException
Parses an ASCII property list from an input stream. This method does not close the specified input stream.- Parameters:
in- The input stream that provides the property list's data.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.java.io.IOException- If an error occurs while reading from the input stream.
-
parse
public static NSObject parse(java.io.InputStream in, java.lang.String encoding) throws java.text.ParseException, java.io.IOException
Parses an ASCII property list from an input stream. This method does not close the specified input stream.- Parameters:
in- The input stream that points to the property list's data.encoding- The name of a supportedcharsetto decode the property list.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.java.io.IOException- If an error occurs while reading from the input stream.java.io.UnsupportedEncodingException- If no support for the named charset is available in this instance of the Java virtual machine.
-
parse
public static NSObject parse(java.io.Reader reader) throws java.text.ParseException, java.io.IOException
Parses an ASCII property list from aReader. This method does not close the specified reader.- Parameters:
reader- The reader that provides the property list's data.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.java.io.IOException- If an error occurs while reading from the input reader.
-
parse
public static NSObject parse(java.lang.String plistData) throws java.text.ParseException
Parses an ASCII property list from aString- Parameters:
plistData- A string containing the property list's data.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.
-
parse
public static NSObject parse(byte[] bytes) throws java.text.ParseException
Parses an ASCII property list from a byte array.- Parameters:
bytes- The ASCII property list data.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.
-
parse
public static NSObject parse(byte[] bytes, java.lang.String encoding) throws java.text.ParseException, java.io.UnsupportedEncodingException
Parses an ASCII property list from a byte array.- Parameters:
bytes- The ASCII property list data.encoding- The name of a supportedCharsetcharset to decode the property list.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
java.text.ParseException- If an error occurs during parsing.java.io.UnsupportedEncodingException- If no support for the named charset is available in this instance of the Java virtual machine.
-
acceptSequence
private boolean acceptSequence(char... sequence)
Checks whether the given sequence of symbols can be accepted.- Parameters:
sequence- The sequence of tokens to look for.- Returns:
- Whether the given tokens occur at the current parsing position.
-
accept
private boolean accept(char... acceptableSymbols)
Checks whether the given symbols can be accepted, that is, if one of the given symbols is found at the current parsing position.- Parameters:
acceptableSymbols- The symbols to check.- Returns:
- Whether one of the symbols can be accepted or not.
-
accept
private boolean accept(char acceptableSymbol)
Checks whether the given symbol can be accepted, that is, if the given symbols is found at the current parsing position.- Parameters:
acceptableSymbol- The symbol to check.- Returns:
- Whether the symbol can be accepted or not.
-
expect
private void expect(char... expectedSymbols) throws java.text.ParseExceptionExpects the input to have one of the given symbols at the current parsing position.- Parameters:
expectedSymbols- The expected symbols.- Throws:
java.text.ParseException- If none of the expected symbols could be found.
-
expect
private void expect(char expectedSymbol) throws java.text.ParseExceptionExpects the input to have the given symbol at the current parsing position.- Parameters:
expectedSymbol- The expected symbol.- Throws:
java.text.ParseException- If the expected symbol could not be found.
-
read
private void read(char symbol) throws java.text.ParseExceptionReads an expected symbol.- Parameters:
symbol- The symbol to read.- Throws:
java.text.ParseException- If the expected symbol could not be read.
-
skip
private void skip()
Skips the current symbol.
-
skip
private void skip(int numSymbols)
Skips several symbols- Parameters:
numSymbols- The amount of symbols to skip.
-
skipWhitespacesAndComments
private void skipWhitespacesAndComments()
Skips all whitespaces and comments from the current parsing position onward.
-
readInputUntil
private java.lang.String readInputUntil(char... symbols)
Reads input until one of the given symbols is found.- Parameters:
symbols- The symbols that can occur after the string to read.- Returns:
- The input until one the given symbols.
-
readInputUntil
private java.lang.String readInputUntil(char symbol)
Reads input until the given symbol is found.- Parameters:
symbol- The symbol that can occur after the string to read.- Returns:
- The input until the given symbol.
-
parse
public NSObject parse() throws java.text.ParseException
Parses the property list from the beginning and returns the root object of the property list.- Returns:
- The root object of the property list. This can either be a NSDictionary or a NSArray.
- Throws:
java.text.ParseException- If an error occurred during parsing
-
parseObject
private NSObject parseObject() throws java.text.ParseException
Parses the NSObject found at the current position in the property list data stream.- Returns:
- The parsed NSObject.
- Throws:
java.text.ParseException- See Also:
index
-
parseArray
private NSArray parseArray() throws java.text.ParseException
Parses an array from the current parsing position. The prerequisite for calling this method is, that an array begin token has been read.- Returns:
- The array found at the parsing position.
- Throws:
java.text.ParseException
-
parseDictionary
private NSDictionary parseDictionary() throws java.text.ParseException
Parses a dictionary from the current parsing position. The prerequisite for calling this method is, that a dictionary begin token has been read.- Returns:
- The dictionary found at the parsing position.
- Throws:
java.text.ParseException
-
parseData
private NSObject parseData() throws java.text.ParseException
Parses a data object from the current parsing position. This can either be a NSData object or a GnuStep NSNumber or NSDate. The prerequisite for calling this method is, that a data begin token has been read.- Returns:
- The data object found at the parsing position.
- Throws:
java.text.ParseException
-
parseDateString
private NSObject parseDateString()
Attempts to parse a plain string as a date if possible.- Returns:
- An NSDate if the string represents such an object. Otherwise, an NSString is returned.
-
parseString
private java.lang.String parseString()
Parses a plain string from the current parsing position. The string is made up of all characters to the next whitespace, delimiter token or assignment token.- Returns:
- The string found at the current parsing position.
-
parseQuotedString
private java.lang.String parseQuotedString() throws java.text.ParseExceptionParses a quoted string from the current parsing position. The prerequisite for calling this method is, that a quoted string begin token has been read.- Returns:
- The quoted string found at the parsing method with all special characters unescaped.
- Throws:
java.text.ParseException- If an error occurred during parsing.
-
parseQuotedString
private static java.lang.String parseQuotedString(java.lang.String s) throws java.text.ParseExceptionParses a string according to the format specified for ASCII property lists. Such strings can contain escape sequences which are unescaped in this method.- Parameters:
s- The escaped string according to the ASCII property list format, without leading and trailing quotation marks.- Returns:
- The unescaped string in UTF-8
- Throws:
java.text.ParseException- The string contains an invalid escape sequence.
-
parseEscapedSequence
private static char parseEscapedSequence(java.text.StringCharacterIterator iterator) throws java.text.ParseExceptionUnescapes an escaped character sequence, e.g. \\u00FC.- Parameters:
iterator- The string character iterator pointing to the first character after the backslash- Returns:
- The unescaped character.
- Throws:
java.text.ParseException- The string contains an invalid escape sequence.
-
-