Top Description Inners Fields Constructors Methods
com.dd.plist

public Class XMLPropertyListParser

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .File, .IOException, .InputStream, .Reader, java.nio.file.Files, .Path, java.util.ArrayList, .List, javax.xml.XMLConstants, javax.xml.parsers.*, javax.xml.transform.Transformer, .TransformerConfigurationException, .TransformerException, .TransformerFactory, javax.xml.transform.dom.DOMResult, javax.xml.transform.sax.SAXSource, org.w3c.dom.Document, .DocumentType, .Node, .NodeList, .Text, org.xml.sax.EntityResolver, .InputSource, .SAXException, .XMLReader

Parses XML property lists.
Author
Daniel Dreibrodt

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
XMLPropertyListParser.PlistDtdResolver

Offline resolver for Apple's PLIST DTDs.

Field Summary

Modifier and TypeField and Description
private static final DocumentBuilderFactory

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static Transformer
private static XMLReader
private static List<Node>

Returns:

The sub-list containing only nodes representing actual elements.
filterElementNodes
(NodeList
The list of nodes to search.
list
)

Returns all element nodes that are contained in a list of nodes.

public static DocumentBuilder

Returns:

A new DocumentBuilder that can parse property lists without an internet connection.
getDocBuilder
()

Gets a DocumentBuilder to parse an XML property list.

private static String

Returns:

The node's text content.
getNodeTextContents
(Node
The node.
n
)

Returns a node's text content.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(File
The XML property list file.
f
)

Parses an XML property list file.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(Path
The XML property list file path.
path
)

Parses an XML property list file.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(final byte[]
The byte array containing the property list's data.
bytes
)

Parses an XML property list from a byte array.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(InputStream
The input stream pointing to the property list's data.
is
)

Parses an XML property list from an input stream.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(Reader
The reader providing the property list's data.
reader
)

Parses an XML property list from a Reader.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(File
The XML property list file.
f
,
boolean
If set to true, the parser will try to collect line information and store it in the parsed object's location information (See NSObject#getLocationInformation()).
withLineInformation
)

Parses an XML property list file.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(Path
The XML property list file path.
path
,
boolean
If set to true, the parser will try to collect line information and store it in the parsed object's location information
withLineInformation
)

Parses an XML property list file.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(final byte[]
The byte array containing the property list's data.
bytes
,
boolean
If set to true, the parser will try to collect line information and store it in the parsed object's location information
withLineInformation
)

Parses an XML property list from a byte array.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(InputStream
The input stream pointing to the property list's data.
is
,
boolean
If set to true, the parser will try to collect line information and store it in the parsed object's location information
withLineInformation
)

Parses an XML property list from an input stream.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(Reader
The reader providing the property list's data.
reader
,
boolean
If set to true, the parser will try to collect line information and store it in the parsed object's location information
withLineInformation
)

Parses an XML property list from a Reader.

public static NSObject

Returns:

The root NSObject of the property list contained in the XML document.
parse
(Document
The XML document.
doc
)

Parses a property list from an XML document.

private static NSObject

Returns:

The corresponding NSObject.
parseObject
(Node
The XML node.
n
,
String xpath)

Parses a node in the XML structure and returns the corresponding NSObject

private static Document
parseXml(InputSource inputSource, boolean withLineInformation)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FACTORYback to summary
private static final DocumentBuilderFactory FACTORY

Constructor Detail

XMLPropertyListParserback to summary
public XMLPropertyListParser()

Method Detail

createSafeTransformerback to summary
private static Transformer createSafeTransformer() throws TransformerConfigurationException
createSafeXmlReaderback to summary
private static XMLReader createSafeXmlReader() throws SAXException, ParserConfigurationException
filterElementNodesback to summary
private static List<Node> filterElementNodes(NodeList list)

Returns all element nodes that are contained in a list of nodes.

Parameters
list:NodeList

The list of nodes to search.

Returns:List<Node>

The sub-list containing only nodes representing actual elements.

getDocBuilderback to summary
public static DocumentBuilder getDocBuilder() throws ParserConfigurationException

Gets a DocumentBuilder to parse an XML property list. As DocumentBuilder instance are not thread-safe a new DocumentBuilder is generated for each request.

Returns:DocumentBuilder

A new DocumentBuilder that can parse property lists without an internet connection.

Exceptions
ParserConfigurationException:
If a document builder for parsing a XML property list could not be created. This should not occur.
getNodeTextContentsback to summary
private static String getNodeTextContents(Node n)

Returns a node's text content. This method will return the text value represented by the node's direct children. If the given node is a TEXT or CDATA node, then its value is returned.

Parameters
n:Node

The node.

Returns:String

The node's text content.

parseback to summary
public static NSObject parse(File f) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException

Parses an XML property list file.

Parameters
f:File

The XML property list file.

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
IOException:
If any I/O error occurs while reading the file.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
See Also
javax.xml.parsers.DocumentBuilder#parse(java.io.File)
parseback to summary
public static NSObject parse(Path path) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException

Parses an XML property list file.

Parameters
path:Path

The XML property list file path.

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
IOException:
If any I/O error occurs while reading the file.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
See Also
javax.xml.parsers.DocumentBuilder#parse(java.io.File)
parseback to summary
public static NSObject parse(final byte[] bytes) throws ParserConfigurationException, SAXException, PropertyListFormatException, IOException

Parses an XML property list from a byte array.

Parameters
bytes:byte[]

The byte array containing the property list's data.

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
IOException:
If any I/O error occurs while reading the file.
parseback to summary
public static NSObject parse(InputStream is) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException

Parses an XML property list from an input stream. This method does not close the specified input stream.

Parameters
is:InputStream

The input stream pointing to the property list's data.

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
IOException:
If any I/O error occurs while reading the file.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
See Also
javax.xml.parsers.DocumentBuilder#parse(java.io.InputStream)
parseback to summary
public static NSObject parse(Reader reader) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException

Parses an XML property list from a Reader. This method does not close the specified reader.

Parameters
reader:Reader

The reader providing the property list's data.

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
IOException:
If any I/O error occurs while reading the file.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
See Also
javax.xml.parsers.DocumentBuilder#parse(java.io.InputStream)
parseback to summary
public static NSObject parse(File f, boolean withLineInformation) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException

Parses an XML property list file.

Parameters
f:File

The XML property list file.

withLineInformation:boolean

If set to true, the parser will try to collect line information and store it in the parsed object's location information (See NSObject#getLocationInformation()).

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
IOException:
If any I/O error occurs while reading the file.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
See Also
javax.xml.parsers.DocumentBuilder#parse(java.io.File)
parseback to summary
public static NSObject parse(Path path, boolean withLineInformation) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException

Parses an XML property list file.

Parameters
path:Path

The XML property list file path.

withLineInformation:boolean

If set to true, the parser will try to collect line information and store it in the parsed object's location information

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
IOException:
If any I/O error occurs while reading the file.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
See Also
javax.xml.parsers.DocumentBuilder#parse(java.io.File)
parseback to summary
public static NSObject parse(final byte[] bytes, boolean withLineInformation) throws ParserConfigurationException, SAXException, PropertyListFormatException, IOException

Parses an XML property list from a byte array.

Parameters
bytes:byte[]

The byte array containing the property list's data.

withLineInformation:boolean

If set to true, the parser will try to collect line information and store it in the parsed object's location information

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
IOException:
If any I/O error occurs while reading the file.
parseback to summary
public static NSObject parse(InputStream is, boolean withLineInformation) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException

Parses an XML property list from an input stream. This method does not close the specified input stream.

Parameters
is:InputStream

The input stream pointing to the property list's data.

withLineInformation:boolean

If set to true, the parser will try to collect line information and store it in the parsed object's location information

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
IOException:
If any I/O error occurs while reading the file.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
See Also
javax.xml.parsers.DocumentBuilder#parse(java.io.InputStream)
parseback to summary
public static NSObject parse(Reader reader, boolean withLineInformation) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException

Parses an XML property list from a Reader. This method does not close the specified reader.

Parameters
reader:Reader

The reader providing the property list's data.

withLineInformation:boolean

If set to true, the parser will try to collect line information and store it in the parsed object's location information

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
ParserConfigurationException:
If a document builder for parsing an XML property list could not be created. This should not occur.
IOException:
If any I/O error occurs while reading the file.
SAXException:
If any XML parsing error occurs.
PropertyListFormatException:
If the given property list has an invalid format.
See Also
javax.xml.parsers.DocumentBuilder#parse(java.io.InputStream)
parseback to summary
public static NSObject parse(Document doc) throws PropertyListFormatException, IOException

Parses a property list from an XML document.

Parameters
doc:Document

The XML document.

Returns:NSObject

The root NSObject of the property list contained in the XML document.

Exceptions
PropertyListFormatException:
If the given property list has an invalid format.
IOException:
If any I/O error occurs while reading the file.
parseObjectback to summary
private static NSObject parseObject(Node n, String xpath) throws PropertyListFormatException

Parses a node in the XML structure and returns the corresponding NSObject

Parameters
n:Node

The XML node.

Returns:NSObject

The corresponding NSObject.

Exceptions
PropertyListFormatException:
A parsing error occurred.
parseXmlback to summary
private static Document parseXml(InputSource inputSource, boolean withLineInformation) throws IOException, SAXException, ParserConfigurationException
com.dd.plist back to summary

private Class XMLPropertyListParser.PlistDtdResolver

extends Object
implements EntityResolver
Class Inheritance
All Implemented Interfaces
org.xml.sax.EntityResolver

Offline resolver for Apple's PLIST DTDs.

Field Summary

Modifier and TypeField and Description
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public InputSource

Returns:

An empty input source for the PLIST DTDs. For all other DTDs null is returned.
resolveEntity
(String
The public identifier of the external entity being referenced, or null if none was supplied.
publicId
,
String
The system identifier of the external entity being referenced.
systemId
)

Implements org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PLIST_PUBLIC_ID_1back to summary
private static final String PLIST_PUBLIC_ID_1
PLIST_PUBLIC_ID_2back to summary
private static final String PLIST_PUBLIC_ID_2

Constructor Detail

PlistDtdResolverback to summary
pack-priv PlistDtdResolver()

Method Detail

resolveEntityback to summary
public InputSource resolveEntity(String publicId, String systemId)

Implements org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities. This specific implementation returns an empty definition for Apple's PLIST DTDs so that parsing can happen offline.

Parameters
publicId:String

The public identifier of the external entity being referenced, or null if none was supplied.

systemId:String

The system identifier of the external entity being referenced.

Returns:InputSource

An empty input source for the PLIST DTDs. For all other DTDs null is returned.