in commons-digester3-core/src/main/java/org/apache/commons/digester3/Digester.java [1262:1374]
public void endElement( final String namespaceURI, final String localName, final String qName )
throws SAXException
{
if ( customContentHandler != null )
{
// forward calls instead of handling them here
customContentHandler.endElement( namespaceURI, localName, qName );
return;
}
final 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.isEmpty() )
{
name = qName;
}
// Fire "body" events for all relevant rules
final List<Rule> rules = matches.pop();
if ( rules != null && !rules.isEmpty() )
{
String bodyText = this.bodyText.toString();
final Substitutor substitutor = getSubstitutor();
if ( substitutor != null )
{
bodyText = substitutor.substitute( bodyText );
}
for ( final Rule rule : rules )
{
try
{
if ( debug )
{
log.debug( " Fire body() for " + rule );
}
rule.body( namespaceURI, name, bodyText );
}
catch ( final Exception e )
{
log.error( "Body event threw exception", e );
throw createSAXException( e );
}
catch ( final 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++ )
{
final int j = rules.size() - i - 1;
try
{
final Rule rule = rules.get( j );
if ( debug )
{
log.debug( " Fire end() for " + rule );
}
rule.end( namespaceURI, name );
}
catch ( final Exception e )
{
log.error( "End event threw exception", e );
throw createSAXException( e );
}
catch ( final Error e )
{
log.error( "End event threw error", e );
throw e;
}
}
}
// Recover the previous match expression
final int slash = match.lastIndexOf( '/' );
if ( slash >= 0 )
{
match = match.substring( 0, slash );
}
else
{
match = "";
}
}