Package com.dd.plist
Class ASCIIPropertyListParser
java.lang.Object
com.dd.plist.ASCIIPropertyListParser
Parser 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:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThe token marking the beginning of an array.static final charThe token marking the end of an array.static final charThe token marking the end of an array element.static final charThe token marking the beginning of a comment.private final char[]Property list source datastatic final charThe token marking the beginning of a data element in Base-64 encoding.static final charThe token marking the end of a data element in Base-64 encoding.static final charThe token marking the beginning of a data element.static final charThe token marking the end of a data element.static final charThe token marking the beginning of a GnuStep boolean value.static final charThe token representing the boolean valuefalsein the GnuStep format.static final charThe token representing the boolean valuetruein the GnuStep format.static final charThe token marking the beginning of a GnuStep date.static final charThe token marking the beginning of a GnuStep integer value.static final charThe token marking the beginning of a GnuStep object.static final charThe token marking the beginning of a GnuStep real value.static final charThe token that marks the beginning of the time zone in the Apple format.static final charThe token that marks the end of the time zone in the Apple format.static final charThe token that separates the parts of a date value (year, month and day).static final charThe token that separates the date and time in the GnuStep format.static final charThe token that separates the parts of a time value (hour, minute and second).static final charThe token marking the assignment of a value to a dictionary key.static final charThe token marking the beginning of a dictionary.static final charThe token marking the end of a dictionary.static final charThe token marking the end of a dictionary entry.private intCurrent parsing indexprivate intThe index at which the current line began.private intCurrent line number.static final charThe token marking the end of a multi-line comment.static final charThe token marking a comment to be multi-line.static final charThe token marking the beginning of a quoted string.static final charThe token marking the end of a quoted string.static final charThe token marking the beginning of an escape sequence in a quoted string.static final charThe token marking a comment to be single-line.static final charThe carriage return character token.static final charThe newline character token.static final charThe space character token.static final charThe tab character token. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateASCIIPropertyListParser(byte[] propertyListContent, 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
Modifier and TypeMethodDescriptionprivate 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 ParseExceptioncreateParseException(String message) private ParseExceptioncreateParseException(String message, int index) 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.parse()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 NSObjectParses an ASCII property list from a byte array.static NSObjectParses an ASCII property list file.static NSObjectParses an ASCII property list file.static NSObjectparse(InputStream in) Parses an ASCII property list from an input stream.static NSObjectparse(InputStream in, String encoding) Parses an ASCII property list from an input stream.static NSObjectParses an ASCII property list from aReader.static NSObjectParses an ASCII property list from aStringstatic NSObjectParses an ASCII property list file.static NSObjectParses an ASCII property list file.private NSArrayparseArray(int depth) Parses an array from the current parsing position.private NSObjectParses a data object from the current parsing position.private NSObjectAttempts to parse a plain string as a date if possible.private NSDictionaryparseDictionary(int depth) Parses a dictionary from the current parsing position.private NSObjectparseObject(int depth) Parses the NSObject found at the current position in the property list data stream.private StringParses a quoted string from the current parsing position.private StringParses a plain string from the current parsing position.private voidread(char symbol) Reads an expected symbol.private StringreadInputUntil(char symbol) Reads input until the given symbol is found.private 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 voidSkips all whitespaces and comments from the current parsing position onward.private void
-
Field Details
-
WHITESPACE_SPACE
public static final char WHITESPACE_SPACEThe space character token.- See Also:
-
WHITESPACE_TAB
public static final char WHITESPACE_TABThe tab character token.- See Also:
-
WHITESPACE_NEWLINE
public static final char WHITESPACE_NEWLINEThe newline character token.- See Also:
-
WHITESPACE_CARRIAGE_RETURN
public static final char WHITESPACE_CARRIAGE_RETURNThe carriage return character token.- See Also:
-
ARRAY_BEGIN_TOKEN
public static final char ARRAY_BEGIN_TOKENThe token marking the beginning of an array.- See Also:
-
ARRAY_END_TOKEN
public static final char ARRAY_END_TOKENThe token marking the end of an array.- See Also:
-
ARRAY_ITEM_DELIMITER_TOKEN
public static final char ARRAY_ITEM_DELIMITER_TOKENThe token marking the end of an array element.- See Also:
-
DICTIONARY_BEGIN_TOKEN
public static final char DICTIONARY_BEGIN_TOKENThe token marking the beginning of a dictionary.- See Also:
-
DICTIONARY_END_TOKEN
public static final char DICTIONARY_END_TOKENThe token marking the end of a dictionary.- See Also:
-
DICTIONARY_ASSIGN_TOKEN
public static final char DICTIONARY_ASSIGN_TOKENThe token marking the assignment of a value to a dictionary key.- See Also:
-
DICTIONARY_ITEM_DELIMITER_TOKEN
public static final char DICTIONARY_ITEM_DELIMITER_TOKENThe token marking the end of a dictionary entry.- See Also:
-
QUOTEDSTRING_BEGIN_TOKEN
public static final char QUOTEDSTRING_BEGIN_TOKENThe token marking the beginning of a quoted string.- See Also:
-
QUOTEDSTRING_END_TOKEN
public static final char QUOTEDSTRING_END_TOKENThe token marking the end of a quoted string.- See Also:
-
QUOTEDSTRING_ESCAPE_TOKEN
public static final char QUOTEDSTRING_ESCAPE_TOKENThe token marking the beginning of an escape sequence in a quoted string.- See Also:
-
DATA_BEGIN_TOKEN
public static final char DATA_BEGIN_TOKENThe token marking the beginning of a data element.- See Also:
-
DATA_END_TOKEN
public static final char DATA_END_TOKENThe token marking the end of a data element.- See Also:
-
DATA_BASE64_BEGIN_TOKEN
public static final char DATA_BASE64_BEGIN_TOKENThe token marking the beginning of a data element in Base-64 encoding.- See Also:
-
DATA_BASE64_END_TOKEN
public static final char DATA_BASE64_END_TOKENThe token marking the end of a data element in Base-64 encoding.- See Also:
-
DATA_GSOBJECT_BEGIN_TOKEN
public static final char DATA_GSOBJECT_BEGIN_TOKENThe token marking the beginning of a GnuStep object.- See Also:
-
DATA_GSDATE_BEGIN_TOKEN
public static final char DATA_GSDATE_BEGIN_TOKENThe token marking the beginning of a GnuStep date.- See Also:
-
DATA_GSBOOL_BEGIN_TOKEN
public static final char DATA_GSBOOL_BEGIN_TOKENThe token marking the beginning of a GnuStep boolean value.- See Also:
-
DATA_GSBOOL_TRUE_TOKEN
public static final char DATA_GSBOOL_TRUE_TOKENThe token representing the boolean valuetruein the GnuStep format.- See Also:
-
DATA_GSBOOL_FALSE_TOKEN
public static final char DATA_GSBOOL_FALSE_TOKENThe token representing the boolean valuefalsein the GnuStep format.- See Also:
-
DATA_GSINT_BEGIN_TOKEN
public static final char DATA_GSINT_BEGIN_TOKENThe token marking the beginning of a GnuStep integer value.- See Also:
-
DATA_GSREAL_BEGIN_TOKEN
public static final char DATA_GSREAL_BEGIN_TOKENThe token marking the beginning of a GnuStep real value.- See Also:
-
DATE_DATE_FIELD_DELIMITER
public static final char DATE_DATE_FIELD_DELIMITERThe token that separates the parts of a date value (year, month and day).- See Also:
-
DATE_TIME_FIELD_DELIMITER
public static final char DATE_TIME_FIELD_DELIMITERThe token that separates the parts of a time value (hour, minute and second).- See Also:
-
DATE_GS_DATE_TIME_DELIMITER
public static final char DATE_GS_DATE_TIME_DELIMITERThe token that separates the date and time in the GnuStep format.- See Also:
-
DATE_APPLE_DATE_TIME_DELIMITER
public static final char DATE_APPLE_DATE_TIME_DELIMITERThe token that marks the beginning of the time zone in the Apple format.- See Also:
-
DATE_APPLE_END_TOKEN
public static final char DATE_APPLE_END_TOKENThe token that marks the end of the time zone in the Apple format.- See Also:
-
COMMENT_BEGIN_TOKEN
public static final char COMMENT_BEGIN_TOKENThe token marking the beginning of a comment.- See Also:
-
MULTILINE_COMMENT_SECOND_TOKEN
public static final char MULTILINE_COMMENT_SECOND_TOKENThe token marking a comment to be multi-line.- See Also:
-
SINGLELINE_COMMENT_SECOND_TOKEN
public static final char SINGLELINE_COMMENT_SECOND_TOKENThe token marking a comment to be single-line.- See Also:
-
MULTILINE_COMMENT_END_TOKEN
public static final char MULTILINE_COMMENT_END_TOKENThe token marking the end of a multi-line comment. Must be preceded by aMULTILINE_COMMENT_SECOND_TOKEN.- See Also:
-
data
private final char[] dataProperty list source data -
index
private int indexCurrent parsing index -
lineNo
private int lineNoCurrent line number. -
lineBeginning
private int lineBeginningThe index at which the current line began.
-
-
Constructor Details
-
ASCIIPropertyListParser
private ASCIIPropertyListParser(byte[] propertyListContent, String encoding) throws UnsupportedEncodingException Creates 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:
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 Details
-
parse
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:
ParseException- If an error occurs during parsing.IOException- If an error occurs while reading from the input stream.
-
parse
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:
ParseException- If an error occurs during parsing.IOException- If an error occurs while reading from the input stream.UnsupportedEncodingException- If no support for the named charset is available in this instance of the Java virtual machine.
-
parse
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:
ParseException- If an error occurs during parsing.IOException- If an error occurs while reading from the input stream.UnsupportedEncodingException- If no support for the named charset is available in this instance of the Java virtual machine.
-
parse
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:
ParseException- If an error occurs during parsing.IOException- If an error occurs while reading from the input stream.
-
parse
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:
ParseException- If an error occurs during parsing.IOException- If an error occurs while reading from the input stream.
-
parse
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:
ParseException- If an error occurs during parsing.IOException- If an error occurs while reading from the input stream.UnsupportedEncodingException- If no support for the named charset is available in this instance of the Java virtual machine.
-
parse
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:
ParseException- If an error occurs during parsing.IOException- If an error occurs while reading from the input reader.
-
parse
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:
ParseException- If an error occurs during parsing.
-
parse
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:
ParseException- If an error occurs during parsing.
-
parse
public static NSObject parse(byte[] bytes, String encoding) throws ParseException, 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:
ParseException- If an error occurs during parsing.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
Expects the input to have one of the given symbols at the current parsing position.- Parameters:
expectedSymbols- The expected symbols.- Throws:
ParseException- If none of the expected symbols could be found.
-
expect
Expects the input to have the given symbol at the current parsing position.- Parameters:
expectedSymbol- The expected symbol.- Throws:
ParseException- If the expected symbol could not be found.
-
read
Reads an expected symbol.- Parameters:
symbol- The symbol to read.- Throws:
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.
-
trackLineBreak
private void trackLineBreak() -
skipWhitespacesAndComments
private void skipWhitespacesAndComments()Skips all whitespaces and comments from the current parsing position onward. -
readInputUntil
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
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
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:
ParseException- If an error occurred during parsing
-
parseObject
Parses the NSObject found at the current position in the property list data stream.- Parameters:
depth- The nesting depth of the object, starting at 1 for the root object. Used to guard against stack overflows from excessively nested input.- Returns:
- The parsed NSObject.
- Throws:
ParseException- See Also:
-
parseArray
Parses an array from the current parsing position. The prerequisite for calling this method is, that an array begin token has been read.- Parameters:
depth- The nesting depth of the array.- Returns:
- The array found at the parsing position.
- Throws:
ParseException
-
parseDictionary
Parses a dictionary from the current parsing position. The prerequisite for calling this method is, that a dictionary begin token has been read.- Parameters:
depth- The nesting depth of the dictionary.- Returns:
- The dictionary found at the parsing position.
- Throws:
ParseException
-
parseData
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:
ParseException
-
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
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
Parses 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:
ParseException- If an error occurred during parsing.
-
createParseException
-
createParseException
-