|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.xml.sax.helpers.DefaultHandler | +--org.apache.commons.digester.Digester
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.
Field Summary | |
protected java.lang.StringBuffer |
bodyText
The body text of the current element. |
protected org.apache.commons.collections.ArrayStack |
bodyTexts
The stack of body text string buffers for surrounding elements. |
protected int |
debug
The debugging detail level of this component. |
protected java.util.HashMap |
dtds
The URLs of DTDs that have been registered, keyed by the public identifier that corresponds. |
protected org.xml.sax.ErrorHandler |
errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur. |
protected static javax.xml.parsers.SAXParserFactory |
factory
The SAXParserFactory that is created the first time we need it. |
protected org.xml.sax.Locator |
locator
The Locator associated with our parser. |
protected java.lang.String |
match
The current match pattern for nested element processing. |
protected boolean |
namespaceAware
Do we want a "namespace aware" parser? |
protected javax.xml.parsers.SAXParser |
parser
The SAXParser we will use to parse the input stream. |
protected java.lang.Object |
root
The "root" element of the stack (in other words, the last object that was popped. |
protected java.util.HashMap |
rules
The set of Rules that have been registered with this Digester. |
protected org.apache.commons.collections.ArrayStack |
stack
The object stack being constructed. |
protected boolean |
validating
Do we want to use a validating parser? |
protected java.io.PrintWriter |
writer
The PrintWriter to which we should send log output, or null to write to System.out . |
Constructor Summary | |
Digester()
Construct a new Digester with default properties. |
|
Digester(javax.xml.parsers.SAXParser parser)
Construct a new Digester, allowing a SAXParser to be passed in. |
Method Summary | |
void |
addCallMethod(java.lang.String pattern,
java.lang.String methodName,
int paramCount)
Add an "call method" rule for the specified parameters. |
void |
addCallMethod(java.lang.String pattern,
java.lang.String methodName,
int paramCount,
java.lang.Class[] paramTypes)
Add an "call method" rule for the specified parameters. |
void |
addCallMethod(java.lang.String pattern,
java.lang.String methodName,
int paramCount,
java.lang.String[] paramTypes)
Add an "call method" rule for the specified parameters. |
void |
addCallParam(java.lang.String pattern,
int paramIndex)
Add a "call parameter" rule for the specified parameters. |
void |
addCallParam(java.lang.String pattern,
int paramIndex,
java.lang.String attributeName)
Add a "call parameter" rule for the specified parameters. |
void |
addObjectCreate(java.lang.String pattern,
java.lang.String className)
Add an "object create" rule for the specified parameters. |
void |
addObjectCreate(java.lang.String pattern,
java.lang.String className,
java.lang.String attributeName)
Add an "object create" rule for the specified parameters. |
void |
addRule(java.lang.String pattern,
Rule rule)
Register a new Rule matching the specified pattern. |
void |
addSetNext(java.lang.String pattern,
java.lang.String methodName)
Add a "set next" rule for the specified parameters. |
void |
addSetNext(java.lang.String pattern,
java.lang.String methodName,
java.lang.String paramType)
Add a "set next" rule for the specified parameters. |
void |
addSetProperties(java.lang.String pattern)
Add a "set properties" rule for the specified parameters. |
void |
addSetProperty(java.lang.String pattern,
java.lang.String name,
java.lang.String value)
Add a "set property" rule for the specified parameters. |
void |
addSetTop(java.lang.String pattern,
java.lang.String methodName)
Add a "set top" rule for the specified parameters. |
void |
addSetTop(java.lang.String pattern,
java.lang.String methodName,
java.lang.String paramType)
Add a "set top" rule for the specified parameters. |
void |
characters(char[] buffer,
int start,
int length)
Process notification of character data received from the body of an XML element. |
void |
clear()
Clear the current contents of the object stack. |
void |
endDocument()
Process notification of the end of the document being reached. |
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
Process notification of the end of an XML element being reached. |
void |
error(org.xml.sax.SAXParseException exception)
Forward notification of a parsing error to the application supplied error handler (if any). |
void |
fatalError(org.xml.sax.SAXParseException exception)
Forward notification of a fatal parsing error to the application supplied error handler (if any). |
int |
getCount()
Return the current depth of the element stack. |
int |
getDebug()
Return the debugging detail level of this Digester. |
org.xml.sax.ErrorHandler |
getErrorHandler()
Return the error handler for this Digester. |
boolean |
getNamespaceAware()
Return the "namespace aware" flag for parsers we create. |
javax.xml.parsers.SAXParser |
getParser()
Return the SAXParser we will use to parse the input stream. |
(package private) java.util.Map |
getRegistrations()
Return the set of DTD URL registrations, keyed by public identifier. |
(package private) java.util.List |
getRules(java.lang.String match)
Return the set of rules that apply to the specified match position. |
boolean |
getValidating()
Return the validating parser flag. |
java.io.PrintWriter |
getWriter()
Return the logging writer for this Digester. |
void |
ignorableWhitespace(char[] buffer,
int start,
int len)
Process notification of ignorable whitespace received from the body of an XML element. |
void |
log(java.lang.String message)
Log a message to the log writer associated with this context. |
void |
log(java.lang.String message,
java.lang.Throwable exception)
Log a message and associated exception to the log writer associated with this context. |
void |
notationDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
Receive notification of a notation declaration event. |
java.lang.Object |
parse(java.io.File file)
Parse the content of the specified file using this Digester. |
java.lang.Object |
parse(org.xml.sax.InputSource input)
Parse the content of the specified input source using this Digester. |
java.lang.Object |
parse(java.io.InputStream input)
Parse the content of the specified input stream using this Digester. |
java.lang.Object |
parse(java.lang.String uri)
Parse the content of the specified URI using this Digester. |
java.lang.Object |
peek()
Return the top object on the stack without removing it. |
java.lang.Object |
peek(int n)
Return the n'th object down the stack, where 0 is the top element and [getCount()-1] is the bottom element. |
java.lang.Object |
pop()
Pop the top object off of the stack, and return it. |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Process notification of a processing instruction that was encountered. |
void |
push(java.lang.Object object)
Push a new object onto the top of the object stack. |
void |
register(java.lang.String publicId,
java.lang.String dtdURL)
Register the specified DTD URL for the specified public identifier. |
org.xml.sax.InputSource |
resolveEntity(java.lang.String publicId,
java.lang.String systemId)
Resolve the requested external entity. |
void |
setDebug(int debug)
Set the debugging detail level of this Digester. |
void |
setDocumentLocator(org.xml.sax.Locator locator)
Set the document locator associated with our parser. |
void |
setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Set the error handler for this Digester. |
void |
setNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create. |
void |
setValidating(boolean validating)
Set the validating parser flag. |
void |
setWriter(java.io.PrintWriter writer)
Set the logging writer for this Digester. |
void |
startDocument()
Process notification of the beginning of the document being reached. |
void |
startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes list)
Process notification of the start of an XML element being reached. |
void |
unparsedEntityDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId,
java.lang.String notation)
Receive notification of an unparsed entity declaration event. |
void |
warning(org.xml.sax.SAXParseException exception)
Forward notification of a parse warning to the application supplied error handler (if any). |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
endPrefixMapping, skippedEntity, startPrefixMapping |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected java.lang.StringBuffer bodyText
protected org.apache.commons.collections.ArrayStack bodyTexts
protected int debug
protected java.util.HashMap dtds
protected org.xml.sax.ErrorHandler errorHandler
protected static javax.xml.parsers.SAXParserFactory factory
protected org.xml.sax.Locator locator
protected java.lang.String match
protected boolean namespaceAware
protected javax.xml.parsers.SAXParser parser
protected java.lang.Object root
protected java.util.HashMap rules
protected org.apache.commons.collections.ArrayStack stack
protected boolean validating
protected java.io.PrintWriter writer
null
to write to System.out
.Constructor Detail |
public Digester()
public Digester(javax.xml.parsers.SAXParser parser)
Method Detail |
public int getCount()
public int getDebug()
public void setDebug(int debug)
debug
- The new debugging detail levelpublic org.xml.sax.ErrorHandler getErrorHandler()
public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
errorHandler
- The new error handlerpublic boolean getNamespaceAware()
public void setNamespaceAware(boolean namespaceAware)
namespaceAware
- The new "namespace aware" flagpublic javax.xml.parsers.SAXParser getParser()
null
.public boolean getValidating()
public void setValidating(boolean validating)
parse()
is called the first time.validating
- The new validating parser flag.public java.io.PrintWriter getWriter()
public void setWriter(java.io.PrintWriter writer)
writer
- The new PrintWriter, or null
for
System.out
.public void characters(char[] buffer, int start, int length) throws org.xml.sax.SAXException
characters
in class org.xml.sax.helpers.DefaultHandler
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlength
- Number of characters from the bufferorg.xml.sax.SAXException
- if a parsing error is to be reportedpublic void endDocument() throws org.xml.sax.SAXException
endDocument
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
endElement
in class org.xml.sax.helpers.DefaultHandler
uri
- - 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.org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void ignorableWhitespace(char[] buffer, int start, int len) throws org.xml.sax.SAXException
ignorableWhitespace
in class org.xml.sax.helpers.DefaultHandler
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlength
- Number of characters from the bufferorg.xml.sax.SAXException
- if a parsing error is to be reportedpublic void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
processingInstruction
in class org.xml.sax.helpers.DefaultHandler
target
- The processing instruction targetdata
- The processing instruction data (if any)org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator
in class org.xml.sax.helpers.DefaultHandler
locator
- The new locatorpublic void startDocument() throws org.xml.sax.SAXException
startDocument
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes list) throws org.xml.sax.SAXException
startElement
in class org.xml.sax.helpers.DefaultHandler
uri
- 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.org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
notationDecl
in class org.xml.sax.helpers.DefaultHandler
name
- The notation namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notation)
unparsedEntityDecl
in class org.xml.sax.helpers.DefaultHandler
name
- The unparsed entity namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)notation
- The name of the associated notationpublic org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
resolveEntity
in class org.xml.sax.helpers.DefaultHandler
publicId
- The public identifier of the entity being referencedsystemId
- The system identifier of the entity being referencedorg.xml.sax.SAXException
- if a parsing exception occurspublic void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
error
in class org.xml.sax.helpers.DefaultHandler
exception
- The error informationorg.xml.sax.SAXException
- if a parsing exception occurspublic void fatalError(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
fatalError
in class org.xml.sax.helpers.DefaultHandler
exception
- The fatal error informationorg.xml.sax.SAXException
- if a parsing exception occurspublic void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
warning
in class org.xml.sax.helpers.DefaultHandler
exception
- The warning informationorg.xml.sax.SAXException
- if a parsing exception occurspublic void log(java.lang.String message)
message
- The message to be loggedpublic void log(java.lang.String message, java.lang.Throwable exception)
message
- The message to be loggedexception
- The associated exception to be loggedpublic java.lang.Object parse(java.io.File file) throws java.io.IOException, org.xml.sax.SAXException
file
- File containing the XML data to be parsedjava.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurspublic java.lang.Object parse(org.xml.sax.InputSource input) throws java.io.IOException, org.xml.sax.SAXException
input
- Input source containing the XML data to be parsedjava.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurspublic java.lang.Object parse(java.io.InputStream input) throws java.io.IOException, org.xml.sax.SAXException
input
- Input stream containing the XML data to be parsedjava.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurspublic java.lang.Object parse(java.lang.String uri) throws java.io.IOException, org.xml.sax.SAXException
uri
- URI containing the XML data to be parsedjava.io.IOException
- if an input/output error occursorg.xml.sax.SAXException
- if a parsing exception occurspublic void register(java.lang.String publicId, java.lang.String dtdURL)
parse()
.publicId
- Public identifier of the DTD to be resolveddtdURL
- The URL to use for reading this DTDpublic void addRule(java.lang.String pattern, Rule rule)
pattern
- Element matching patternrule
- Rule to be registeredpublic void addCallMethod(java.lang.String pattern, java.lang.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)public void addCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount, java.lang.String[] paramTypes)
pattern
- Element matching patternmethodName
- Method name to be calledparamCount
- Number of expected parameters (or zero
for a single parameter from the body of this element)paramTypes
- Set of Java class names for the types
of the expected parameters
(if you wish to use a primitive type, specify the corresonding
Java wrapper class instead, such as java.lang.Boolean
for a boolean
parameter)public void addCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount, java.lang.Class[] paramTypes)
pattern
- Element matching patternmethodName
- Method name to be calledparamCount
- Number of expected parameters (or zero
for a single parameter from the body of this element)paramTypes
- The Java class names of the arguments
(if you wish to use a primitive type, specify the corresonding
Java wrapper class instead, such as java.lang.Boolean
for a boolean
parameter)public void addCallParam(java.lang.String pattern, int paramIndex)
pattern
- Element matching patternparamIndex
- Zero-relative parameter index to set
(from the body of this element)public void addCallParam(java.lang.String pattern, int paramIndex, java.lang.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 valuepublic void addObjectCreate(java.lang.String pattern, java.lang.String className)
pattern
- Element matching patternclassName
- Java class name to be createdpublic void addObjectCreate(java.lang.String pattern, java.lang.String className, java.lang.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 createdpublic void addSetNext(java.lang.String pattern, java.lang.String methodName)
pattern
- Element matching patternmethodName
- Method name to call on the parent elementpublic void addSetNext(java.lang.String pattern, java.lang.String methodName, java.lang.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 corresonding
Java wrapper class instead, such as java.lang.Boolean
for a boolean
parameter)public void addSetProperties(java.lang.String pattern)
pattern
- Element matching patternpublic void addSetProperty(java.lang.String pattern, java.lang.String name, java.lang.String value)
pattern
- Element matching patternname
- Attribute name containing the property name to be setvalue
- Attribute name containing the property value to setpublic void addSetTop(java.lang.String pattern, java.lang.String methodName)
pattern
- Element matching patternmethodName
- Method name to call on the parent elementpublic void addSetTop(java.lang.String pattern, java.lang.String methodName, java.lang.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 corresonding
Java wrapper class instead, such as java.lang.Boolean
for a boolean
parameter)public void clear()
public java.lang.Object peek()
null
.public java.lang.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 java.lang.Object pop()
null
.public void push(java.lang.Object object)
object
- The new objectjava.util.Map getRegistrations()
java.util.List getRules(java.lang.String match)
match
- The current match position
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |