Top Description Inners Fields Constructors Methods
org.apache.tomcat.util.digester

public Class Digester

extends DefaultHandler2
Class Inheritance
Imports
java.io.File, .FileInputStream, .IOException, .InputStream, .UnsupportedEncodingException, java.lang.reflect.InvocationTargetException, java.net.URI, .URISyntaxException, java.util.ArrayList, .EmptyStackException, .HashMap, .HashSet, .List, .Map, .Properties, .Set, .StringTokenizer, javax.xml.parsers.ParserConfigurationException, .SAXParser, .SAXParserFactory, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.ExceptionUtils, .IntrospectionUtils, .IntrospectionUtils.PropertySource, org.apache.tomcat.util.buf.B2CConverter, org.apache.tomcat.util.res.StringManager, org.xml.sax.Attributes, .EntityResolver, .ErrorHandler, .InputSource, .Locator, .SAXException, .SAXNotRecognizedException, .SAXNotSupportedException, .SAXParseException, .XMLReader, org.xml.sax.ext.DefaultHandler2, .EntityResolver2, .Locator2, org.xml.sax.helpers.AttributesImpl

A Digester processes an XML input stream by matching a series of element nesting patterns to execute Rules that have been added prior to the start of parsing. This package was inspired by the XmlMapper class that was part of Tomcat 3.0 and 3.1, but is organized somewhat differently.

See the Digester Developer Guide for more information.

Implementation Note

- A single Digester instance may only be used within the context of a single thread at a time, and a call to parse() must be completed before another can be initiated even from the same thread.

Implementation Note

- A bug in Xerces 2.0.2 prevents the support of XML schema. You need Xerces 2.1/2.3 and up to make this class working with XML schema

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
public static interface

Field Summary

Modifier and TypeField and Description
protected StringBuilder
bodyText

The body text of the current element.

protected ArrayStack<StringBuilder>
bodyTexts

The stack of body text string buffers for surrounding elements.

protected ClassLoader
classLoader

The class loader to use for instantiating application objects.

protected StringBuilder
code

Generated code.

protected boolean
configured

Has this Digester been configured yet.

protected EntityResolver
entityResolver

The EntityResolver used by the SAX parser.

protected HashMap<String, String>
entityValidator

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

protected ErrorHandler
errorHandler

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

protected SAXParserFactory
factory

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

private static final HashSet<String>
private static Digester.GeneratedCodeLoader
protected ArrayList<Object>
protected Locator
locator

The Locator associated with our parser.

protected Log
log

The Log to which most logging calls will be made.

protected String
match

The current match pattern for nested element processing.

protected ArrayStack<List<Rule>>
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 HashMap<String, ArrayStack<String>>
namespaces

Registered namespaces we are currently processing.

protected ArrayStack<Object>
params

The parameters stack being utilized by CallMethodRule and CallParamRule rules.

protected SAXParser
parser

The SAXParser we will use to parse the input stream.

protected static IntrospectionUtils.PropertySource[]
private static boolean
protected String
publicId

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

protected XMLReader
reader

The XMLReader used to parse digester rules.

protected Object
root

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

protected Rules
rules

The Rules implementation containing our collection of Rule instances and associated matching policy.

protected boolean
rulesValidation

Warn on missing attributes and elements.

protected Log
saxLog

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

protected static final StringManager
protected IntrospectionUtils.PropertySource[]
protected ArrayStack<Object>
stack

The object stack being constructed.

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.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addCallMethod(String
Element matching pattern
pattern
,
String
Method name to be called
methodName
)

Add an "call method" rule for a method which accepts no arguments.

public void
addCallMethod(String
Element matching pattern
pattern
,
String
Method name to be called
methodName
,
int
Number of expected parameters (or zero for a single parameter from the body of this element)
paramCount
)

Add an "call method" rule for the specified parameters.

public void
addCallParam(String
Element matching pattern
pattern
,
int
Zero-relative parameter index to set (from the body of this element)
paramIndex
)

Add a "call parameter" rule for the specified parameters.

public void
addFactoryCreate(String
Element matching pattern
pattern
,
ObjectCreationFactory
Previously instantiated ObjectCreationFactory to be utilized
creationFactory
,
boolean
when true any exceptions thrown during object creation will be ignored.
ignoreCreateExceptions
)

Add a "factory create" rule for the specified parameters.

public static void
public void
addObjectCreate(String
Element matching pattern
pattern
,
String
Java class name to be created
className
)

Add an "object create" rule for the specified parameters.

public void
addObjectCreate(String
Element matching pattern
pattern
,
String
Default Java class name to be created
className
,
String
Attribute name that optionally overrides the default Java class name to be created
attributeName
)

Add an "object create" rule for the specified parameters.

public void
addRule(String
Element matching pattern
pattern
,
Rule
Rule to be registered
rule
)

Register a new Rule matching the specified pattern.

public void
addRuleSet(RuleSet
The RuleSet instance to configure from
ruleSet
)

Register a set of Rule instances defined in a RuleSet.

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

Add a "set next" rule for the specified parameters.

public void
addSetProperties(String
Element matching pattern
pattern
)

Add a "set properties" rule for the specified parameters.

public void
addSetProperties(String pattern, String[] excludes)

public void
characters(char[]
The characters from the XML document
buffer
,
int
Starting offset into the buffer
start
,
int
Number of characters from the buffer
length
)

Overrides org.xml.sax.helpers.DefaultHandler.characters.

Implements org.xml.sax.ContentHandler.characters.

Process notification of character data received from the body of an XML element.

public void
clear()

Clear the current contents of the object stack.

protected void
configure()

Provide a hook for lazy configuration of this Digester instance.

public SAXException

Returns:

the new exception
createSAXException
(String
The error message
message
,
Exception
The root cause
e
)

Create a SAX exception which also understands about the location in the digester file where the exception occurs

public SAXException

Returns:

the new exception
createSAXException
(Exception
The root cause
e
)

Create a SAX exception which also understands about the location in the digester file where the exception occurs

public SAXException

Returns:

the new exception
createSAXException
(String
The error message
message
)

Create a SAX exception which also understands about the location in the digester file where the exception occurs

public void
endDocument()

Overrides org.xml.sax.helpers.DefaultHandler.endDocument.

Implements org.xml.sax.ContentHandler.endDocument.

Process notification of the end of the document being reached.

public void
endElement(String
- The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
namespaceURI
,
String
- The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
String
- The qualified XML 1.0 name (with prefix), or the empty string if qualified names are not available.
qName
)

Overrides org.xml.sax.helpers.DefaultHandler.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Process notification of the end of an XML element being reached.

public void
public void
endPrefixMapping(String
Prefix that is going out of scope
prefix
)

Overrides org.xml.sax.helpers.DefaultHandler.endPrefixMapping.

Implements org.xml.sax.ContentHandler.endPrefixMapping.

Process notification that a namespace prefix is going out of scope.

public void
error(SAXParseException
The error information
exception
)

Overrides org.xml.sax.helpers.DefaultHandler.error.

Implements org.xml.sax.ErrorHandler.error.

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

public void
fatalError(SAXParseException
The fatal error information
exception
)

Overrides org.xml.sax.helpers.DefaultHandler.fatalError.

Implements org.xml.sax.ErrorHandler.fatalError.

Forward notification of a fatal parsing error to the application supplied error handler (if any).

public String

Returns:

the namespace URI
findNamespaceURI
(String
Prefix to look up
prefix
)

Return the currently mapped namespace URI for the specified prefix, if any; otherwise return null.

public ClassLoader

Returns:

the classloader
getClassLoader
()

Return the class loader to be used for instantiating application objects when required.

public int

Returns:

the current depth of the element stack.
getCount
()

public String

Returns:

the name of the XML element that is currently being processed.
getCurrentElementName
()

public Locator

Returns:

the Locator supplied by the document parser
getDocumentLocator
()

Gets the document locator associated with our parser.

public EntityResolver

Returns:

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

Return the Entity Resolver used by the SAX parser.

public ErrorHandler

Returns:

the error handler for this Digester.
getErrorHandler
()

public SAXParserFactory

Returns:

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

SAX parser factory method.

public Map<Class<?>, List<String>>

Returns:

the fake attributes list.
getFakeAttributes
()

public static String[]
public StringBuilder
public Log

Returns:

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

public String

Returns:

the current rule match path
getMatch
()

public boolean

Returns:

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

public SAXParser

Returns:

the SAXParser we will use to parse the input stream. If there is a problem creating the parser, return null.
getParser
()

public Object

Returns:

the property value
getProperty
(String
Property name to be retrieved
property
)

Return the current value of the specified property for the underlying XMLReader implementation.

public String

Returns:

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

public Object

Returns:

the root object that has been created after parsing or null if the digester has not parsed any XML yet.
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.

public Rules

Returns:

the rules
getRules
()

Return the Rules implementation object containing our rules collection and associated matching policy.

public boolean

Returns:

the rules validation flag.
getRulesValidation
()

public Log

Returns:

the SAX logger
getSAXLogger
()

Gets the logger used for logging SAX-related information

Note

the output is finely grained.

public boolean

Returns:

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

public boolean

Returns:

the validating parser flag.
getValidating
()

public XMLReader

Returns:

the XML reader
getXMLReader
()

Return the XMLReader to be used for parsing the input document.

public void
ignorableWhitespace(char[]
The characters from the XML document
buffer
,
int
Starting offset into the buffer
start
,
int
Number of characters from the buffer
len
)

Overrides org.xml.sax.helpers.DefaultHandler.ignorableWhitespace.

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

Process notification of ignorable whitespace received from the body of an XML element.

public boolean

Returns:

true if this is a fake attribute
isFakeAttribute
(Object
The object
object
,
String
The attribute name
name
)

Determine if an attribute is a fake attribute.

public static boolean
public static Object
public void
notationDecl(String
The notation name
name
,
String
The public identifier (if any)
publicId
,
String
The system identifier (if any)
systemId
)

Overrides org.xml.sax.helpers.DefaultHandler.notationDecl.

Implements org.xml.sax.DTDHandler.notationDecl.

Receive notification of a notation declaration event.

public Object

Returns:

the root object
parse
(File
File containing the XML data to be parsed
file
)

Parse the content of the specified file using this Digester.

public Object

Returns:

the root object
parse
(InputSource
Input source containing the XML data to be parsed
input
)

Parse the content of the specified input source using this Digester.

public Object

Returns:

the root object
parse
(InputStream
Input stream containing the XML data to be parsed
input
)

Parse the content of the specified input stream using this Digester.

public Object

Returns:

the top object
peek
()

Return the top object on the stack without removing it.

public Object

Returns:

the specified object
peek
(int
Index of the desired element, where 0 is the top of the stack, 1 is the next element down, and so on.
n
)

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

public Object

Returns:

the top object on the parameters stack
peekParams
()

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

public Object

Returns:

the top object
pop
()

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

public Object

Returns:

the top object on the parameters stack
popParams
()

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

public void
processingInstruction(String
The processing instruction target
target
,
String
The processing instruction data (if any)
data
)

Overrides org.xml.sax.helpers.DefaultHandler.processingInstruction.

Implements org.xml.sax.ContentHandler.processingInstruction.

Process notification of a processing instruction that was encountered.

public void
push(Object
The new object
object
)

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

public void
pushParams(Object
The new object
object
)

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

public void
register(String
Public identifier of the DTD to be resolved
publicId
,
String
The URL to use for reading this DTD
entityURL
)

Register the specified DTD URL for the specified public identifier.

public static void
public void
public InputSource
resolveEntity(String
Identifies the external entity being resolved. Either "[dtd]" for the external subset, or a name starting with "%" to indicate a parameter entity, or else the name of a general entity. This is never null when invoked by a SAX2 parser.
name
,
String
The public identifier of the external entity being referenced (normalized as required by the XML specification), or null if none was supplied.
publicId
,
String
The URI with respect to which relative systemIDs are interpreted. This is always an absolute URI, unless it is null (likely because the XMLReader was given an InputSource without one). This URI is defined by the XML specification to be the one associated with the "<" starting the relevant declaration.
baseURI
,
String
The system identifier of the external entity being referenced; either a relative or absolute URI. This is never null when invoked by a SAX2 parser; only declared entities, and any external subset, are resolved by such parsers.
systemId
)

Overrides org.xml.sax.ext.DefaultHandler2.resolveEntity.

Implements org.xml.sax.ext.EntityResolver2.resolveEntity.

Tells the parser to resolve the systemId against the baseURI and read the entity text from that resulting absolute URI.

public void
setClassLoader(ClassLoader
The new class loader to use, or null to revert to the standard rules
classLoader
)

Set the class loader to be used for instantiating application objects when required.

public void
setDocumentLocator(Locator
The new locator
locator
)

Overrides org.xml.sax.helpers.DefaultHandler.setDocumentLocator.

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Sets the document locator associated with our parser.

public void
setEntityResolver(EntityResolver
a class that implement the EntityResolver interface.
entityResolver
)

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

public void
setErrorHandler(ErrorHandler
The new error handler
errorHandler
)

Set the error handler for this Digester.

public void
setFakeAttributes(Map<Class<?>, List<String>>
The new fake attributes.
fakeAttributes
)

Set the fake attributes.

public void
setFeature(String
Name of the feature to set the status for
feature
,
boolean
The new value for this feature
value
)

Sets a flag indicating whether the requested feature is supported by the underlying implementation of org.xml.sax.XMLReader.

public static void
public void
setKnown(Object object)

public void
setLogger(Log
The logger that will be used
log
)

Set the current logger for this Digester.

public void
setNamespaceAware(boolean
The new "namespace aware" flag
namespaceAware
)

Set the "namespace aware" flag for parsers we create.

public static void
public static void
public void
setPublicId(String
the DTD/Schema public's id.
publicId
)

Set the public id of the current file being parse.

public void
setRules(Rules
New Rules implementation
rules
)

Set the Rules implementation object containing our rules collection and associated matching policy.

public void
setRulesValidation(boolean
The new rules validation flag.
rulesValidation
)

Set the rules validation flag.

public void
setSAXLogger(Log
Log, not null
saxLog
)

Sets the logger used for logging SAX-related information

Note

the output is finely grained.

public void
setUseContextClassLoader(boolean
determines whether to use Context ClassLoader.
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.

public void
setValidating(boolean
The new validating parser flag.
validating
)

Set the validating parser flag.

public void
skippedEntity(String
Name of the skipped entity
name
)

Overrides org.xml.sax.helpers.DefaultHandler.skippedEntity.

Implements org.xml.sax.ContentHandler.skippedEntity.

Process notification of a skipped entity.

public void
startDocument()

Overrides org.xml.sax.helpers.DefaultHandler.startDocument.

Implements org.xml.sax.ContentHandler.startDocument.

Process notification of the beginning of the document being reached.

public void
startDTD(String
The document type name.
name
,
String
The declared public identifier for the external DTD subset, or null if none was declared.
publicId
,
String
The declared system identifier for the external DTD subset, or null if none was declared. (Note that this is not resolved against the document base URI.)
systemId
)

Overrides org.xml.sax.ext.DefaultHandler2.startDTD.

Implements org.xml.sax.ext.LexicalHandler.startDTD.

Report the start of DTD declarations, if any.

public void
startElement(String
The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
namespaceURI
,
String
The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
String
The qualified name (with prefix), or the empty string if qualified names are not available.\
qName
,
Attributes
The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
list
)

Overrides org.xml.sax.helpers.DefaultHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Process notification of the start of an XML element being reached.

public void
public void
startPrefixMapping(String
Prefix that is being declared
prefix
,
String
Corresponding namespace URI being mapped to
namespaceURI
)

Overrides org.xml.sax.helpers.DefaultHandler.startPrefixMapping.

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Process notification that a namespace prefix is coming in to scope.

public String
public void
unparsedEntityDecl(String
The unparsed entity name
name
,
String
The public identifier (if any)
publicId
,
String
The system identifier (if any)
systemId
,
String
The name of the associated notation
notation
)

Overrides org.xml.sax.helpers.DefaultHandler.unparsedEntityDecl.

Implements org.xml.sax.DTDHandler.unparsedEntityDecl.

Receive notification of an unparsed entity declaration event.

private Attributes
updateAttributes(Attributes list)

Returns an attributes list which contains all the attributes passed in, with any text of form "${xxx}" in an attribute value replaced by the appropriate value from the system property.

private StringBuilder
updateBodyText(StringBuilder bodyText)

Return a new StringBuilder containing the same contents as the input buffer, except that data of form ${varname} have been replaced by the value of that var as defined in the system property.

public void
warning(SAXParseException
The warning information
exception
)

Overrides org.xml.sax.helpers.DefaultHandler.warning.

Implements org.xml.sax.ErrorHandler.warning.

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

Inherited from org.xml.sax.ext.DefaultHandler2:
attributeDeclcommentelementDeclendCDATAendDTDendEntityexternalEntityDeclgetExternalSubsetinternalEntityDeclresolveEntitystartCDATAstartEntity