Class Digester
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
,DeclHandler
,EntityResolver2
,LexicalHandler
A Digester processes an XML input stream by matching a
series of element nesting patterns to execute Rules that have been added
prior to the start of parsing. This package was inspired by the
XmlMapper
class that was part of Tomcat 3.0 and 3.1,
but is organized somewhat differently.
See the Digester Developer Guide for more information.
IMPLEMENTATION NOTE - A single Digester instance may
only be used within the context of a single thread at a time, and a call
to parse()
must be completed before another can be initiated
even from the same thread.
IMPLEMENTATION NOTE - A bug in Xerces 2.0.2 prevents the support of XML schema. You need Xerces 2.1/2.3 and up to make this class working with XML schema
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Deprecated.static interface
-
Field Summary
Modifier and TypeFieldDescriptionprotected StringBuilder
The body text of the current element.protected ArrayStack<StringBuilder>
The stack of body text string buffers for surrounding elements.protected ClassLoader
The class loader to use for instantiating application objects.protected StringBuilder
Generated code.protected boolean
Has this Digester been configured yet.protected EntityResolver
The EntityResolver used by the SAX parser.The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds.protected ErrorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur.protected SAXParserFactory
The SAXParserFactory that is created the first time we need it.Fake attributes map (attributes are often used for object creation).protected Locator
The Locator associated with our parser.protected Log
The Log to which most logging calls will be made.protected String
The current match pattern for nested element processing.protected ArrayStack<List<Rule>>
Stack whose elements are List objects, each containing a list of Rule objects as returned from Rules.getMatch().protected boolean
Do we want a "namespace aware" parser.protected HashMap<String,
ArrayStack<String>> Registered namespaces we are currently processing.protected ArrayStack<Object>
The parameters stack being utilized by CallMethodRule and CallParamRule rules.protected SAXParser
The SAXParser we will use to parse the input stream.protected static IntrospectionUtils.PropertySource[]
protected String
The public identifier of the DTD we are currently parsing under (if any).protected XMLReader
The XMLReader used to parse digester rules.protected Object
The "root" element of the stack (in other words, the last object that was popped.protected Rules
TheRules
implementation containing our collection ofRule
instances and associated matching policy.protected boolean
Warn on missing attributes and elements.protected Log
The Log to which all SAX event related logging calls will be made.protected static final StringManager
protected IntrospectionUtils.PropertySource[]
protected ArrayStack<Object>
The object stack being constructed.protected boolean
Do we want to use the Context ClassLoader when loading classes for instantiating new objects.protected boolean
Do we want to use a validating parser. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCallMethod
(String pattern, String methodName) Add an "call method" rule for a method which accepts no arguments.void
addCallMethod
(String pattern, String methodName, int paramCount) Add an "call method" rule for the specified parameters.void
addCallParam
(String pattern, int paramIndex) Add a "call parameter" rule for the specified parameters.void
addFactoryCreate
(String pattern, ObjectCreationFactory creationFactory, boolean ignoreCreateExceptions) Add a "factory create" rule for the specified parameters.static void
addGeneratedClass
(String className) void
addObjectCreate
(String pattern, String className) Add an "object create" rule for the specified parameters.void
addObjectCreate
(String pattern, String className, String attributeName) Add an "object create" rule for the specified parameters.void
Register a new Rule matching the specified pattern.void
addRuleSet
(RuleSet ruleSet) Register a set of Rule instances defined in a RuleSet.void
addSetNext
(String pattern, String methodName, String paramType) Add a "set next" rule for the specified parameters.void
addSetProperties
(String pattern) Add a "set properties" rule for the specified parameters.void
addSetProperties
(String pattern, String[] excludes) void
characters
(char[] buffer, int start, int length) Process notification of character data received from the body of an XML element.void
clear()
Clear the current contents of the object stack.protected void
Provide a hook for lazy configuration of thisDigester
instance.Create a SAX exception which also understands about the location in the digester file where the exception occurscreateSAXException
(String message) Create a SAX exception which also understands about the location in the digester file where the exception occurscreateSAXException
(String message, Exception e) Create a SAX exception which also understands about the location in the digester file where the exception occursvoid
Process notification of the end of the document being reached.void
endElement
(String namespaceURI, String localName, String qName) Process notification of the end of an XML element being reached.void
void
endPrefixMapping
(String prefix) Process notification that a namespace prefix is going out of scope.void
error
(SAXParseException exception) Forward notification of a parsing error to the application supplied error handler (if any).void
fatalError
(SAXParseException exception) Forward notification of a fatal parsing error to the application supplied error handler (if any).findNamespaceURI
(String prefix) Return the currently mapped namespace URI for the specified prefix, if any; otherwise returnnull
.Return the class loader to be used for instantiating application objects when required.int
getCount()
Gets the document locator associated with our parser.Return the Entity Resolver used by the SAX parser.SAX parser factory method.static String[]
getMatch()
boolean
getProperty
(String property) Return the current value of the specified property for the underlyingXMLReader
implementation.getRoot()
When the Digester is being used as a SAXContentHandler, this method allows you to access the root object that has been created after parsing.getRules()
Return theRules
implementation object containing our rules collection and associated matching policy.boolean
Gets the logger used for logging SAX-related information.boolean
boolean
Return the XMLReader to be used for parsing the input document.void
ignorableWhitespace
(char[] buffer, int start, int len) Process notification of ignorable whitespace received from the body of an XML element.boolean
isFakeAttribute
(Object object, String name) Determine if an attribute is a fake attribute.static boolean
static Object
loadGeneratedClass
(String className) void
notationDecl
(String name, String publicId, String systemId) Receive notification of a notation declaration event.Parse the content of the specified file using this Digester.parse
(InputStream input) Parse the content of the specified input stream using this Digester.parse
(InputSource input) Parse the content of the specified input source using this Digester.peek()
Return the top object on the stack without removing it.peek
(int n) Return the n'th object down the stack, where 0 is the top element and [getCount()-1] is the bottom element.Return the top object on the parameters stack without removing it.pop()
Pop the top object off of the stack, and return it.Pop the top object off of the parameters stack, and return it.void
processingInstruction
(String target, String data) Process notification of a processing instruction that was encountered.void
Push a new object onto the top of the object stack.void
pushParams
(Object object) Push a new object onto the top of the parameters stack.void
Register the specified DTD URL for the specified public identifier.static void
void
reset()
resolveEntity
(String name, String publicId, String baseURI, String systemId) void
setClassLoader
(ClassLoader classLoader) Set the class loader to be used for instantiating application objects when required.void
setDocumentLocator
(Locator locator) Sets the document locator associated with our parser.void
setEntityResolver
(EntityResolver entityResolver) Set theEntityResolver
used by SAX when resolving public id and system id.void
setErrorHandler
(ErrorHandler errorHandler) Set the error handler for this Digester.void
setFakeAttributes
(Map<Class<?>, List<String>> fakeAttributes) Set the fake attributes.void
setFeature
(String feature, boolean value) Sets a flag indicating whether the requested feature is supported by the underlying implementation oforg.xml.sax.XMLReader
.static void
setGeneratedCodeLoader
(Digester.GeneratedCodeLoader generatedCodeLoader) void
void
Set the current logger for this Digester.void
setNamespaceAware
(boolean namespaceAware) Set the "namespace aware" flag for parsers we create.static void
setPropertySource
(IntrospectionUtils.PropertySource propertySource) static void
setPropertySource
(IntrospectionUtils.PropertySource[] propertySources) void
setPublicId
(String publicId) Set the public id of the current file being parse.void
Set theRules
implementation object containing our rules collection and associated matching policy.void
setRulesValidation
(boolean rulesValidation) Set the rules validation flag.void
setSAXLogger
(Log saxLog) Sets the logger used for logging SAX-related information.void
setUseContextClassLoader
(boolean use) Determine whether to use the Context ClassLoader (the one found by callingThread.currentThread().getContextClassLoader()
) to resolve/load classes that are defined in various rules.void
setValidating
(boolean validating) Set the validating parser flag.void
skippedEntity
(String name) Process notification of a skipped entity.void
Process notification of the beginning of the document being reached.void
void
startElement
(String namespaceURI, String localName, String qName, Attributes list) Process notification of the start of an XML element being reached.void
void
startPrefixMapping
(String prefix, String namespaceURI) Process notification that a namespace prefix is coming in to scope.toVariableName
(Object object) void
unparsedEntityDecl
(String name, String publicId, String systemId, String notation) Receive notification of an unparsed entity declaration event.void
warning
(SAXParseException exception) Forward notification of a parse warning to the application supplied error handler (if any).Methods inherited from class org.xml.sax.ext.DefaultHandler2
attributeDecl, comment, elementDecl, endCDATA, endDTD, endEntity, externalEntityDecl, getExternalSubset, internalEntityDecl, resolveEntity, startCDATA, startEntity
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
propertySources
-
sm
-
source
-
bodyText
The body text of the current element. -
bodyTexts
The stack of body text string buffers for surrounding elements. -
matches
Stack whose elements are List objects, each containing a list of Rule objects as returned from Rules.getMatch(). As each xml element in the input is entered, the matching rules are pushed onto this stack. After the end tag is reached, the matches are popped again. The depth of is stack is therefore exactly the same as the current "nesting" level of the input xml.- Since:
- 1.6
-
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. -
configured
protected boolean configuredHas this Digester been configured yet. -
entityResolver
The EntityResolver used by the SAX parser. By default it use this class -
entityValidator
The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds. -
errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur. -
factory
The SAXParserFactory that is created the first time we need it. -
locator
The Locator associated with our parser. -
match
The current match pattern for nested element processing. -
namespaceAware
protected boolean namespaceAwareDo we want a "namespace aware" parser. -
namespaces
Registered namespaces we are currently processing. The key is the namespace prefix that was declared in the document. The value is an ArrayStack of the namespace URIs this prefix has been mapped to -- the top Stack element is the most current one. (This architecture is required because documents can declare nested uses of the same prefix for different Namespace URIs). -
params
The parameters stack being utilized by CallMethodRule and CallParamRule rules. -
parser
The SAXParser we will use to parse the input stream. -
publicId
The public identifier of the DTD we are currently parsing under (if any). -
reader
The XMLReader used to parse digester rules. -
root
The "root" element of the stack (in other words, the last object that was popped. -
rules
TheRules
implementation containing our collection ofRule
instances and associated matching policy. If not established before the first rule is added, a default implementation will be provided. -
stack
The object stack being constructed. -
useContextClassLoader
protected boolean useContextClassLoaderDo we want to use the Context ClassLoader when loading classes for instantiating new objects. Default isfalse
. -
validating
protected boolean validatingDo we want to use a validating parser. -
rulesValidation
protected boolean rulesValidationWarn on missing attributes and elements. -
fakeAttributes
Fake attributes map (attributes are often used for object creation). -
log
The Log to which most logging calls will be made. -
saxLog
The Log to which all SAX event related logging calls will be made. -
code
Generated code. -
known
-
-
Constructor Details
-
Digester
public Digester()
-
-
Method Details
-
setPropertySource
-
setPropertySource
-
addGeneratedClass
-
getGeneratedClasses
-
isGeneratedCodeLoaderSet
public static boolean isGeneratedCodeLoaderSet() -
setGeneratedCodeLoader
-
loadGeneratedClass
-
replaceSystemProperties
public static void replaceSystemProperties() -
startGeneratingCode
public void startGeneratingCode() -
endGeneratingCode
public void endGeneratingCode() -
getGeneratedCode
-
setKnown
-
toVariableName
-
findNamespaceURI
Return the currently mapped namespace URI for the specified prefix, if any; otherwise returnnull
. These mappings come and go dynamically as the document is parsed.- Parameters:
prefix
- Prefix to look up- Returns:
- the namespace URI
-
getClassLoader
Return the class loader to be used for instantiating application objects when required. This is determined based upon the following rules:- The class loader set by
setClassLoader()
, if any - The thread context class loader, if it exists and the
useContextClassLoader
property is set to true - The class loader used to load the Digester class itself.
- Returns:
- the classloader
- The class loader set by
-
setClassLoader
Set the class loader to be used for instantiating application objects when required.- Parameters:
classLoader
- The new class loader to use, ornull
to revert to the standard rules
-
getCount
public int getCount()- Returns:
- the current depth of the element stack.
-
getCurrentElementName
- Returns:
- the name of the XML element that is currently being processed.
-
getErrorHandler
- Returns:
- the error handler for this Digester.
-
setErrorHandler
Set the error handler for this Digester.- Parameters:
errorHandler
- The new error handler
-
getFactory
public SAXParserFactory getFactory() throws SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationExceptionSAX parser factory method.- Returns:
- the SAXParserFactory we will use, creating one if necessary.
- Throws:
ParserConfigurationException
- Error creating parserSAXNotSupportedException
- Error creating parserSAXNotRecognizedException
- Error creating parser
-
setFeature
public void setFeature(String feature, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException Sets a flag indicating whether the requested feature is supported by the underlying implementation oforg.xml.sax.XMLReader
. See http://www.saxproject.org/apidoc/xml/sax/package-summary.html#package-description for information about the standard SAX2 feature flags. In order to be effective, this method must be called before thegetParser()
method is called for the first time, either directly or indirectly.- Parameters:
feature
- Name of the feature to set the status forvalue
- The new value for this feature- Throws:
ParserConfigurationException
- if a parser configuration error occursSAXNotRecognizedException
- if the property name is not recognizedSAXNotSupportedException
- if the property name is recognized but not supported
-
getLogger
- Returns:
- the current Logger associated with this instance of the Digester
-
setLogger
Set the current logger for this Digester.- Parameters:
log
- The logger that will be used
-
getSAXLogger
Gets the logger used for logging SAX-related information. Note the output is finely grained.- Returns:
- the SAX logger
- Since:
- 1.6
-
setSAXLogger
Sets the logger used for logging SAX-related information. Note the output is finely grained.- Parameters:
saxLog
- Log, not null- Since:
- 1.6
-
getMatch
- Returns:
- the current rule match path
-
getNamespaceAware
public boolean getNamespaceAware()- Returns:
- the "namespace aware" flag for parsers we create.
-
setNamespaceAware
public void setNamespaceAware(boolean namespaceAware) Set the "namespace aware" flag for parsers we create.- Parameters:
namespaceAware
- The new "namespace aware" flag
-
setPublicId
Set the public id of the current file being parse.- Parameters:
publicId
- the DTD/Schema public's id.
-
getPublicId
- Returns:
- the public identifier of the DTD we are currently parsing under, if any.
-
getParser
- Returns:
- the SAXParser we will use to parse the input stream. If there
is a problem creating the parser, return
null
.
-
getProperty
public Object getProperty(String property) throws SAXNotRecognizedException, SAXNotSupportedException Return the current value of the specified property for the underlyingXMLReader
implementation. See http://www.saxproject.org/apidoc/xml/sax/package-summary.html#package-description for information about the standard SAX2 properties.- Parameters:
property
- Property name to be retrieved- Returns:
- the property value
- Throws:
SAXNotRecognizedException
- if the property name is not recognizedSAXNotSupportedException
- if the property name is recognized but not supported
-
getRules
Return theRules
implementation object containing our rules collection and associated matching policy. If none has been established, a default implementation will be created and returned.- Returns:
- the rules
-
setRules
Set theRules
implementation object containing our rules collection and associated matching policy.- Parameters:
rules
- New Rules implementation
-
getUseContextClassLoader
public boolean getUseContextClassLoader()- Returns:
- the boolean as to whether the context classloader should be used.
-
setUseContextClassLoader
public void setUseContextClassLoader(boolean use) 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:
use
- determines whether to use Context ClassLoader.
-
getValidating
public boolean getValidating()- Returns:
- the validating parser flag.
-
setValidating
public void setValidating(boolean validating) Set the validating parser flag. This must be called beforeparse()
is called the first time.- Parameters:
validating
- The new validating parser flag.
-
getRulesValidation
public boolean getRulesValidation()- Returns:
- the rules validation flag.
-
setRulesValidation
public void setRulesValidation(boolean rulesValidation) Set the rules validation flag. This must be called beforeparse()
is called the first time.- Parameters:
rulesValidation
- The new rules validation flag.
-
getFakeAttributes
- Returns:
- the fake attributes list.
-
isFakeAttribute
Determine if an attribute is a fake attribute.- Parameters:
object
- The objectname
- The attribute name- Returns:
true
if this is a fake attribute
-
setFakeAttributes
Set the fake attributes.- Parameters:
fakeAttributes
- The new fake attributes.
-
getXMLReader
Return the XMLReader to be used for parsing the input document. FIX ME: there is a bug in JAXP/XERCES that prevent the use of a parser that contains a schema with a DTD.- Returns:
- the XML reader
- Throws:
SAXException
- if no XMLReader can be instantiated
-
characters
Process notification of character data received from the body of an XML element.- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Parameters:
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlength
- Number of characters from the buffer- Throws:
SAXException
- if a parsing error is to be reported
-
endDocument
Process notification of the end of the document being reached.- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in classDefaultHandler
- Throws:
SAXException
- if a parsing error is to be reported
-
endElement
Process notification of the end of an XML element being reached.- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Parameters:
namespaceURI
- - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.localName
- - The local name (without prefix), or the empty string if Namespace processing is not being performed.qName
- - The qualified XML 1.0 name (with prefix), or the empty string if qualified names are not available.- Throws:
SAXException
- if a parsing error is to be reported
-
endPrefixMapping
Process notification that a namespace prefix is going out of scope.- Specified by:
endPrefixMapping
in interfaceContentHandler
- Overrides:
endPrefixMapping
in classDefaultHandler
- Parameters:
prefix
- Prefix that is going out of scope- Throws:
SAXException
- if a parsing error is to be reported
-
ignorableWhitespace
Process notification of ignorable whitespace received from the body of an XML element.- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Overrides:
ignorableWhitespace
in classDefaultHandler
- Parameters:
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlen
- Number of characters from the buffer- Throws:
SAXException
- if a parsing error is to be reported
-
processingInstruction
Process notification of a processing instruction that was encountered.- Specified by:
processingInstruction
in interfaceContentHandler
- Overrides:
processingInstruction
in classDefaultHandler
- Parameters:
target
- The processing instruction targetdata
- The processing instruction data (if any)- Throws:
SAXException
- if a parsing error is to be reported
-
getDocumentLocator
Gets the document locator associated with our parser.- Returns:
- the Locator supplied by the document parser
-
setDocumentLocator
Sets the document locator associated with our parser.- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classDefaultHandler
- Parameters:
locator
- The new locator
-
skippedEntity
Process notification of a skipped entity.- Specified by:
skippedEntity
in interfaceContentHandler
- Overrides:
skippedEntity
in classDefaultHandler
- Parameters:
name
- Name of the skipped entity- Throws:
SAXException
- if a parsing error is to be reported
-
startDocument
Process notification of the beginning of the document being reached.- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classDefaultHandler
- Throws:
SAXException
- if a parsing error is to be reported
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXException Process notification of the start of an XML element being reached.- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Parameters:
namespaceURI
- The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.localName
- The local name (without prefix), or the empty string if Namespace processing is not being performed.qName
- The qualified name (with prefix), or the empty string if qualified names are not available.\list
- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.- Throws:
SAXException
- if a parsing error is to be reported
-
startPrefixMapping
Process notification that a namespace prefix is coming in to scope.- Specified by:
startPrefixMapping
in interfaceContentHandler
- Overrides:
startPrefixMapping
in classDefaultHandler
- Parameters:
prefix
- Prefix that is being declarednamespaceURI
- Corresponding namespace URI being mapped to- Throws:
SAXException
- if a parsing error is to be reported
-
notationDecl
Receive notification of a notation declaration event.- Specified by:
notationDecl
in interfaceDTDHandler
- Overrides:
notationDecl
in classDefaultHandler
- Parameters:
name
- The notation namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)
-
unparsedEntityDecl
Receive notification of an unparsed entity declaration event.- Specified by:
unparsedEntityDecl
in interfaceDTDHandler
- Overrides:
unparsedEntityDecl
in classDefaultHandler
- Parameters:
name
- The unparsed entity namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)notation
- The name of the associated notation
-
setEntityResolver
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.
-
getEntityResolver
Return the Entity Resolver used by the SAX parser.- Returns:
- Return the Entity Resolver used by the SAX parser.
-
resolveEntity
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException - Specified by:
resolveEntity
in interfaceEntityResolver2
- Overrides:
resolveEntity
in classDefaultHandler2
- Throws:
SAXException
IOException
-
startDTD
- Specified by:
startDTD
in interfaceLexicalHandler
- Overrides:
startDTD
in classDefaultHandler2
- Throws:
SAXException
-
error
Forward notification of a parsing error to the application supplied error handler (if any).- Specified by:
error
in interfaceErrorHandler
- Overrides:
error
in classDefaultHandler
- Parameters:
exception
- The error information- Throws:
SAXException
- if a parsing exception occurs
-
fatalError
Forward notification of a fatal parsing error to the application supplied error handler (if any).- Specified by:
fatalError
in interfaceErrorHandler
- Overrides:
fatalError
in classDefaultHandler
- Parameters:
exception
- The fatal error information- Throws:
SAXException
- if a parsing exception occurs
-
warning
Forward notification of a parse warning to the application supplied error handler (if any).- Specified by:
warning
in interfaceErrorHandler
- Overrides:
warning
in classDefaultHandler
- Parameters:
exception
- The warning information- Throws:
SAXException
- if a parsing exception occurs
-
parse
Parse the content of the specified file using this Digester. Returns the root element from the object stack (if any).- Parameters:
file
- File containing the XML data to be parsed- Returns:
- the root object
- Throws:
IOException
- if an input/output error occursSAXException
- if a parsing exception occurs
-
parse
Parse the content of the specified input source using this Digester. Returns the root element from the object stack (if any).- Parameters:
input
- Input source containing the XML data to be parsed- Returns:
- the root object
- Throws:
IOException
- if an input/output error occursSAXException
- if a parsing exception occurs
-
parse
Parse the content of the specified input stream using this Digester. Returns the root element from the object stack (if any).- Parameters:
input
- Input stream containing the XML data to be parsed- Returns:
- the root object
- Throws:
IOException
- if an input/output error occursSAXException
- if a parsing exception occurs
-
register
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(org.xml.sax.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
-
addRule
Register a new Rule matching the specified pattern. This method sets the
Digester
property on the rule.- Parameters:
pattern
- Element matching patternrule
- Rule to be registered
-
addRuleSet
Register a set of Rule instances defined in a RuleSet.- Parameters:
ruleSet
- The RuleSet instance to configure from
-
addCallMethod
Add an "call method" rule for a method which accepts no arguments.- Parameters:
pattern
- Element matching patternmethodName
- Method name to be called- See Also:
-
addCallMethod
Add an "call method" rule for the specified parameters.- Parameters:
pattern
- Element matching patternmethodName
- Method name to be calledparamCount
- Number of expected parameters (or zero for a single parameter from the body of this element)- See Also:
-
addCallParam
Add a "call parameter" rule for the specified parameters.- Parameters:
pattern
- Element matching patternparamIndex
- Zero-relative parameter index to set (from the body of this element)- See Also:
-
addFactoryCreate
public void addFactoryCreate(String pattern, ObjectCreationFactory creationFactory, boolean ignoreCreateExceptions) Add a "factory create" rule for the specified parameters.- Parameters:
pattern
- Element matching patterncreationFactory
- Previously instantiated ObjectCreationFactory to be utilizedignoreCreateExceptions
- whentrue
any exceptions thrown during object creation will be ignored.- See Also:
-
addObjectCreate
Add an "object create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternclassName
- Java class name to be created- See Also:
-
addObjectCreate
Add an "object create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternclassName
- Default Java class name to be createdattributeName
- Attribute name that optionally overrides the default Java class name to be created- See Also:
-
addSetNext
Add a "set next" rule for the specified parameters.- Parameters:
pattern
- Element matching patternmethodName
- Method name to call on the parent elementparamType
- Java class name of the expected parameter type (if you wish to use a primitive type, specify the corresponding Java wrapper class instead, such asjava.lang.Boolean
for aboolean
parameter)- See Also:
-
addSetProperties
Add a "set properties" rule for the specified parameters.- Parameters:
pattern
- Element matching pattern- See Also:
-
addSetProperties
-
clear
public void clear()Clear the current contents of the object stack.Calling this method might allow another document of the same type to be correctly parsed. However this method was not intended for this purpose. In general, a separate Digester object should be created for each document to be parsed.
-
reset
public void reset() -
peek
Return the top object on the stack without removing it. If there are no objects on the stack, returnnull
.- Returns:
- the top object
-
peek
Return the n'th object down the stack, where 0 is the top element and [getCount()-1] is the bottom element. If the specified index is out of range, returnnull
.- Parameters:
n
- Index of the desired element, where 0 is the top of the stack, 1 is the next element down, and so on.- Returns:
- the specified object
-
pop
Pop the top object off of the stack, and return it. If there are no objects on the stack, returnnull
.- Returns:
- the top object
-
push
Push a new object onto the top of the object stack.- Parameters:
object
- The new object
-
getRoot
When the Digester is being used as a SAXContentHandler, this method allows you to access the root object that has been created after parsing.- Returns:
- the root object that has been created after parsing or null if the digester has not parsed any XML yet.
-
configure
protected void configure()Provide a hook for lazy configuration of this
Digester
instance. The default implementation does nothing, but subclasses can override as needed.Note This method may be called more than once.
-
peekParams
Return the top object on the parameters stack without removing it. If there are no objects on the stack, return
null
.The parameters stack is used to store
CallMethodRule
parameters. Seeparams
.- Returns:
- the top object on the parameters stack
-
popParams
Pop the top object off of the parameters stack, and return it. If there are no objects on the stack, return
null
.The parameters stack is used to store
CallMethodRule
parameters. Seeparams
.- Returns:
- the top object on the parameters stack
-
pushParams
Push a new object onto the top of the parameters stack.
The parameters stack is used to store
CallMethodRule
parameters. Seeparams
.- Parameters:
object
- The new object
-
createSAXException
Create a SAX exception which also understands about the location in the digester file where the exception occurs- Parameters:
message
- The error messagee
- The root cause- Returns:
- the new exception
-
createSAXException
Create a SAX exception which also understands about the location in the digester file where the exception occurs- Parameters:
e
- The root cause- Returns:
- the new exception
-
createSAXException
Create a SAX exception which also understands about the location in the digester file where the exception occurs- Parameters:
message
- The error message- Returns:
- the new exception
-
EnvironmentPropertySource
This will be removed in Tomcat 10 onwards.