Class XMLUtils


  • public class XMLUtils
    extends Object

    XMLUtils: utility class for parsing XML files.

    • Constructor Summary

      Constructors 
      Constructor Description
      XMLUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.w3c.dom.Node getNodeByTagName​(org.w3c.dom.Element node, String name)
      Return a child Node by tag name.
      static String getNodeValue​(org.w3c.dom.Node node)
      Return the text value of a node.
      static String getNodeValueByTagName​(org.w3c.dom.Element node, String name)
      Get a child Node value by tag name.
      static String getVersion​(org.w3c.dom.Element root)
      Given a Wowza XML file's root element, parse the version attribute
      static boolean getXMLPropertyBool​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root, boolean defaultVal)
      Get a boolean int value pointed to by xpath or defaultVal if not found.
      static double getXMLPropertyDouble​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root, double defaultVal)
      Get a single double value pointed to by xpath or defaultVal if not found.
      static boolean getXMLPropertyExists​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root)  
      static int getXMLPropertyInt​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root, int defaultVal)
      Get a single int value pointed to by xpath or defaultVal if not found.
      static int getXMLPropertyIntSize​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root, int defaultVal)  
      static long getXMLPropertyLong​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root, long defaultVal)
      Get a single long value pointed to by xpath or defaultVal if not found.
      static long getXMLPropertyLongSize​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root, long defaultVal)  
      static String getXMLPropertyStr​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root)
      Get a single string value pointed to by xpath or null if not found.
      static String getXMLPropertyStr​(javax.xml.xpath.XPath xpath, String xpathStr, org.w3c.dom.Element root, String defaultVal)
      Get a single string value pointed to by xpath or defaultVal if not found.
      static void loadConfigProperies​(org.w3c.dom.Element root, String propertiesXPath, WMSProperties properties)
      Loads <Properties> elemnt by xpath into properties object.
      static void loadConfigProperies​(org.w3c.dom.NodeList resultList, WMSProperties properties)
      Given a nodeList load children as properties.
      static javax.xml.xpath.XPathFactory newXPathFactory()
      Get a new XPath factory object.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XMLUtils

        public XMLUtils()
    • Method Detail

      • getNodeValueByTagName

        public static String getNodeValueByTagName​(org.w3c.dom.Element node,
                                                   String name)
        Get a child Node value by tag name. Return null if does not exist.
        Parameters:
        node - parent node
        name - tag name
        Returns:
        node value or null if does not exist
      • getNodeByTagName

        public static org.w3c.dom.Node getNodeByTagName​(org.w3c.dom.Element node,
                                                        String name)
        Return a child Node by tag name. Return null if does not exist.
        Parameters:
        node - parent node
        name - tag name
        Returns:
        Node or null if does not exist
      • getNodeValue

        public static String getNodeValue​(org.w3c.dom.Node node)
        Return the text value of a node. Return concatenated value of all children nodes that are text nodes.
        Parameters:
        node - parent node
        Returns:
        concatenated text nodes or empty string if not found or no children
      • loadConfigProperies

        public static void loadConfigProperies​(org.w3c.dom.Element root,
                                               String propertiesXPath,
                                               WMSProperties properties)
        Loads <Properties> elemnt by xpath into properties object.
        Parameters:
        root - root node
        propertiesXPath - xpath to search for <Properties> element
        properties - properties to add values to
      • loadConfigProperies

        public static void loadConfigProperies​(org.w3c.dom.NodeList resultList,
                                               WMSProperties properties)
        Given a nodeList load children as properties.
        Parameters:
        resultList - node list
        properties - properties to add values to
      • getXMLPropertyStr

        public static String getXMLPropertyStr​(javax.xml.xpath.XPath xpath,
                                               String xpathStr,
                                               org.w3c.dom.Element root)
        Get a single string value pointed to by xpath or null if not found.
        Parameters:
        xpath - XPath interface
        xpathStr - xpath string
        root - root node to start search
        Returns:
        single string value pointed to by xpath or null if not found
      • getXMLPropertyStr

        public static String getXMLPropertyStr​(javax.xml.xpath.XPath xpath,
                                               String xpathStr,
                                               org.w3c.dom.Element root,
                                               String defaultVal)
        Get a single string value pointed to by xpath or defaultVal if not found.
        Parameters:
        xpath - XPath interface
        xpathStr - xpath string
        root - node to start search
        defaultVal - default value
        Returns:
        single string value pointed to by xpath or defaultVal if not found
      • getXMLPropertyExists

        public static boolean getXMLPropertyExists​(javax.xml.xpath.XPath xpath,
                                                   String xpathStr,
                                                   org.w3c.dom.Element root)
      • getXMLPropertyInt

        public static int getXMLPropertyInt​(javax.xml.xpath.XPath xpath,
                                            String xpathStr,
                                            org.w3c.dom.Element root,
                                            int defaultVal)
        Get a single int value pointed to by xpath or defaultVal if not found.
        Parameters:
        xpath - XPath interface
        xpathStr - xpath string
        root - node to start search
        defaultVal - default value
        Returns:
        int value or defaultVal if not found
      • getXMLPropertyIntSize

        public static int getXMLPropertyIntSize​(javax.xml.xpath.XPath xpath,
                                                String xpathStr,
                                                org.w3c.dom.Element root,
                                                int defaultVal)
      • getXMLPropertyLong

        public static long getXMLPropertyLong​(javax.xml.xpath.XPath xpath,
                                              String xpathStr,
                                              org.w3c.dom.Element root,
                                              long defaultVal)
        Get a single long value pointed to by xpath or defaultVal if not found.
        Parameters:
        xpath - XPath interface
        xpathStr - xpath string
        root - node to start search
        defaultVal - default value
        Returns:
        long value or defaultVal if not found
      • getXMLPropertyLongSize

        public static long getXMLPropertyLongSize​(javax.xml.xpath.XPath xpath,
                                                  String xpathStr,
                                                  org.w3c.dom.Element root,
                                                  long defaultVal)
      • getXMLPropertyDouble

        public static double getXMLPropertyDouble​(javax.xml.xpath.XPath xpath,
                                                  String xpathStr,
                                                  org.w3c.dom.Element root,
                                                  double defaultVal)
        Get a single double value pointed to by xpath or defaultVal if not found.
        Parameters:
        xpath - XPath interface
        xpathStr - xpath string
        root - node to start search
        defaultVal - default value
        Returns:
        double value or defaultVal if not found
      • getXMLPropertyBool

        public static boolean getXMLPropertyBool​(javax.xml.xpath.XPath xpath,
                                                 String xpathStr,
                                                 org.w3c.dom.Element root,
                                                 boolean defaultVal)
        Get a boolean int value pointed to by xpath or defaultVal if not found.
        Parameters:
        xpath - XPath interface
        xpathStr - xpath string
        root - node to start search
        defaultVal - default value
        Returns:
        boolean value or defaultVal if not found
      • newXPathFactory

        public static javax.xml.xpath.XPathFactory newXPathFactory()
        Get a new XPath factory object. There is a bug in certain implementations of the Sun VM that forces an explicit creation of the "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl". This method will try the correct method for creation and if fails will directly create "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl" object.
        Returns:
        XPathFactory or null if not found
      • getVersion

        public static String getVersion​(org.w3c.dom.Element root)
        Given a Wowza XML file's root element, parse the version attribute
        Parameters:
        root -
        Returns:
        version or "0" if not specified