public class Digester extends DefaultHandler2
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
Modifier and Type | Class and Description |
---|---|
static class |
Digester.EnvironmentPropertySource
Deprecated.
Use
EnvironmentPropertySource
This will be removed in Tomcat 10 onwards. |
Modifier and Type | Field 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 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).
|
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 |
propertySource |
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 IntrospectionUtils.PropertySource[] |
source |
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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
addCallMethod(String pattern,
String methodName)
Add an "call method" rule for a method which accepts no arguments.
|
void |
addCallMethod(String pattern,
String methodName,
int paramCount)
Add an "call method" rule for the specified parameters.
|
void |
addCallMethod(String pattern,
String methodName,
int paramCount,
Class<?>[] paramTypes)
Add an "call method" rule for the specified parameters.
|
void |
addCallMethod(String pattern,
String methodName,
int paramCount,
String[] paramTypes)
Add an "call method" rule for the specified parameters.
|
void |
addCallParam(String pattern,
int paramIndex)
Add a "call parameter" rule for the specified parameters.
|
void |
addCallParam(String pattern,
int paramIndex,
boolean fromStack)
Add a "call parameter" rule.
|
void |
addCallParam(String pattern,
int paramIndex,
int stackIndex)
Add a "call parameter" rule that sets a parameter from the stack.
|
void |
addCallParam(String pattern,
int paramIndex,
String attributeName)
Add a "call parameter" rule for the specified parameters.
|
void |
addCallParamPath(String pattern,
int paramIndex)
Add a "call parameter" rule that sets a parameter from the current
Digester matching path. |
void |
addFactoryCreate(String pattern,
Class<?> clazz)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
Class<?> clazz,
boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
Class<?> clazz,
String attributeName)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
Class<?> clazz,
String attributeName,
boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
ObjectCreationFactory creationFactory)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
ObjectCreationFactory creationFactory,
boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
String className)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
String className,
boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
String className,
String attributeName)
Add a "factory create" rule for the specified parameters.
|
void |
addFactoryCreate(String pattern,
String className,
String attributeName,
boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters.
|
void |
addObjectCreate(String pattern,
Class<?> clazz)
Add an "object create" rule for the specified parameters.
|
void |
addObjectCreate(String pattern,
String className)
Add an "object create" rule for the specified parameters.
|
void |
addObjectCreate(String pattern,
String attributeName,
Class<?> clazz)
Add an "object create" rule for the specified parameters.
|
void |
addObjectCreate(String pattern,
String className,
String attributeName)
Add an "object create" rule for the specified parameters.
|
void |
addObjectParam(String pattern,
int paramIndex,
Object paramObj)
Add a "call parameter" rule that sets a parameter from a
caller-provided object.
|
void |
addRule(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 |
addSetNext(String pattern,
String methodName)
Add a "set next" rule for the specified parameters.
|
void |
addSetNext(String pattern,
String methodName,
String paramType)
Add a "set next" rule for the specified parameters.
|
void |
addSetProperties(String pattern)
Add a "set properties" rule for the specified parameters.
|
void |
addSetProperties(String pattern,
String[] attributeNames,
String[] propertyNames)
Add a "set properties" rule with overridden parameters.
|
void |
addSetProperties(String pattern,
String attributeName,
String propertyName)
Add a "set properties" rule with a single overridden parameter.
|
void |
addSetProperty(String pattern,
String name,
String value)
Add a "set property" rule for the specified parameters.
|
void |
addSetRoot(String pattern,
String methodName)
Add
SetRootRule with the specified parameters. |
void |
addSetRoot(String pattern,
String methodName,
String paramType)
Add
SetRootRule with the specified parameters. |
void |
addSetTop(String pattern,
String methodName)
Add a "set top" rule for the specified parameters.
|
void |
addSetTop(String pattern,
String methodName,
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 this
Digester
instance. |
SAXException |
createSAXException(Exception e)
Create a SAX exception which also understands about the location in
the digester file where the exception occurs
|
SAXException |
createSAXException(String message)
Create a SAX exception which also understands about the location in
the digester file where the exception occurs
|
SAXException |
createSAXException(String message,
Exception e)
Create a SAX exception which also understands about the location in
the digester file where the exception occurs
|
void |
endDocument()
Process notification of the end of the document being reached.
|
void |
endElement(String namespaceURI,
String localName,
String qName)
Process notification of the end of an XML element being reached.
|
void |
endPrefixMapping(String prefix)
Process notification that a namespace prefix is going out of scope.
|
void |
error(SAXParseException exception)
Forward notification of a parsing error to the application supplied
error handler (if any).
|
void |
fatalError(SAXParseException exception)
Forward notification of a fatal parsing error to the application
supplied error handler (if any).
|
String |
findNamespaceURI(String prefix)
Return the currently mapped namespace URI for the specified prefix,
if any; otherwise return
null . |
ClassLoader |
getClassLoader()
Return the class loader to be used for instantiating application objects
when required.
|
int |
getCount() |
String |
getCurrentElementName() |
Locator |
getDocumentLocator()
Gets the document locator associated with our parser.
|
EntityResolver |
getEntityResolver()
Return the Entity Resolver used by the SAX parser.
|
ErrorHandler |
getErrorHandler() |
SAXParserFactory |
getFactory()
SAX parser factory method.
|
Map<Class<?>,List<String>> |
getFakeAttributes() |
boolean |
getFeature(String feature)
Returns a flag indicating whether the requested feature is supported
by the underlying implementation of
org.xml.sax.XMLReader . |
Log |
getLogger() |
String |
getMatch() |
boolean |
getNamespaceAware() |
SAXParser |
getParser() |
Object |
getProperty(String property)
Return the current value of the specified property for the underlying
XMLReader implementation. |
String |
getPublicId() |
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.
|
String |
getRuleNamespaceURI()
Return the namespace URI that will be applied to all subsequently
added
Rule objects. |
Rules |
getRules()
Return the
Rules implementation object containing our
rules collection and associated matching policy. |
boolean |
getRulesValidation() |
Log |
getSAXLogger()
Gets the logger used for logging SAX-related information.
|
boolean |
getUseContextClassLoader() |
boolean |
getValidating() |
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 this
Digester
instance. |
boolean |
isEmpty(String stackName)
Is the stack with the given name empty?
|
boolean |
isFakeAttribute(Object object,
String name)
Determine if an attribute is a fake attribute.
|
void |
notationDecl(String name,
String publicId,
String systemId)
Receive notification of a notation declaration event.
|
Object |
parse(File file)
Parse the content of the specified file using this Digester.
|
Object |
parse(InputSource input)
Parse the content of the specified input source using this Digester.
|
Object |
parse(InputStream input)
Parse the content of the specified input stream using this Digester.
|
Object |
parse(Reader reader)
Parse the content of the specified reader using this Digester.
|
Object |
parse(String uri)
Parse the content of the specified URI using this Digester.
|
Object |
peek()
Return the top object on the stack without removing it.
|
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.
|
Object |
peek(String stackName)
Gets the top object from the stack with the given name.
|
Object |
peekParams()
Return the top object on the parameters stack without removing it.
|
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.
|
Object |
pop()
Pop the top object off of the stack, and return it.
|
Object |
pop(String stackName)
Pops (gets and removes) the top object from the stack with the given name.
|
Object |
popParams()
Pop the top object off of the parameters stack, and return it.
|
void |
processingInstruction(String target,
String data)
Process notification of a processing instruction that was encountered.
|
void |
push(Object object)
Push a new object onto the top of the object stack.
|
void |
push(String stackName,
Object value)
Pushes the given object onto the stack with the given name.
|
void |
pushParams(Object object)
Push a new object onto the top of the parameters stack.
|
void |
register(String publicId,
String entityURL)
Register the specified DTD URL for the specified public identifier.
|
void |
reset() |
InputSource |
resolveEntity(String name,
String publicId,
String baseURI,
String systemId) |
void |
setClassLoader(ClassLoader classLoader)
Set the class loader to be used for instantiating application objects
when required.
|
void |
setDocumentLocator(Locator locator)
Sets the document locator associated with our parser.
|
void |
setEntityResolver(EntityResolver entityResolver)
Set the
EntityResolver used by SAX when resolving
public id and system id. |
void |
setErrorHandler(ErrorHandler errorHandler)
Set the error handler for this Digester.
|
void |
setFakeAttributes(Map<Class<?>,List<String>> fakeAttributes)
Set the fake attributes.
|
void |
setFeature(String feature,
boolean value)
Sets a flag indicating whether the requested feature is supported
by the underlying implementation of
org.xml.sax.XMLReader . |
void |
setLogger(Log log)
Set the current logger for this Digester.
|
void |
setNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create.
|
void |
setProperty(String property,
Object value)
Set the current value of the specified property for the underlying
XMLReader implementation. |
void |
setPublicId(String publicId)
Set the public id of the current file being parse.
|
void |
setRuleNamespaceURI(String ruleNamespaceURI)
Set the namespace URI that will be applied to all subsequently
added
Rule objects. |
void |
setRules(Rules rules)
Set the
Rules implementation object containing our
rules collection and associated matching policy. |
void |
setRulesValidation(boolean rulesValidation)
Set the rules validation flag.
|
void |
setSAXLogger(Log saxLog)
Sets the logger used for logging SAX-related information.
|
void |
setUseContextClassLoader(boolean use)
Determine whether to use the Context ClassLoader (the one found by
calling
Thread.currentThread().getContextClassLoader() )
to resolve/load classes that are defined in various rules. |
void |
setValidating(boolean validating)
Set the validating parser flag.
|
void |
skippedEntity(String name)
Process notification of a skipped entity.
|
void |
startDocument()
Process notification of the beginning of the document being reached.
|
void |
startDTD(String name,
String publicId,
String systemId) |
void |
startElement(String namespaceURI,
String localName,
String qName,
Attributes list)
Process notification of the start of an XML element being reached.
|
void |
startPrefixMapping(String prefix,
String namespaceURI)
Process notification that a namespace prefix is coming in to scope.
|
void |
unparsedEntityDecl(String name,
String publicId,
String systemId,
String notation)
Receive notification of an unparsed entity declaration event.
|
void |
warning(SAXParseException exception)
Forward notification of a parse warning to the application supplied
error handler (if any).
|
attributeDecl, comment, elementDecl, endCDATA, endDTD, endEntity, externalEntityDecl, getExternalSubset, internalEntityDecl, resolveEntity, startCDATA, startEntity
protected static IntrospectionUtils.PropertySource propertySource
protected IntrospectionUtils.PropertySource[] source
protected StringBuilder bodyText
protected ArrayStack<StringBuilder> bodyTexts
protected ArrayStack<List<Rule>> matches
protected ClassLoader classLoader
useContextClassLoader
variable.protected boolean configured
protected EntityResolver entityResolver
protected HashMap<String,String> entityValidator
protected ErrorHandler errorHandler
protected SAXParserFactory factory
protected Locator locator
protected String match
protected boolean namespaceAware
protected HashMap<String,ArrayStack<String>> namespaces
protected ArrayStack<Object> params
protected SAXParser parser
protected String publicId
protected XMLReader reader
protected Object root
protected Rules rules
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.protected ArrayStack<Object> stack
protected boolean useContextClassLoader
false
.protected boolean validating
protected boolean rulesValidation
protected Map<Class<?>,List<String>> fakeAttributes
protected Log log
protected Log saxLog
public Digester()
public Digester(SAXParser parser)
public Digester(XMLReader reader)
public String findNamespaceURI(String prefix)
null
. These mappings come and
go dynamically as the document is parsed.prefix
- Prefix to look uppublic ClassLoader getClassLoader()
setClassLoader()
, if anyuseContextClassLoader
property is set to truepublic void setClassLoader(ClassLoader classLoader)
classLoader
- The new class loader to use, or null
to revert to the standard rulespublic int getCount()
public String getCurrentElementName()
public ErrorHandler getErrorHandler()
public void setErrorHandler(ErrorHandler errorHandler)
errorHandler
- The new error handlerpublic SAXParserFactory getFactory() throws SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationException
ParserConfigurationException
- Error creating parserSAXNotSupportedException
- Error creating parserSAXNotRecognizedException
- Error creating parserpublic boolean getFeature(String feature) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException
org.xml.sax.XMLReader
.
See
http://www.saxproject.org/apidoc/xml/sax/package-summary.html#package-description
for information about the standard SAX2 feature flags.feature
- Name of the feature to inquire aboutParserConfigurationException
- if a parser configuration error
occursSAXNotRecognizedException
- if the property name is
not recognizedSAXNotSupportedException
- if the property name is
recognized but not supportedpublic void setFeature(String feature, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException
org.xml.sax.XMLReader
.
See
http://www.saxproject.org/apidoc/xml/sax/package-summary.html#package-description
for information about the standard SAX2 feature flags. In order to be
effective, this method must be called before the
getParser()
method is called for the first time, either
directly or indirectly.feature
- Name of the feature to set the status forvalue
- The new value for this featureParserConfigurationException
- if a parser configuration error
occursSAXNotRecognizedException
- if the property name is
not recognizedSAXNotSupportedException
- if the property name is
recognized but not supportedpublic Log getLogger()
public void setLogger(Log log)
log
- The logger that will be usedpublic Log getSAXLogger()
public void setSAXLogger(Log saxLog)
saxLog
- Log, not nullpublic String getMatch()
public boolean getNamespaceAware()
public void setNamespaceAware(boolean namespaceAware)
namespaceAware
- The new "namespace aware" flagpublic void setPublicId(String publicId)
publicId
- the DTD/Schema public's id.public String getPublicId()
public String getRuleNamespaceURI()
Rule
objects.public void setRuleNamespaceURI(String ruleNamespaceURI)
Rule
objects.ruleNamespaceURI
- Namespace URI that must match on all
subsequently added rules, or null
for matching
regardless of the current namespace URIpublic SAXParser getParser()
null
.public Object getProperty(String property) throws SAXNotRecognizedException, SAXNotSupportedException
XMLReader
implementation.
See
http://www.saxproject.org/apidoc/xml/sax/package-summary.html#package-description
for information about the standard SAX2 properties.property
- Property name to be retrievedSAXNotRecognizedException
- if the property name is
not recognizedSAXNotSupportedException
- if the property name is
recognized but not supportedpublic void setProperty(String property, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
XMLReader
implementation.
See
http://www.saxproject.org/apidoc/xml/sax/package-summary.html#package-description
for information about the standard SAX2 properties.property
- Property name to be setvalue
- Property value to be setSAXNotRecognizedException
- if the property name is
not recognizedSAXNotSupportedException
- if the property name is
recognized but not supportedpublic Rules getRules()
Rules
implementation object containing our
rules collection and associated matching policy. If none has been
established, a default implementation will be created and returned.public void setRules(Rules rules)
Rules
implementation object containing our
rules collection and associated matching policy.rules
- New Rules implementationpublic boolean getUseContextClassLoader()
public void setUseContextClassLoader(boolean use)
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.use
- determines whether to use Context ClassLoader.public boolean getValidating()
public void setValidating(boolean validating)
parse()
is called the first time.validating
- The new validating parser flag.public boolean getRulesValidation()
public void setRulesValidation(boolean rulesValidation)
parse()
is called the first time.rulesValidation
- The new rules validation flag.public Map<Class<?>,List<String>> getFakeAttributes()
public boolean isFakeAttribute(Object object, String name)
object
- The objectname
- The attribute nametrue
if this is a fake attributepublic void setFakeAttributes(Map<Class<?>,List<String>> fakeAttributes)
fakeAttributes
- The new fake attributes.public XMLReader getXMLReader() throws SAXException
SAXException
- if no XMLReader can be instantiatedpublic void characters(char[] buffer, int start, int length) throws SAXException
characters
in interface ContentHandler
characters
in class DefaultHandler
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlength
- Number of characters from the bufferSAXException
- if a parsing error is to be reportedpublic void endDocument() throws SAXException
endDocument
in interface ContentHandler
endDocument
in class DefaultHandler
SAXException
- if a parsing error is to be reportedpublic void endElement(String namespaceURI, String localName, String qName) throws SAXException
endElement
in interface ContentHandler
endElement
in class DefaultHandler
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.SAXException
- if a parsing error is to be reportedpublic void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping
in interface ContentHandler
endPrefixMapping
in class DefaultHandler
prefix
- Prefix that is going out of scopeSAXException
- if a parsing error is to be reportedpublic void ignorableWhitespace(char[] buffer, int start, int len) throws SAXException
ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in class DefaultHandler
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlen
- Number of characters from the bufferSAXException
- if a parsing error is to be reportedpublic void processingInstruction(String target, String data) throws SAXException
processingInstruction
in interface ContentHandler
processingInstruction
in class DefaultHandler
target
- The processing instruction targetdata
- The processing instruction data (if any)SAXException
- if a parsing error is to be reportedpublic Locator getDocumentLocator()
public void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
setDocumentLocator
in class DefaultHandler
locator
- The new locatorpublic void skippedEntity(String name) throws SAXException
skippedEntity
in interface ContentHandler
skippedEntity
in class DefaultHandler
name
- Name of the skipped entitySAXException
- if a parsing error is to be reportedpublic void startDocument() throws SAXException
startDocument
in interface ContentHandler
startDocument
in class DefaultHandler
SAXException
- if a parsing error is to be reportedpublic void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXException
startElement
in interface ContentHandler
startElement
in class DefaultHandler
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.SAXException
- if a parsing error is to be reportedpublic void startPrefixMapping(String prefix, String namespaceURI) throws SAXException
startPrefixMapping
in interface ContentHandler
startPrefixMapping
in class DefaultHandler
prefix
- Prefix that is being declarednamespaceURI
- Corresponding namespace URI being mapped toSAXException
- if a parsing error is to be reportedpublic void notationDecl(String name, String publicId, String systemId)
notationDecl
in interface DTDHandler
notationDecl
in class DefaultHandler
name
- The notation namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)public void unparsedEntityDecl(String name, String publicId, String systemId, String notation)
unparsedEntityDecl
in interface DTDHandler
unparsedEntityDecl
in class DefaultHandler
name
- The unparsed entity namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)notation
- The name of the associated notationpublic void setEntityResolver(EntityResolver entityResolver)
EntityResolver
used by SAX when resolving
public id and system id.
This must be called before the first call to parse()
.entityResolver
- a class that implement the EntityResolver
interface.public EntityResolver getEntityResolver()
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException
resolveEntity
in interface EntityResolver2
resolveEntity
in class DefaultHandler2
SAXException
IOException
public void startDTD(String name, String publicId, String systemId) throws SAXException
startDTD
in interface LexicalHandler
startDTD
in class DefaultHandler2
SAXException
public void error(SAXParseException exception) throws SAXException
error
in interface ErrorHandler
error
in class DefaultHandler
exception
- The error informationSAXException
- if a parsing exception occurspublic void fatalError(SAXParseException exception) throws SAXException
fatalError
in interface ErrorHandler
fatalError
in class DefaultHandler
exception
- The fatal error informationSAXException
- if a parsing exception occurspublic void warning(SAXParseException exception) throws SAXException
warning
in interface ErrorHandler
warning
in class DefaultHandler
exception
- The warning informationSAXException
- if a parsing exception occurspublic Object parse(File file) throws IOException, SAXException
file
- File containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Object parse(InputSource input) throws IOException, SAXException
input
- Input source containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Object parse(InputStream input) throws IOException, SAXException
input
- Input stream containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Object parse(Reader reader) throws IOException, SAXException
reader
- Reader containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Object parse(String uri) throws IOException, SAXException
uri
- URI containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic 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 setEntityResolver(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 custom
EntityResolver
overrides the internal implementation.)
publicId
- Public identifier of the DTD to be resolvedentityURL
- The URL to use for reading this DTDpublic void addRule(String pattern, Rule rule)
Register a new Rule matching the specified pattern.
This method sets the Digester
property on the rule.
pattern
- Element matching patternrule
- Rule to be registeredpublic void addRuleSet(RuleSet ruleSet)
ruleSet
- The RuleSet instance to configure frompublic void addCallMethod(String pattern, String methodName)
pattern
- Element matching patternmethodName
- Method name to be calledCallMethodRule
public void addCallMethod(String pattern, String methodName, int paramCount)
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)CallMethodRule
public void addCallMethod(String pattern, String methodName, int paramCount, String[] paramTypes)
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.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 corresponding
Java wrapper class instead, such as java.lang.Boolean
for a boolean
parameter)CallMethodRule
public void addCallMethod(String pattern, String methodName, int paramCount, Class<?>[] paramTypes)
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.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 corresponding
Java wrapper class instead, such as java.lang.Boolean
for a boolean
parameter)CallMethodRule
public void addCallParam(String pattern, int paramIndex)
pattern
- Element matching patternparamIndex
- Zero-relative parameter index to set
(from the body of this element)CallParamRule
public void addCallParam(String pattern, int paramIndex, String attributeName)
pattern
- Element matching patternparamIndex
- Zero-relative parameter index to set
(from the specified attribute)attributeName
- Attribute whose value is used as the
parameter valueCallParamRule
public void addCallParam(String pattern, int paramIndex, boolean fromStack)
paramIndex
- The zero-relative parameter numberfromStack
- Should the call parameter be taken from the top of the stack?CallParamRule
public void addCallParam(String pattern, int paramIndex, int stackIndex)
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 onCallMethodRule
public void addCallParamPath(String pattern, int paramIndex)
Digester
matching path.
This is sometimes useful when using rules that support wildcards.pattern
- the pattern that this rule should matchparamIndex
- The zero-relative parameter numberCallMethodRule
public void addObjectParam(String pattern, int paramIndex, Object paramObj)
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).
paramIndex
- The zero-relative parameter numberparamObj
- Any arbitrary object to be passed to the target
method.CallMethodRule
public void addFactoryCreate(String pattern, String className)
pattern
- Element matching patternclassName
- Java class name of the object creation factory classFactoryCreateRule
public void addFactoryCreate(String pattern, Class<?> clazz)
pattern
- Element matching patternclazz
- Java class of the object creation factory classFactoryCreateRule
public void addFactoryCreate(String pattern, String className, String attributeName)
pattern
- Element matching patternclassName
- Java class name of the object creation factory classattributeName
- Attribute name which, if present, overrides the
value specified by className
FactoryCreateRule
public void addFactoryCreate(String pattern, Class<?> clazz, String attributeName)
pattern
- Element matching patternclazz
- Java class of the object creation factory classattributeName
- Attribute name which, if present, overrides the
value specified by className
FactoryCreateRule
public void addFactoryCreate(String pattern, ObjectCreationFactory creationFactory)
pattern
- Element matching patterncreationFactory
- Previously instantiated ObjectCreationFactory
to be utilizedFactoryCreateRule
public void addFactoryCreate(String pattern, String className, boolean ignoreCreateExceptions)
pattern
- Element matching patternclassName
- Java class name of the object creation factory classignoreCreateExceptions
- when true
any exceptions thrown during
object creation will be ignored.FactoryCreateRule
public void addFactoryCreate(String pattern, Class<?> clazz, boolean ignoreCreateExceptions)
pattern
- Element matching patternclazz
- Java class of the object creation factory classignoreCreateExceptions
- when true
any exceptions thrown during
object creation will be ignored.FactoryCreateRule
public void addFactoryCreate(String pattern, String className, String attributeName, boolean ignoreCreateExceptions)
pattern
- Element matching patternclassName
- Java class name of the object creation factory classattributeName
- Attribute name which, if present, overrides the
value specified by className
ignoreCreateExceptions
- when true
any exceptions thrown during
object creation will be ignored.FactoryCreateRule
public void addFactoryCreate(String pattern, Class<?> clazz, String attributeName, boolean ignoreCreateExceptions)
pattern
- Element matching patternclazz
- Java class of the object creation factory classattributeName
- Attribute name which, if present, overrides the
value specified by className
ignoreCreateExceptions
- when true
any exceptions thrown during
object creation will be ignored.FactoryCreateRule
public void addFactoryCreate(String pattern, ObjectCreationFactory creationFactory, boolean ignoreCreateExceptions)
pattern
- Element matching patterncreationFactory
- Previously instantiated ObjectCreationFactory
to be utilizedignoreCreateExceptions
- when true
any exceptions thrown during
object creation will be ignored.FactoryCreateRule
public void addObjectCreate(String pattern, String className)
pattern
- Element matching patternclassName
- Java class name to be createdObjectCreateRule
public void addObjectCreate(String pattern, Class<?> clazz)
pattern
- Element matching patternclazz
- Java class to be createdObjectCreateRule
public void addObjectCreate(String pattern, String className, String attributeName)
pattern
- Element matching patternclassName
- Default Java class name to be createdattributeName
- Attribute name that optionally overrides
the default Java class name to be createdObjectCreateRule
public void addObjectCreate(String pattern, String attributeName, Class<?> clazz)
pattern
- Element matching patternattributeName
- Attribute name that optionally overridesclazz
- Default Java class to be created
the default Java class name to be createdObjectCreateRule
public void addSetNext(String pattern, String methodName)
pattern
- Element matching patternmethodName
- Method name to call on the parent elementSetNextRule
public void addSetNext(String pattern, String methodName, String paramType)
pattern
- Element matching patternmethodName
- Method name to call on the parent elementparamType
- Java class name of the expected parameter type
(if you wish to use a primitive type, specify the corresponding
Java wrapper class instead, such as java.lang.Boolean
for a boolean
parameter)SetNextRule
public void addSetRoot(String pattern, String methodName)
SetRootRule
with the specified parameters.pattern
- Element matching patternmethodName
- Method name to call on the root objectSetRootRule
public void addSetRoot(String pattern, String methodName, String paramType)
SetRootRule
with the specified parameters.pattern
- Element matching patternmethodName
- Method name to call on the root objectparamType
- Java class name of the expected parameter typeSetRootRule
public void addSetProperties(String pattern)
pattern
- Element matching patternSetPropertiesRule
public void addSetProperties(String pattern, String attributeName, String propertyName)
SetPropertiesRule.SetPropertiesRule(String attributeName, String propertyName)
pattern
- Element matching patternattributeName
- map this attributepropertyName
- to this propertySetPropertiesRule
public void addSetProperties(String pattern, String[] attributeNames, String[] propertyNames)
SetPropertiesRule.SetPropertiesRule(String [] attributeNames, String [] propertyNames)
pattern
- Element matching patternattributeNames
- names of attributes with custom mappingspropertyNames
- property names these attributes map toSetPropertiesRule
public void addSetProperty(String pattern, String name, String value)
pattern
- Element matching patternname
- Attribute name containing the property name to be setvalue
- Attribute name containing the property value to setSetPropertyRule
public void addSetTop(String pattern, String methodName)
pattern
- Element matching patternmethodName
- Method name to call on the parent elementSetTopRule
public void addSetTop(String pattern, String methodName, String paramType)
pattern
- Element matching patternmethodName
- Method name to call on the parent elementparamType
- Java class name of the expected parameter type
(if you wish to use a primitive type, specify the corresponding
Java wrapper class instead, such as java.lang.Boolean
for a boolean
parameter)SetTopRule
public void clear()
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.
public void reset()
public Object peek()
null
.public Object peek(int n)
null
.n
- Index of the desired element, where 0 is the top of the stack,
1 is the next element down, and so on.public Object pop()
null
.public void push(Object object)
object
- The new objectpublic void push(String stackName, Object value)
stackName
- the name of the stack onto which the object should be pushedvalue
- the Object to be pushed onto the named stack.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.
stackName
- the name of the stack from which the top value is to be poppedObject
on the stack or or null if the stack is either
empty or has not been created yetEmptyStackException
- if the named stack is emptypublic 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.
stackName
- the name of the stack to be peekedObject
on the stack or null if the stack is either
empty or has not been created yetEmptyStackException
- if the named stack is emptypublic 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.
stackName
- the name of the stack whose emptiness
should be evaluatedpublic Object getRoot()
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 the
configured
flag.
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 the configured
flag is false.
Subclasses that override configure
or who set configured
may find that this method may be called more than once.
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
.
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
.
n
- Index of the desired element, where 0 is the top of the stack,
1 is the next element down, and so on.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
.
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
.
object
- The new objectpublic SAXException createSAXException(String message, Exception e)
message
- The error messagee
- The root causepublic SAXException createSAXException(Exception e)
e
- The root causepublic SAXException createSAXException(String message)
message
- The error messageCopyright © 2000-2021 Apache Software Foundation. All Rights Reserved.