Class XMLUtils

Object
com.wowza.util.XMLUtils

public class XMLUtils extends Object

XMLUtils: utility class for parsing XML files.

  • Constructor Details

    • XMLUtils

      public XMLUtils()
  • Method Details

    • getNodeValueByTagName

      public static String getNodeValueByTagName(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 Node getNodeByTagName(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(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(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(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(XPath xpath, String xpathStr, 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(XPath xpath, String xpathStr, 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(XPath xpath, String xpathStr, Element root)
    • getXMLPropertyInt

      public static int getXMLPropertyInt(XPath xpath, String xpathStr, 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(XPath xpath, String xpathStr, Element root, int defaultVal)
    • getXMLPropertyLong

      public static long getXMLPropertyLong(XPath xpath, String xpathStr, 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(XPath xpath, String xpathStr, Element root, long defaultVal)
    • getXMLPropertyDouble

      public static double getXMLPropertyDouble(XPath xpath, String xpathStr, 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(XPath xpath, String xpathStr, 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 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
    • newStrictDocumentBuilderFactory

      public static DocumentBuilderFactory newStrictDocumentBuilderFactory() throws ParserConfigurationException
      Get a DocumentBuilderFactory for configuration and other structured data. Any DOCTYPE is rejected and external entities, DTDs, schemas and XIncludes are never loaded.
      Returns:
      DocumentBuilderFactory
      Throws:
      ParserConfigurationException - if the parser does not support a required feature
    • newContentDocumentBuilderFactory

      public static DocumentBuilderFactory newContentDocumentBuilderFactory() throws ParserConfigurationException
      Get a DocumentBuilderFactory for media documents such as SMIL and TTML. A DOCTYPE is allowed, but external entities, DTDs, schemas and XIncludes are never loaded and entity expansion is limited.
      Returns:
      DocumentBuilderFactory
      Throws:
      ParserConfigurationException - if the parser does not support a required feature
    • newStrictSAXParserFactory

      public static SAXParserFactory newStrictSAXParserFactory() throws ParserConfigurationException, SAXException
      Get a SAXParserFactory that rejects any DOCTYPE and never loads external entities, DTDs or XIncludes.
      Returns:
      SAXParserFactory
      Throws:
      ParserConfigurationException - if the parser does not support a required feature
      SAXException - if the parser does not support a required feature
    • newStrictXMLReader

      public static XMLReader newStrictXMLReader() throws ParserConfigurationException, SAXException
      Get a namespace-aware XMLReader that rejects any DOCTYPE and never loads external entities, DTDs or XIncludes.
      Returns:
      XMLReader
      Throws:
      ParserConfigurationException - if the parser does not support a required feature
      SAXException - if the parser does not support a required feature
    • newTransformerFactory

      public static TransformerFactory newTransformerFactory()
      Get a TransformerFactory that never loads external DTDs or stylesheets.
      Returns:
      TransformerFactory
    • newSchemaFactory

      public static SchemaFactory newSchemaFactory() throws SAXException
      Get a W3C XML Schema SchemaFactory that never loads external DTDs or schemas.
      Returns:
      SchemaFactory
      Throws:
      SAXException - if the factory does not support a required property
    • newStrictXMLInputFactory

      public static XMLInputFactory newStrictXMLInputFactory()
      Get a StAX XMLInputFactory whose readers reject any DOCTYPE and never load external entities or DTDs.
      Returns:
      XMLInputFactory
    • newXmlMapper

      public static com.fasterxml.jackson.dataformat.xml.XmlMapper newXmlMapper()
      Get a Jackson XmlMapper that rejects any DOCTYPE and never loads external entities or DTDs.
      Returns:
      XmlMapper
    • getVersion

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