com.opensymphony.xwork2.config.providers

## Class XmlDocConfigurationProvider

- java.lang.Object
- - com.opensymphony.xwork2.config.providers.XmlDocConfigurationProvider

- All Implemented Interfaces:
    ConfigurationProvider, ContainerProvider, PackageProvider
  Direct Known Subclasses:
    XmlConfigurationProvider

      public abstract class XmlDocConfigurationProvider
      extends Object
      implements ConfigurationProvider

  This is a base XWork2 `ConfigurationProvider` for loading configuration from a parsed `XML document`. By extending this class, configuration can be loaded from any source that an XML document can be parsed from. Note that this class does not validate the document against any provided DTDs. For loading configuration from an XML file with DTD validation, please see `StrutsXmlConfigurationProvider`.
  Since:
    6.2.0

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Set<Class<?>>` | `allowlistClasses`
    `protected Configuration` | `configuration`
    `protected Map<String,Element>` | `declaredPackages`
    `protected List<Document>` | `documents`
    `protected Map<String,String>` | `dtdMappings`
    `protected ObjectFactory` | `objectFactory`
    `protected ProviderAllowlist` | `providerAllowlist`
    `protected boolean` | `throwExceptionOnDuplicateBeans`
    `protected ValueSubstitutor` | `valueSubstitutor`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XmlDocConfigurationProvider(Document... documents)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addAction(Element actionElement, PackageConfig.Builder packageContext)`
    `protected static void` | `addAllowedMethodsToSet(Node allowedMethodsNode, Set<String> allowedMethodsSet)`
    `protected PackageConfig` | `addPackage(Element packageElement)` Create a PackageConfig from an XML element representing it.
    `protected void` | `addResultTypes(PackageConfig.Builder packageContext, Element element)`
    `protected Class<?>` | `allowAndLoadClass(String className)`
    `protected ActionConfig` | `buildActionConfig(Element actionElement, Location location, PackageConfig.Builder packageContext, Map<String,ResultConfig> results)`
    `protected Set<String>` | `buildAllowedMethods(Element element, PackageConfig.Builder packageContext)`
    `protected List<ExceptionMappingConfig>` | `buildExceptionMappings(Element element)` Build a list of exception mapping objects from below a given XML element.
    `protected List<ExceptionMappingConfig>` | `buildExceptionMappings(Element element, PackageConfig.Builder packageContext)` Deprecated. since 6.2.0, use `buildExceptionMappings(Element)`
    `protected InterceptorConfig` | `buildInterceptorConfig(Element interceptorElement)`
    `protected List<InterceptorMapping>` | `buildInterceptorList(Element element, PackageConfig.Builder context)`
    `protected PackageConfig.Builder` | `buildPackageContext(Element packageElement)` This method builds a package context by looking for the parents of this new package.
    `protected ResultConfig` | `buildResultConfig(String name, ResultTypeConfig config, Location location, Map<String,String> params)`
    `protected Map<String,String>` | `buildResultParams(Element resultElement, ResultTypeConfig config)`
    `protected Map<String,ResultConfig>` | `buildResults(Element element, PackageConfig.Builder packageContext)` Build a map of ResultConfig objects from below a given XML element.
    `protected ResultTypeConfig` | `buildResultTypeConfig(Element resultTypeElement, Location location, String paramName)`
    `void` | `destroy()` Called before removed from the configuration manager
    `Map<String,String>` | `getDtdMappings()` Returns an unmodifiable map of DTD mappings
    `protected static String` | `guessResultType(String type)`
    `void` | `init(Configuration configuration)` Initializes with the configuration
    `static void` | `iterateChildren(Node node, Consumer<Node> function)`
    `static void` | `iterateChildrenByTagName(Element el, String tagName, Consumer<Element> function)`
    `static void` | `iterateElementChildren(Document doc, Consumer<Element> function)`
    `static void` | `iterateElementChildren(Node node, Consumer<Element> function)`
    `protected Class<?>` | `loadClass(String className)`
    `protected void` | `loadDefaultActionRef(PackageConfig.Builder packageContext, Element element)`
    `protected void` | `loadDefaultClassRef(PackageConfig.Builder packageContext, Element element)`
    `protected void` | `loadDefaultInterceptorRef(PackageConfig.Builder packageContext, Element element)`
    `protected void` | `loadExtraConfiguration(Document doc)` Allows subclasses to load extra information from the document
    `protected void` | `loadGlobalAllowedMethods(PackageConfig.Builder packageContext, Element packageElement)`
    `protected void` | `loadGlobalExceptionMappings(PackageConfig.Builder packageContext, Element packageElement)` Load all the global results for this package from the XML element.
    `protected void` | `loadGlobalResults(PackageConfig.Builder packageContext, Element packageElement)` Load all the global results for this package from the XML element.
    `protected void` | `loadInterceptors(PackageConfig.Builder context, Element element)`
    `protected InterceptorStackConfig` | `loadInterceptorStack(Element element, PackageConfig.Builder context)`
    `protected void` | `loadInterceptorStacks(Element element, PackageConfig.Builder context)`
    `void` | `loadPackages()` Loads the packages for the configuration.
    `protected List<InterceptorMapping>` | `lookupInterceptorReference(PackageConfig.Builder context, Element interceptorRefElement)` Looks up the Interceptor Class from the interceptor-ref name and creates an instance, which is added to the provided List, or, if this is a ref to a stack, it adds the Interceptor instances from the List to this stack.
    `boolean` | `needsReload()` Tells whether the ContainerProvider should reload its configuration
    `void` | `register(ContainerBuilder containerBuilder, LocatableProperties props)` Registers beans and properties for the Container
    `protected void` | `registerBean(Element child, Map<String,Node> loadedBeans, ContainerBuilder containerBuilder)`
    `protected void` | `registerBeanSelection(Element child, ContainerBuilder containerBuilder, LocatableProperties props)`
    `protected void` | `registerConstant(Element child, LocatableProperties props)`
    `protected void` | `registerUnknownHandlerStack(Element child)`
    `void` | `setDtdMappings(Map<String,String> mappings)`
    `void` | `setObjectFactory(ObjectFactory objectFactory)`
    `void` | `setProviderAllowlist(ProviderAllowlist providerAllowlist)`
    `void` | `setThrowExceptionOnDuplicateBeans(boolean val)`
    `void` | `setValueSubstitutor(ValueSubstitutor valueSubstitutor)`
    `protected void` | `verifyAction(String className, Location loc)`
    `protected boolean` | `verifyAction(String className, String name, Location loc)` Deprecated. since 6.2.0, use `verifyAction(String, Location)`
    `protected void` | `verifyInterceptor(String className, Location loc)`
    `protected Class<?>` | `verifyResultType(String className, Location loc)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### declaredPackages

          protected final Map<String,Element> declaredPackages

    - #### documents

          protected List<Document> documents

    - #### objectFactory

          protected ObjectFactory objectFactory

    - #### dtdMappings

          protected Map<String,String> dtdMappings

    - #### configuration

          protected Configuration configuration

    - #### providerAllowlist

          protected ProviderAllowlist providerAllowlist

    - #### throwExceptionOnDuplicateBeans

          protected boolean throwExceptionOnDuplicateBeans

    - #### valueSubstitutor

          protected ValueSubstitutor valueSubstitutor

    - #### allowlistClasses

          protected Set<Class<?>> allowlistClasses

  - ### Constructor Detail

    - #### XmlDocConfigurationProvider

          public XmlDocConfigurationProvider(Document... documents)

  - ### Method Detail

    - #### setObjectFactory

          public void setObjectFactory(ObjectFactory objectFactory)

    - #### setValueSubstitutor

          public void setValueSubstitutor(ValueSubstitutor valueSubstitutor)

    - #### setProviderAllowlist

          public void setProviderAllowlist(ProviderAllowlist providerAllowlist)

    - #### setThrowExceptionOnDuplicateBeans

          public void setThrowExceptionOnDuplicateBeans(boolean val)

    - #### setDtdMappings

          public void setDtdMappings(Map<String,String> mappings)

    - #### getDtdMappings

          public Map<String,String> getDtdMappings()

      Returns an unmodifiable map of DTD mappings
      Returns:
        map of DTD mappings

    - #### init

          public void init(Configuration configuration)

      Description copied from interface: `ContainerProvider`
      Initializes with the configuration
      Specified by:
        `init` in interface `ContainerProvider`
      Specified by:
        `init` in interface `PackageProvider`
      Parameters:
        `configuration` - The configuration

    - #### destroy

          public void destroy()

      Description copied from interface: `ContainerProvider`
      Called before removed from the configuration manager
      Specified by:
        `destroy` in interface `ContainerProvider`

    - #### allowAndLoadClass

          protected Class<?> allowAndLoadClass(String className)
                                        throws ClassNotFoundException

      Throws:
        `ClassNotFoundException`

    - #### loadClass

          protected Class<?> loadClass(String className)
                                throws ClassNotFoundException

      Throws:
        `ClassNotFoundException`

    - #### iterateElementChildren

          public static void iterateElementChildren(Document doc,
                                                    Consumer<Element> function)

    - #### iterateElementChildren

          public static void iterateElementChildren(Node node,
                                                    Consumer<Element> function)

    - #### iterateChildren

          public static void iterateChildren(Node node,
                                             Consumer<Node> function)

    - #### iterateChildrenByTagName

          public static void iterateChildrenByTagName(Element el,
                                                      String tagName,
                                                      Consumer<Element> function)

    - #### register

          public void register(ContainerBuilder containerBuilder,
                               LocatableProperties props)
                        throws ConfigurationException

      Description copied from interface: `ContainerProvider`
      Registers beans and properties for the Container
      Specified by:
        `register` in interface `ContainerProvider`
      Parameters:
        `containerBuilder` - The builder to register beans with
        `props` - The properties to register constants with
      Throws:
        `ConfigurationException` - If anything goes wrong

    - #### registerBeanSelection

          protected void registerBeanSelection(Element child,
                                               ContainerBuilder containerBuilder,
                                               LocatableProperties props)

    - #### registerBean

          protected void registerBean(Element child,
                                      Map<String,Node> loadedBeans,
                                      ContainerBuilder containerBuilder)

    - #### registerConstant

          protected void registerConstant(Element child,
                                          LocatableProperties props)

    - #### registerUnknownHandlerStack

          protected void registerUnknownHandlerStack(Element child)

    - #### needsReload

          public boolean needsReload()

      Description copied from interface: `ContainerProvider`
      Tells whether the ContainerProvider should reload its configuration
      Specified by:
        `needsReload` in interface `ContainerProvider`
      Specified by:
        `needsReload` in interface `PackageProvider`
      Returns:
        `true`, whether the ContainerProvider should reload its configuration, `false`otherwise.

    - #### loadPackages

          public void loadPackages()
                            throws ConfigurationException

      Description copied from interface: `PackageProvider`
      Loads the packages for the configuration.
      Specified by:
        `loadPackages` in interface `PackageProvider`
      Throws:
        `ConfigurationException` - in case of configuration errors

    - #### loadExtraConfiguration

          protected void loadExtraConfiguration(Document doc)

      Allows subclasses to load extra information from the document
      Parameters:
        `doc` - The configuration document

    - #### addPackage

          protected PackageConfig addPackage(Element packageElement)
                                      throws ConfigurationException

      Create a PackageConfig from an XML element representing it.
      Parameters:
        `packageElement` - the given XML element
      Returns:
        the package config
      Throws:
        `ConfigurationException` - in case of configuration errors

    - #### addAction

          protected void addAction(Element actionElement,
                                   PackageConfig.Builder packageContext)
                            throws ConfigurationException

      Throws:
        `ConfigurationException`

    - #### buildActionConfig

          protected ActionConfig buildActionConfig(Element actionElement,
                                                   Location location,
                                                   PackageConfig.Builder packageContext,
                                                   Map<String,ResultConfig> results)

    - #### verifyAction

          @Deprecated
          protected boolean verifyAction(String className,
                                                     String name,
                                                     Location loc)

      Deprecated. since 6.2.0, use `verifyAction(String, Location)`

    - #### verifyAction

          protected void verifyAction(String className,
                                      Location loc)

    - #### addResultTypes

          protected void addResultTypes(PackageConfig.Builder packageContext,
                                        Element element)

    - #### buildResultTypeConfig

          protected ResultTypeConfig buildResultTypeConfig(Element resultTypeElement,
                                                           Location location,
                                                           String paramName)

    - #### verifyResultType

          protected Class<?> verifyResultType(String className,
                                              Location loc)

    - #### buildPackageContext

          protected PackageConfig.Builder buildPackageContext(Element packageElement)

      This method builds a package context by looking for the parents of this new package.

      If no parents are found, it will return a root package.

      Parameters:
        `packageElement` - the package element
      Returns:
        the package config builder

    - #### buildResults

          protected Map<String,ResultConfig> buildResults(Element element,
                                                          PackageConfig.Builder packageContext)

      Build a map of ResultConfig objects from below a given XML element.
      Parameters:
        `element` - the given XML element
        `packageContext` - the package context
      Returns:
        map of result config objects

    - #### buildResultConfig

          protected ResultConfig buildResultConfig(String name,
                                                   ResultTypeConfig config,
                                                   Location location,
                                                   Map<String,String> params)

    - #### buildResultParams

          protected Map<String,String> buildResultParams(Element resultElement,
                                                         ResultTypeConfig config)

    - #### guessResultType

          protected static String guessResultType(String type)

    - #### buildExceptionMappings

          @Deprecated
          protected List<ExceptionMappingConfig> buildExceptionMappings(Element element,
                                                                                    PackageConfig.Builder packageContext)

      Deprecated. since 6.2.0, use `buildExceptionMappings(Element)`

    - #### buildExceptionMappings

          protected List<ExceptionMappingConfig> buildExceptionMappings(Element element)

      Build a list of exception mapping objects from below a given XML element.
      Parameters:
        `element` - the given XML element
      Returns:
        list of exception mapping config objects

    - #### buildAllowedMethods

          protected Set<String> buildAllowedMethods(Element element,
                                                    PackageConfig.Builder packageContext)

    - #### loadDefaultActionRef

          protected void loadDefaultActionRef(PackageConfig.Builder packageContext,
                                              Element element)

    - #### loadGlobalResults

          protected void loadGlobalResults(PackageConfig.Builder packageContext,
                                           Element packageElement)

      Load all the global results for this package from the XML element.
      Parameters:
        `packageContext` - the package context
        `packageElement` - the given XML element

    - #### loadGlobalAllowedMethods

          protected void loadGlobalAllowedMethods(PackageConfig.Builder packageContext,
                                                  Element packageElement)

    - #### addAllowedMethodsToSet

          protected static void addAllowedMethodsToSet(Node allowedMethodsNode,
                                                       Set<String> allowedMethodsSet)

    - #### loadDefaultClassRef

          protected void loadDefaultClassRef(PackageConfig.Builder packageContext,
                                             Element element)

    - #### loadGlobalExceptionMappings

          protected void loadGlobalExceptionMappings(PackageConfig.Builder packageContext,
                                                     Element packageElement)

      Load all the global results for this package from the XML element.
      Parameters:
        `packageContext` - the package context
        `packageElement` - the given XML element

    - #### buildInterceptorList

          protected List<InterceptorMapping> buildInterceptorList(Element element,
                                                                  PackageConfig.Builder context)
                                                           throws ConfigurationException

      Throws:
        `ConfigurationException`

    - #### loadInterceptors

          protected void loadInterceptors(PackageConfig.Builder context,
                                          Element element)
                                   throws ConfigurationException

      Throws:
        `ConfigurationException`

    - #### verifyInterceptor

          protected void verifyInterceptor(String className,
                                           Location loc)

    - #### buildInterceptorConfig

          protected InterceptorConfig buildInterceptorConfig(Element interceptorElement)

    - #### loadInterceptorStacks

          protected void loadInterceptorStacks(Element element,
                                               PackageConfig.Builder context)
                                        throws ConfigurationException

      Throws:
        `ConfigurationException`

    - #### loadInterceptorStack

          protected InterceptorStackConfig loadInterceptorStack(Element element,
                                                                PackageConfig.Builder context)
                                                         throws ConfigurationException

      Throws:
        `ConfigurationException`

    - #### lookupInterceptorReference

          protected List<InterceptorMapping> lookupInterceptorReference(PackageConfig.Builder context,
                                                                        Element interceptorRefElement)
                                                                 throws ConfigurationException

      Looks up the Interceptor Class from the interceptor-ref name and creates an instance, which is added to the provided List, or, if this is a ref to a stack, it adds the Interceptor instances from the List to this stack.
      Parameters:
        `context` - The PackageConfig to look up the interceptor from
        `interceptorRefElement` - Element to pull interceptor ref data from
      Returns:
        A list of Interceptor objects
      Throws:
        `ConfigurationException` - in case of configuration errors

    - #### loadDefaultInterceptorRef

          protected void loadDefaultInterceptorRef(PackageConfig.Builder packageContext,
                                                   Element element)

Copyright © 2000–2025 Apache Software Foundation. All rights reserved.