Class XmlUtils


  • public final class XmlUtils
    extends java.lang.Object
    XML utils, mainly used to construct safe factories.
    Since:
    13901
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private XmlUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.w3c.dom.Element getFirstChildElement​(org.w3c.dom.Node parent)
      Get the first child element
      static javax.xml.parsers.DocumentBuilder newSafeDOMBuilder()
      Returns a new secure DOM builder, supporting XML namespaces.
      static javax.xml.parsers.SAXParser newSafeSAXParser()
      Returns a new secure SAX parser, supporting XML namespaces.
      static javax.xml.transform.TransformerFactory newSafeTransformerFactory()
      Returns a new secure TransformerFactory.
      static javax.xml.validation.Validator newSafeValidator​(javax.xml.validation.Schema schema)
      Returns a new secure Validator.
      static javax.xml.stream.XMLInputFactory newSafeXMLInputFactory()
      Returns a new secure XMLInputFactory.
      static javax.xml.validation.SchemaFactory newXmlSchemaFactory()
      Returns the W3C XML Schema factory implementation.
      static org.w3c.dom.Document parseSafeDOM​(java.io.InputStream is)
      Parse the content given InputStream as XML.
      static void parseSafeSAX​(org.xml.sax.InputSource is, org.xml.sax.helpers.DefaultHandler dh)
      Parse the content given InputSource as XML using the specified DefaultHandler.
      • Methods inherited from class java.lang.Object

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

      • newXmlSchemaFactory

        public static javax.xml.validation.SchemaFactory newXmlSchemaFactory()
        Returns the W3C XML Schema factory implementation. Robust method dealing with ContextClassLoader problems.
        Returns:
        the W3C XML Schema factory implementation
      • newSafeDOMBuilder

        public static javax.xml.parsers.DocumentBuilder newSafeDOMBuilder()
                                                                   throws javax.xml.parsers.ParserConfigurationException
        Returns a new secure DOM builder, supporting XML namespaces.
        Returns:
        a new secure DOM builder, supporting XML namespaces
        Throws:
        javax.xml.parsers.ParserConfigurationException - if a parser cannot be created which satisfies the requested configuration.
      • parseSafeDOM

        public static org.w3c.dom.Document parseSafeDOM​(java.io.InputStream is)
                                                 throws javax.xml.parsers.ParserConfigurationException,
                                                        java.io.IOException,
                                                        org.xml.sax.SAXException
        Parse the content given InputStream as XML. This method uses a secure DOM builder, supporting XML namespaces.
        Parameters:
        is - The InputStream containing the content to be parsed.
        Returns:
        the result DOM document
        Throws:
        javax.xml.parsers.ParserConfigurationException - if a parser cannot be created which satisfies the requested configuration.
        java.io.IOException - if any IO errors occur.
        org.xml.sax.SAXException - for SAX errors.
      • newSafeSAXParser

        public static javax.xml.parsers.SAXParser newSafeSAXParser()
                                                            throws javax.xml.parsers.ParserConfigurationException,
                                                                   org.xml.sax.SAXException
        Returns a new secure SAX parser, supporting XML namespaces.
        Returns:
        a new secure SAX parser, supporting XML namespaces
        Throws:
        javax.xml.parsers.ParserConfigurationException - if a parser cannot be created which satisfies the requested configuration.
        org.xml.sax.SAXException - for SAX errors.
      • parseSafeSAX

        public static void parseSafeSAX​(org.xml.sax.InputSource is,
                                        org.xml.sax.helpers.DefaultHandler dh)
                                 throws javax.xml.parsers.ParserConfigurationException,
                                        org.xml.sax.SAXException,
                                        java.io.IOException
        Parse the content given InputSource as XML using the specified DefaultHandler. This method uses a secure SAX parser, supporting XML namespaces.
        Parameters:
        is - The InputSource containing the content to be parsed.
        dh - The SAX DefaultHandler to use.
        Throws:
        javax.xml.parsers.ParserConfigurationException - if a parser cannot be created which satisfies the requested configuration.
        org.xml.sax.SAXException - for SAX errors.
        java.io.IOException - if any IO errors occur.
      • newSafeXMLInputFactory

        public static javax.xml.stream.XMLInputFactory newSafeXMLInputFactory()
        Returns a new secure XMLInputFactory.
        Returns:
        a new secure XMLInputFactory, for which external entities are not loaded
      • newSafeTransformerFactory

        public static javax.xml.transform.TransformerFactory newSafeTransformerFactory()
                                                                                throws javax.xml.transform.TransformerConfigurationException
        Returns a new secure TransformerFactory.
        Returns:
        a new secure TransformerFactory
        Throws:
        javax.xml.transform.TransformerConfigurationException - if the factory or the Transformers or Templates it creates cannot support this feature.
      • newSafeValidator

        public static javax.xml.validation.Validator newSafeValidator​(javax.xml.validation.Schema schema)
        Returns a new secure Validator.
        Parameters:
        schema - XML schema
        Returns:
        a new secure Validator
        Since:
        14441
      • getFirstChildElement

        public static org.w3c.dom.Element getFirstChildElement​(org.w3c.dom.Node parent)
        Get the first child element
        Parameters:
        parent - parent node
        Returns:
        the first child element
        Since:
        14348