Class Digester
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.apache.commons.digester.Digester
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler
,org.xml.sax.DTDHandler
,org.xml.sax.EntityResolver
,org.xml.sax.ErrorHandler
public class Digester extends org.xml.sax.helpers.DefaultHandler
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
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringBuffer
bodyText
The body text of the current element.protected org.apache.commons.collections.ArrayStack
bodyTexts
The stack of body text string buffers for surrounding elements.protected java.lang.ClassLoader
classLoader
The class loader to use for instantiating application objects.protected boolean
configured
Has this Digester been configured yet.private org.xml.sax.ContentHandler
customContentHandler
If not null, then calls by the parser to this object's characters, startElement, endElement and processingInstruction methods are forwarded to the specified object.protected org.xml.sax.EntityResolver
entityResolver
The EntityResolver used by the SAX parser.protected java.util.HashMap
entityValidator
The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds.protected org.xml.sax.ErrorHandler
errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur.protected javax.xml.parsers.SAXParserFactory
factory
The SAXParserFactory that is created the first time we need it.protected java.lang.String
JAXP_SCHEMA_LANGUAGE
Deprecated.This is now managed byParserFeatureSetterFactory
protected org.xml.sax.Locator
locator
The Locator associated with our parser.protected org.apache.commons.logging.Log
log
The Log to which most logging calls will be made.protected java.lang.String
match
The current match pattern for nested element processing.protected org.apache.commons.collections.ArrayStack
matches
Stack whose elements are List objects, each containing a list of Rule objects as returned from Rules.getMatch().protected boolean
namespaceAware
Do we want a "namespace aware" parser.protected java.util.HashMap
namespaces
Registered namespaces we are currently processing.protected org.apache.commons.collections.ArrayStack
params
The parameters stack being utilized by CallMethodRule and CallParamRule rules.protected javax.xml.parsers.SAXParser
parser
The SAXParser we will use to parse the input stream.protected java.lang.String
publicId
The public identifier of the DTD we are currently parsing under (if any).protected org.xml.sax.XMLReader
reader
The XMLReader used to parse digester rules.protected java.lang.Object
root
The "root" element of the stack (in other words, the last object that was popped.protected Rules
rules
TheRules
implementation containing our collection ofRule
instances and associated matching policy.protected org.apache.commons.logging.Log
saxLog
The Log to which all SAX event related logging calls will be made.protected java.lang.String
schemaLanguage
The XML schema language to use for validating an XML instance.protected java.lang.String
schemaLocation
The XML schema to use for validating an XML instance.protected org.apache.commons.collections.ArrayStack
stack
The object stack being constructed.private java.util.HashMap
stacksByName
Stacks used for interrule communication, indexed by name Stringprotected Substitutor
substitutor
An optional class that substitutes values in attributes and body text.protected boolean
useContextClassLoader
Do we want to use the Context ClassLoader when loading classes for instantiating new objects.protected boolean
validating
Do we want to use a validating parser.protected static java.lang.String
W3C_XML_SCHEMA
The schema language supported.
-
Constructor Summary
Constructors Constructor Description Digester()
Construct a new Digester with default properties.Digester(javax.xml.parsers.SAXParser parser)
Construct a new Digester, allowing a SAXParser to be passed in.Digester(org.xml.sax.XMLReader reader)
Construct a new Digester, allowing an XMLReader to be passed in.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addBeanPropertySetter(java.lang.String pattern)
Add a "bean property setter" rule for the specified parameters.void
addBeanPropertySetter(java.lang.String pattern, java.lang.String propertyName)
Add a "bean property setter" rule for the specified parameters.void
addCallMethod(java.lang.String pattern, java.lang.String methodName)
Add an "call method" rule for a method which accepts no arguments.void
addCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount)
Add an "call method" rule for the specified parameters.void
addCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount, java.lang.Class[] paramTypes)
Add an "call method" rule for the specified parameters.void
addCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount, java.lang.String[] paramTypes)
Add an "call method" rule for the specified parameters.void
addCallParam(java.lang.String pattern, int paramIndex)
Add a "call parameter" rule for the specified parameters.void
addCallParam(java.lang.String pattern, int paramIndex, boolean fromStack)
Add a "call parameter" rule.void
addCallParam(java.lang.String pattern, int paramIndex, int stackIndex)
Add a "call parameter" rule that sets a parameter from the stack.void
addCallParam(java.lang.String pattern, int paramIndex, java.lang.String attributeName)
Add a "call parameter" rule for the specified parameters.void
addCallParamPath(java.lang.String pattern, int paramIndex)
Add a "call parameter" rule that sets a parameter from the currentDigester
matching path.void
addFactoryCreate(java.lang.String pattern, java.lang.Class clazz)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, java.lang.Class clazz, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, java.lang.Class clazz, java.lang.String attributeName)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, java.lang.Class clazz, java.lang.String attributeName, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, java.lang.String className)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, java.lang.String className, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, ObjectCreationFactory creationFactory)
Add a "factory create" rule for the specified parameters.void
addFactoryCreate(java.lang.String pattern, ObjectCreationFactory creationFactory, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.void
addObjectCreate(java.lang.String pattern, java.lang.Class clazz)
Add an "object create" rule for the specified parameters.void
addObjectCreate(java.lang.String pattern, java.lang.String className)
Add an "object create" rule for the specified parameters.void
addObjectCreate(java.lang.String pattern, java.lang.String attributeName, java.lang.Class clazz)
Add an "object create" rule for the specified parameters.void
addObjectCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName)
Add an "object create" rule for the specified parameters.void
addObjectParam(java.lang.String pattern, int paramIndex, java.lang.Object paramObj)
Add a "call parameter" rule that sets a parameter from a caller-provided object.void
addRule(java.lang.String pattern, Rule rule)
Register a new Rule matching the specified pattern.void
addRuleSet(RuleSet ruleSet)
Register a set of Rule instances defined in a RuleSet.void
addSetNestedProperties(java.lang.String pattern)
Adds anSetNestedPropertiesRule
.void
addSetNestedProperties(java.lang.String pattern, java.lang.String[] elementNames, java.lang.String[] propertyNames)
Adds anSetNestedPropertiesRule
.void
addSetNestedProperties(java.lang.String pattern, java.lang.String elementName, java.lang.String propertyName)
Adds anSetNestedPropertiesRule
.void
addSetNext(java.lang.String pattern, java.lang.String methodName)
Add a "set next" rule for the specified parameters.void
addSetNext(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
Add a "set next" rule for the specified parameters.void
addSetProperties(java.lang.String pattern)
Add a "set properties" rule for the specified parameters.void
addSetProperties(java.lang.String pattern, java.lang.String[] attributeNames, java.lang.String[] propertyNames)
Add a "set properties" rule with overridden parameters.void
addSetProperties(java.lang.String pattern, java.lang.String attributeName, java.lang.String propertyName)
Add a "set properties" rule with a single overridden parameter.void
addSetProperty(java.lang.String pattern, java.lang.String name, java.lang.String value)
Add a "set property" rule for the specified parameters.void
addSetRoot(java.lang.String pattern, java.lang.String methodName)
AddSetRootRule
with the specified parameters.void
addSetRoot(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
AddSetRootRule
with the specified parameters.void
addSetTop(java.lang.String pattern, java.lang.String methodName)
Add a "set top" rule for the specified parameters.void
addSetTop(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
Add a "set top" rule for the specified parameters.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
configure()
Provide a hook for lazy configuration of thisDigester
instance.org.xml.sax.SAXException
createSAXException(java.lang.Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occursorg.xml.sax.SAXException
createSAXException(java.lang.String message)
Create a SAX exception which also understands about the location in the digester file where the exception occursorg.xml.sax.SAXException
createSAXException(java.lang.String message, java.lang.Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occursvoid
endDocument()
Process notification of the end of the document being reached.void
endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
Process notification of the end of an XML element being reached.void
endPrefixMapping(java.lang.String prefix)
Process notification that a namespace prefix is going out of scope.void
error(org.xml.sax.SAXParseException exception)
Forward notification of a parsing error to the application supplied error handler (if any).void
fatalError(org.xml.sax.SAXParseException exception)
Forward notification of a fatal parsing error to the application supplied error handler (if any).java.lang.String
findNamespaceURI(java.lang.String prefix)
Return the currently mapped namespace URI for the specified prefix, if any; otherwise returnnull
.java.lang.ClassLoader
getClassLoader()
Return the class loader to be used for instantiating application objects when required.int
getCount()
Return the current depth of the element stack.java.lang.String
getCurrentElementName()
Return the name of the XML element that is currently being processed.org.xml.sax.ContentHandler
getCustomContentHandler()
int
getDebug()
Deprecated.This method now always returns 0.org.xml.sax.Locator
getDocumentLocator()
Gets the document locator associated with our parser.org.xml.sax.EntityResolver
getEntityResolver()
Return the Entity Resolver used by the SAX parser.org.xml.sax.ErrorHandler
getErrorHandler()
Return the error handler for this Digester.javax.xml.parsers.SAXParserFactory
getFactory()
Return the SAXParserFactory we will use, creating one if necessary.boolean
getFeature(java.lang.String feature)
Returns a flag indicating whether the requested feature is supported by the underlying implementation oforg.xml.sax.XMLReader
.org.apache.commons.logging.Log
getLogger()
Return the current Logger associated with this instance of the Digesterjava.lang.String
getMatch()
Return the current rule match pathboolean
getNamespaceAware()
Return the "namespace aware" flag for parsers we create.javax.xml.parsers.SAXParser
getParser()
Return the SAXParser we will use to parse the input stream.java.lang.Object
getProperty(java.lang.String property)
Return the current value of the specified property for the underlyingXMLReader
implementation.java.lang.String
getPublicId()
Return the public identifier of the DTD we are currently parsing under, if any.org.xml.sax.XMLReader
getReader()
Deprecated.Use getXMLReader() instead, which can throw a SAXException if the reader cannot be instantiated(package private) java.util.Map
getRegistrations()
Return the set of DTD URL registrations, keyed by public identifier.java.lang.Object
getRoot()
Returns the root element of the tree of objects created as a result of applying the rule objects to the input XML.java.lang.String
getRuleNamespaceURI()
Return the namespace URI that will be applied to all subsequently addedRule
objects.Rules
getRules()
Return theRules
implementation object containing our rules collection and associated matching policy.(package private) java.util.List
getRules(java.lang.String match)
Deprecated.Callmatch()
on theRules
implementation returned bygetRules()
org.apache.commons.logging.Log
getSAXLogger()
Gets the logger used for logging SAX-related information.java.lang.String
getSchema()
Return the XML Schema URI used for validating an XML instance.java.lang.String
getSchemaLanguage()
Return the XML Schema language used when parsing.Substitutor
getSubstitutor()
Gets theSubstitutor
used to convert attributes and body text.boolean
getUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.boolean
getValidating()
Return the validating parser flag.org.xml.sax.XMLReader
getXMLReader()
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.protected void
initialize()
Provides a hook for lazy initialization of thisDigester
instance.boolean
isEmpty(java.lang.String stackName)
Is the stack with the given name empty?void
log(java.lang.String message)
Deprecated.Call getLogger() and use it's logging methodsvoid
log(java.lang.String message, java.lang.Throwable exception)
Deprecated.Call getLogger() and use it's logging methodsvoid
notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
Receive notification of a notation declaration event.java.lang.Object
parse(java.io.File file)
Parse the content of the specified file using this Digester.java.lang.Object
parse(java.io.InputStream input)
Parse the content of the specified input stream using this Digester.java.lang.Object
parse(java.io.Reader reader)
Parse the content of the specified reader using this Digester.java.lang.Object
parse(java.lang.String uri)
Parse the content of the specified URI using this Digester.java.lang.Object
parse(org.xml.sax.InputSource input)
Parse the content of the specified input source using this Digester.java.lang.Object
peek()
Return the top object on the stack without removing it.java.lang.Object
peek(int n)
Return the n'th object down the stack, where 0 is the top element and [getCount()-1] is the bottom element.java.lang.Object
peek(java.lang.String stackName)
Gets the top object from the stack with the given name.java.lang.Object
peek(java.lang.String stackName, int n)
Gets the top object from the stack with the given name.java.lang.Object
peekParams()
Return the top object on the parameters stack without removing it.java.lang.Object
peekParams(int n)
Return the n'th object down the parameters stack, where 0 is the top element and [getCount()-1] is the bottom element.java.lang.Object
pop()
Pop the top object off of the stack, and return it.java.lang.Object
pop(java.lang.String stackName)
Pops (gets and removes) the top object from the stack with the given name.java.lang.Object
popParams()
Pop the top object off of the parameters stack, and return it.void
processingInstruction(java.lang.String target, java.lang.String data)
Process notification of a processing instruction that was encountered.void
push(java.lang.Object object)
Push a new object onto the top of the object stack.void
push(java.lang.String stackName, java.lang.Object value)
Pushes the given object onto the stack with the given name.void
pushParams(java.lang.Object object)
Push a new object onto the top of the parameters stack.void
register(java.lang.String publicId, java.lang.String entityURL)
Register the specified DTD URL for the specified public identifier.void
resetRoot()
This method allows the "root" variable to be reset to null.org.xml.sax.InputSource
resolveEntity(java.lang.String publicId, java.lang.String systemId)
Resolve the requested external entity.void
setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.void
setCustomContentHandler(org.xml.sax.ContentHandler handler)
Redirects (or cancels redirecting) of SAX ContentHandler events to an external object.void
setDebug(int debug)
Deprecated.This method now has no effect at all.void
setDocumentLocator(org.xml.sax.Locator locator)
Sets the document locator associated with our parser.void
setEntityResolver(org.xml.sax.EntityResolver entityResolver)
Set theEntityResolver
used by SAX when resolving public id and system id.void
setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Set the error handler for this Digester.void
setFeature(java.lang.String feature, boolean value)
Sets a flag indicating whether the requested feature is supported by the underlying implementation oforg.xml.sax.XMLReader
.void
setLogger(org.apache.commons.logging.Log log)
Set the current logger for this Digester.void
setNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create.void
setProperty(java.lang.String property, java.lang.Object value)
Set the current value of the specified property for the underlyingXMLReader
implementation.void
setPublicId(java.lang.String publicId)
Set the publid id of the current file being parse.void
setRuleNamespaceURI(java.lang.String ruleNamespaceURI)
Set the namespace URI that will be applied to all subsequently addedRule
objects.void
setRules(Rules rules)
Set theRules
implementation object containing our rules collection and associated matching policy.void
setSAXLogger(org.apache.commons.logging.Log saxLog)
Sets the logger used for logging SAX-related information.void
setSchema(java.lang.String schemaLocation)
Set the XML Schema URI used for validating a XML Instance.void
setSchemaLanguage(java.lang.String schemaLanguage)
Set the XML Schema language used when parsing.void
setSubstitutor(Substitutor substitutor)
Sets theSubstitutor
to be used to convert attributes and body text.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(java.lang.String name)
Process notification of a skipped entity.void
startDocument()
Process notification of the beginning of the document being reached.void
startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes list)
Process notification of the start of an XML element being reached.void
startPrefixMapping(java.lang.String prefix, java.lang.String namespaceURI)
Process notification that a namespace prefix is coming in to scope.void
unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notation)
Receive notification of an unparsed entity declaration event.void
warning(org.xml.sax.SAXParseException exception)
Forward notification of a parse warning to the application supplied error handler (if any).
-
-
-
Field Detail
-
bodyText
protected java.lang.StringBuffer bodyText
The body text of the current element.
-
bodyTexts
protected org.apache.commons.collections.ArrayStack bodyTexts
The stack of body text string buffers for surrounding elements.
-
matches
protected org.apache.commons.collections.ArrayStack 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
protected java.lang.ClassLoader 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 configured
Has this Digester been configured yet.
-
entityResolver
protected org.xml.sax.EntityResolver entityResolver
The EntityResolver used by the SAX parser. By default it use this class
-
entityValidator
protected java.util.HashMap entityValidator
The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds.
-
errorHandler
protected org.xml.sax.ErrorHandler errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur.
-
factory
protected javax.xml.parsers.SAXParserFactory factory
The SAXParserFactory that is created the first time we need it.
-
JAXP_SCHEMA_LANGUAGE
protected java.lang.String JAXP_SCHEMA_LANGUAGE
Deprecated.This is now managed byParserFeatureSetterFactory
-
locator
protected org.xml.sax.Locator locator
The Locator associated with our parser.
-
match
protected java.lang.String match
The current match pattern for nested element processing.
-
namespaceAware
protected boolean namespaceAware
Do we want a "namespace aware" parser.
-
namespaces
protected java.util.HashMap 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
protected org.apache.commons.collections.ArrayStack params
The parameters stack being utilized by CallMethodRule and CallParamRule rules.
-
parser
protected javax.xml.parsers.SAXParser parser
The SAXParser we will use to parse the input stream.
-
publicId
protected java.lang.String publicId
The public identifier of the DTD we are currently parsing under (if any).
-
reader
protected org.xml.sax.XMLReader reader
The XMLReader used to parse digester rules.
-
root
protected java.lang.Object root
The "root" element of the stack (in other words, the last object that was popped.
-
rules
protected Rules 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.
-
schemaLanguage
protected java.lang.String schemaLanguage
The XML schema language to use for validating an XML instance. By default this value is set toW3C_XML_SCHEMA
-
schemaLocation
protected java.lang.String schemaLocation
The XML schema to use for validating an XML instance.
-
stack
protected org.apache.commons.collections.ArrayStack stack
The object stack being constructed.
-
useContextClassLoader
protected boolean useContextClassLoader
Do we want to use the Context ClassLoader when loading classes for instantiating new objects. Default isfalse
.
-
validating
protected boolean validating
Do we want to use a validating parser.
-
log
protected org.apache.commons.logging.Log log
The Log to which most logging calls will be made.
-
saxLog
protected org.apache.commons.logging.Log saxLog
The Log to which all SAX event related logging calls will be made.
-
W3C_XML_SCHEMA
protected static final java.lang.String W3C_XML_SCHEMA
The schema language supported. By default, we use this one.- See Also:
- Constant Field Values
-
substitutor
protected 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.
-
stacksByName
private java.util.HashMap stacksByName
Stacks used for interrule communication, indexed by name String
-
customContentHandler
private org.xml.sax.ContentHandler customContentHandler
If not null, then calls by the parser to this object's characters, startElement, endElement and processingInstruction methods are forwarded to the specified object. This is intended to allow rules to temporarily "take control" of the sax events. In particular, this is used by NodeCreateRule.See setCustomContentHandler.
-
-
Constructor Detail
-
Digester
public Digester()
Construct a new Digester with default properties.
-
Digester
public Digester(javax.xml.parsers.SAXParser parser)
Construct a new Digester, allowing a SAXParser to be passed in. This allows Digester to be used in environments which are unfriendly to JAXP1.1 (such as WebLogic 6.0). Thanks for the request to change go to James House (james@interobjective.com). This may help in places where you are able to load JAXP 1.1 classes yourself.
-
Digester
public Digester(org.xml.sax.XMLReader reader)
Construct a new Digester, allowing an XMLReader to be passed in. This allows Digester to be used in environments which are unfriendly to JAXP1.1 (such as WebLogic 6.0). Note that if you use this option you have to configure namespace and validation support yourself, as these properties only affect the SAXParser and emtpy constructor.
-
-
Method Detail
-
findNamespaceURI
public java.lang.String findNamespaceURI(java.lang.String prefix)
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
-
getClassLoader
public java.lang.ClassLoader 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.
- The class loader set by
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
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()
Return the current depth of the element stack.
-
getCurrentElementName
public java.lang.String getCurrentElementName()
Return the name of the XML element that is currently being processed.
-
getDebug
public int getDebug()
Deprecated.This method now always returns 0. Digester uses the apache jakarta commons-logging library; see the documentation for that library for more information.Return the debugging detail level of our currently enabled logger.
-
setDebug
public void setDebug(int debug)
Deprecated.This method now has no effect at all. Digester uses the apache jakarta comons-logging library; see the documentation for that library for more information.Set the debugging detail level of our currently enabled logger.- Parameters:
debug
- New debugging detail level (0=off, increasing integers for more detail)
-
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
Return the error handler for this Digester.
-
setErrorHandler
public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Set the error handler for this Digester.- Parameters:
errorHandler
- The new error handler
-
getFactory
public javax.xml.parsers.SAXParserFactory getFactory()
Return the SAXParserFactory we will use, creating one if necessary.
-
getFeature
public boolean getFeature(java.lang.String feature) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Returns a flag indicating whether the requested feature is supported by the underlying implementation oforg.xml.sax.XMLReader
. See the saxproject website for information about the standard SAX2 feature flags.- Parameters:
feature
- Name of the feature to inquire about- Throws:
javax.xml.parsers.ParserConfigurationException
- if a parser configuration error occursorg.xml.sax.SAXNotRecognizedException
- if the property name is not recognizedorg.xml.sax.SAXNotSupportedException
- if the property name is recognized but not supported
-
setFeature
public void setFeature(java.lang.String feature, boolean value) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Sets a flag indicating whether the requested feature is supported by the underlying implementation oforg.xml.sax.XMLReader
. See the saxproject website 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:
javax.xml.parsers.ParserConfigurationException
- if a parser configuration error occursorg.xml.sax.SAXNotRecognizedException
- if the property name is not recognizedorg.xml.sax.SAXNotSupportedException
- if the property name is recognized but not supported
-
getLogger
public org.apache.commons.logging.Log getLogger()
Return the current Logger associated with this instance of the Digester
-
setLogger
public void setLogger(org.apache.commons.logging.Log log)
Set the current logger for this Digester.
-
getSAXLogger
public org.apache.commons.logging.Log getSAXLogger()
Gets the logger used for logging SAX-related information. Note the output is finely grained.- Since:
- 1.6
-
setSAXLogger
public void setSAXLogger(org.apache.commons.logging.Log saxLog)
Sets the logger used for logging SAX-related information. Note the output is finely grained.- Parameters:
saxLog
- Log, not null- Since:
- 1.6
-
getMatch
public java.lang.String getMatch()
Return the current rule match path
-
getNamespaceAware
public boolean getNamespaceAware()
Return 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
public void setPublicId(java.lang.String publicId)
Set the publid id of the current file being parse.- Parameters:
publicId
- the DTD/Schema public's id.
-
getPublicId
public java.lang.String getPublicId()
Return the public identifier of the DTD we are currently parsing under, if any.
-
getRuleNamespaceURI
public java.lang.String getRuleNamespaceURI()
Return the namespace URI that will be applied to all subsequently addedRule
objects.
-
setRuleNamespaceURI
public void setRuleNamespaceURI(java.lang.String ruleNamespaceURI)
Set the namespace URI that will be applied to all subsequently addedRule
objects.- Parameters:
ruleNamespaceURI
- Namespace URI that must match on all subsequently added rules, ornull
for matching regardless of the current namespace URI
-
getParser
public javax.xml.parsers.SAXParser getParser()
Return the SAXParser we will use to parse the input stream. If there is a problem creating the parser, returnnull
.
-
getProperty
public java.lang.Object getProperty(java.lang.String property) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Return the current value of the specified property for the underlyingXMLReader
implementation. See the saxproject website for information about the standard SAX2 properties.- Parameters:
property
- Property name to be retrieved- Throws:
org.xml.sax.SAXNotRecognizedException
- if the property name is not recognizedorg.xml.sax.SAXNotSupportedException
- if the property name is recognized but not supported
-
setProperty
public void setProperty(java.lang.String property, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Set the current value of the specified property for the underlyingXMLReader
implementation. See the saxproject website for information about the standard SAX2 properties.- Parameters:
property
- Property name to be setvalue
- Property value to be set- Throws:
org.xml.sax.SAXNotRecognizedException
- if the property name is not recognizedorg.xml.sax.SAXNotSupportedException
- if the property name is recognized but not supported
-
getReader
public org.xml.sax.XMLReader getReader()
Deprecated.Use getXMLReader() instead, which can throw a SAXException if the reader cannot be instantiatedBy setting the reader in the constructor, you can bypass JAXP and be able to use digester in Weblogic 6.0.
-
getRules
public Rules 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.
-
setRules
public void setRules(Rules rules)
Set theRules
implementation object containing our rules collection and associated matching policy.- Parameters:
rules
- New Rules implementation
-
getSchema
public java.lang.String getSchema()
Return the XML Schema URI used for validating an XML instance.
-
setSchema
public void setSchema(java.lang.String schemaLocation)
Set the XML Schema URI used for validating a XML Instance.- Parameters:
schemaLocation
- a URI to the schema.
-
getSchemaLanguage
public java.lang.String getSchemaLanguage()
Return the XML Schema language used when parsing.
-
setSchemaLanguage
public void setSchemaLanguage(java.lang.String schemaLanguage)
Set the XML Schema language used when parsing. By default, we use W3C.- Parameters:
schemaLanguage
- a URI to the schema language.
-
getUseContextClassLoader
public boolean getUseContextClassLoader()
Return 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()
Return 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.
-
getXMLReader
public org.xml.sax.XMLReader getXMLReader() throws org.xml.sax.SAXException
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.- Throws:
org.xml.sax.SAXException
- if no XMLReader can be instantiated
-
getSubstitutor
public Substitutor getSubstitutor()
Gets theSubstitutor
used to convert attributes and body text.- Returns:
- Substitutor, null if not substitutions are to be performed.
-
setSubstitutor
public void 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.
-
getCustomContentHandler
public org.xml.sax.ContentHandler getCustomContentHandler()
-
setCustomContentHandler
public void setCustomContentHandler(org.xml.sax.ContentHandler handler)
Redirects (or cancels redirecting) of SAX ContentHandler events to an external object.When this object's customContentHandler is non-null, any SAX events received from the parser will simply be passed on to the specified object instead of this object handling them. This allows Rule classes to take control of the SAX event stream for a while in order to do custom processing. Such a rule should save the old value before setting a new one, and restore the old value in order to resume normal digester processing.
An example of a Rule which needs this feature is NodeCreateRule.
Note that saving the old value is probably not needed as it should always be null; a custom rule that wants to take control could only have been called when there was no custom content handler. But it seems cleaner to properly save/restore the value and maybe some day this will come in useful.
Note also that this is not quite equivalent to
digester.getXMLReader().setContentHandler(handler)
for these reasons:- Some xml parsers don't like having setContentHandler called after parsing has started. The Aelfred parser is one example.
- Directing the events via the Digester object potentially allows us to log information about those SAX events at the digester level.
- Since:
- 1.7
-
characters
public void characters(char[] buffer, int start, int length) throws org.xml.sax.SAXException
Process notification of character data received from the body of an XML element.- Specified by:
characters
in interfaceorg.xml.sax.ContentHandler
- Overrides:
characters
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlength
- Number of characters from the buffer- Throws:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
endDocument
public void endDocument() throws org.xml.sax.SAXException
Process notification of the end of the document being reached.- Specified by:
endDocument
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endDocument
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
Process notification of the end of an XML element being reached.- Specified by:
endElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endElement
in classorg.xml.sax.helpers.DefaultHandler
- 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:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
Process notification that a namespace prefix is going out of scope.- Specified by:
endPrefixMapping
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endPrefixMapping
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
prefix
- Prefix that is going out of scope- Throws:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
ignorableWhitespace
public void ignorableWhitespace(char[] buffer, int start, int len) throws org.xml.sax.SAXException
Process notification of ignorable whitespace received from the body of an XML element.- Specified by:
ignorableWhitespace
in interfaceorg.xml.sax.ContentHandler
- Overrides:
ignorableWhitespace
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlen
- Number of characters from the buffer- Throws:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
Process notification of a processing instruction that was encountered.- Specified by:
processingInstruction
in interfaceorg.xml.sax.ContentHandler
- Overrides:
processingInstruction
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
target
- The processing instruction targetdata
- The processing instruction data (if any)- Throws:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
getDocumentLocator
public org.xml.sax.Locator getDocumentLocator()
Gets the document locator associated with our parser.- Returns:
- the Locator supplied by the document parser
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
Sets the document locator associated with our parser.- Specified by:
setDocumentLocator
in interfaceorg.xml.sax.ContentHandler
- Overrides:
setDocumentLocator
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
locator
- The new locator
-
skippedEntity
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
Process notification of a skipped entity.- Specified by:
skippedEntity
in interfaceorg.xml.sax.ContentHandler
- Overrides:
skippedEntity
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
name
- Name of the skipped entity- Throws:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
startDocument
public void startDocument() throws org.xml.sax.SAXException
Process notification of the beginning of the document being reached.- Specified by:
startDocument
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startDocument
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes list) throws org.xml.sax.SAXException
Process notification of the start of an XML element being reached.- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startElement
in classorg.xml.sax.helpers.DefaultHandler
- 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:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String namespaceURI) throws org.xml.sax.SAXException
Process notification that a namespace prefix is coming in to scope.- Specified by:
startPrefixMapping
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startPrefixMapping
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
prefix
- Prefix that is being declarednamespaceURI
- Corresponding namespace URI being mapped to- Throws:
org.xml.sax.SAXException
- if a parsing error is to be reported
-
notationDecl
public void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
Receive notification of a notation declaration event.- Specified by:
notationDecl
in interfaceorg.xml.sax.DTDHandler
- Overrides:
notationDecl
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
name
- The notation namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)
-
unparsedEntityDecl
public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notation)
Receive notification of an unparsed entity declaration event.- Specified by:
unparsedEntityDecl
in interfaceorg.xml.sax.DTDHandler
- Overrides:
unparsedEntityDecl
in classorg.xml.sax.helpers.DefaultHandler
- 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
public void 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.
-
getEntityResolver
public org.xml.sax.EntityResolver getEntityResolver()
Return the Entity Resolver used by the SAX parser.- Returns:
- Return the Entity Resolver used by the SAX parser.
-
resolveEntity
public org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
Resolve the requested external entity.- Specified by:
resolveEntity
in interfaceorg.xml.sax.EntityResolver
- Overrides:
resolveEntity
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
publicId
- The public identifier of the entity being referencedsystemId
- The system identifier of the entity being referenced- Throws:
org.xml.sax.SAXException
- if a parsing exception occurs
-
error
public void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
Forward notification of a parsing error to the application supplied error handler (if any).- Specified by:
error
in interfaceorg.xml.sax.ErrorHandler
- Overrides:
error
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
exception
- The error information- Throws:
org.xml.sax.SAXException
- if a parsing exception occurs
-
fatalError
public void fatalError(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
Forward notification of a fatal parsing error to the application supplied error handler (if any).- Specified by:
fatalError
in interfaceorg.xml.sax.ErrorHandler
- Overrides:
fatalError
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
exception
- The fatal error information- Throws:
org.xml.sax.SAXException
- if a parsing exception occurs
-
warning
public void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
Forward notification of a parse warning to the application supplied error handler (if any).- Specified by:
warning
in interfaceorg.xml.sax.ErrorHandler
- Overrides:
warning
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
exception
- The warning information- Throws:
org.xml.sax.SAXException
- if a parsing exception occurs
-
log
public void log(java.lang.String message)
Deprecated.Call getLogger() and use it's logging methodsLog a message to our associated logger.- Parameters:
message
- The message to be logged
-
log
public void log(java.lang.String message, java.lang.Throwable exception)
Deprecated.Call getLogger() and use it's logging methodsLog a message and exception to our associated logger.- Parameters:
message
- The message to be logged
-
parse
public java.lang.Object parse(java.io.File file) throws java.io.IOException, org.xml.sax.SAXException
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- Throws:
java.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurs
-
parse
public java.lang.Object parse(org.xml.sax.InputSource input) throws java.io.IOException, org.xml.sax.SAXException
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- Throws:
java.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurs
-
parse
public java.lang.Object parse(java.io.InputStream input) throws java.io.IOException, org.xml.sax.SAXException
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- Throws:
java.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurs
-
parse
public java.lang.Object parse(java.io.Reader reader) throws java.io.IOException, org.xml.sax.SAXException
Parse the content of the specified reader using this Digester. Returns the root element from the object stack (if any).- Parameters:
reader
- Reader containing the XML data to be parsed- Throws:
java.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurs
-
parse
public java.lang.Object parse(java.lang.String uri) throws java.io.IOException, org.xml.sax.SAXException
Parse the content of the specified URI using this Digester. Returns the root element from the object stack (if any).- Parameters:
uri
- URI containing the XML data to be parsed- Throws:
java.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurs
-
register
public void register(java.lang.String publicId, java.lang.String 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(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
public void addRule(java.lang.String pattern, Rule rule)
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
public void addRuleSet(RuleSet ruleSet)
Register a set of Rule instances defined in a RuleSet.- Parameters:
ruleSet
- The RuleSet instance to configure from
-
addBeanPropertySetter
public void addBeanPropertySetter(java.lang.String pattern)
Add a "bean property setter" rule for the specified parameters.- Parameters:
pattern
- Element matching pattern- See Also:
BeanPropertySetterRule
-
addBeanPropertySetter
public void addBeanPropertySetter(java.lang.String pattern, java.lang.String propertyName)
Add a "bean property setter" rule for the specified parameters.- Parameters:
pattern
- Element matching patternpropertyName
- Name of property to set- See Also:
BeanPropertySetterRule
-
addCallMethod
public void addCallMethod(java.lang.String pattern, java.lang.String methodName)
Add an "call method" rule for a method which accepts no arguments.- Parameters:
pattern
- Element matching patternmethodName
- Method name to be called- See Also:
CallMethodRule
-
addCallMethod
public void addCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount)
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:
CallMethodRule
-
addCallMethod
public void addCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount, java.lang.String[] paramTypes)
Add an "call method" rule for the specified parameters. IfparamCount
is set to zero the rule will use the body of the matched element as the single argument of the method, unlessparamTypes
is null or empty, in this case the rule will call the specified method with no arguments.- 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)paramTypes
- Set of Java class names for the types of the expected parameters (if you wish to use a primitive type, specify the corresonding Java wrapper class instead, such asjava.lang.Boolean
for aboolean
parameter)- See Also:
CallMethodRule
-
addCallMethod
public void addCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount, java.lang.Class[] paramTypes)
Add an "call method" rule for the specified parameters. IfparamCount
is set to zero the rule will use the body of the matched element as the single argument of the method, unlessparamTypes
is null or empty, in this case the rule will call the specified method with no arguments.- 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)paramTypes
- The Java class names of the arguments (if you wish to use a primitive type, specify the corresonding Java wrapper class instead, such asjava.lang.Boolean
for aboolean
parameter)- See Also:
CallMethodRule
-
addCallParam
public void addCallParam(java.lang.String pattern, int paramIndex)
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:
CallParamRule
-
addCallParam
public void addCallParam(java.lang.String pattern, int paramIndex, java.lang.String attributeName)
Add a "call parameter" rule for the specified parameters.- Parameters:
pattern
- Element matching patternparamIndex
- Zero-relative parameter index to set (from the specified attribute)attributeName
- Attribute whose value is used as the parameter value- See Also:
CallParamRule
-
addCallParam
public void addCallParam(java.lang.String pattern, int paramIndex, boolean fromStack)
Add a "call parameter" rule. This will either take a parameter from the stack or from the current element body text.- Parameters:
paramIndex
- The zero-relative parameter numberfromStack
- Should the call parameter be taken from the top of the stack?- See Also:
CallParamRule
-
addCallParam
public void addCallParam(java.lang.String pattern, int paramIndex, int stackIndex)
Add a "call parameter" rule that sets a parameter from the stack. This takes a parameter from the given position on the stack.- Parameters:
paramIndex
- The zero-relative parameter numberstackIndex
- set the call parameter to the stackIndex'th object down the stack, where 0 is the top of the stack, 1 the next element down and so on- See Also:
CallMethodRule
-
addCallParamPath
public void addCallParamPath(java.lang.String pattern, int paramIndex)
Add a "call parameter" rule that sets a parameter from the currentDigester
matching path. This is sometimes useful when using rules that support wildcards.- Parameters:
pattern
- the pattern that this rule should matchparamIndex
- The zero-relative parameter number- See Also:
CallMethodRule
-
addObjectParam
public void addObjectParam(java.lang.String pattern, int paramIndex, java.lang.Object paramObj)
Add a "call parameter" rule that sets a parameter from a caller-provided object. This can be used to pass constants such as strings to methods; it can also be used to pass mutable objects, providing ways for objects to do things like "register" themselves with some shared object.Note that when attempting to locate a matching method to invoke, the true type of the paramObj is used, so that despite the paramObj being passed in here as type Object, the target method can declare its parameters as being the true type of the object (or some ancestor type, according to the usual type-conversion rules).
- Parameters:
paramIndex
- The zero-relative parameter numberparamObj
- Any arbitrary object to be passed to the target method.- Since:
- 1.6
- See Also:
CallMethodRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, java.lang.String className)
Add a "factory create" rule for the specified parameters. Exceptions thrown during the object creation process will be propagated.- Parameters:
pattern
- Element matching patternclassName
- Java class name of the object creation factory class- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, java.lang.Class clazz)
Add a "factory create" rule for the specified parameters. Exceptions thrown during the object creation process will be propagated.- Parameters:
pattern
- Element matching patternclazz
- Java class of the object creation factory class- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName)
Add a "factory create" rule for the specified parameters. Exceptions thrown during the object creation process will be propagated.- Parameters:
pattern
- Element matching patternclassName
- Java class name of the object creation factory classattributeName
- Attribute name which, if present, overrides the value specified byclassName
- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, java.lang.Class clazz, java.lang.String attributeName)
Add a "factory create" rule for the specified parameters. Exceptions thrown during the object creation process will be propagated.- Parameters:
pattern
- Element matching patternclazz
- Java class of the object creation factory classattributeName
- Attribute name which, if present, overrides the value specified byclassName
- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, ObjectCreationFactory creationFactory)
Add a "factory create" rule for the specified parameters. Exceptions thrown during the object creation process will be propagated.- Parameters:
pattern
- Element matching patterncreationFactory
- Previously instantiated ObjectCreationFactory to be utilized- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, java.lang.String className, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternclassName
- Java class name of the object creation factory classignoreCreateExceptions
- whentrue
any exceptions thrown during object creation will be ignored.- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, java.lang.Class clazz, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternclazz
- Java class of the object creation factory classignoreCreateExceptions
- whentrue
any exceptions thrown during object creation will be ignored.- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternclassName
- Java class name of the object creation factory classattributeName
- Attribute name which, if present, overrides the value specified byclassName
ignoreCreateExceptions
- whentrue
any exceptions thrown during object creation will be ignored.- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.String pattern, java.lang.Class clazz, java.lang.String attributeName, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternclazz
- Java class of the object creation factory classattributeName
- Attribute name which, if present, overrides the value specified byclassName
ignoreCreateExceptions
- whentrue
any exceptions thrown during object creation will be ignored.- See Also:
FactoryCreateRule
-
addFactoryCreate
public void addFactoryCreate(java.lang.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:
FactoryCreateRule
-
addObjectCreate
public void addObjectCreate(java.lang.String pattern, java.lang.String className)
Add an "object create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternclassName
- Java class name to be created- See Also:
ObjectCreateRule
-
addObjectCreate
public void addObjectCreate(java.lang.String pattern, java.lang.Class clazz)
Add an "object create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternclazz
- Java class to be created- See Also:
ObjectCreateRule
-
addObjectCreate
public void addObjectCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName)
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:
ObjectCreateRule
-
addObjectCreate
public void addObjectCreate(java.lang.String pattern, java.lang.String attributeName, java.lang.Class clazz)
Add an "object create" rule for the specified parameters.- Parameters:
pattern
- Element matching patternattributeName
- Attribute name that optionally overridesclazz
- Default Java class to be created the default Java class name to be created- See Also:
ObjectCreateRule
-
addSetNestedProperties
public void addSetNestedProperties(java.lang.String pattern)
Adds anSetNestedPropertiesRule
.- Parameters:
pattern
- register the rule with this pattern- Since:
- 1.6
-
addSetNestedProperties
public void addSetNestedProperties(java.lang.String pattern, java.lang.String elementName, java.lang.String propertyName)
Adds anSetNestedPropertiesRule
.- Parameters:
pattern
- register the rule with this patternelementName
- elment name that a property maps topropertyName
- property name of the element mapped from- Since:
- 1.6
-
addSetNestedProperties
public void addSetNestedProperties(java.lang.String pattern, java.lang.String[] elementNames, java.lang.String[] propertyNames)
Adds anSetNestedPropertiesRule
.- Parameters:
pattern
- register the rule with this patternelementNames
- elment names that (in order) map to propertiespropertyNames
- property names that (in order) elements are mapped to- Since:
- 1.6
-
addSetNext
public void addSetNext(java.lang.String pattern, java.lang.String methodName)
Add a "set next" rule for the specified parameters.- Parameters:
pattern
- Element matching patternmethodName
- Method name to call on the parent element- See Also:
SetNextRule
-
addSetNext
public void addSetNext(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
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 corresonding Java wrapper class instead, such asjava.lang.Boolean
for aboolean
parameter)- See Also:
SetNextRule
-
addSetRoot
public void addSetRoot(java.lang.String pattern, java.lang.String methodName)
AddSetRootRule
with the specified parameters.- Parameters:
pattern
- Element matching patternmethodName
- Method name to call on the root object- See Also:
SetRootRule
-
addSetRoot
public void addSetRoot(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
AddSetRootRule
with the specified parameters.- Parameters:
pattern
- Element matching patternmethodName
- Method name to call on the root objectparamType
- Java class name of the expected parameter type- See Also:
SetRootRule
-
addSetProperties
public void addSetProperties(java.lang.String pattern)
Add a "set properties" rule for the specified parameters.- Parameters:
pattern
- Element matching pattern- See Also:
SetPropertiesRule
-
addSetProperties
public void addSetProperties(java.lang.String pattern, java.lang.String attributeName, java.lang.String propertyName)
Add a "set properties" rule with a single overridden parameter. SeeSetPropertiesRule(String attributeName, String propertyName)
- Parameters:
pattern
- Element matching patternattributeName
- map this attributepropertyName
- to this property- See Also:
SetPropertiesRule
-
addSetProperties
public void addSetProperties(java.lang.String pattern, java.lang.String[] attributeNames, java.lang.String[] propertyNames)
Add a "set properties" rule with overridden parameters. SeeSetPropertiesRule(String [] attributeNames, String [] propertyNames)
- Parameters:
pattern
- Element matching patternattributeNames
- names of attributes with custom mappingspropertyNames
- property names these attributes map to- See Also:
SetPropertiesRule
-
addSetProperty
public void addSetProperty(java.lang.String pattern, java.lang.String name, java.lang.String value)
Add a "set property" rule for the specified parameters.- Parameters:
pattern
- Element matching patternname
- Attribute name containing the property name to be setvalue
- Attribute name containing the property value to set- See Also:
SetPropertyRule
-
addSetTop
public void addSetTop(java.lang.String pattern, java.lang.String methodName)
Add a "set top" rule for the specified parameters.- Parameters:
pattern
- Element matching patternmethodName
- Method name to call on the parent element- See Also:
SetTopRule
-
addSetTop
public void addSetTop(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
Add a "set top" 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 corresonding Java wrapper class instead, such asjava.lang.Boolean
for aboolean
parameter)- See Also:
SetTopRule
-
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.
-
peek
public java.lang.Object peek()
Return the top object on the stack without removing it. If there are no objects on the stack, returnnull
.
-
peek
public java.lang.Object peek(int n)
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.
-
pop
public java.lang.Object pop()
Pop the top object off of the stack, and return it. If there are no objects on the stack, returnnull
.
-
push
public void push(java.lang.Object object)
Push a new object onto the top of the object stack.- Parameters:
object
- The new object
-
push
public void push(java.lang.String stackName, java.lang.Object value)
Pushes the given object onto the stack with the given name. If no stack already exists with the given name then one will be created.- Parameters:
stackName
- the name of the stack onto which the object should be pushedvalue
- the Object to be pushed onto the named stack.- Since:
- 1.6
-
pop
public java.lang.Object pop(java.lang.String stackName)
Pops (gets and removes) the top object from the stack with the given name.
Note: a stack is considered empty if no objects have been pushed onto it yet.
- Parameters:
stackName
- the name of the stack from which the top value is to be popped- Returns:
- the top
Object
on the stack or or null if the stack is either empty or has not been created yet - Throws:
java.util.EmptyStackException
- if the named stack is empty- Since:
- 1.6
-
peek
public java.lang.Object peek(java.lang.String stackName)
Gets the top object from the stack with the given name. This method does not remove the object from the stack.
Note: a stack is considered empty if no objects have been pushed onto it yet.
- Parameters:
stackName
- the name of the stack to be peeked- Returns:
- the top
Object
on the stack or null if the stack is either empty or has not been created yet - Throws:
java.util.EmptyStackException
- if the named stack is empty- Since:
- 1.6
-
peek
public java.lang.Object peek(java.lang.String stackName, int n)
Gets the top object from the stack with the given name. This method does not remove the object from the stack.
Note: a stack is considered empty if no objects have been pushed onto it yet.
- Parameters:
stackName
- the name of the stack to be peekedn
- 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
on the stack. - Throws:
java.util.EmptyStackException
- if the named stack is empty- Since:
- 1.6
-
isEmpty
public boolean isEmpty(java.lang.String stackName)
Is the stack with the given name empty?
Note: a stack is considered empty if no objects have been pushed onto it yet.
- Parameters:
stackName
- the name of the stack whose emptiness should be evaluated- Returns:
- true if the given stack if empty
- Since:
- 1.6
-
getRoot
public java.lang.Object getRoot()
Returns the root element of the tree of objects created as a result of applying the rule objects to the input XML.If the digester stack was "primed" by explicitly pushing a root object onto the stack before parsing started, then that root object is returned here.
Alternatively, if a Rule which creates an object (eg ObjectCreateRule) matched the root element of the xml, then the object created will be returned here.
In other cases, the object most recently pushed onto an empty digester stack is returned. This would be a most unusual use of digester, however; one of the previous configurations is much more likely.
Note that when using one of the Digester.parse methods, the return value from the parse method is exactly the same as the return value from this method. However when the Digester is being used as a SAXContentHandler, no such return value is available; in this case, this method allows you to access the root object that has been created after parsing has completed.
- Returns:
- the root object that has been created after parsing or null if the digester has not parsed any XML yet.
-
resetRoot
public void resetRoot()
This method allows the "root" variable to be reset to null.It is not considered safe for a digester instance to be reused to parse multiple xml documents. However if you are determined to do so, then you should call both clear() and resetRoot() before each parse.
- Since:
- 1.7
-
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. Once only initialization code should be placed in
initialize()
or the code should take responsibility by checking and setting theconfigured
flag.
-
initialize
protected void initialize()
Provides a hook for lazy initialization of this
Digester
instance. The default implementation does nothing, but subclasses can override as needed. Digester (by default) only calls this method once.Note This method will be called by
configure()
only when theconfigured
flag is false. Subclasses that overrideconfigure
or who setconfigured
may find that this method may be called more than once.- Since:
- 1.6
-
getRegistrations
java.util.Map getRegistrations()
Return the set of DTD URL registrations, keyed by public identifier.
-
getRules
java.util.List getRules(java.lang.String match)
Deprecated.Callmatch()
on theRules
implementation returned bygetRules()
Return the set of rules that apply to the specified match position. The selected rules are those that match exactly, or those rules that specify a suffix match and the tail of the rule matches the current match position. Exact matches have precedence over suffix matches, then (among suffix matches) the longest match is preferred.- Parameters:
match
- The current match position
-
peekParams
public java.lang.Object 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
.
-
peekParams
public java.lang.Object peekParams(int n)
Return the n'th object down the parameters stack, where 0 is the top element and [getCount()-1] is the bottom element. If the specified index is out of range, return
null
.The parameters stack is used to store
CallMethodRule
parameters. Seeparams
.- Parameters:
n
- Index of the desired element, where 0 is the top of the stack, 1 is the next element down, and so on.
-
popParams
public java.lang.Object 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
.
-
pushParams
public void pushParams(java.lang.Object object)
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
public org.xml.sax.SAXException createSAXException(java.lang.String message, java.lang.Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occurs- Returns:
- the new exception
-
createSAXException
public org.xml.sax.SAXException createSAXException(java.lang.Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occurs- Returns:
- the new exception
-
createSAXException
public org.xml.sax.SAXException createSAXException(java.lang.String message)
Create a SAX exception which also understands about the location in the digester file where the exception occurs- Returns:
- the new exception
-
-