org.springframework.beans.factory.xml

Class DefaultDocumentLoader

  • java.lang.Object
    • org.springframework.beans.factory.xml.DefaultDocumentLoader
  • All Implemented Interfaces:
    DocumentLoader


    public class DefaultDocumentLoader
    extends java.lang.Object
    implements DocumentLoader
    Spring's default DocumentLoader implementation.

    Simply loads documents using the standard JAXP-configured XML parser. If you want to change the DocumentBuilder that is used to load documents, then one strategy is to define a corresponding Java system property when starting your JVM. For example, to use the Oracle DocumentBuilder, you might start your application like as follows:

    java -Djavax.xml.parsers.DocumentBuilderFactory=oracle.xml.jaxp.JXDocumentBuilderFactory MyMainClass
    Since:
    2.0
    Author:
    Rob Harrop, Juergen Hoeller
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      protected javax.xml.parsers.DocumentBuilder createDocumentBuilder(javax.xml.parsers.DocumentBuilderFactory factory, org.xml.sax.EntityResolver entityResolver, org.xml.sax.ErrorHandler errorHandler)
      Create a JAXP DocumentBuilder that this bean definition reader will use for parsing XML documents.
      protected javax.xml.parsers.DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware)
      Create the DocumentBuilderFactory instance.
      org.w3c.dom.Document loadDocument(org.xml.sax.InputSource inputSource, org.xml.sax.EntityResolver entityResolver, org.xml.sax.ErrorHandler errorHandler, int validationMode, boolean namespaceAware)
      Load the Document at the supplied InputSource using the standard JAXP-configured XML parser.
      • Methods inherited from class java.lang.Object

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

      • DefaultDocumentLoader

        public DefaultDocumentLoader()
    • Method Detail

      • loadDocument

        public org.w3c.dom.Document loadDocument(org.xml.sax.InputSource inputSource,
                                                 org.xml.sax.EntityResolver entityResolver,
                                                 org.xml.sax.ErrorHandler errorHandler,
                                                 int validationMode,
                                                 boolean namespaceAware)
                                          throws java.lang.Exception
        Load the Document at the supplied InputSource using the standard JAXP-configured XML parser.
        Specified by:
        loadDocument in interface DocumentLoader
        Parameters:
        inputSource - the source of the document that is to be loaded
        entityResolver - the resolver that is to be used to resolve any entities
        errorHandler - used to report any errors during document loading
        validationMode - the type of validation DTD or XSD)
        namespaceAware - true if support for XML namespaces is to be provided
        Returns:
        the loaded document
        Throws:
        java.lang.Exception - if an error occurs
      • createDocumentBuilderFactory

        protected javax.xml.parsers.DocumentBuilderFactory createDocumentBuilderFactory(int validationMode,
                                                                                        boolean namespaceAware)
                                                                                 throws javax.xml.parsers.ParserConfigurationException
        Create the DocumentBuilderFactory instance.
        Parameters:
        validationMode - the type of validation: DTD or XSD)
        namespaceAware - whether the returned factory is to provide support for XML namespaces
        Returns:
        the JAXP DocumentBuilderFactory
        Throws:
        javax.xml.parsers.ParserConfigurationException - if we failed to build a proper DocumentBuilderFactory
      • createDocumentBuilder

        protected javax.xml.parsers.DocumentBuilder createDocumentBuilder(javax.xml.parsers.DocumentBuilderFactory factory,
                                                                          @Nullable
                                                                          org.xml.sax.EntityResolver entityResolver,
                                                                          @Nullable
                                                                          org.xml.sax.ErrorHandler errorHandler)
                                                                   throws javax.xml.parsers.ParserConfigurationException
        Create a JAXP DocumentBuilder that this bean definition reader will use for parsing XML documents. Can be overridden in subclasses, adding further initialization of the builder.
        Parameters:
        factory - the JAXP DocumentBuilderFactory that the DocumentBuilder should be created with
        entityResolver - the SAX EntityResolver to use
        errorHandler - the SAX ErrorHandler to use
        Returns:
        the JAXP DocumentBuilder
        Throws:
        javax.xml.parsers.ParserConfigurationException - if thrown by JAXP methods