Class XMLUtilities

  • java.lang.Object
    • com.thingworx.common.utils.XMLUtilities
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean ENABLE_XXE  
    • Constructor Summary

      Constructors 
      Constructor Description
      XMLUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static org.w3c.dom.Document createDocument()  
      static org.w3c.dom.Document createDocument​(java.lang.String contentStr)  
      static javax.xml.parsers.DocumentBuilderFactory createDocumentBuilderFactory()  
      static org.w3c.dom.Document createDocumentFromStream​(java.io.InputStream is)  
      static org.w3c.dom.Element getChildElementByTagName​(org.w3c.dom.Element node, java.lang.String element)  
      static java.util.ArrayList<org.w3c.dom.Element> getChildElements​(org.w3c.dom.Element node)  
      static java.util.ArrayList<org.w3c.dom.Element> getChildElementsByTagName​(org.w3c.dom.Element node, java.lang.String element)  
      static java.lang.String getChildElementValueByTagName​(org.w3c.dom.Element node, java.lang.String element)  
      static java.lang.String getChildElementValueByTagNameWithNull​(org.w3c.dom.Element node, java.lang.String element)  
      static org.w3c.dom.Document getDocument​(java.io.InputStream in)  
      static org.w3c.dom.Document getDocument​(java.io.Reader in)  
      static org.w3c.dom.Element getElementByTagName​(org.w3c.dom.Element node, java.lang.String element)  
      static java.lang.String getElementValueByTagName​(org.w3c.dom.Element node, java.lang.String element)  
      static java.lang.String getNodeValue​(org.w3c.dom.Node node)


      Will return the String value of the given node.
      static java.lang.String getTextContent​(org.w3c.dom.Node node)  
      static java.lang.String outputXMLDoc​(org.w3c.dom.Document doc)


      Used for XML POST and PUT
      static void outputXMLDoc​(org.w3c.dom.Document doc, java.io.OutputStream output)  
      static void outputXMLDoc​(org.w3c.dom.Document doc, java.io.Writer output)  
      static java.lang.String outputXMLDocFormatted​(org.w3c.dom.Document doc)


      static void outputXMLDocFormatted​(org.w3c.dom.Document doc, java.io.OutputStream output)  
      static void outputXMLDocFormatted​(org.w3c.dom.Document doc, java.io.OutputStream output, java.lang.Integer indent)
      Deprecated.
      indent is no longer supported
      static void outputXMLDocFormatted​(org.w3c.dom.Document doc, java.io.Writer output)  
      static java.lang.String outputXMLDocFormatted​(org.w3c.dom.Document doc, java.lang.Integer indent)
      Deprecated.
      indent is no longer supported
      static void outputXMLDocFormatted​(org.w3c.dom.Document outdoc, java.lang.String filepath)  
      static void setNodeValue​(org.w3c.dom.Node nodeTarget, java.lang.String value)  
      • Methods inherited from class java.lang.Object

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

      • ENABLE_XXE

        public static boolean ENABLE_XXE
    • Constructor Detail

      • XMLUtilities

        public XMLUtilities()
    • Method Detail

      • createDocumentBuilderFactory

        @ThingworxExtensionApiMethod(since={6,6})
        public static javax.xml.parsers.DocumentBuilderFactory createDocumentBuilderFactory()
                                                                                     throws javax.xml.parsers.ParserConfigurationException
        Throws:
        javax.xml.parsers.ParserConfigurationException - If an error occurs
      • createDocumentFromStream

        @ThingworxExtensionApiMethod(since={6,6})
        public static org.w3c.dom.Document createDocumentFromStream​(java.io.InputStream is)
                                                             throws java.lang.Exception
        Throws:
        java.lang.Exception - If an error occurs

        Used for importing Entity from file and attachments
      • createDocument

        @ThingworxExtensionApiMethod(since={6,6})
        public static org.w3c.dom.Document createDocument​(java.lang.String contentStr)
                                                   throws java.lang.Exception
        Throws:
        java.lang.Exception - If an error occurs

        Currently used for service requests
      • getDocument

        @ThingworxExtensionApiMethod(since={6,6})
        public static org.w3c.dom.Document getDocument​(java.io.InputStream in)
                                                throws java.lang.Exception
        Throws:
        java.lang.Exception - If an error occurs

        Currently used for importing default entities for High Availability (HA) and getDocument(File).
      • getDocument

        @ThingworxExtensionApiMethod(since={6,6})
        public static org.w3c.dom.Document getDocument​(java.io.Reader in)
                                                throws java.lang.Exception
        Throws:
        java.lang.Exception - If an error occurs

        Currently used for converting to Primitive and storing data.
      • outputXMLDoc

        @ThingworxExtensionApiMethod(since={6,6})
        public static void outputXMLDoc​(org.w3c.dom.Document doc,
                                        java.io.OutputStream output)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception - If an error occurs

        Used for generating unformatted XML.
      • outputXMLDoc

        @ThingworxExtensionApiMethod(since={6,6})
        public static void outputXMLDoc​(org.w3c.dom.Document doc,
                                        java.io.Writer output)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception - If an error occurs

        Used for generating unformatted XML.
      • outputXMLDocFormatted

        @ThingworxExtensionApiMethod(since={8,1})
        public static void outputXMLDocFormatted​(org.w3c.dom.Document doc,
                                                 java.io.Writer output)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception - If an error occurs

        Used for generating formatted XML for Source Export operations. The XML will be indented using four spaces, line feed for new line, expand empty elements, add new lines for element attributes, format CDATA.
      • getElementValueByTagName

        @ThingworxExtensionApiMethod(since={6,6})
        public static java.lang.String getElementValueByTagName​(org.w3c.dom.Element node,
                                                                java.lang.String element)
      • getChildElementByTagName

        @ThingworxExtensionApiMethod(since={6,6})
        public static org.w3c.dom.Element getChildElementByTagName​(org.w3c.dom.Element node,
                                                                   java.lang.String element)
      • getChildElementsByTagName

        @ThingworxExtensionApiMethod(since={6,6})
        public static java.util.ArrayList<org.w3c.dom.Element> getChildElementsByTagName​(org.w3c.dom.Element node,
                                                                                         java.lang.String element)
      • getChildElementValueByTagNameWithNull

        @ThingworxExtensionApiMethod(since={6,6})
        public static java.lang.String getChildElementValueByTagNameWithNull​(org.w3c.dom.Element node,
                                                                             java.lang.String element)
      • getChildElementValueByTagName

        @ThingworxExtensionApiMethod(since={6,6})
        public static java.lang.String getChildElementValueByTagName​(org.w3c.dom.Element node,
                                                                     java.lang.String element)
      • getElementByTagName

        @ThingworxExtensionApiMethod(since={6,6})
        public static org.w3c.dom.Element getElementByTagName​(org.w3c.dom.Element node,
                                                              java.lang.String element)
      • getNodeValue

        @ThingworxExtensionApiMethod(since={6,6})
        public static java.lang.String getNodeValue​(org.w3c.dom.Node node)


        Will return the String value of the given node. This method accepts Node's of type Node.ELEMENT_NODE, Node.ATTRIBUTE_NODE, Node.TEXT_NODE and Node.CDATA_SECTION_NODE. All other Node types will return an empty string.

        Note: As of 7.2.0, if an Node.ELEMENT_NODE node has child Node.TEXT_NODE nodes containing only whitespace characters (like newlines or tabs) the node will be treated as an empty string. For example, if Node.TEXT_NODE node only contains "\n\t\t\t", the value will be "".

        Parameters:
        node - The DOM node that you want to retrieve the text value from
        Returns:
        The value of the given DOM node