nsEntry : namespaces.entrySet()) {
try {
currentNamespaces.put(nsEntry.getKey(),
nsEntry.getValue().peek());
} catch (RuntimeException e) {
// rethrow, after logging
log.error(e.getMessage(), e);
throw e;
}
}
return currentNamespaces;
}
// ------------------------------------------------- ContentHandler Methods
/**
* Process notification of character data received from the body of
* an XML element.
*
* @param buffer The characters from the XML document
* @param start Starting offset into the buffer
* @param length Number of characters from the buffer
*
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void characters(char buffer[], int start, int length)
throws SAXException {
if (customContentHandler != null) {
// forward calls instead of handling them here
customContentHandler.characters(buffer, start, length);
return;
}
if (saxLog.isDebugEnabled()) {
saxLog.debug("characters(" + new String(buffer, start, length) + ")");
}
bodyText.append(buffer, start, length);
}
/**
* Process notification of the end of the document being reached.
*
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void endDocument() throws SAXException {
if (saxLog.isDebugEnabled()) {
if (getCount() > 1) {
saxLog.debug("endDocument(): " + getCount() +
" elements left");
} else {
saxLog.debug("endDocument()");
}
}
// Fire "finish" events for all defined rules
for (Rule rule : getRules().rules()) {
try {
rule.finish();
} catch (Exception e) {
log.error("Finish event threw exception", e);
throw createSAXException(e);
} catch (Error e) {
log.error("Finish event threw error", e);
throw e;
}
}
// Perform final cleanup
clear();
}
/**
* Process notification of the end of an XML element being reached.
*
* @param namespaceURI - The Namespace URI, or the empty string if the
* element has no Namespace URI or if Namespace processing is not
* being performed.
* @param localName - The local name (without prefix), or the empty
* string if Namespace processing is not being performed.
* @param qName - The qualified XML 1.0 name (with prefix), or the
* empty string if qualified names are not available.
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void endElement(String namespaceURI, String localName,
String qName) throws SAXException {
if (customContentHandler != null) {
// forward calls instead of handling them here
customContentHandler.endElement(namespaceURI, localName, qName);
return;
}
boolean debug = log.isDebugEnabled();
if (debug) {
if (saxLog.isDebugEnabled()) {
saxLog.debug("endElement(" + namespaceURI + "," + localName +
"," + qName + ")");
}
log.debug(" match='" + match + "'");
log.debug(" bodyText='" + bodyText + "'");
}
// the actual element name is either in localName or qName, depending
// on whether the parser is namespace aware
String name = localName;
if ((name == null) || (name.length() < 1)) {
name = qName;
}
// Fire "body" events for all relevant rules
List<Rule> rules = matches.pop();
if ((rules != null) && (rules.size() > 0)) {
String bodyText = this.bodyText.toString();
Substitutor substitutor = getSubstitutor();
if (substitutor!= null) {
bodyText = substitutor.substitute(bodyText);
}
for (int i = 0; i < rules.size(); i++) {
try {
Rule rule = rules.get(i);
if (debug) {
log.debug(" Fire body() for " + rule);
}
rule.body(namespaceURI, name, bodyText);
} catch (Exception e) {
log.error("Body event threw exception", e);
throw createSAXException(e);
} catch (Error e) {
log.error("Body event threw error", e);
throw e;
}
}
} else {
if (debug) {
log.debug(" No rules found matching '" + match + "'.");
}
}
// Recover the body text from the surrounding element
bodyText = bodyTexts.pop();
if (debug) {
log.debug(" Popping body text '" + bodyText.toString() + "'");
}
// Fire "end" events for all relevant rules in reverse order
if (rules != null) {
for (int i = 0; i < rules.size(); i++) {
int j = (rules.size() - i) - 1;
try {
Rule rule = rules.get(j);
if (debug) {
log.debug(" Fire end() for " + rule);
}
rule.end(namespaceURI, name);
} catch (Exception e) {
log.error("End event threw exception", e);
throw createSAXException(e);
} catch (Error e) {
log.error("End event threw error", e);
throw e;
}
}
}
// Recover the previous match expression
int slash = match.lastIndexOf('/');
if (slash >= 0) {
match = match.substring(0, slash);
} else {
match = "";
}
}
/**
* Process notification that a namespace prefix is going out of scope.
*
* @param prefix Prefix that is going out of scope
*
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void endPrefixMapping(String prefix) throws SAXException {
if (saxLog.isDebugEnabled()) {
saxLog.debug("endPrefixMapping(" + prefix + ")");
}
// Deregister this prefix mapping
Stack<String> stack = namespaces.get(prefix);
if (stack == null) {
return;
}
try {
stack.pop();
if (stack.empty())
namespaces.remove(prefix);
} catch (EmptyStackException e) {
throw createSAXException("endPrefixMapping popped too many times");
}
}
/**
* Process notification of ignorable whitespace received from the body of
* an XML element.
*
* @param buffer The characters from the XML document
* @param start Starting offset into the buffer
* @param len Number of characters from the buffer
*
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void ignorableWhitespace(char buffer[], int start, int len)
throws SAXException {
if (saxLog.isDebugEnabled()) {
saxLog.debug("ignorableWhitespace(" +
new String(buffer, start, len) + ")");
}
// No processing required
}
/**
* Process notification of a processing instruction that was encountered.
*
* @param target The processing instruction target
* @param data The processing instruction data (if any)
*
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void processingInstruction(String target, String data)
throws SAXException {
if (customContentHandler != null) {
// forward calls instead of handling them here
customContentHandler.processingInstruction(target, data);
return;
}
if (saxLog.isDebugEnabled()) {
saxLog.debug("processingInstruction('" + target + "','" + data + "')");
}
// No processing is required
}
/**
* Gets the document locator associated with our parser.
*
* @return the Locator supplied by the document parser
*/
public Locator getDocumentLocator() {
return locator;
}
/**
* Sets the document locator associated with our parser.
*
* @param locator The new locator
*/
@Override
public void setDocumentLocator(Locator locator) {
if (saxLog.isDebugEnabled()) {
saxLog.debug("setDocumentLocator(" + locator + ")");
}
this.locator = locator;
}
/**
* Process notification of a skipped entity.
*
* @param name Name of the skipped entity
*
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void skippedEntity(String name) throws SAXException {
if (saxLog.isDebugEnabled()) {
saxLog.debug("skippedEntity(" + name + ")");
}
// No processing required
}
/**
* Process notification of the beginning of the document being reached.
*
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void startDocument() throws SAXException {
if (saxLog.isDebugEnabled()) {
saxLog.debug("startDocument()");
}
// ensure that the digester is properly configured, as
// the digester could be used as a SAX ContentHandler
// rather than via the parse() methods.
configure();
}
/**
* Process notification of the start of an XML element being reached.
*
* @param namespaceURI The Namespace URI, or the empty string if the element
* has no Namespace URI or if Namespace processing is not being performed.
* @param localName The local name (without prefix), or the empty
* string if Namespace processing is not being performed.
* @param qName The qualified name (with prefix), or the empty
* string if qualified names are not available.\
* @param list The attributes attached to the element. If there are
* no attributes, it shall be an empty Attributes object.
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void startElement(String namespaceURI, String localName,
String qName, Attributes list)
throws SAXException {
boolean debug = log.isDebugEnabled();
if (customContentHandler != null) {
// forward calls instead of handling them here
customContentHandler.startElement(namespaceURI, localName, qName, list);
return;
}
if (saxLog.isDebugEnabled()) {
saxLog.debug("startElement(" + namespaceURI + "," + localName + "," +
qName + ")");
}
// Save the body text accumulated for our surrounding element
bodyTexts.push(bodyText);
if (debug) {
log.debug(" Pushing body text '" + bodyText.toString() + "'");
}
bodyText = new StringBuffer();
// the actual element name is either in localName or qName, depending
// on whether the parser is namespace aware
String name = localName;
if ((name == null) || (name.length() < 1)) {
name = qName;
}
// Compute the current matching rule
StringBuffer sb = new StringBuffer(match);
if (match.length() > 0) {
sb.append('/');
}
sb.append(name);
match = sb.toString();
if (debug) {
log.debug(" New match='" + match + "'");
}
// Fire "begin" events for all relevant rules
List<Rule> rules = getRules().match(namespaceURI, match);
matches.push(rules);
if ((rules != null) && (rules.size() > 0)) {
Substitutor substitutor = getSubstitutor();
if (substitutor!= null) {
list = substitutor.substitute(list);
}
for (int i = 0; i < rules.size(); i++) {
try {
Rule rule = rules.get(i);
if (debug) {
log.debug(" Fire begin() for " + rule);
}
rule.begin(namespaceURI, name, list);
} catch (Exception e) {
log.error("Begin event threw exception", e);
throw createSAXException(e);
} catch (Error e) {
log.error("Begin event threw error", e);
throw e;
}
}
} else {
if (debug) {
log.debug(" No rules found matching '" + match + "'.");
}
}
}
/**
* Process notification that a namespace prefix is coming in to scope.
*
* @param prefix Prefix that is being declared
* @param namespaceURI Corresponding namespace URI being mapped to
*
* @exception SAXException if a parsing error is to be reported
*/
@Override
public void startPrefixMapping(String prefix, String namespaceURI)
throws SAXException {
if (saxLog.isDebugEnabled()) {
saxLog.debug("startPrefixMapping(" + prefix + "," + namespaceURI + ")");
}
// Register this prefix mapping
Stack<String> stack = namespaces.get(prefix);
if (stack == null) {
stack = new Stack<String>();
namespaces.put(prefix, stack);
}
stack.push(namespaceURI);
}
// ----------------------------------------------------- DTDHandler Methods
/**
* Receive notification of a notation declaration event.
*
* @param name The notation name
* @param publicId The public identifier (if any)
* @param systemId The system identifier (if any)
*/
@Override
public void notationDecl(String name, String publicId, String systemId) {
if (saxLog.isDebugEnabled()) {
saxLog.debug("notationDecl(" + name + "," + publicId + "," +
systemId + ")");
}
}
/**
* Receive notification of an unparsed entity declaration event.
*
* @param name The unparsed entity name
* @param publicId The public identifier (if any)
* @param systemId The system identifier (if any)
* @param notation The name of the associated notation
*/
@Override
public void unparsedEntityDecl(String name, String publicId,
String systemId, String notation) {
if (saxLog.isDebugEnabled()) {
saxLog.debug("unparsedEntityDecl(" + name + "," + publicId + "," +
systemId + "," + notation + ")");
}
}
// ----------------------------------------------- EntityResolver Methods
/**
* Set the <code>EntityResolver used by SAX when resolving
* public id and system id.
* This must be called before the first call to <code>parse().
* @param entityResolver a class that implement the <code>EntityResolver interface.
*/
public void setEntityResolver(EntityResolver entityResolver){
this.entityResolver = entityResolver;
}
/**
* Return the Entity Resolver used by the SAX parser.
* @return Return the Entity Resolver used by the SAX parser.
*/
public EntityResolver getEntityResolver(){
return entityResolver;
}
/**
* Resolve the requested external entity.
*
* @param publicId The public identifier of the entity being referenced
* @param systemId The system identifier of the entity being referenced
*
* @exception SAXException if a parsing exception occurs
*
*/
@Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException {
if (saxLog.isDebugEnabled()) {
saxLog.debug("resolveEntity('" + publicId + "', '" + systemId + "')");
}
if (publicId != null)
this.publicId = publicId;
// Has this system identifier been registered?
URL entityURL = null;
if (publicId != null) {
entityURL = entityValidator.get(publicId);
}
// Redirect the schema location to a local destination
if (schemaLocation != null && entityURL == null && systemId != null){
entityURL = entityValidator.get(systemId);
}
if (entityURL == null) {
if (systemId == null) {
// cannot resolve
if (log.isDebugEnabled()) {
log.debug(" Cannot resolve null entity, returning null InputSource");
}
return (null);
} else {
// try to resolve using system ID
if (log.isDebugEnabled()) {
log.debug(" Trying to resolve using system ID '" + systemId + "'");
}
try {
entityURL = new URL(systemId);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Malformed URL '" + systemId
+ "' : " + e.getMessage());
}
}
}
// Return an input source to our alternative URL
if (log.isDebugEnabled()) {
log.debug(" Resolving to alternate DTD '" + entityURL + "'");
}
try {
return createInputSourceFromURL(entityURL);
} catch (Exception e) {
throw createSAXException(e);
}
}
// ------------------------------------------------- ErrorHandler Methods
/**
* Forward notification of a parsing error to the application supplied
* error handler (if any).
*
* @param exception The error information
*
* @exception SAXException if a parsing exception occurs
*/
@Override
public void error(SAXParseException exception) throws SAXException {
log.error("Parse Error at line " + exception.getLineNumber() +
" column " + exception.getColumnNumber() + ": " +
exception.getMessage(), exception);
if (errorHandler != null) {
errorHandler.error(exception);
}
}
/**
* Forward notification of a fatal parsing error to the application
* supplied error handler (if any).
*
* @param exception The fatal error information
*
* @exception SAXException if a parsing exception occurs
*/
@Override
public void fatalError(SAXParseException exception) throws SAXException {
log.error("Parse Fatal Error at line " + exception.getLineNumber() +
" column " + exception.getColumnNumber() + ": " +
exception.getMessage(), exception);
if (errorHandler != null) {
errorHandler.fatalError(exception);
}
}
/**
* Forward notification of a parse warning to the application supplied
* error handler (if any).
*
* @param exception The warning information
*
* @exception SAXException if a parsing exception occurs
*/
@Override
public void warning(SAXParseException exception) throws SAXException {
if (errorHandler != null) {
log.warn("Parse Warning Error at line " + exception.getLineNumber() +
" column " + exception.getColumnNumber() + ": " +
exception.getMessage(), exception);
errorHandler.warning(exception);
}
}
// ------------------------------------------------------- Public Methods
/**
* Log a message to our associated logger.
*
* @param message The message to be logged
* @deprecated Call getLogger() and use it's logging methods
*/
@Deprecated
public void log(String message) {
log.info(message);
}
/**
* Log a message and exception to our associated logger.
*
* @param message The message to be logged
* @deprecated Call getLogger() and use it's logging methods
*/
@Deprecated
public void log(String message, Throwable exception) {
log.error(message, exception);
}
/**
* Parse the content of the specified file using this Digester. Returns
* the root element from the object stack (if any).
*
* @param file File containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(File file) throws IOException, SAXException {
if (file == null) {
throw new IllegalArgumentException("File to parse is null");
}
configure();
InputSource input = new InputSource(new FileInputStream(file));
input.setSystemId(file.toURI().toURL().toString());
getXMLReader().parse(input);
cleanup();
return (root);
}
/**
* Parse the content of the specified input source using this Digester.
* Returns the root element from the object stack (if any).
*
* @param input Input source containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(InputSource input) throws IOException, SAXException {
if (input == null) {
throw new IllegalArgumentException("InputSource to parse is null");
}
configure();
getXMLReader().parse(input);
cleanup();
return (root);
}
/**
* Parse the content of the specified input stream using this Digester.
* Returns the root element from the object stack (if any).
*
* @param input Input stream containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(InputStream input) throws IOException, SAXException {
if (input == null) {
throw new IllegalArgumentException("InputStream to parse is null");
}
configure();
InputSource is = new InputSource(input);
getXMLReader().parse(is);
cleanup();
return (root);
}
/**
* Parse the content of the specified reader using this Digester.
* Returns the root element from the object stack (if any).
*
* @param reader Reader containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(Reader reader) throws IOException, SAXException {
if (reader == null) {
throw new IllegalArgumentException("Reader to parse is null");
}
configure();
InputSource is = new InputSource(reader);
getXMLReader().parse(is);
cleanup();
return (root);
}
/**
* Parse the content of the specified URI using this Digester.
* Returns the root element from the object stack (if any).
*
* @param uri URI containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(String uri) throws IOException, SAXException {
if (uri == null) {
throw new IllegalArgumentException("String URI to parse is null");
}
configure();
InputSource is = createInputSourceFromURL(uri);
getXMLReader().parse(is);
cleanup();
return (root);
}
/**
* Parse the content of the specified URL using this Digester.
* Returns the root element from the object stack (if any).
*
* @param url URL containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*
* @since 1.8
*/
public Object parse(URL url) throws IOException, SAXException {
if (url == null) {
throw new IllegalArgumentException("URL to parse is null");
}
configure();
InputSource is = createInputSourceFromURL(url);
getXMLReader().parse(is);
cleanup();
return (root);
}
/**
* <p>Register the specified DTD URL for the specified public identifier.
* This must be called before the first call to <code>parse().
* </p>
* <code>Digester contains an internal EntityResolver
* implementation. This maps <code>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 <code>SYSTEM
* URI on every processed xml document is local. This implementation provides
* only basic functionality. If more sophisticated features are required,
* using {@link #setEntityResolver} to set a custom resolver is recommended.
* </p>
* <strong>Note: This method will have no effect when a custom
* <code>EntityResolver has been set. (Setting a custom
* <code>EntityResolver overrides the internal implementation.)
* </p>
* @param publicId Public identifier of the DTD to be resolved
* @param entityURL The URL to use for reading this DTD
*
* @since 1.8
*/
public void register(String publicId, URL entityURL) {
if (log.isDebugEnabled()) {
log.debug("register('" + publicId + "', '" + entityURL + "'");
}
entityValidator.put(publicId, entityURL);
}
/**
* <p>Convenience method that registers the string version of an entity URL
* instead of a URL version.</p>
*
* @param publicId Public identifier of the entity to be resolved
* @param entityURL The URL to use for reading this entity
*/
public void register(String publicId, String entityURL) {
if (log.isDebugEnabled()) {
log.debug("register('" + publicId + "', '" + entityURL + "'");
}
try {
entityValidator.put(publicId, new URL(entityURL));
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Malformed URL '" + entityURL
+ "' : " + e.getMessage());
}
}
/**
* <p>List
of InputSource
instances
* created by a <code>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.</p>
*/
protected List<InputSource> inputSources = new ArrayList(5);
/**
* Given a URL, return an InputSource that reads from that URL.
* <p>
* Ideally this function would not be needed and code could just use
* <code>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.
* <p>
* 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:
* <pre>
* URL location = new URL(expandedSystemId);
* URLConnection connect = location.openConnection();
* if (connect instanceof HttpURLConnection) {
* setHttpProperties(connect,xmlInputSource);
* }
* stream = connect.getInputStream();
* </pre>
* This method pretty much duplicates the standard behaviour, except
* that it calls URLConnection.setUseCaches(false) before opening
* the connection.
*
* @since 1.8
*/
public InputSource createInputSourceFromURL(URL url)
throws MalformedURLException, IOException {
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
InputStream stream = connection.getInputStream();
InputSource source = new InputSource(stream);
source.setSystemId(url.toExternalForm());
inputSources.add(source);
return source;
}
/**
* <p>Convenience method that creates an InputSource
* from the string version of a URL.</p>
*
* @param url URL for which to create an <code>InputSource
*
* @since 1.8
*/
public InputSource createInputSourceFromURL(String url)
throws MalformedURLException, IOException {
return createInputSourceFromURL(new URL(url));
}
// --------------------------------------------------------- Rule Methods
/**
* <p>Register a new Rule matching the specified pattern.
* This method sets the <code>Digester property on the rule.
*
* @param pattern Element matching pattern
* @param rule Rule to be registered
*/
public void addRule(String pattern, Rule rule) {
rule.setDigester(this);
getRules().add(pattern, rule);
}
/**
* Register a set of Rule instances defined in a RuleSet.
*
* @param ruleSet The RuleSet instance to configure from
*/
public void addRuleSet(RuleSet ruleSet) {
String oldNamespaceURI = getRuleNamespaceURI();
String newNamespaceURI = ruleSet.getNamespaceURI();
if (log.isDebugEnabled()) {
if (newNamespaceURI == null) {
log.debug("addRuleSet() with no namespace URI");
} else {
log.debug("addRuleSet() with namespace URI " + newNamespaceURI);
}
}
setRuleNamespaceURI(newNamespaceURI);
ruleSet.addRuleInstances(this);
setRuleNamespaceURI(oldNamespaceURI);
}
/**
* Add a "bean property setter" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @see BeanPropertySetterRule
*/
public void addBeanPropertySetter(String pattern) {
addRule(pattern,
new BeanPropertySetterRule());
}
/**
* Add a "bean property setter" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param propertyName Name of property to set
* @see BeanPropertySetterRule
*/
public void addBeanPropertySetter(String pattern,
String propertyName) {
addRule(pattern,
new BeanPropertySetterRule(propertyName));
}
/**
* Add an "call method" rule for a method which accepts no arguments.
*
* @param pattern Element matching pattern
* @param methodName Method name to be called
* @see CallMethodRule
*/
public void addCallMethod(String pattern, String methodName) {
addRule(
pattern,
new CallMethodRule(methodName));
}
/**
* Add an "call method" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param methodName Method name to be called
* @param paramCount Number of expected parameters (or zero
* for a single parameter from the body of this element)
* @see CallMethodRule
*/
public void addCallMethod(String pattern, String methodName,
int paramCount) {
addRule(pattern,
new CallMethodRule(methodName, paramCount));
}
/**
* Add an "call method" rule for the specified parameters.
* If <code>paramCount is set to zero the rule will use
* the body of the matched element as the single argument of the
* method, unless <code>paramTypes is null or empty, in this
* case the rule will call the specified method with no arguments.
*
* @param pattern Element matching pattern
* @param methodName Method name to be called
* @param paramCount Number of expected parameters (or zero
* for a single parameter from the body of this element)
* @param 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 <code>java.lang.Boolean
* for a <code>boolean parameter)
* @see CallMethodRule
*/
public void addCallMethod(String pattern, String methodName,
int paramCount, String paramTypes[]) {
addRule(pattern,
new CallMethodRule(
methodName,
paramCount,
paramTypes));
}
/**
* Add an "call method" rule for the specified parameters.
* If <code>paramCount is set to zero the rule will use
* the body of the matched element as the single argument of the
* method, unless <code>paramTypes is null or empty, in this
* case the rule will call the specified method with no arguments.
*
* @param pattern Element matching pattern
* @param methodName Method name to be called
* @param paramCount Number of expected parameters (or zero
* for a single parameter from the body of this element)
* @param 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 <code>java.lang.Boolean
* for a <code>boolean parameter)
* @see CallMethodRule
*/
public void addCallMethod(String pattern, String methodName,
int paramCount, Class<?> paramTypes[]) {
addRule(pattern,
new CallMethodRule(
methodName,
paramCount,
paramTypes));
}
/**
* Add a "call parameter" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param paramIndex Zero-relative parameter index to set
* (from the body of this element)
* @see CallParamRule
*/
public void addCallParam(String pattern, int paramIndex) {
addRule(pattern,
new CallParamRule(paramIndex));
}
/**
* Add a "call parameter" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param paramIndex Zero-relative parameter index to set
* (from the specified attribute)
* @param attributeName Attribute whose value is used as the
* parameter value
* @see CallParamRule
*/
public void addCallParam(String pattern, int paramIndex,
String attributeName) {
addRule(pattern,
new CallParamRule(paramIndex, attributeName));
}
/**
* Add a "call parameter" rule.
* This will either take a parameter from the stack
* or from the current element body text.
*
* @param paramIndex The zero-relative parameter number
* @param fromStack Should the call parameter be taken from the top of the stack?
* @see CallParamRule
*/
public void addCallParam(String pattern, int paramIndex, boolean fromStack) {
addRule(pattern,
new CallParamRule(paramIndex, fromStack));
}
/**
* Add a "call parameter" rule that sets a parameter from the stack.
* This takes a parameter from the given position on the stack.
*
* @param paramIndex The zero-relative parameter number
* @param stackIndex set the call parameter to the stackIndex'th object down the stack,
* where 0 is the top of the stack, 1 the next element down and so on
* @see CallMethodRule
*/
public void addCallParam(String pattern, int paramIndex, int stackIndex) {
addRule(pattern,
new CallParamRule(paramIndex, stackIndex));
}
/**
* Add a "call parameter" rule that sets a parameter from the current
* <code>Digester matching path.
* This is sometimes useful when using rules that support wildcards.
*
* @param pattern the pattern that this rule should match
* @param paramIndex The zero-relative parameter number
* @see CallMethodRule
*/
public void addCallParamPath(String pattern,int paramIndex) {
addRule(pattern, new PathCallParamRule(paramIndex));
}
/**
* Add a "call parameter" rule that sets a parameter from a
* caller-provided object. This can be used to pass constants such as
* strings to methods; it can also be used to pass mutable objects,
* providing ways for objects to do things like "register" themselves
* with some shared object.
* <p>
* 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).
*
* @param paramIndex The zero-relative parameter number
* @param paramObj Any arbitrary object to be passed to the target
* method.
* @see CallMethodRule
*
* @since 1.6
*/
public void addObjectParam(String pattern, int paramIndex,
Object paramObj) {
addRule(pattern,
new ObjectParamRule(paramIndex, paramObj));
}
/**
* Add a "factory create" rule for the specified parameters.
* Exceptions thrown during the object creation process will be propagated.
*
* @param pattern Element matching pattern
* @param className Java class name of the object creation factory class
* @see FactoryCreateRule
*/
public void addFactoryCreate(String pattern, String className) {
addFactoryCreate(pattern, className, false);
}
/**
* Add a "factory create" rule for the specified parameters.
* Exceptions thrown during the object creation process will be propagated.
*
* @param pattern Element matching pattern
* @param clazz Java class of the object creation factory class
* @see FactoryCreateRule
*/
public void addFactoryCreate(String pattern, Class<?> clazz) {
addFactoryCreate(pattern, clazz, false);
}
/**
* Add a "factory create" rule for the specified parameters.
* Exceptions thrown during the object creation process will be propagated.
*
* @param pattern Element matching pattern
* @param className Java class name of the object creation factory class
* @param attributeName Attribute name which, if present, overrides the
* value specified by <code>className
* @see FactoryCreateRule
*/
public void addFactoryCreate(String pattern, String className,
String attributeName) {
addFactoryCreate(pattern, className, attributeName, false);
}
/**
* Add a "factory create" rule for the specified parameters.
* Exceptions thrown during the object creation process will be propagated.
*
* @param pattern Element matching pattern
* @param clazz Java class of the object creation factory class
* @param attributeName Attribute name which, if present, overrides the
* value specified by <code>className
* @see FactoryCreateRule
*/
public void addFactoryCreate(String pattern, Class<?> clazz,
String attributeName) {
addFactoryCreate(pattern, clazz, attributeName, false);
}
/**
* Add a "factory create" rule for the specified parameters.
* Exceptions thrown during the object creation process will be propagated.
*
* @param pattern Element matching pattern
* @param creationFactory Previously instantiated ObjectCreationFactory
* to be utilized
* @see FactoryCreateRule
*/
public void addFactoryCreate(String pattern,
ObjectCreationFactory creationFactory) {
addFactoryCreate(pattern, creationFactory, false);
}
/**
* Add a "factory create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param className Java class name of the object creation factory class
* @param ignoreCreateExceptions when <code>true any exceptions thrown during
* object creation will be ignored.
* @see FactoryCreateRule
*/
public void addFactoryCreate(
String pattern,
String className,
boolean ignoreCreateExceptions) {
addRule(
pattern,
new FactoryCreateRule(className, ignoreCreateExceptions));
}
/**
* Add a "factory create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param clazz Java class of the object creation factory class
* @param ignoreCreateExceptions when <code>true any exceptions thrown during
* object creation will be ignored.
* @see FactoryCreateRule
*/
public void addFactoryCreate(
String pattern,
Class<?> clazz,
boolean ignoreCreateExceptions) {
addRule(
pattern,
new FactoryCreateRule(clazz, ignoreCreateExceptions));
}
/**
* Add a "factory create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param className Java class name of the object creation factory class
* @param attributeName Attribute name which, if present, overrides the
* value specified by <code>className
* @param ignoreCreateExceptions when <code>true any exceptions thrown during
* object creation will be ignored.
* @see FactoryCreateRule
*/
public void addFactoryCreate(
String pattern,
String className,
String attributeName,
boolean ignoreCreateExceptions) {
addRule(
pattern,
new FactoryCreateRule(className, attributeName, ignoreCreateExceptions));
}
/**
* Add a "factory create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param clazz Java class of the object creation factory class
* @param attributeName Attribute name which, if present, overrides the
* value specified by <code>className
* @param ignoreCreateExceptions when <code>true any exceptions thrown during
* object creation will be ignored.
* @see FactoryCreateRule
*/
public void addFactoryCreate(
String pattern,
Class<?> clazz,
String attributeName,
boolean ignoreCreateExceptions) {
addRule(
pattern,
new FactoryCreateRule(clazz, attributeName, ignoreCreateExceptions));
}
/**
* Add a "factory create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param creationFactory Previously instantiated ObjectCreationFactory
* to be utilized
* @param ignoreCreateExceptions when <code>true any exceptions thrown during
* object creation will be ignored.
* @see FactoryCreateRule
*/
public void addFactoryCreate(String pattern,
ObjectCreationFactory creationFactory,
boolean ignoreCreateExceptions) {
creationFactory.setDigester(this);
addRule(pattern,
new FactoryCreateRule(creationFactory, ignoreCreateExceptions));
}
/**
* Add an "object create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param className Java class name to be created
* @see ObjectCreateRule
*/
public void addObjectCreate(String pattern, String className) {
addRule(pattern,
new ObjectCreateRule(className));
}
/**
* Add an "object create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param clazz Java class to be created
* @see ObjectCreateRule
*/
public void addObjectCreate(String pattern, Class<?> clazz) {
addRule(pattern,
new ObjectCreateRule(clazz));
}
/**
* Add an "object create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param className Default Java class name to be created
* @param attributeName Attribute name that optionally overrides
* the default Java class name to be created
* @see ObjectCreateRule
*/
public void addObjectCreate(String pattern, String className,
String attributeName) {
addRule(pattern,
new ObjectCreateRule(className, attributeName));
}
/**
* Add an "object create" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param attributeName Attribute name that optionally overrides
* @param clazz Default Java class to be created
* the default Java class name to be created
* @see ObjectCreateRule
*/
public void addObjectCreate(String pattern,
String attributeName,
Class<?> clazz) {
addRule(pattern,
new ObjectCreateRule(attributeName, clazz));
}
/**
* Adds an {@link SetNestedPropertiesRule}.
*
* @param pattern register the rule with this pattern
*
* @since 1.6
*/
public void addSetNestedProperties(String pattern) {
addRule(pattern, new SetNestedPropertiesRule());
}
/**
* Adds an {@link SetNestedPropertiesRule}.
*
* @param pattern register the rule with this pattern
* @param elementName elment name that a property maps to
* @param propertyName property name of the element mapped from
*
* @since 1.6
*/
public void addSetNestedProperties(String pattern, String elementName, String propertyName) {
addRule(pattern, new SetNestedPropertiesRule(elementName, propertyName));
}
/**
* Adds an {@link SetNestedPropertiesRule}.
*
* @param pattern register the rule with this pattern
* @param elementNames elment names that (in order) map to properties
* @param propertyNames property names that (in order) elements are mapped to
*
* @since 1.6
*/
public void addSetNestedProperties(String pattern, String[] elementNames, String[] propertyNames) {
addRule(pattern, new SetNestedPropertiesRule(elementNames, propertyNames));
}
/**
* Add a "set next" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param methodName Method name to call on the parent element
* @see SetNextRule
*/
public void addSetNext(String pattern, String methodName) {
addRule(pattern,
new SetNextRule(methodName));
}
/**
* Add a "set next" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param methodName Method name to call on the parent element
* @param paramType Java class name of the expected parameter type
* (if you wish to use a primitive type, specify the corresonding
* Java wrapper class instead, such as <code>java.lang.Boolean
* for a <code>boolean parameter)
* @see SetNextRule
*/
public void addSetNext(String pattern, String methodName,
String paramType) {
addRule(pattern,
new SetNextRule(methodName, paramType));
}
/**
* Add {@link SetRootRule} with the specified parameters.
*
* @param pattern Element matching pattern
* @param methodName Method name to call on the root object
* @see SetRootRule
*/
public void addSetRoot(String pattern, String methodName) {
addRule(pattern,
new SetRootRule(methodName));
}
/**
* Add {@link SetRootRule} with the specified parameters.
*
* @param pattern Element matching pattern
* @param methodName Method name to call on the root object
* @param paramType Java class name of the expected parameter type
* @see SetRootRule
*/
public void addSetRoot(String pattern, String methodName,
String paramType) {
addRule(pattern,
new SetRootRule(methodName, paramType));
}
/**
* Add a "set properties" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @see SetPropertiesRule
*/
public void addSetProperties(String pattern) {
addRule(pattern,
new SetPropertiesRule());
}
/**
* Add a "set properties" rule with a single overridden parameter.
* See {@link SetPropertiesRule#SetPropertiesRule(String attributeName, String propertyName)}
*
* @param pattern Element matching pattern
* @param attributeName map this attribute
* @param propertyName to this property
* @see SetPropertiesRule
*/
public void addSetProperties(
String pattern,
String attributeName,
String propertyName) {
addRule(pattern,
new SetPropertiesRule(attributeName, propertyName));
}
/**
* Add a "set properties" rule with overridden parameters.
* See {@link SetPropertiesRule#SetPropertiesRule(String [] attributeNames, String [] propertyNames)}
*
* @param pattern Element matching pattern
* @param attributeNames names of attributes with custom mappings
* @param propertyNames property names these attributes map to
* @see SetPropertiesRule
*/
public void addSetProperties(
String pattern,
String [] attributeNames,
String [] propertyNames) {
addRule(pattern,
new SetPropertiesRule(attributeNames, propertyNames));
}
/**
* Add a "set property" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param name Attribute name containing the property name to be set
* @param value Attribute name containing the property value to set
* @see SetPropertyRule
*/
public void addSetProperty(String pattern, String name, String value) {
addRule(pattern,
new SetPropertyRule(name, value));
}
/**
* Add a "set top" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param methodName Method name to call on the parent element
* @see SetTopRule
*/
public void addSetTop(String pattern, String methodName) {
addRule(pattern,
new SetTopRule(methodName));
}
/**
* Add a "set top" rule for the specified parameters.
*
* @param pattern Element matching pattern
* @param methodName Method name to call on the parent element
* @param paramType Java class name of the expected parameter type
* (if you wish to use a primitive type, specify the corresonding
* Java wrapper class instead, such as <code>java.lang.Boolean
* for a <code>boolean parameter)
* @see SetTopRule
*/
public void addSetTop(String pattern, String methodName,
String paramType) {
addRule(pattern,
new SetTopRule(methodName, paramType));
}
// --------------------------------------------------- Object Stack Methods
/**
* Clear the current contents of the default object stack, the param stack,
* all named stacks, and other internal variables.
* <p>
* Calling this method <i>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.
* <p>
* 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 <i>must be called manually
* after a parse failure.
*/
public void clear() {
match = "";
bodyTexts.clear();
params.clear();
publicId = null;
stack.clear();
stacksByName.clear();
customContentHandler = null;
}
/**
* Return the top object on the stack without removing it. If there are
* no objects on the stack, return <code>null.
*/
public Object peek() {
try {
return (stack.peek());
} catch (EmptyStackException e) {
log.warn("Empty stack (returning null)");
return (null);
}
}
/**
* Return the n'th object down the stack, where 0 is the top element
* and [getCount()-1] is the bottom element. If the specified index
* is out of range, return <code>null.
*
* @param 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 peek(int n) {
int index = (stack.size() - 1) - n;
if (index < 0) {
log.warn("Empty stack (returning null)");
return (null);
}
try {
return (stack.get(index));
} catch (EmptyStackException e) {
log.warn("Empty stack (returning null)");
return (null);
}
}
/**
* Pop the top object off of the stack, and return it. If there are
* no objects on the stack, return <code>null.
*/
public Object pop() {
try {
Object popped = stack.pop();
if (stackAction != null) {
popped = stackAction.onPop(this, null, popped);
}
return popped;
} catch (EmptyStackException e) {
log.warn("Empty stack (returning null)");
return (null);
}
}
/**
* Push a new object onto the top of the object stack.
*
* @param object The new object
*/
public void push(Object object) {
if (stackAction != null) {
object = stackAction.onPush(this, null, object);
}
if (stack.size() == 0) {
root = object;
}
stack.push(object);
}
/**
* Pushes the given object onto the stack with the given name.
* If no stack already exists with the given name then one will be created.
*
* @param stackName the name of the stack onto which the object should be pushed
* @param value the Object to be pushed onto the named stack.
*
* @since 1.6
*/
public void push(String stackName, Object value) {
if (stackAction != null) {
value = stackAction.onPush(this, stackName, value);
}
Stack<Object> namedStack = stacksByName.get(stackName);
if (namedStack == null) {
namedStack = new Stack<Object>();
stacksByName.put(stackName, namedStack);
}
namedStack.push(value);
}
/**
* <p>Pops (gets and removes) the top object from the stack with the given name.
*
* <p>Note: a stack is considered empty
* if no objects have been pushed onto it yet.</p>
*
* @param stackName the name of the stack from which the top value is to be popped.
* @return the top <code>Object on the stack or or null if the stack is either
* empty or has not been created yet
* @throws EmptyStackException if the named stack is empty
*
* @since 1.6
*/
public Object pop(String stackName) {
Object result = null;
Stack<Object> namedStack = stacksByName.get(stackName);
if (namedStack == null) {
if (log.isDebugEnabled()) {
log.debug("Stack '" + stackName + "' is empty");
}
throw new EmptyStackException();
}
result = namedStack.pop();
if (stackAction != null) {
result = stackAction.onPop(this, stackName, result);
}
return result;
}
/**
* <p>Gets the top object from the stack with the given name.
* This method does not remove the object from the stack.
* </p>
* <p>Note: a stack is considered empty
* if no objects have been pushed onto it yet.</p>
*
* @param stackName the name of the stack to be peeked
* @return the top <code>Object on the stack or null if the stack is either
* empty or has not been created yet
* @throws EmptyStackException if the named stack is empty
*
* @since 1.6
*/
public Object peek(String stackName) {
return peek(stackName, 0);
}
/**
* <p>Gets the top object from the stack with the given name.
* This method does not remove the object from the stack.
* </p>
* <p>Note: a stack is considered empty
* if no objects have been pushed onto it yet.</p>
*
* @param stackName the name of the stack to be peeked
* @param n Index of the desired element, where 0 is the top of the stack,
* 1 is the next element down, and so on.
* @return the specified <code>Object on the stack.
* @throws EmptyStackException if the named stack is empty
*
* @since 1.6
*/
public Object peek(String stackName, int n) {
Object result = null;
Stack<Object> namedStack = stacksByName.get(stackName);
if (namedStack == null ) {
if (log.isDebugEnabled()) {
log.debug("Stack '" + stackName + "' is empty");
}
throw new EmptyStackException();
} else {
int index = (namedStack.size() - 1) - n;
if (index < 0) {
throw new EmptyStackException();
}
result = namedStack.get(index);
}
return result;
}
/**
* <p>Is the stack with the given name empty?
* <p>Note: a stack is considered empty
* if no objects have been pushed onto it yet.</p>
* @param stackName the name of the stack whose emptiness
* should be evaluated
* @return true if the given stack if empty
*
* @since 1.6
*/
public boolean isEmpty(String stackName) {
boolean result = true;
Stack<Object> namedStack = stacksByName.get(stackName);
if (namedStack != null ) {
result = namedStack.isEmpty();
}
return result;
}
/**
* Returns the root element of the tree of objects created as a result
* of applying the rule objects to the input XML.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
*
* @return the root object that has been created after parsing
* or null if the digester has not parsed any XML yet.
*/
public Object getRoot() {
return root;
}
/**
* This method allows the "root" variable to be reset to null.
* <p>
* 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.
*
* @since 1.7
*/
public void resetRoot() {
root = null;
}
// ------------------------------------------------ Parameter Stack Methods
// ------------------------------------------------------ Protected Methods
/**
* <p>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 <code>super.cleanup() to invoke this logic.
*
* @since 1.8
*/
protected void cleanup() {
// If we created any InputSource objects in this instance,
// they each have an input stream that should be closed
for (InputSource source : inputSources) {
try {
source.getByteStream().close();
} catch (IOException e) {
// Fall through so we get them all
}
}
inputSources.clear();
}
/**
* <p>
* Provide a hook for lazy configuration of this <code>Digester
* instance. The default implementation does nothing, but subclasses
* can override as needed.
* </p>
*
* <p>
* <strong>Note This method may be called more than once.
* Once only initialization code should be placed in {@link #initialize}
* or the code should take responsibility by checking and setting the
* {@link #configured} flag.
* </p>
*/
protected void configure() {
// Do not configure more than once
if (configured) {
return;
}
// Perform lazy configuration as needed
initialize(); // call hook method for subclasses that want to be initialized once only
// Nothing else required by default
// Set the configuration flag to avoid repeating
configured = true;
}
/**
* <p>
* Provides a hook for lazy initialization of this <code>Digester
* instance.
* The default implementation does nothing, but subclasses
* can override as needed.
* Digester (by default) only calls this method once.
* </p>
*
* <p>
* <strong>Note This method will be called by {@link #configure}
* only when the {@link #configured} flag is false.
* Subclasses that override <code>configure or who set configured
* may find that this method may be called more than once.
* </p>
*
* @since 1.6
*/
protected void initialize() {
// Perform lazy initialization as needed
// Nothing required by default
}
// -------------------------------------------------------- Package Methods
/**
* Return the set of DTD URL registrations, keyed by public identifier.
*/
Map<String, URL> getRegistrations() {
return (entityValidator);
}
/**
* Return the set of rules that apply to the specified match position.
* The selected rules are those that match exactly, or those rules
* that specify a suffix match and the tail of the rule matches the
* current match position. Exact matches have precedence over
* suffix matches, then (among suffix matches) the longest match
* is preferred.
*
* @param match The current match position
*
* @deprecated Call <code>match() on the Rules
* implementation returned by <code>getRules()
*/
@Deprecated
List<Rule> getRules(String match) {
return (getRules().match(match));
}
/**
* <p>Return the top object on the parameters stack without removing it. If there are
* no objects on the stack, return <code>null.
*
* <p>The parameters stack is used to store CallMethodRule
parameters.
* See {@link #params}.</p>
*/
public Object peekParams() {
try {
return (params.peek());
} catch (EmptyStackException e) {
log.warn("Empty stack (returning null)");
return (null);
}
}
/**
* <p>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 <code>null.
*
* <p>The parameters stack is used to store CallMethodRule
parameters.
* See {@link #params}.</p>
*
* @param 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 peekParams(int n) {
int index = (params.size() - 1) - n;
if (index < 0) {
log.warn("Empty stack (returning null)");
return (null);
}
try {
return (params.get(index));
} catch (EmptyStackException e) {
log.warn("Empty stack (returning null)");
return (null);
}
}
/**
* <p>Pop the top object off of the parameters stack, and return it. If there are
* no objects on the stack, return <code>null.
*
* <p>The parameters stack is used to store CallMethodRule
parameters.
* See {@link #params}.</p>
*/
public Object popParams() {
try {
if (log.isTraceEnabled()) {
log.trace("Popping params");
}
return (params.pop());
} catch (EmptyStackException e) {
log.warn("Empty stack (returning null)");
return (null);
}
}
/**
* <p>Push a new object onto the top of the parameters stack.
*
* <p>The parameters stack is used to store CallMethodRule
parameters.
* See {@link #params}.</p>
*
* @param object The new object
*/
public void pushParams(Object object) {
if (log.isTraceEnabled()) {
log.trace("Pushing params");
}
params.push(object);
}
/**
* Create a SAX exception which also understands about the location in
* the digester file where the exception occurs
*
* @return the new exception
*/
public SAXException createSAXException(String message, Exception e) {
if ((e != null) &&
(e instanceof InvocationTargetException)) {
Throwable t = ((InvocationTargetException) e).getTargetException();
if ((t != null) && (t instanceof Exception)) {
e = (Exception) t;
}
}
if (locator != null) {
String error = "Error at line " + locator.getLineNumber() + " char " +
locator.getColumnNumber() + ": " + message;
if (e != null) {
return new SAXParseException(error, locator, e);
} else {
return new SAXParseException(error, locator);
}
}
log.error("No Locator!");
if (e != null) {
return new SAXException(message, e);
} else {
return new SAXException(message);
}
}
/**
* Create a SAX exception which also understands about the location in
* the digester file where the exception occurs
*
* @return the new exception
*/
public SAXException createSAXException(Exception e) {
if (e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException) e).getTargetException();
if ((t != null) && (t instanceof Exception)) {
e = (Exception) t;
}
}
return createSAXException(e.getMessage(), e);
}
/**
* Create a SAX exception which also understands about the location in
* the digester file where the exception occurs
*
* @return the new exception
*/
public SAXException createSAXException(String message) {
return createSAXException(message, null);
}
}
Other Commons Digester examples (source code examples)
Here is a short list of links related to this Commons Digester Digester.java source code file: