Class XmlDocConfigurationProvider
java.lang.Object
org.apache.struts2.config.providers.XmlDocConfigurationProvider
- All Implemented Interfaces:
ConfigurationProvider
,ContainerProvider
,PackageProvider
- Direct Known Subclasses:
XmlConfigurationProvider
This is a base Struts
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
FieldsModifier and TypeFieldDescriptionprotected Configuration
protected ObjectFactory
protected ProviderAllowlist
protected boolean
protected ValueSubstitutor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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) 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 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) 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 managerReturns an unmodifiable map of DTD mappingsprotected static String
guessResultType
(String type) void
init
(Configuration configuration) Initializes with the configurationstatic 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<?>
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
Allows subclasses to load extra information from the documentprotected 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
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
Tells whether the ContainerProvider should reload its configurationvoid
register
(ContainerBuilder containerBuilder, LocatableProperties props) Registers beans and properties for the Containerprotected 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
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 void
verifyInterceptor
(String className, Location loc) protected Class<?>
verifyResultType
(String className, Location loc)
-
Field Details
-
declaredPackages
-
documents
-
objectFactory
-
dtdMappings
-
configuration
-
providerAllowlist
-
throwExceptionOnDuplicateBeans
protected boolean throwExceptionOnDuplicateBeans -
valueSubstitutor
-
allowlistClasses
-
-
Constructor Details
-
XmlDocConfigurationProvider
-
-
Method Details
-
setObjectFactory
-
setValueSubstitutor
-
setProviderAllowlist
-
setThrowExceptionOnDuplicateBeans
public void setThrowExceptionOnDuplicateBeans(boolean val) -
setDtdMappings
-
getDtdMappings
Returns an unmodifiable map of DTD mappings- Returns:
- map of DTD mappings
-
init
Description copied from interface:ContainerProvider
Initializes with the configuration- Specified by:
init
in interfaceContainerProvider
- Specified by:
init
in interfacePackageProvider
- Parameters:
configuration
- The configuration
-
destroy
public void destroy()Description copied from interface:ContainerProvider
Called before removed from the configuration manager- Specified by:
destroy
in interfaceContainerProvider
-
allowAndLoadClass
- Throws:
ClassNotFoundException
-
loadClass
- Throws:
ClassNotFoundException
-
iterateElementChildren
-
iterateElementChildren
-
iterateChildren
-
iterateChildrenByTagName
-
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 interfaceContainerProvider
- Parameters:
containerBuilder
- The builder to register beans withprops
- 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
-
registerUnknownHandlerStack
-
needsReload
public boolean needsReload()Description copied from interface:ContainerProvider
Tells whether the ContainerProvider should reload its configuration- Specified by:
needsReload
in interfaceContainerProvider
- Specified by:
needsReload
in interfacePackageProvider
- Returns:
- true, whether the ContainerProvider should reload its configuration, falseotherwise.
-
loadPackages
Description copied from interface:PackageProvider
Loads the packages for the configuration.- Specified by:
loadPackages
in interfacePackageProvider
- Throws:
ConfigurationException
- in case of configuration errors
-
loadExtraConfiguration
Allows subclasses to load extra information from the document- Parameters:
doc
- The configuration document
-
addPackage
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
-
addResultTypes
-
buildResultTypeConfig
protected ResultTypeConfig buildResultTypeConfig(Element resultTypeElement, Location location, String paramName) -
verifyResultType
-
buildPackageContext
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 elementpackageContext
- the package context- Returns:
- map of result config objects
-
buildResultConfig
protected ResultConfig buildResultConfig(String name, ResultTypeConfig config, Location location, Map<String, String> params) -
buildResultParams
-
guessResultType
-
buildExceptionMappings
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
-
loadDefaultActionRef
-
loadGlobalResults
Load all the global results for this package from the XML element.- Parameters:
packageContext
- the package contextpackageElement
- the given XML element
-
loadGlobalAllowedMethods
protected void loadGlobalAllowedMethods(PackageConfig.Builder packageContext, Element packageElement) -
addAllowedMethodsToSet
-
loadDefaultClassRef
-
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 contextpackageElement
- 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
-
buildInterceptorConfig
-
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 frominterceptorRefElement
- Element to pull interceptor ref data from- Returns:
- A list of Interceptor objects
- Throws:
ConfigurationException
- in case of configuration errors
-
loadDefaultInterceptorRef
-