Class DigesterLoader
- java.lang.Object
-
- org.apache.commons.digester3.binder.DigesterLoader
-
public final class DigesterLoader extends java.lang.Object
This class manages the creation of Digester instances from digester rules modules.
-
-
Field Summary
Fields Modifier and Type Field Description private BinderClassLoader
classLoader
The class loader to use for instantiating application objects.private org.xml.sax.EntityResolver
entityResolver
The EntityResolver used by the SAX parser.private java.util.Map<java.lang.String,java.net.URL>
entityValidator
The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds.private org.xml.sax.ErrorHandler
errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur.private java.util.concurrent.ExecutorService
executorService
The executor service to run asynchronous parse method.private javax.xml.parsers.SAXParserFactory
factory
The SAXParserFactory to create new defaultDigester
instances.private static java.lang.String
HEADING
The default head when reporting an errors list.private org.xml.sax.Locator
locator
The Locator associated with our parser.private DefaultRulesBinder
rulesBinder
The concreteRulesBinder
implementation.private java.lang.Iterable<RulesModule>
rulesModules
private StackAction
stackAction
Object which will receive callbacks for every pop/push action on the default stack or named stacks.private Substitutor
substitutor
An optional class that substitutes values in attributes and body text.
-
Constructor Summary
Constructors Modifier Constructor Description private
DigesterLoader(java.lang.Iterable<RulesModule> rulesModules)
Creates a newDigesterLoader
instance given a collection ofRulesModule
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRules(Digester digester)
Add rules to an already created Digester instance, analyzing the digester annotations in the target class.RuleSet
createRuleSet()
Creates a newRuleSet
instance based on the current configuration.org.xml.sax.Locator
getDocumentLocator()
Gets the document locator associated with our parser.org.xml.sax.ErrorHandler
getErrorHandler()
Return the error handler for this Digester.java.util.concurrent.ExecutorService
getExecutorService()
Returns the executor service used to run asynchronous parse method.java.util.Map<java.lang.String,java.net.URL>
getRegistrations()
Return the set of DTD URL registrations, keyed by public identifier.boolean
isNamespaceAware()
Return the "namespace aware" flag for parsers we create.boolean
isValidating()
Return the validating parser flag.boolean
isXIncludeAware()
Return the XInclude-aware flag for parsers we create;Digester
newDigester()
Digester
newDigester(javax.xml.parsers.SAXParser parser)
Digester
newDigester(javax.xml.parsers.SAXParser parser, Rules rules)
Digester
newDigester(Rules rules)
Digester
newDigester(org.xml.sax.XMLReader reader)
Creates a newXMLReader
instance that relies on the givenXMLReader
and the defaultRules
implementation.Digester
newDigester(org.xml.sax.XMLReader reader, Rules rules)
Creates a newXMLReader
instance that relies on the givenXMLReader
and custom user defineRules
implementation.static DigesterLoader
newLoader(java.lang.Iterable<RulesModule> rulesModules)
Creates a newDigesterLoader
instance given a collection ofRulesModule
instance.static DigesterLoader
newLoader(RulesModule... rulesModules)
Creates a newDigesterLoader
instance given one or moreRulesModule
instance.DigesterLoader
register(java.lang.String publicId, java.lang.String entityURL)
Convenience method that registers the string version of an entity URL instead of a URL version.DigesterLoader
register(java.lang.String publicId, java.net.URL entityURL)
Register the specified DTD URL for the specified public identifier.DigesterLoader
setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.DigesterLoader
setDocumentLocator(org.xml.sax.Locator locator)
Sets the document locator associated with our parser.DigesterLoader
setEntityResolver(org.xml.sax.EntityResolver entityResolver)
Set theEntityResolver
used by SAX when resolving public id and system id.DigesterLoader
setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Set the error handler for this Digester.DigesterLoader
setExecutorService(java.util.concurrent.ExecutorService executorService)
Sets the executor service to run asynchronous parse method.DigesterLoader
setNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create.DigesterLoader
setSchema(javax.xml.validation.Schema schema)
Set the XML Schema to be used when parsing.DigesterLoader
setStackAction(StackAction stackAction)
Sets the Object which will receive callbacks for every pop/push action on the default stack or named stacks.DigesterLoader
setSubstitutor(Substitutor substitutor)
Sets theSubstitutor
to be used to convert attributes and body text.DigesterLoader
setUseContextClassLoader(boolean useContextClassLoader)
Determine whether to use the Context ClassLoader (the one found by callingThread.currentThread().getContextClassLoader()
) to resolve/load classes that are defined in various rules.DigesterLoader
setValidating(boolean validating)
Set the validating parser flag.DigesterLoader
setXIncludeAware(boolean xIncludeAware)
Set the XInclude-aware flag for parsers we create.
-
-
-
Field Detail
-
HEADING
private static final java.lang.String HEADING
The default head when reporting an errors list.- See Also:
- Constant Field Values
-
rulesBinder
private final DefaultRulesBinder rulesBinder
The concreteRulesBinder
implementation.
-
entityValidator
private final java.util.Map<java.lang.String,java.net.URL> entityValidator
The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds.
-
factory
private final javax.xml.parsers.SAXParserFactory factory
The SAXParserFactory to create new defaultDigester
instances.
-
rulesModules
private final java.lang.Iterable<RulesModule> rulesModules
-
classLoader
private BinderClassLoader classLoader
The class loader to use for instantiating application objects. If not specified, the context class loader, or the class loader used to load Digester itself, is used, based on the value of theuseContextClassLoader
variable.
-
substitutor
private Substitutor substitutor
An optional class that substitutes values in attributes and body text. This may be null and so a null check is always required before use.
-
entityResolver
private org.xml.sax.EntityResolver entityResolver
The EntityResolver used by the SAX parser. By default it use this class
-
stackAction
private StackAction stackAction
Object which will receive callbacks for every pop/push action on the default stack or named stacks.
-
executorService
private java.util.concurrent.ExecutorService executorService
The executor service to run asynchronous parse method.- Since:
- 3.1
-
errorHandler
private org.xml.sax.ErrorHandler errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur.- Since:
- 3.2
-
locator
private org.xml.sax.Locator locator
The Locator associated with our parser.- Since:
- 3.2
-
-
Constructor Detail
-
DigesterLoader
private DigesterLoader(java.lang.Iterable<RulesModule> rulesModules)
Creates a newDigesterLoader
instance given a collection ofRulesModule
instance.- Parameters:
rulesModules
- The modules containing theRule
binding
-
-
Method Detail
-
newLoader
public static DigesterLoader newLoader(RulesModule... rulesModules)
Creates a newDigesterLoader
instance given one or moreRulesModule
instance.- Parameters:
rulesModules
- The modules containing theRule
binding- Returns:
- A new
DigesterLoader
instance
-
newLoader
public static DigesterLoader newLoader(java.lang.Iterable<RulesModule> rulesModules)
Creates a newDigesterLoader
instance given a collection ofRulesModule
instance.- Parameters:
rulesModules
- The modules containing theRule
binding- Returns:
- A new
DigesterLoader
instance
-
setUseContextClassLoader
public DigesterLoader setUseContextClassLoader(boolean useContextClassLoader)
Determine whether to use the Context ClassLoader (the one found by callingThread.currentThread().getContextClassLoader()
) to resolve/load classes that are defined in various rules. If not using Context ClassLoader, then the class-loading defaults to using the calling-class' ClassLoader.- Parameters:
useContextClassLoader
- determines whether to use Context ClassLoader.- Returns:
- This loader instance, useful to chain methods.
-
setClassLoader
public DigesterLoader setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.- Parameters:
classLoader
- the class loader to be used for instantiating application objects when required.- Returns:
- This loader instance, useful to chain methods.
-
setSubstitutor
public DigesterLoader setSubstitutor(Substitutor substitutor)
Sets theSubstitutor
to be used to convert attributes and body text.- Parameters:
substitutor
- the Substitutor to be used to convert attributes and body text or null if not substitution of these values is to be performed.- Returns:
- This loader instance, useful to chain methods.
-
setNamespaceAware
public DigesterLoader setNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create.- Parameters:
namespaceAware
- The new "namespace aware" flag- Returns:
- This loader instance, useful to chain methods.
-
isNamespaceAware
public boolean isNamespaceAware()
Return the "namespace aware" flag for parsers we create.- Returns:
- true, if the "namespace aware" flag for parsers we create, false otherwise.
-
setXIncludeAware
public DigesterLoader setXIncludeAware(boolean xIncludeAware)
Set the XInclude-aware flag for parsers we create. This additionally requires namespace-awareness.- Parameters:
xIncludeAware
- The new XInclude-aware flag- Returns:
- This loader instance, useful to chain methods.
- See Also:
setNamespaceAware(boolean)
-
isXIncludeAware
public boolean isXIncludeAware()
Return the XInclude-aware flag for parsers we create;- Returns:
- true, if the XInclude-aware flag for parsers we create is set, false otherwise
-
setValidating
public DigesterLoader setValidating(boolean validating)
Set the validating parser flag.- Parameters:
validating
- The new validating parser flag.- Returns:
- This loader instance, useful to chain methods.
-
isValidating
public boolean isValidating()
Return the validating parser flag.- Returns:
- true, if the validating parser flag is set, false otherwise
-
setSchema
public DigesterLoader setSchema(javax.xml.validation.Schema schema)
Set the XML Schema to be used when parsing.- Parameters:
schema
- TheSchema
instance to use.- Returns:
- This loader instance, useful to chain methods.
-
register
public DigesterLoader register(java.lang.String publicId, java.net.URL entityURL)
Register the specified DTD URL for the specified public identifier. This must be called before the first call to
parse()
.Digester
contains an internalEntityResolver
implementation. This mapsPUBLICID
's to URLs (from which the resource will be loaded). A common use case for this method is to register local URLs (possibly computed at runtime by a classloader) for DTDs. This allows the performance advantage of using a local version without having to ensure everySYSTEM
URI on every processed xml document is local. This implementation provides only basic functionality. If more sophisticated features are required, usingsetEntityResolver(EntityResolver)
to set a custom resolver is recommended.Note: This method will have no effect when a custom
EntityResolver
has been set. (Setting a customEntityResolver
overrides the internal implementation.)- Parameters:
publicId
- Public identifier of the DTD to be resolvedentityURL
- The URL to use for reading this DTD- Returns:
- This loader instance, useful to chain methods.
-
register
public DigesterLoader register(java.lang.String publicId, java.lang.String entityURL)
Convenience method that registers the string version of an entity URL instead of a URL version.
- Parameters:
publicId
- Public identifier of the entity to be resolvedentityURL
- The URL to use for reading this entity- Returns:
- This loader instance, useful to chain methods.
-
getRegistrations
public java.util.Map<java.lang.String,java.net.URL> getRegistrations()
Return the set of DTD URL registrations, keyed by public identifier.- Returns:
- the set of DTD URL registrations.
-
setEntityResolver
public DigesterLoader setEntityResolver(org.xml.sax.EntityResolver entityResolver)
Set theEntityResolver
used by SAX when resolving public id and system id. This must be called before the first call toparse()
.- Parameters:
entityResolver
- a class that implement theEntityResolver
interface.- Returns:
- This loader instance, useful to chain methods.
-
setStackAction
public DigesterLoader setStackAction(StackAction stackAction)
Sets the Object which will receive callbacks for every pop/push action on the default stack or named stacks.- Parameters:
stackAction
- the Object which will receive callbacks for every pop/push action on the default stack or named stacks.- Returns:
- This loader instance, useful to chain methods.
-
getExecutorService
public java.util.concurrent.ExecutorService getExecutorService()
Returns the executor service used to run asynchronous parse method.- Returns:
- the executor service used to run asynchronous parse method
- Since:
- 3.1
-
setExecutorService
public DigesterLoader setExecutorService(java.util.concurrent.ExecutorService executorService)
Sets the executor service to run asynchronous parse method.- Parameters:
executorService
- the executor service to run asynchronous parse method- Returns:
- This loader instance, useful to chain methods.
- Since:
- 3.1
-
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
Return the error handler for this Digester.- Returns:
- the error handler for this Digester.
- Since:
- 3.2
-
setErrorHandler
public DigesterLoader setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Set the error handler for this Digester.- Parameters:
errorHandler
- The new error handler- Returns:
- This loader instance, useful to chain methods.
- Since:
- 3.2
-
getDocumentLocator
public org.xml.sax.Locator getDocumentLocator()
Gets the document locator associated with our parser.- Returns:
- the Locator supplied by the document parser
- Since:
- 3.2
-
setDocumentLocator
public DigesterLoader setDocumentLocator(org.xml.sax.Locator locator)
Sets the document locator associated with our parser.- Parameters:
locator
- the document locator associated with our parser.- Returns:
- This loader instance, useful to chain methods.
- Since:
- 3.2
-
newDigester
public Digester newDigester(javax.xml.parsers.SAXParser parser)
Creates a newDigester
instance that relies on the givenSAXParser
and the defaultRules
implementation.- Parameters:
parser
- the user definedSAXParser
- Returns:
- a new
Digester
instance
-
newDigester
public Digester newDigester(org.xml.sax.XMLReader reader)
Creates a newXMLReader
instance that relies on the givenXMLReader
and the defaultRules
implementation.- Parameters:
reader
- The user definedXMLReader
- Returns:
- a new
Digester
instance
-
newDigester
public Digester newDigester(org.xml.sax.XMLReader reader, Rules rules)
Creates a newXMLReader
instance that relies on the givenXMLReader
and custom user defineRules
implementation.
-
addRules
public void addRules(Digester digester)
Add rules to an already created Digester instance, analyzing the digester annotations in the target class.- Parameters:
digester
- the Digester instance reference.
-
-