org.apache.tomcat.util.digester

Class Digester

public class Digester extends 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
protected StringBufferbodyText
The body text of the current element.
protected ArrayStackbodyTexts
The stack of body text string buffers for surrounding elements.
protected ClassLoaderclassLoader
The class loader to use for instantiating application objects.
protected booleanconfigured
Has this Digester been configured yet.
protected EntityResolverentityResolver
The EntityResolver used by the SAX parser.
protected HashMapentityValidator
The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds.
protected ErrorHandlererrorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur.
protected SAXParserFactoryfactory
The SAXParserFactory that is created the first time we need it.
protected Map<Class,List<String>>fakeAttributes
Fake attributes map (attributes are often used for object creation).
protected StringJAXP_SCHEMA_LANGUAGE
protected Locatorlocator
The Locator associated with our parser.
protected Loglog
The Log to which most logging calls will be made.
protected Stringmatch
The current match pattern for nested element processing.
protected ArrayStackmatches
Stack whose elements are List objects, each containing a list of Rule objects as returned from Rules.getMatch().
protected booleannamespaceAware
Do we want a "namespace aware" parser.
protected HashMapnamespaces
Registered namespaces we are currently processing.
protected ArrayStackparams
The parameters stack being utilized by CallMethodRule and CallParamRule rules.
protected SAXParserparser
The SAXParser we will use to parse the input stream.
protected StringpublicId
The public identifier of the DTD we are currently parsing under (if any).
protected XMLReaderreader
The XMLReader used to parse digester rules.
protected Objectroot
The "root" element of the stack (in other words, the last object that was popped.
protected Rulesrules
The Rules implementation containing our collection of Rule instances and associated matching policy.
protected booleanrulesValidation
Warn on missing attributes and elements.
protected LogsaxLog
The Log to which all SAX event related logging calls will be made.
protected StringschemaLanguage
The XML schema language to use for validating an XML instance.
protected StringschemaLocation
The XML schema to use for validating an XML instance.
protected static IntrospectionUtils.PropertySource[]source
protected ArrayStackstack
The object stack being constructed.
protected booleanuseContextClassLoader
Do we want to use the Context ClassLoader when loading classes for instantiating new objects.
protected booleanvalidating
Do we want to use a validating parser.
protected static StringW3C_XML_SCHEMA
The schema language supported.
Constructor Summary
Digester()
Construct a new Digester with default properties.
Digester(SAXParser parser)
Construct a new Digester, allowing a SAXParser to be passed in.
Digester(XMLReader reader)
Construct a new Digester, allowing an XMLReader to be passed in.
Method Summary
voidaddCallMethod(String pattern, String methodName)
Add an "call method" rule for a method which accepts no arguments.
voidaddCallMethod(String pattern, String methodName, int paramCount)
Add an "call method" rule for the specified parameters.
voidaddCallMethod(String pattern, String methodName, int paramCount, String[] paramTypes)
Add an "call method" rule for the specified parameters.
voidaddCallMethod(String pattern, String methodName, int paramCount, Class[] paramTypes)
Add an "call method" rule for the specified parameters.
voidaddCallParam(String pattern, int paramIndex)
Add a "call parameter" rule for the specified parameters.
voidaddCallParam(String pattern, int paramIndex, String attributeName)
Add a "call parameter" rule for the specified parameters.
voidaddCallParam(String pattern, int paramIndex, boolean fromStack)
Add a "call parameter" rule.
voidaddCallParam(String pattern, int paramIndex, int stackIndex)
Add a "call parameter" rule that sets a parameter from the stack.
voidaddCallParamPath(String pattern, int paramIndex)
Add a "call parameter" rule that sets a parameter from the current Digester matching path.
voidaddFactoryCreate(String pattern, String className)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, Class clazz)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, String className, String attributeName)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, Class clazz, String attributeName)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, ObjectCreationFactory creationFactory)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, String className, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, Class clazz, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, String className, String attributeName, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, Class clazz, String attributeName, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
voidaddFactoryCreate(String pattern, ObjectCreationFactory creationFactory, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
voidaddObjectCreate(String pattern, String className)
Add an "object create" rule for the specified parameters.
voidaddObjectCreate(String pattern, Class clazz)
Add an "object create" rule for the specified parameters.
voidaddObjectCreate(String pattern, String className, String attributeName)
Add an "object create" rule for the specified parameters.
voidaddObjectCreate(String pattern, String attributeName, Class clazz)
Add an "object create" rule for the specified parameters.
voidaddObjectParam(String pattern, int paramIndex, Object paramObj)
Add a "call parameter" rule that sets a parameter from a caller-provided object.
voidaddRule(String pattern, Rule rule)

Register a new Rule matching the specified pattern.

voidaddRuleSet(RuleSet ruleSet)
Register a set of Rule instances defined in a RuleSet.
voidaddSetNext(String pattern, String methodName)
Add a "set next" rule for the specified parameters.
voidaddSetNext(String pattern, String methodName, String paramType)
Add a "set next" rule for the specified parameters.
voidaddSetProperties(String pattern)
Add a "set properties" rule for the specified parameters.
voidaddSetProperties(String pattern, String attributeName, String propertyName)
Add a "set properties" rule with a single overridden parameter.
voidaddSetProperties(String pattern, String[] attributeNames, String[] propertyNames)
Add a "set properties" rule with overridden parameters.
voidaddSetProperty(String pattern, String name, String value)
Add a "set property" rule for the specified parameters.
voidaddSetRoot(String pattern, String methodName)
Add SetRootRule with the specified parameters.
voidaddSetRoot(String pattern, String methodName, String paramType)
Add SetRootRule with the specified parameters.
voidaddSetTop(String pattern, String methodName)
Add a "set top" rule for the specified parameters.
voidaddSetTop(String pattern, String methodName, String paramType)
Add a "set top" rule for the specified parameters.
voidcharacters(char[] buffer, int start, int length)
Process notification of character data received from the body of an XML element.
voidclear()
Clear the current contents of the object stack.
protected voidconfigure()

Provide a hook for lazy configuration of this Digester instance.

SAXExceptioncreateSAXException(String message, Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occurs
SAXExceptioncreateSAXException(Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occurs
SAXExceptioncreateSAXException(String message)
Create a SAX exception which also understands about the location in the digester file where the exception occurs
voidendDocument()
Process notification of the end of the document being reached.
voidendElement(String namespaceURI, String localName, String qName)
Process notification of the end of an XML element being reached.
voidendPrefixMapping(String prefix)
Process notification that a namespace prefix is going out of scope.
voiderror(SAXParseException exception)
Forward notification of a parsing error to the application supplied error handler (if any).
voidfatalError(SAXParseException exception)
Forward notification of a fatal parsing error to the application supplied error handler (if any).
StringfindNamespaceURI(String prefix)
Return the currently mapped namespace URI for the specified prefix, if any; otherwise return null.
ClassLoadergetClassLoader()
Return the class loader to be used for instantiating application objects when required.
intgetCount()
Return the current depth of the element stack.
StringgetCurrentElementName()
Return the name of the XML element that is currently being processed.
intgetDebug()
Return the debugging detail level of our currently enabled logger.
LocatorgetDocumentLocator()
Gets the document locator associated with our parser.
EntityResolvergetEntityResolver()
Return the Entity Resolver used by the SAX parser.
ErrorHandlergetErrorHandler()
Return the error handler for this Digester.
SAXParserFactorygetFactory()
Return the SAXParserFactory we will use, creating one if necessary.
Map<Class,List<String>>getFakeAttributes()
Return the fake attributes list.
booleangetFeature(String feature)
Returns a flag indicating whether the requested feature is supported by the underlying implementation of org.xml.sax.XMLReader.
LoggetLogger()
Return the current Logger associated with this instance of the Digester
StringgetMatch()
Return the current rule match path
booleangetNamespaceAware()
Return the "namespace aware" flag for parsers we create.
SAXParsergetParser()
Return the SAXParser we will use to parse the input stream.
ObjectgetProperty(String property)
Return the current value of the specified property for the underlying XMLReader implementation.
StringgetPublicId()
Return the public identifier of the DTD we are currently parsing under, if any.
XMLReadergetReader()
By setting the reader in the constructor, you can bypass JAXP and be able to use digester in Weblogic 6.0.
ObjectgetRoot()
When the Digester is being used as a SAXContentHandler, this method allows you to access the root object that has been created after parsing.
StringgetRuleNamespaceURI()
Return the namespace URI that will be applied to all subsequently added Rule objects.
RulesgetRules()
Return the Rules implementation object containing our rules collection and associated matching policy.
booleangetRulesValidation()
Return the rules validation flag.
LoggetSAXLogger()
Gets the logger used for logging SAX-related information.
StringgetSchema()
Return the XML Schema URI used for validating an XML instance.
StringgetSchemaLanguage()
Return the XML Schema language used when parsing.
booleangetUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.
booleangetValidating()
Return the validating parser flag.
XMLReadergetXMLReader()
Return the XMLReader to be used for parsing the input document.
voidignorableWhitespace(char[] buffer, int start, int len)
Process notification of ignorable whitespace received from the body of an XML element.
protected voidinitialize()

Provides a hook for lazy initialization of this Digester instance.

booleanisEmpty(String stackName)

Is the stack with the given name empty?

booleanisFakeAttribute(Object object, String name)
Determine if an attribute is a fake attribute.
voidlog(String message)
Log a message to our associated logger.
voidlog(String message, Throwable exception)
Log a message and exception to our associated logger.
voidnotationDecl(String name, String publicId, String systemId)
Receive notification of a notation declaration event.
Objectparse(File file)
Parse the content of the specified file using this Digester.
Objectparse(InputSource input)
Parse the content of the specified input source using this Digester.
Objectparse(InputStream input)
Parse the content of the specified input stream using this Digester.
Objectparse(Reader reader)
Parse the content of the specified reader using this Digester.
Objectparse(String uri)
Parse the content of the specified URI using this Digester.
Objectpeek()
Return the top object on the stack without removing it.
Objectpeek(int n)
Return the n'th object down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
Objectpeek(String stackName)

Gets the top object from the stack with the given name.

ObjectpeekParams()

Return the top object on the parameters stack without removing it.

ObjectpeekParams(int n)

Return the n'th object down the parameters stack, where 0 is the top element and [getCount()-1] is the bottom element.

Objectpop()
Pop the top object off of the stack, and return it.
Objectpop(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.

ObjectpopParams()

Pop the top object off of the parameters stack, and return it.

voidprocessingInstruction(String target, String data)
Process notification of a processing instruction that was encountered.
voidpush(Object object)
Push a new object onto the top of the object stack.
voidpush(String stackName, Object value)
Pushes the given object onto the stack with the given name.
voidpushParams(Object object)

Push a new object onto the top of the parameters stack.

The parameters stack is used to store CallMethodRule parameters.

voidregister(String publicId, String entityURL)

Register the specified DTD URL for the specified public identifier.

voidreset()
InputSourceresolveEntity(String publicId, String systemId)
Resolve the requested external entity.
voidsetClassLoader(ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.
voidsetDebug(int debug)
Set the debugging detail level of our currently enabled logger.
voidsetDocumentLocator(Locator locator)
Sets the document locator associated with our parser.
voidsetEntityResolver(EntityResolver entityResolver)
Set the EntityResolver used by SAX when resolving public id and system id.
voidsetErrorHandler(ErrorHandler errorHandler)
Set the error handler for this Digester.
voidsetFakeAttributes(Map<Class,List<String>> fakeAttributes)
Set the fake attributes.
voidsetFeature(String feature, boolean value)
Sets a flag indicating whether the requested feature is supported by the underlying implementation of org.xml.sax.XMLReader.
voidsetLogger(Log log)
Set the current logger for this Digester.
voidsetNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create.
voidsetProperty(String property, Object value)
Set the current value of the specified property for the underlying XMLReader implementation.
voidsetPublicId(String publicId)
Set the publid id of the current file being parse.
voidsetRuleNamespaceURI(String ruleNamespaceURI)
Set the namespace URI that will be applied to all subsequently added Rule objects.
voidsetRules(Rules rules)
Set the Rules implementation object containing our rules collection and associated matching policy.
voidsetRulesValidation(boolean rulesValidation)
Set the rules validation flag.
voidsetSAXLogger(Log saxLog)
Sets the logger used for logging SAX-related information.
voidsetSchema(String schemaLocation)
Set the XML Schema URI used for validating a XML Instance.
voidsetSchemaLanguage(String schemaLanguage)
Set the XML Schema language used when parsing.
voidsetUseContextClassLoader(boolean use)
Determine whether to use the Context ClassLoader (the one found by calling Thread.currentThread().getContextClassLoader()) to resolve/load classes that are defined in various rules.
voidsetValidating(boolean validating)
Set the validating parser flag.
voidskippedEntity(String name)
Process notification of a skipped entity.
voidstartDocument()
Process notification of the beginning of the document being reached.
voidstartElement(String namespaceURI, String localName, String qName, Attributes list)
Process notification of the start of an XML element being reached.
voidstartPrefixMapping(String prefix, String namespaceURI)
Process notification that a namespace prefix is coming in to scope.
voidunparsedEntityDecl(String name, String publicId, String systemId, String notation)
Receive notification of an unparsed entity declaration event.
voidwarning(SAXParseException exception)
Forward notification of a parse warning to the application supplied error handler (if any).

Field Detail

bodyText

protected StringBuffer bodyText
The body text of the current element.

bodyTexts

protected ArrayStack bodyTexts
The stack of body text string buffers for surrounding elements.

classLoader

protected 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 the useContextClassLoader variable.

configured

protected boolean configured
Has this Digester been configured yet.

entityResolver

protected EntityResolver entityResolver
The EntityResolver used by the SAX parser. By default it use this class

entityValidator

protected HashMap entityValidator
The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds.

errorHandler

protected ErrorHandler errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur.

factory

protected SAXParserFactory factory
The SAXParserFactory that is created the first time we need it.

fakeAttributes

protected Map<Class,List<String>> fakeAttributes
Fake attributes map (attributes are often used for object creation).

JAXP_SCHEMA_LANGUAGE

protected String JAXP_SCHEMA_LANGUAGE

Deprecated: This is now managed by ParserFeatureSetterFactory

locator

protected Locator locator
The Locator associated with our parser.

log

protected Log log
The Log to which most logging calls will be made.

match

protected String match
The current match pattern for nested element processing.

matches

protected 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

namespaceAware

protected boolean namespaceAware
Do we want a "namespace aware" parser.

namespaces

protected 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 ArrayStack params
The parameters stack being utilized by CallMethodRule and CallParamRule rules.

parser

protected SAXParser parser
The SAXParser we will use to parse the input stream.

publicId

protected String publicId
The public identifier of the DTD we are currently parsing under (if any).

reader

protected XMLReader reader
The XMLReader used to parse digester rules.

root

protected Object root
The "root" element of the stack (in other words, the last object that was popped.

rules

protected Rules rules
The Rules implementation containing our collection of Rule instances and associated matching policy. If not established before the first rule is added, a default implementation will be provided.

rulesValidation

protected boolean rulesValidation
Warn on missing attributes and elements.

saxLog

protected Log saxLog
The Log to which all SAX event related logging calls will be made.

schemaLanguage

protected String schemaLanguage
The XML schema language to use for validating an XML instance. By default this value is set to W3C_XML_SCHEMA

schemaLocation

protected String schemaLocation
The XML schema to use for validating an XML instance.

source

protected static IntrospectionUtils.PropertySource[] source

stack

protected 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 is false.

validating

protected boolean validating
Do we want to use a validating parser.

W3C_XML_SCHEMA

protected static final String W3C_XML_SCHEMA
The schema language supported. By default, we use this one.

Constructor Detail

Digester

public Digester()
Construct a new Digester with default properties.

Digester

public Digester(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(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

addCallMethod

public void addCallMethod(String pattern, String methodName)
Add an "call method" rule for a method which accepts no arguments.

Parameters: pattern Element matching pattern methodName Method name to be called

See Also: CallMethodRule

addCallMethod

public void addCallMethod(String pattern, String methodName, int paramCount)
Add an "call method" rule for the specified parameters.

Parameters: pattern Element matching pattern methodName Method name to be called paramCount Number of expected parameters (or zero for a single parameter from the body of this element)

See Also: CallMethodRule

addCallMethod

public void addCallMethod(String pattern, String methodName, int paramCount, String[] paramTypes)
Add an "call method" rule for the specified parameters. If paramCount is set to zero the rule will use the body of the matched element as the single argument of the method, unless paramTypes is null or empty, in this case the rule will call the specified method with no arguments.

Parameters: pattern Element matching pattern methodName Method name to be called paramCount 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 as java.lang.Boolean for a boolean parameter)

See Also: CallMethodRule

addCallMethod

public void addCallMethod(String pattern, String methodName, int paramCount, Class[] paramTypes)
Add an "call method" rule for the specified parameters. If paramCount is set to zero the rule will use the body of the matched element as the single argument of the method, unless paramTypes is null or empty, in this case the rule will call the specified method with no arguments.

Parameters: pattern Element matching pattern methodName Method name to be called paramCount 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 as java.lang.Boolean for a boolean parameter)

See Also: CallMethodRule

addCallParam

public void addCallParam(String pattern, int paramIndex)
Add a "call parameter" rule for the specified parameters.

Parameters: pattern Element matching pattern paramIndex Zero-relative parameter index to set (from the body of this element)

See Also: CallParamRule

addCallParam

public void addCallParam(String pattern, int paramIndex, String attributeName)
Add a "call parameter" rule for the specified parameters.

Parameters: pattern Element matching pattern paramIndex 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(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 number fromStack Should the call parameter be taken from the top of the stack?

See Also: CallParamRule

addCallParam

public void addCallParam(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 number stackIndex 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(String pattern, int paramIndex)
Add a "call parameter" rule that sets a parameter from the current Digester matching path. This is sometimes useful when using rules that support wildcards.

Parameters: pattern the pattern that this rule should match paramIndex The zero-relative parameter number

See Also: CallMethodRule

addFactoryCreate

public void addFactoryCreate(String pattern, 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 pattern className Java class name of the object creation factory class

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(String pattern, 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 pattern clazz Java class of the object creation factory class

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(String pattern, String className, 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 pattern className Java class name of the object creation factory class attributeName Attribute name which, if present, overrides the value specified by className

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(String pattern, Class clazz, 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 pattern clazz Java class of the object creation factory class attributeName Attribute name which, if present, overrides the value specified by className

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(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 pattern creationFactory Previously instantiated ObjectCreationFactory to be utilized

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(String pattern, String className, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.

Parameters: pattern Element matching pattern className Java class name of the object creation factory class ignoreCreateExceptions when true any exceptions thrown during object creation will be ignored.

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(String pattern, Class clazz, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.

Parameters: pattern Element matching pattern clazz Java class of the object creation factory class ignoreCreateExceptions when true any exceptions thrown during object creation will be ignored.

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(String pattern, String className, String attributeName, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.

Parameters: pattern Element matching pattern className Java class name of the object creation factory class attributeName Attribute name which, if present, overrides the value specified by className ignoreCreateExceptions when true any exceptions thrown during object creation will be ignored.

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(String pattern, Class clazz, String attributeName, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.

Parameters: pattern Element matching pattern clazz Java class of the object creation factory class attributeName Attribute name which, if present, overrides the value specified by className ignoreCreateExceptions when true any exceptions thrown during object creation will be ignored.

See Also: FactoryCreateRule

addFactoryCreate

public void addFactoryCreate(String pattern, ObjectCreationFactory creationFactory, boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.

Parameters: pattern Element matching pattern creationFactory Previously instantiated ObjectCreationFactory to be utilized ignoreCreateExceptions when true any exceptions thrown during object creation will be ignored.

See Also: FactoryCreateRule

addObjectCreate

public void addObjectCreate(String pattern, String className)
Add an "object create" rule for the specified parameters.

Parameters: pattern Element matching pattern className Java class name to be created

See Also: ObjectCreateRule

addObjectCreate

public void addObjectCreate(String pattern, Class clazz)
Add an "object create" rule for the specified parameters.

Parameters: pattern Element matching pattern clazz Java class to be created

See Also: ObjectCreateRule

addObjectCreate

public void addObjectCreate(String pattern, String className, String attributeName)
Add an "object create" rule for the specified parameters.

Parameters: pattern Element matching pattern className Default Java class name to be created attributeName Attribute name that optionally overrides the default Java class name to be created

See Also: ObjectCreateRule

addObjectCreate

public void addObjectCreate(String pattern, String attributeName, Class clazz)
Add an "object create" rule for the specified parameters.

Parameters: pattern Element matching pattern attributeName Attribute name that optionally overrides clazz Default Java class to be created the default Java class name to be created

See Also: ObjectCreateRule

addObjectParam

public void addObjectParam(String pattern, int paramIndex, 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 number paramObj Any arbitrary object to be passed to the target method.

Since: 1.6

See Also:

addRule

public void addRule(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 pattern rule 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

addSetNext

public void addSetNext(String pattern, String methodName)
Add a "set next" rule for the specified parameters.

Parameters: pattern Element matching pattern methodName Method name to call on the parent element

See Also: SetNextRule

addSetNext

public void addSetNext(String pattern, String methodName, String paramType)
Add a "set next" rule for the specified parameters.

Parameters: pattern Element matching pattern methodName Method name to call on the parent element paramType Java class name of the expected parameter type (if you wish to use a primitive type, specify the corresonding Java wrapper class instead, such as java.lang.Boolean for a boolean parameter)

See Also: SetNextRule

addSetProperties

public void addSetProperties(String pattern)
Add a "set properties" rule for the specified parameters.

Parameters: pattern Element matching pattern

See Also: SetPropertiesRule

addSetProperties

public void addSetProperties(String pattern, String attributeName, String propertyName)
Add a "set properties" rule with a single overridden parameter. See SetPropertiesRule

Parameters: pattern Element matching pattern attributeName map this attribute propertyName to this property

See Also: SetPropertiesRule

addSetProperties

public void addSetProperties(String pattern, String[] attributeNames, String[] propertyNames)
Add a "set properties" rule with overridden parameters. See (String [] attributeNames, String [] propertyNames)

Parameters: pattern Element matching pattern attributeNames names of attributes with custom mappings propertyNames property names these attributes map to

See Also: SetPropertiesRule

addSetProperty

public void addSetProperty(String pattern, String name, String value)
Add a "set property" rule for the specified parameters.

Parameters: pattern Element matching pattern name Attribute name containing the property name to be set value Attribute name containing the property value to set

See Also: SetPropertyRule

addSetRoot

public void addSetRoot(String pattern, String methodName)
Add SetRootRule with the specified parameters.

Parameters: pattern Element matching pattern methodName Method name to call on the root object

See Also: SetRootRule

addSetRoot

public void addSetRoot(String pattern, String methodName, String paramType)
Add SetRootRule with the specified parameters.

Parameters: pattern Element matching pattern methodName Method name to call on the root object paramType Java class name of the expected parameter type

See Also: SetRootRule

addSetTop

public void addSetTop(String pattern, String methodName)
Add a "set top" rule for the specified parameters.

Parameters: pattern Element matching pattern methodName Method name to call on the parent element

See Also: SetTopRule

addSetTop

public void addSetTop(String pattern, String methodName, String paramType)
Add a "set top" rule for the specified parameters.

Parameters: pattern Element matching pattern methodName Method name to call on the parent element paramType Java class name of the expected parameter type (if you wish to use a primitive type, specify the corresonding Java wrapper class instead, such as java.lang.Boolean for a boolean parameter)

See Also: SetTopRule

characters

public void characters(char[] buffer, int start, int length)
Process notification of character data received from the body of an XML element.

Parameters: buffer The characters from the XML document start Starting offset into the buffer length Number of characters from the buffer

Throws: SAXException if a parsing error is to be reported

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.

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 Digester or the code should take responsibility by checking and setting the configured flag.

createSAXException

public SAXException createSAXException(String message, 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 SAXException createSAXException(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 SAXException createSAXException(String message)
Create a SAX exception which also understands about the location in the digester file where the exception occurs

Returns: the new exception

endDocument

public void endDocument()
Process notification of the end of the document being reached.

Throws: SAXException if a parsing error is to be reported

endElement

public void endElement(String namespaceURI, String localName, String qName)
Process notification of the end of an XML element being reached.

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

public void endPrefixMapping(String prefix)
Process notification that a namespace prefix is going out of scope.

Parameters: prefix Prefix that is going out of scope

Throws: SAXException if a parsing error is to be reported

error

public void error(SAXParseException exception)
Forward notification of a parsing error to the application supplied error handler (if any).

Parameters: exception The error information

Throws: SAXException if a parsing exception occurs

fatalError

public void fatalError(SAXParseException exception)
Forward notification of a fatal parsing error to the application supplied error handler (if any).

Parameters: exception The fatal error information

Throws: SAXException if a parsing exception occurs

findNamespaceURI

public String findNamespaceURI(String prefix)
Return the currently mapped namespace URI for the specified prefix, if any; otherwise return null. These mappings come and go dynamically as the document is parsed.

Parameters: prefix Prefix to look up

getClassLoader

public ClassLoader getClassLoader()
Return the class loader to be used for instantiating application objects when required. This is determined based upon the following rules:

getCount

public int getCount()
Return the current depth of the element stack.

getCurrentElementName

public 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. This copy of Digester uses JULI; see the documentation for that library for more information.

Return the debugging detail level of our currently enabled logger.

getDocumentLocator

public Locator getDocumentLocator()
Gets the document locator associated with our parser.

Returns: the Locator supplied by the document parser

getEntityResolver

public EntityResolver getEntityResolver()
Return the Entity Resolver used by the SAX parser.

Returns: Return the Entity Resolver used by the SAX parser.

getErrorHandler

public ErrorHandler getErrorHandler()
Return the error handler for this Digester.

getFactory

public SAXParserFactory getFactory()
Return the SAXParserFactory we will use, creating one if necessary.

getFakeAttributes

public Map<Class,List<String>> getFakeAttributes()
Return the fake attributes list.

getFeature

public boolean getFeature(String feature)
Returns a flag indicating whether the requested feature is supported by the underlying implementation of org.xml.sax.XMLReader. See for information about the standard SAX2 feature flags.

Parameters: feature Name of the feature to inquire about

Throws: ParserConfigurationException if a parser configuration error occurs SAXNotRecognizedException if the property name is not recognized SAXNotSupportedException if the property name is recognized but not supported

getLogger

public Log getLogger()
Return the current Logger associated with this instance of the Digester

getMatch

public String getMatch()
Return the current rule match path

getNamespaceAware

public boolean getNamespaceAware()
Return the "namespace aware" flag for parsers we create.

getParser

public SAXParser getParser()
Return 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)
Return the current value of the specified property for the underlying XMLReader implementation. See for information about the standard SAX2 properties.

Parameters: property Property name to be retrieved

Throws: SAXNotRecognizedException if the property name is not recognized SAXNotSupportedException if the property name is recognized but not supported

getPublicId

public String getPublicId()
Return the public identifier of the DTD we are currently parsing under, if any.

getReader

public XMLReader getReader()

Deprecated: Use getXMLReader() instead, which can throw a SAXException if the reader cannot be instantiated

By setting the reader in the constructor, you can bypass JAXP and be able to use digester in Weblogic 6.0.

getRoot

public 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.

getRuleNamespaceURI

public String getRuleNamespaceURI()
Return the namespace URI that will be applied to all subsequently added Rule objects.

getRules

public Rules getRules()
Return the Rules implementation object containing our rules collection and associated matching policy. If none has been established, a default implementation will be created and returned.

getRulesValidation

public boolean getRulesValidation()
Return the rules validation flag.

getSAXLogger

public Log getSAXLogger()
Gets the logger used for logging SAX-related information. Note the output is finely grained.

Since: 1.6

getSchema

public String getSchema()
Return the XML Schema URI used for validating an XML instance.

getSchemaLanguage

public String getSchemaLanguage()
Return the XML Schema language used when parsing.

getUseContextClassLoader

public boolean getUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.

getValidating

public boolean getValidating()
Return the validating parser flag.

getXMLReader

public XMLReader 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.

Throws: SAXException if no XMLReader can be instantiated

ignorableWhitespace

public void ignorableWhitespace(char[] buffer, int start, int len)
Process notification of ignorable whitespace received from the body of an XML element.

Parameters: buffer The characters from the XML document start Starting offset into the buffer len Number of characters from the buffer

Throws: SAXException if a parsing error is to be reported

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 Digester only when the configured flag is false. Subclasses that override configure or who set configured may find that this method may be called more than once.

Since: 1.6

isEmpty

public boolean isEmpty(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

isFakeAttribute

public boolean isFakeAttribute(Object object, String name)
Determine if an attribute is a fake attribute.

log

public void log(String message)

Deprecated: Call getLogger() and use it's logging methods

Log a message to our associated logger.

Parameters: message The message to be logged

log

public void log(String message, Throwable exception)

Deprecated: Call getLogger() and use it's logging methods

Log a message and exception to our associated logger.

Parameters: message The message to be logged

notationDecl

public void notationDecl(String name, String publicId, String systemId)
Receive notification of a notation declaration event.

Parameters: name The notation name publicId The public identifier (if any) systemId The system identifier (if any)

parse

public Object parse(File file)
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: IOException if an input/output error occurs SAXException if a parsing exception occurs

parse

public Object parse(InputSource input)
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: IOException if an input/output error occurs SAXException if a parsing exception occurs

parse

public Object parse(InputStream input)
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: IOException if an input/output error occurs SAXException if a parsing exception occurs

parse

public Object parse(Reader reader)
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: IOException if an input/output error occurs SAXException if a parsing exception occurs

parse

public Object parse(String uri)
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: IOException if an input/output error occurs SAXException if a parsing exception occurs

peek

public Object peek()
Return the top object on the stack without removing it. If there are no objects on the stack, return null.

peek

public 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, return null.

Parameters: n Index of the desired element, where 0 is the top of the stack, 1 is the next element down, and so on.

peek

public Object peek(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: EmptyStackException if the named stack is empty

Since: 1.6

peekParams

public 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. See params.

peekParams

public 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. See params.

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 Object pop()
Pop the top object off of the stack, and return it. If there are no objects on the stack, return null.

pop

public Object pop(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: EmptyStackException if the named stack is empty

Since: 1.6

popParams

public 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. See params.

processingInstruction

public void processingInstruction(String target, String data)
Process notification of a processing instruction that was encountered.

Parameters: target The processing instruction target data The processing instruction data (if any)

Throws: SAXException if a parsing error is to be reported

push

public void push(Object object)
Push a new object onto the top of the object stack.

Parameters: object The new object

push

public void push(String stackName, 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 pushed value the Object to be pushed onto the named stack.

Since: 1.6

pushParams

public void pushParams(Object object)

Push a new object onto the top of the parameters stack.

The parameters stack is used to store CallMethodRule parameters. See params.

Parameters: object The new object

register

public void register(String publicId, 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 internal EntityResolver implementation. This maps PUBLICID'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 every SYSTEM URI on every processed xml document is local. This implementation provides only basic functionality. If more sophisticated features are required, using Digester to set a custom resolver is recommended.

Note: This method will have no effect when a custom EntityResolver has been set. (Setting a custom EntityResolver overrides the internal implementation.)

Parameters: publicId Public identifier of the DTD to be resolved entityURL The URL to use for reading this DTD

reset

public void reset()

resolveEntity

public InputSource resolveEntity(String publicId, String systemId)
Resolve the requested external entity.

Parameters: publicId The public identifier of the entity being referenced systemId The system identifier of the entity being referenced

Throws: SAXException if a parsing exception occurs

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.

Parameters: classLoader The new class loader to use, or null to revert to the standard rules

setDebug

public void setDebug(int debug)

Deprecated: This method now has no effect at all. This copy of Digester uses JULI; 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)

setDocumentLocator

public void setDocumentLocator(Locator locator)
Sets the document locator associated with our parser.

Parameters: locator The new locator

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)
Set the EntityResolver used by SAX when resolving public id and system id. This must be called before the first call to parse().

Parameters: entityResolver a class that implement the EntityResolver interface.

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
Set the error handler for this Digester.

Parameters: errorHandler The new error handler

setFakeAttributes

public void setFakeAttributes(Map<Class,List<String>> fakeAttributes)
Set the fake attributes.

Parameters: fakeAttributes The new fake attributes.

setFeature

public void setFeature(String feature, boolean value)
Sets a flag indicating whether the requested feature is supported by the underlying implementation of org.xml.sax.XMLReader. See for information about the standard SAX2 feature flags. In order to be effective, this method must be called before the getParser() method is called for the first time, either directly or indirectly.

Parameters: feature Name of the feature to set the status for value The new value for this feature

Throws: ParserConfigurationException if a parser configuration error occurs SAXNotRecognizedException if the property name is not recognized SAXNotSupportedException if the property name is recognized but not supported

setLogger

public void setLogger(Log log)
Set the current logger for this Digester.

setNamespaceAware

public void setNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create.

Parameters: namespaceAware The new "namespace aware" flag

setProperty

public void setProperty(String property, Object value)
Set the current value of the specified property for the underlying XMLReader implementation. See for information about the standard SAX2 properties.

Parameters: property Property name to be set value Property value to be set

Throws: SAXNotRecognizedException if the property name is not recognized SAXNotSupportedException if the property name is recognized but not supported

setPublicId

public void setPublicId(String publicId)
Set the publid id of the current file being parse.

Parameters: publicId the DTD/Schema public's id.

setRuleNamespaceURI

public void setRuleNamespaceURI(String ruleNamespaceURI)
Set the namespace URI that will be applied to all subsequently added Rule objects.

Parameters: ruleNamespaceURI Namespace URI that must match on all subsequently added rules, or null for matching regardless of the current namespace URI

setRules

public void setRules(Rules rules)
Set the Rules implementation object containing our rules collection and associated matching policy.

Parameters: rules New Rules implementation

setRulesValidation

public void setRulesValidation(boolean rulesValidation)
Set the rules validation flag. This must be called before parse() is called the first time.

Parameters: rulesValidation The new rules validation flag.

setSAXLogger

public void setSAXLogger(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

setSchema

public void setSchema(String schemaLocation)
Set the XML Schema URI used for validating a XML Instance.

Parameters: schemaLocation a URI to the schema.

setSchemaLanguage

public void setSchemaLanguage(String schemaLanguage)
Set the XML Schema language used when parsing. By default, we use W3C.

Parameters: schemaLanguage a URI to the schema language.

setUseContextClassLoader

public void setUseContextClassLoader(boolean use)
Determine whether to use the Context ClassLoader (the one found by calling Thread.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.

setValidating

public void setValidating(boolean validating)
Set the validating parser flag. This must be called before parse() is called the first time.

Parameters: validating The new validating parser flag.

skippedEntity

public void skippedEntity(String name)
Process notification of a skipped entity.

Parameters: name Name of the skipped entity

Throws: SAXException if a parsing error is to be reported

startDocument

public void startDocument()
Process notification of the beginning of the document being reached.

Throws: SAXException if a parsing error is to be reported

startElement

public void startElement(String namespaceURI, String localName, String qName, Attributes list)
Process notification of the start of an XML element being reached.

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

public void startPrefixMapping(String prefix, String namespaceURI)
Process notification that a namespace prefix is coming in to scope.

Parameters: prefix Prefix that is being declared namespaceURI Corresponding namespace URI being mapped to

Throws: SAXException if a parsing error is to be reported

unparsedEntityDecl

public void unparsedEntityDecl(String name, String publicId, String systemId, String notation)
Receive notification of an unparsed entity declaration event.

Parameters: name The unparsed entity name publicId The public identifier (if any) systemId The system identifier (if any) notation The name of the associated notation

warning

public void warning(SAXParseException exception)
Forward notification of a parse warning to the application supplied error handler (if any).

Parameters: exception The warning information

Throws: SAXException if a parsing exception occurs

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.