|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xml.sax.helpers.DefaultHandler org.apache.commons.digester3.Digester
public class 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.
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.
A Digester instance should not be used for parsing more than one input document. The problem is that the Digester class has quite a few member variables whose values "evolve" as SAX events are received during a parse. When reusing the Digester instance, all these members must be reset back to their initial states before the second parse begins. The "clear()" method makes a stab at resetting these, but it is actually rather a difficult problem. If you are determined to reuse Digester instances, then at the least you should call the clear() method before each parse, and must call it if the Digester parse terminates due to an exception during a parse.
LEGACY IMPLEMENTATION NOTE - When using the legacy XML schema support (instead of using the
Schema
class), 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 work with the legacy XML schema support.
This package was inspired by the XmlMapper
class that was part of Tomcat 3.0 and 3.1, but is organized
somewhat differently.
Field Summary | |
---|---|
protected List<InputSource> |
inputSources
List of InputSource instances created by a createInputSourceFromURL()
method call. |
protected static String |
W3C_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 | ||
---|---|---|
void |
addBeanPropertySetter(String pattern)
Add a "bean property setter" rule for the specified parameters. |
|
void |
addBeanPropertySetter(String pattern,
String propertyName)
Add a "bean property setter" rule for the specified parameters. |
|
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<? extends ObjectCreationFactory<?>> clazz)
Add a "factory create" rule for the specified parameters. |
|
void |
addFactoryCreate(String pattern,
Class<? extends ObjectCreationFactory<?>> clazz,
boolean ignoreCreateExceptions)
Add a "factory create" rule for the specified parameters. |
|
void |
addFactoryCreate(String pattern,
Class<? extends ObjectCreationFactory<?>> clazz,
String attributeName)
Add a "factory create" rule for the specified parameters. |
|
void |
addFactoryCreate(String pattern,
Class<? extends ObjectCreationFactory<?>> 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 |
addSetNestedProperties(String pattern)
Adds an SetNestedPropertiesRule . |
|
void |
addSetNestedProperties(String pattern,
String[] elementNames,
String[] propertyNames)
Adds an SetNestedPropertiesRule . |
|
void |
addSetNestedProperties(String pattern,
String elementName,
String propertyName)
Adds an SetNestedPropertiesRule . |
|
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. |
|
|
asyncParse(File file)
Creates a Callable instance that parse the content of the specified reader using this Digester. |
|
|
asyncParse(InputSource input)
Creates a Callable instance that parse the content of the specified reader using this Digester. |
|
|
asyncParse(InputStream input)
Creates a Callable instance that parse the content of the specified reader using this Digester. |
|
|
asyncParse(Reader reader)
Creates a Callable instance that parse the content of the specified reader using this Digester. |
|
|
asyncParse(String uri)
Creates a Callable instance that parse the content of the specified reader using this Digester. |
|
|
asyncParse(URL url)
Creates a Callable instance that parse the content of the specified reader using this Digester. |
|
void |
characters(char[] buffer,
int start,
int length)
|
|
protected void |
cleanup()
Clean up allocated resources after parsing is complete. |
|
void |
clear()
Clear the current contents of the default object stack, the param stack, all named stacks, and other internal variables. |
|
protected void |
configure()
Provide a hook for lazy configuration of this Digester instance. |
|
InputSource |
createInputSourceFromURL(String url)
Convenience method that creates an InputSource from the string version of a URL. |
|
InputSource |
createInputSourceFromURL(URL url)
Given a URL, return an InputSource that reads from that URL. |
|
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()
|
|
void |
endElement(String namespaceURI,
String localName,
String qName)
|
|
void |
endPrefixMapping(String prefix)
|
|
void |
error(SAXParseException exception)
|
|
void |
fatalError(SAXParseException exception)
|
|
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()
Return the current depth of the element stack. |
|
String |
getCurrentElementName()
Return the name of the XML element that is currently being processed. |
|
Map<String,String> |
getCurrentNamespaces()
Get the most current namespaces for all prefixes. |
|
ContentHandler |
getCustomContentHandler()
returns the custom SAX ContentHandler where events are redirected. |
|
Locator |
getDocumentLocator()
Gets the document locator associated with our parser. |
|
EntityResolver |
getEntityResolver()
Return the Entity Resolver used by the SAX parser. |
|
ErrorHandler |
getErrorHandler()
Return the error handler for this Digester. |
|
ExecutorService |
getExecutorService()
Returns the executor service used to run asynchronous parse method. |
|
SAXParserFactory |
getFactory()
Return the SAXParserFactory we will use, creating one if necessary. |
|
boolean |
getFeature(String feature)
Returns a flag indicating whether the requested feature is supported by the underlying implementation of org.xml.sax.XMLReader . |
|
org.apache.commons.logging.Log |
getLogger()
Return the current Logger associated with this instance of the Digester |
|
String |
getMatch()
Return the current rule match path |
|
Stack<List<Rule>> |
getMatches()
Return a Stack whose elements are List objects, each containing a list of Rule objects as returned from Rules.getMatch(). |
|
boolean |
getNamespaceAware()
Return the "namespace aware" flag for parsers we create. |
|
SAXParser |
getParser()
Return the SAXParser we will use to parse the input stream. |
|
Object |
getProperty(String property)
Return the current value of the specified property for the underlying XMLReader implementation. |
|
String |
getPublicId()
Return the public identifier of the DTD we are currently parsing under, if any. |
|
|
getRoot()
Returns the root element of the tree of objects created as a result of applying the rule objects to the input XML. |
|
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. |
|
org.apache.commons.logging.Log |
getSAXLogger()
Gets the logger used for logging SAX-related information. |
|
StackAction |
getStackAction()
Return the callback object which is invoked whenever an object is pushed onto a digester object stack, or popped off one. |
|
Substitutor |
getSubstitutor()
Gets the Substitutor used to convert attributes and body text. |
|
boolean |
getUseContextClassLoader()
Return the boolean as to whether the context ClassLoader should be used. |
|
boolean |
getValidating()
Return the validating parser flag. |
|
boolean |
getXIncludeAware()
Return the XInclude-aware flag for parsers we create. |
|
XMLReader |
getXMLReader()
Return the XMLReader to be used for parsing the input document. |
|
Schema |
getXMLSchema()
Return the XML Schema used when parsing. |
|
void |
ignorableWhitespace(char[] buffer,
int start,
int len)
|
|
protected void |
initialize()
Provides a hook for lazy initialization of this Digester instance. |
|
boolean |
isConfigured()
Checks the Digester instance has been configured. |
|
boolean |
isEmpty(String stackName)
Is the stack with the given name empty? |
|
void |
notationDecl(String name,
String publicId,
String systemId)
|
|
|
parse(File file)
Parse the content of the specified file using this Digester. |
|
|
parse(InputSource input)
Parse the content of the specified input source using this Digester. |
|
|
parse(InputStream input)
Parse the content of the specified input stream using this Digester. |
|
|
parse(Reader reader)
Parse the content of the specified reader using this Digester. |
|
|
parse(String uri)
Parse the content of the specified URI using this Digester. |
|
|
parse(URL url)
Parse the content of the specified URL using this Digester. |
|
|
peek()
Return the top object on the stack without removing it. |
|
|
peek(int n)
Return the n'th object down the stack, where 0 is the top element and [getCount()-1] is the bottom element. |
|
|
peek(String stackName)
Gets the top object from the stack with the given name. |
|
|
peek(String stackName,
int n)
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. |
|
|
pop()
Pop the top object off of the stack, and return it. |
|
|
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)
|
|
|
push(String stackName,
T value)
Pushes the given object onto the stack with the given name. |
|
|
push(T object)
Push a new object onto the top of the object stack. |
|
void |
pushParams(Object... object)
Push a new object onto the top of the parameters stack. |
|
void |
register(String publicId,
String entityURL)
Convenience method that registers the string version of an entity URL instead of a URL version. |
|
void |
register(String publicId,
URL entityURL)
Register the specified DTD URL for the specified public identifier. |
|
void |
registerAll(Map<String,URL> entityValidator)
Convenience method that registers DTD URLs for the specified public identifiers. |
|
void |
resetRoot()
This method allows the "root" variable to be reset to null. |
|
InputSource |
resolveEntity(String publicId,
String systemId)
|
|
void |
setClassLoader(ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required. |
|
void |
setCustomContentHandler(ContentHandler handler)
Redirects (or cancels redirecting) of SAX ContentHandler events to an external object. |
|
void |
setDocumentLocator(Locator locator)
|
|
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 |
setExecutorService(ExecutorService executorService)
Sets the executor service to run asynchronous parse method. |
|
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(org.apache.commons.logging.Log log)
Set the current logger for this Digester. |
|
void |
setNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create. |
|
void |
setProperty(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 |
setSAXLogger(org.apache.commons.logging.Log saxLog)
Sets the logger used for logging SAX-related information. |
|
void |
setStackAction(StackAction stackAction)
Define a callback object which is invoked whenever an object is pushed onto a digester object stack, or popped off one. |
|
void |
setSubstitutor(Substitutor substitutor)
Sets the Substitutor to be used to convert attributes and body text. |
|
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 |
setXIncludeAware(boolean xincludeAware)
Set the XInclude-aware flag for parsers we create. |
|
void |
setXMLSchema(Schema schema)
Set the XML Schema to be used when parsing. |
|
void |
skippedEntity(String name)
|
|
void |
startDocument()
|
|
void |
startElement(String namespaceURI,
String localName,
String qName,
Attributes list)
|
|
void |
startPrefixMapping(String prefix,
String namespaceURI)
|
|
void |
unparsedEntityDecl(String name,
String publicId,
String systemId,
String notation)
|
|
void |
warning(SAXParseException exception)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String W3C_XML_SCHEMA
protected List<InputSource> inputSources
List
of InputSource
instances created by a createInputSourceFromURL()
method call. These represent open input streams that need to be closed to avoid resource leaks, as well as
potentially locked JAR files on Windows.
Constructor Detail |
---|
public Digester()
public Digester(SAXParser parser)
parser
- The SAXParser used to parse XML streamspublic Digester(XMLReader reader)
reader
- The XMLReader used to parse XML streamsMethod Detail |
---|
public String findNamespaceURI(String prefix)
null
.
These mappings come and go dynamically as the document is parsed.
prefix
- Prefix to look up
public ClassLoader getClassLoader()
setClassLoader()
, if anyuseContextClassLoader
property is set to
true
public 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()
public boolean getFeature(String feature) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException
org.xml.sax.XMLReader
. See the saxproject website for
information about the standard SAX2 feature flags.
feature
- Name of the feature to inquire about
org.xml.sax.XMLReader
, false otherwise
ParserConfigurationException
- if a parser configuration error occurs
SAXNotRecognizedException
- if the property name is not recognized
SAXNotSupportedException
- if the property name is recognized but not supportedpublic void setFeature(String feature, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException
org.xml.sax.XMLReader
. See the saxproject website for
information about the standard SAX2 feature flags. In order to be effective, this method must be called
before 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 feature
ParserConfigurationException
- if a parser configuration error occurs
SAXNotRecognizedException
- if the property name is not recognized
SAXNotSupportedException
- if the property name is recognized but not supportedpublic org.apache.commons.logging.Log getLogger()
public void setLogger(org.apache.commons.logging.Log log)
log
- the current logger for this Digester.public org.apache.commons.logging.Log getSAXLogger()
public void setSAXLogger(org.apache.commons.logging.Log saxLog)
saxLog
- the logger used for logging SAX-related information, not nullpublic String getMatch()
public Stack<List<Rule>> getMatches()
public boolean getNamespaceAware()
public void setNamespaceAware(boolean namespaceAware)
namespaceAware
- The new "namespace aware" flagpublic boolean getXIncludeAware()
getNamespaceAware()
public void setXIncludeAware(boolean xincludeAware)
xincludeAware
- The new XInclude-aware flagsetNamespaceAware(boolean)
public void setPublicId(String publicId)
publicId
- the DTD/Schema public's id.public String getPublicId()
public String getRuleNamespaceURI()
Rule
objects.
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 the saxproject website for information about the standard SAX2
properties.
property
- Property name to be retrieved
XMLReader
implementation.
SAXNotRecognizedException
- if the property name is not recognized
SAXNotSupportedException
- if the property name is recognized but not supportedpublic void setProperty(String property, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
XMLReader
implementation. See the saxproject website for information about the standard SAX2 properties.
property
- Property name to be setvalue
- Property value to be set
SAXNotRecognizedException
- if the property name is not recognized
SAXNotSupportedException
- 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.
Rules
implementation object.public void setRules(Rules rules)
Rules
implementation object containing our rules collection and associated matching policy.
rules
- New Rules implementationpublic Schema getXMLSchema()
Schema
instance in use.public void setXMLSchema(Schema schema)
schema
- The Schema
instance to use.public 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 XMLReader getXMLReader() throws SAXException
SAXException
- if no XMLReader can be instantiatedpublic Substitutor getSubstitutor()
Substitutor
used to convert attributes and body text.
Substitutor
used to convert attributes and body text,
null if not substitutions are to be performed.public void setSubstitutor(Substitutor substitutor)
Substitutor
to be used to convert attributes and body text.
substitutor
- the Substitutor to be used to convert attributes and body text or null if not substitution of
these values is to be performed.public ContentHandler getCustomContentHandler()
setCustomContentHandler(ContentHandler)
public void setCustomContentHandler(ContentHandler handler)
When this object's customContentHandler is non-null, any SAX events received from the parser will simply be passed on to the specified object instead of this object handling them. This allows Rule classes to take control of the SAX event stream for a while in order to do custom processing. Such a rule should save the old value before setting a new one, and restore the old value in order to resume normal digester processing.
An example of a Rule which needs this feature is NodeCreateRule.
Note that saving the old value is probably not needed as it should always be null; a custom rule that wants to take control could only have been called when there was no custom content handler. But it seems cleaner to properly save/restore the value and maybe some day this will come in useful.
Note also that this is not quite equivalent to
digester.getXMLReader().setContentHandler( handler )for these reasons:
handler
- the custom SAX ContentHandler where events are redirected.public void setStackAction(StackAction stackAction)
stackAction
- the callback object which is invoked whenever an object is pushed onto a digester
object stack, or popped off one.public StackAction getStackAction()
setStackAction(StackAction)
public Map<String,String> getCurrentNamespaces()
public ExecutorService getExecutorService()
public void setExecutorService(ExecutorService executorService)
executorService
- the executor service to run asynchronous parse methodpublic void characters(char[] buffer, int start, int length) throws SAXException
characters
in interface ContentHandler
characters
in class DefaultHandler
SAXException
public void endDocument() throws SAXException
endDocument
in interface ContentHandler
endDocument
in class DefaultHandler
SAXException
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
endElement
in interface ContentHandler
endElement
in class DefaultHandler
SAXException
public void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping
in interface ContentHandler
endPrefixMapping
in class DefaultHandler
SAXException
public void ignorableWhitespace(char[] buffer, int start, int len) throws SAXException
ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in class DefaultHandler
SAXException
public void processingInstruction(String target, String data) throws SAXException
processingInstruction
in interface ContentHandler
processingInstruction
in class DefaultHandler
SAXException
public Locator getDocumentLocator()
public void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
setDocumentLocator
in class DefaultHandler
public void skippedEntity(String name) throws SAXException
skippedEntity
in interface ContentHandler
skippedEntity
in class DefaultHandler
SAXException
public void startDocument() throws SAXException
startDocument
in interface ContentHandler
startDocument
in class DefaultHandler
SAXException
public void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXException
startElement
in interface ContentHandler
startElement
in class DefaultHandler
SAXException
public void startPrefixMapping(String prefix, String namespaceURI) throws SAXException
startPrefixMapping
in interface ContentHandler
startPrefixMapping
in class DefaultHandler
SAXException
public void notationDecl(String name, String publicId, String systemId)
notationDecl
in interface DTDHandler
notationDecl
in class DefaultHandler
public void unparsedEntityDecl(String name, String publicId, String systemId, String notation)
unparsedEntityDecl
in interface DTDHandler
unparsedEntityDecl
in class DefaultHandler
public 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 publicId, String systemId) throws SAXException
resolveEntity
in interface EntityResolver
resolveEntity
in class DefaultHandler
SAXException
public void error(SAXParseException exception) throws SAXException
error
in interface ErrorHandler
error
in class DefaultHandler
SAXException
public void fatalError(SAXParseException exception) throws SAXException
fatalError
in interface ErrorHandler
fatalError
in class DefaultHandler
SAXException
public void warning(SAXParseException exception) throws SAXException
warning
in interface ErrorHandler
warning
in class DefaultHandler
SAXException
public <T> T parse(File file) throws IOException, SAXException
T
- the type used to auto-cast the returned object to the assigned variable typefile
- File containing the XML data to be parsed
IOException
- if an input/output error occurs
SAXException
- if a parsing exception occurspublic <T> Future<T> asyncParse(File file)
T
- The result type returned by the returned Future's get
methodfile
- File containing the XML data to be parsed
parse(File)
public <T> T parse(InputSource input) throws IOException, SAXException
T
- the type used to auto-cast the returned object to the assigned variable typeinput
- Input source containing the XML data to be parsed
IOException
- if an input/output error occurs
SAXException
- if a parsing exception occurspublic <T> Future<T> asyncParse(InputSource input)
T
- The result type returned by the returned Future's get
methodinput
- Input source containing the XML data to be parsed
parse(InputSource)
public <T> T parse(InputStream input) throws IOException, SAXException
T
- the type used to auto-cast the returned object to the assigned variable typeinput
- Input stream containing the XML data to be parsed
IOException
- if an input/output error occurs
SAXException
- if a parsing exception occurspublic <T> Future<T> asyncParse(InputStream input)
T
- The result type returned by the returned Future's get
methodinput
- Input stream containing the XML data to be parsed
parse(InputStream)
public <T> T parse(Reader reader) throws IOException, SAXException
T
- the type used to auto-cast the returned object to the assigned variable typereader
- Reader containing the XML data to be parsed
IOException
- if an input/output error occurs
SAXException
- if a parsing exception occurspublic <T> Future<T> asyncParse(Reader reader)
T
- The result type returned by the returned Future's get
methodreader
- Reader containing the XML data to be parsed
parse(Reader)
public <T> T parse(String uri) throws IOException, SAXException
T
- the type used to auto-cast the returned object to the assigned variable typeuri
- URI containing the XML data to be parsed
IOException
- if an input/output error occurs
SAXException
- if a parsing exception occurspublic <T> Future<T> asyncParse(String uri)
T
- The result type returned by the returned Future's get
methoduri
- URI containing the XML data to be parsed
parse(String)
public <T> T parse(URL url) throws IOException, SAXException
T
- the type used to auto-cast the returned object to the assigned variable typeurl
- URL containing the XML data to be parsed
IOException
- if an input/output error occurs
SAXException
- if a parsing exception occurspublic <T> Future<T> asyncParse(URL url)
T
- The result type returned by the returned Future's get
methodurl
- URL containing the XML data to be parsed
parse(URL)
public void register(String publicId, URL 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 register(String publicId, String entityURL)
Convenience method that registers the string version of an entity URL instead of a URL version.
publicId
- Public identifier of the entity to be resolvedentityURL
- The URL to use for reading this entitypublic void registerAll(Map<String,URL> entityValidator)
entityValidator
- The URLs of entityValidator that have been registered, keyed by the public
identifier that corresponds.public InputSource createInputSourceFromURL(URL url) throws IOException
Ideally this function would not be needed and code could just use new InputSource(entityURL)
.
Unfortunately it appears that when the entityURL points to a file within a jar archive a caching mechanism inside
the InputSource implementation causes a file-handle to the jar file to remain open. On Windows systems this then
causes the jar archive file to be locked on disk ("in use") which makes it impossible to delete the jar file -
and that really stuffs up "undeploy" in webapps in particular.
In JDK1.4 and later, Apache XercesJ is used as the xml parser. The InputSource object provided is converted into an XMLInputSource, and eventually passed to an instance of XMLDocumentScannerImpl to specify the source data to be converted into tokens for the rest of the XMLReader code to handle. XMLDocumentScannerImpl calls fEntityManager.startDocumentEntity(source), where fEntityManager is declared in ancestor class XMLScanner to be an XMLEntityManager. In that class, if the input source stream is null, then:
URL location = new URL( expandedSystemId ); URLConnection connect = location.openConnection(); if ( connect instanceof HttpURLConnection ) { setHttpProperties( connect, xmlInputSource ); } stream = connect.getInputStream();This method pretty much duplicates the standard behaviour, except that it calls URLConnection.setUseCaches(false) before opening the connection.
url
- The URL has to be read
IOException
- if any error occurs while reading the input URLpublic InputSource createInputSourceFromURL(String url) throws IOException
Convenience method that creates an InputSource
from the string version of a URL.
url
- URL for which to create an InputSource
IOException
- if any error occurs while reading the input URLpublic 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 addBeanPropertySetter(String pattern)
pattern
- Element matching patternBeanPropertySetterRule
public void addBeanPropertySetter(String pattern, String propertyName)
pattern
- Element matching patternpropertyName
- Name of property to setBeanPropertySetterRule
public 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 corresonding 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
corresonding 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)
pattern
- Element matching patternparamIndex
- 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)
pattern
- Element matching patternparamIndex
- 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).
pattern
- Element matching patternparamIndex
- 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<? extends ObjectCreationFactory<?>> 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<? extends ObjectCreationFactory<?>> 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<? extends ObjectCreationFactory<?>> 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<? extends ObjectCreationFactory<?>> 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 addSetNestedProperties(String pattern)
SetNestedPropertiesRule
.
pattern
- register the rule with this patternpublic void addSetNestedProperties(String pattern, String elementName, String propertyName)
SetNestedPropertiesRule
.
pattern
- register the rule with this patternelementName
- elment name that a property maps topropertyName
- property name of the element mapped frompublic void addSetNestedProperties(String pattern, String[] elementNames, String[] propertyNames)
SetNestedPropertiesRule
.
pattern
- register the rule with this patternelementNames
- elment names that (in order) map to propertiespropertyNames
- property names that (in order) elements are mapped topublic 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
corresonding 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
corresonding 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 (just to tidy up memory usage). In general, a separate Digester object should be created for each document to be parsed.
Note that this method is called automatically after a document has been successfully parsed by a Digester instance. However it is not invoked automatically when a parse fails, so when reusing a Digester instance (which is not recommended) this method must be called manually after a parse failure.
public <T> T peek()
null
.
T
- the type used to auto-cast the returned object to the assigned variable type
public <T> T peek(int n)
null
.
T
- the type used to auto-cast the returned object to the assigned variable typen
- Index of the desired element, where 0 is the top of the stack, 1 is the next element down, and so on.
public <T> T pop()
null
.
T
- the type used to auto-cast the returned object to the assigned variable type
public <T> void push(T object)
T
- any type of the pushed objectobject
- The new objectpublic <T> void push(String stackName, T value)
T
- any type of the pushed objectstackName
- the name of the stack onto which the object should be pushedvalue
- the Object to be pushed onto the named stack.public <T> T 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.
T
- the type used to auto-cast the returned object to the assigned variable typestackName
- the name of the stack from which the top value is to be popped.
Object
on the stack or or null if the stack is either empty or has not been created
yetpublic <T> T 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.
T
- the type used to auto-cast the returned object to the assigned variable typestackName
- the name of the stack to be peeked
Object
on the stack or null if the stack is either empty or has not been created yetpublic <T> T peek(String stackName, int n)
Gets the top object from the stack with the given name. This method does not remove the object from the stack.
Note: a stack is considered empty if no objects have been pushed onto it yet.
T
- the type used to auto-cast the returned object to the assigned variable typestackName
- the name of the stack to be peekedn
- Index of the desired element, where 0 is the top of the stack, 1 is the next element down, and so on.
Object
on the stack.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.
stackName
- the name of the stack whose emptiness should be evaluated
public <T> T getRoot()
If the digester stack was "primed" by explicitly pushing a root object onto the stack before parsing started, then that root object is returned here.
Alternatively, if a Rule which creates an object (eg ObjectCreateRule) matched the root element of the xml, then the object created will be returned here.
In other cases, the object most recently pushed onto an empty digester stack is returned. This would be a most unusual use of digester, however; one of the previous configurations is much more likely.
Note that when using one of the Digester.parse methods, the return value from the parse method is exactly the same as the return value from this method. However when the Digester is being used as a SAXContentHandler, no such return value is available; in this case, this method allows you to access the root object that has been created after parsing has completed.
T
- the type used to auto-cast the returned object to the assigned variable type
public void resetRoot()
It is not considered safe for a digester instance to be reused to parse multiple xml documents. However if you are determined to do so, then you should call both clear() and resetRoot() before each parse.
protected void cleanup()
Clean up allocated resources after parsing is complete. The default method closes input streams that have been
created by Digester itself. If you override this method in a subclass, be sure to call
super.cleanup()
to invoke this logic.
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.
public boolean isConfigured()
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 custom SAX exception messagee
- the exception cause
public SAXException createSAXException(Exception e)
e
- the exception cause
public SAXException createSAXException(String message)
message
- the custom SAX exception message
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |