Package com.dd.plist

Class XMLPropertyListParser


  • public class XMLPropertyListParser
    extends java.lang.Object
    Parses XML property lists.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static javax.xml.parsers.DocumentBuilderFactory FACTORY  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.util.List<org.w3c.dom.Node> filterElementNodes​(org.w3c.dom.NodeList list)
      Returns all element nodes that are contained in a list of nodes.
      static javax.xml.parsers.DocumentBuilder getDocBuilder()
      Gets a DocumentBuilder to parse an XML property list.
      private static java.lang.String getNodeTextContents​(org.w3c.dom.Node n)
      Returns a node's text content.
      static NSObject parse​(byte[] bytes)
      Parses an XML property list from a byte array.
      static NSObject parse​(java.io.File f)
      Parses an XML property list file.
      static NSObject parse​(java.io.InputStream is)
      Parses an XML property list from an input stream.
      static NSObject parse​(java.io.Reader reader)
      Parses an XML property list from a Reader.
      static NSObject parse​(java.nio.file.Path path)
      Parses an XML property list file.
      static NSObject parse​(org.w3c.dom.Document doc)
      Parses a property list from an XML document.
      private static NSObject parseObject​(org.w3c.dom.Node n)
      Parses a node in the XML structure and returns the corresponding NSObject
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FACTORY

        private static final javax.xml.parsers.DocumentBuilderFactory FACTORY
    • Constructor Detail

      • XMLPropertyListParser

        public XMLPropertyListParser()
    • Method Detail

      • getDocBuilder

        public static javax.xml.parsers.DocumentBuilder getDocBuilder()
                                                               throws javax.xml.parsers.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:
        A new DocumentBuilder that can parse property lists without an internet connection.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing a XML property list could not be created. This should not occur.
      • parse

        public static NSObject parse​(java.io.File f)
                              throws javax.xml.parsers.ParserConfigurationException,
                                     java.io.IOException,
                                     org.xml.sax.SAXException,
                                     PropertyListFormatException,
                                     java.text.ParseException
        Parses an XML property list file.
        Parameters:
        f - The XML property list file.
        Returns:
        The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a number or date string could not be parsed.
        See Also:
        DocumentBuilder.parse(java.io.File)
      • parse

        public static NSObject parse​(java.nio.file.Path path)
                              throws javax.xml.parsers.ParserConfigurationException,
                                     java.io.IOException,
                                     org.xml.sax.SAXException,
                                     PropertyListFormatException,
                                     java.text.ParseException
        Parses an XML property list file.
        Parameters:
        path - The XML property list file path.
        Returns:
        The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a number or date string could not be parsed.
        See Also:
        DocumentBuilder.parse(java.io.File)
      • parse

        public static NSObject parse​(byte[] bytes)
                              throws javax.xml.parsers.ParserConfigurationException,
                                     java.text.ParseException,
                                     org.xml.sax.SAXException,
                                     PropertyListFormatException,
                                     java.io.IOException
        Parses an XML property list from a byte array.
        Parameters:
        bytes - The byte array containing the property list's data.
        Returns:
        The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a number or date string could not be parsed.
      • parse

        public static NSObject parse​(java.io.InputStream is)
                              throws javax.xml.parsers.ParserConfigurationException,
                                     java.io.IOException,
                                     org.xml.sax.SAXException,
                                     PropertyListFormatException,
                                     java.text.ParseException
        Parses an XML property list from an input stream. This method does not close the specified input stream.
        Parameters:
        is - The input stream pointing to the property list's data.
        Returns:
        The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a number or date string could not be parsed.
        See Also:
        DocumentBuilder.parse(java.io.InputStream)
      • parse

        public static NSObject parse​(java.io.Reader reader)
                              throws javax.xml.parsers.ParserConfigurationException,
                                     java.io.IOException,
                                     org.xml.sax.SAXException,
                                     PropertyListFormatException,
                                     java.text.ParseException
        Parses an XML property list from a Reader. This method does not close the specified reader.
        Parameters:
        reader - The reader providing the property list's data.
        Returns:
        The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a number or date string could not be parsed.
        See Also:
        DocumentBuilder.parse(java.io.InputStream)
      • parse

        public static NSObject parse​(org.w3c.dom.Document doc)
                              throws PropertyListFormatException,
                                     java.io.IOException,
                                     java.text.ParseException
        Parses a property list from an XML document.
        Parameters:
        doc - The XML document.
        Returns:
        The root NSObject of the property list contained in the XML document.
        Throws:
        java.io.IOException - If any I/O error occurs while reading the file.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a number or date string could not be parsed.
      • parseObject

        private static NSObject parseObject​(org.w3c.dom.Node n)
                                     throws java.text.ParseException,
                                            java.io.IOException
        Parses a node in the XML structure and returns the corresponding NSObject
        Parameters:
        n - The XML node.
        Returns:
        The corresponding NSObject.
        Throws:
        java.io.IOException - If any I/O error occurs while parsing a Base64 encoded NSData object.
        java.text.ParseException - If a number or date string could not be parsed.
      • filterElementNodes

        private static java.util.List<org.w3c.dom.Node> filterElementNodes​(org.w3c.dom.NodeList list)
        Returns all element nodes that are contained in a list of nodes.
        Parameters:
        list - The list of nodes to search.
        Returns:
        The sub-list containing only nodes representing actual elements.
      • getNodeTextContents

        private static java.lang.String getNodeTextContents​(org.w3c.dom.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 - The node.
        Returns:
        The node's text content.