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 Configurationprotected ObjectFactoryprotected ProviderAllowlistprotected booleanprotected ValueSubstitutor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAction(Element actionElement, PackageConfig.Builder packageContext) protected static voidaddAllowedMethodsToSet(Node allowedMethodsNode, Set<String> allowedMethodsSet) protected PackageConfigaddPackage(Element packageElement) Create a PackageConfig from an XML element representing it.protected voidaddResultTypes(PackageConfig.Builder packageContext, Element element) protected Class<?>allowAndLoadClass(String className) protected ActionConfigbuildActionConfig(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 InterceptorConfigbuildInterceptorConfig(Element interceptorElement) protected List<InterceptorMapping>buildInterceptorList(Element element, PackageConfig.Builder context) protected PackageConfig.BuilderbuildPackageContext(Element packageElement) This method builds a package context by looking for the parents of this new package.protected ResultConfigbuildResultConfig(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 ResultTypeConfigbuildResultTypeConfig(Element resultTypeElement, Location location, String paramName) voiddestroy()Called before removed from the configuration managerReturns an unmodifiable map of DTD mappingsprotected static StringguessResultType(String type) voidinit(Configuration configuration) Initializes with the configurationstatic voiditerateChildren(Node node, Consumer<Node> function) static voiditerateChildrenByTagName(Element el, String tagName, Consumer<Element> function) static voiditerateElementChildren(Document doc, Consumer<Element> function) static voiditerateElementChildren(Node node, Consumer<Element> function) protected Class<?>protected voidloadDefaultActionRef(PackageConfig.Builder packageContext, Element element) protected voidloadDefaultClassRef(PackageConfig.Builder packageContext, Element element) protected voidloadDefaultInterceptorRef(PackageConfig.Builder packageContext, Element element) protected voidAllows subclasses to load extra information from the documentprotected voidloadGlobalAllowedMethods(PackageConfig.Builder packageContext, Element packageElement) protected voidloadGlobalExceptionMappings(PackageConfig.Builder packageContext, Element packageElement) Load all the global results for this package from the XML element.protected voidloadGlobalResults(PackageConfig.Builder packageContext, Element packageElement) Load all the global results for this package from the XML element.protected voidloadInterceptors(PackageConfig.Builder context, Element element) protected InterceptorStackConfigloadInterceptorStack(Element element, PackageConfig.Builder context) protected voidloadInterceptorStacks(Element element, PackageConfig.Builder context) voidLoads 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.booleanTells whether the ContainerProvider should reload its configurationvoidregister(ContainerBuilder containerBuilder, LocatableProperties props) Registers beans and properties for the Containerprotected voidregisterBean(Element child, Map<String, Node> loadedBeans, ContainerBuilder containerBuilder) protected voidregisterBeanSelection(Element child, ContainerBuilder containerBuilder, LocatableProperties props) protected voidregisterConstant(Element child, LocatableProperties props) protected voidvoidsetDtdMappings(Map<String, String> mappings) voidsetObjectFactory(ObjectFactory objectFactory) voidsetProviderAllowlist(ProviderAllowlist providerAllowlist) voidsetThrowExceptionOnDuplicateBeans(boolean val) voidsetValueSubstitutor(ValueSubstitutor valueSubstitutor) protected voidverifyAction(String className, Location loc) protected voidverifyInterceptor(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:ContainerProviderInitializes with the configuration- Specified by:
initin interfaceContainerProvider- Specified by:
initin interfacePackageProvider- Parameters:
configuration- The configuration
-
destroy
public void destroy()Description copied from interface:ContainerProviderCalled before removed from the configuration manager- Specified by:
destroyin 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:ContainerProviderRegisters beans and properties for the Container- Specified by:
registerin 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:ContainerProviderTells whether the ContainerProvider should reload its configuration- Specified by:
needsReloadin interfaceContainerProvider- Specified by:
needsReloadin interfacePackageProvider- Returns:
- true, whether the ContainerProvider should reload its configuration, falseotherwise.
-
loadPackages
Description copied from interface:PackageProviderLoads the packages for the configuration.- Specified by:
loadPackagesin 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
-