FileDocCategorySizeDatePackage
Digester.javaAPI DocApache Tomcat 6.0.1489009Fri Jul 20 04:20:34 BST 2007org.apache.tomcat.util.digester

Digester

public class Digester extends DefaultHandler

A Digester processes an XML input stream by matching a series of element nesting patterns to execute Rules that have been added prior to the start of parsing. This package was inspired by the XmlMapper class that was part of Tomcat 3.0 and 3.1, but is organized somewhat differently.

See the Digester Developer Guide for more information.

IMPLEMENTATION NOTE - A single Digester instance may only be used within the context of a single thread at a time, and a call to parse() must be completed before another can be initiated even from the same thread.

IMPLEMENTATION NOTE - A bug in Xerces 2.0.2 prevents the support of XML schema. You need Xerces 2.1/2.3 and up to make this class working with XML schema

Fields Summary
protected static IntrospectionUtils.PropertySource[]
source
protected StringBuffer
bodyText
The body text of the current element.
protected ArrayStack
bodyTexts
The stack of body text string buffers for surrounding elements.
protected ArrayStack
matches
Stack whose elements are List objects, each containing a list of Rule objects as returned from Rules.getMatch(). As each xml element in the input is entered, the matching rules are pushed onto this stack. After the end tag is reached, the matches are popped again. The depth of is stack is therefore exactly the same as the current "nesting" level of the input xml.
protected ClassLoader
classLoader
The class loader to use for instantiating application objects. If not specified, the context class loader, or the class loader used to load Digester itself, is used, based on the value of the useContextClassLoader variable.
protected boolean
configured
Has this Digester been configured yet.
protected EntityResolver
entityResolver
The EntityResolver used by the SAX parser. By default it use this class
protected HashMap
entityValidator
The URLs of entityValidator that have been registered, keyed by the public identifier that corresponds.
protected ErrorHandler
errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur.
protected SAXParserFactory
factory
The SAXParserFactory that is created the first time we need it.
protected String
JAXP_SCHEMA_LANGUAGE
protected Locator
locator
The Locator associated with our parser.
protected String
match
The current match pattern for nested element processing.
protected boolean
namespaceAware
Do we want a "namespace aware" parser.
protected HashMap
namespaces
Registered namespaces we are currently processing. The key is the namespace prefix that was declared in the document. The value is an ArrayStack of the namespace URIs this prefix has been mapped to -- the top Stack element is the most current one. (This architecture is required because documents can declare nested uses of the same prefix for different Namespace URIs).
protected ArrayStack
params
The parameters stack being utilized by CallMethodRule and CallParamRule rules.
protected SAXParser
parser
The SAXParser we will use to parse the input stream.
protected String
publicId
The public identifier of the DTD we are currently parsing under (if any).
protected XMLReader
reader
The XMLReader used to parse digester rules.
protected Object
root
The "root" element of the stack (in other words, the last object that was popped.
protected Rules
rules
The Rules implementation containing our collection of Rule instances and associated matching policy. If not established before the first rule is added, a default implementation will be provided.
protected String
schemaLanguage
The XML schema language to use for validating an XML instance. By default this value is set to W3C_XML_SCHEMA
protected String
schemaLocation
The XML schema to use for validating an XML instance.
protected ArrayStack
stack
The object stack being constructed.
protected boolean
useContextClassLoader
Do we want to use the Context ClassLoader when loading classes for instantiating new objects. Default is false.
protected boolean
validating
Do we want to use a validating parser.
protected org.apache.juli.logging.Log
log
The Log to which most logging calls will be made.
protected org.apache.juli.logging.Log
saxLog
The Log to which all SAX event related logging calls will be made.
protected static final String
W3C_XML_SCHEMA
The schema language supported. By default, we use this one.
private HashMap
stacksByName
Stacks used for interrule communication, indexed by name String
Constructors Summary
public Digester()
Construct a new Digester with default properties.



    // --------------------------------------------------------- Constructors


                
      

        super();

    
public Digester(SAXParser parser)
Construct a new Digester, allowing a SAXParser to be passed in. This allows Digester to be used in environments which are unfriendly to JAXP1.1 (such as WebLogic 6.0). Thanks for the request to change go to James House (james@interobjective.com). This may help in places where you are able to load JAXP 1.1 classes yourself.


        super();

        this.parser = parser;

    
public Digester(XMLReader reader)
Construct a new Digester, allowing an XMLReader to be passed in. This allows Digester to be used in environments which are unfriendly to JAXP1.1 (such as WebLogic 6.0). Note that if you use this option you have to configure namespace and validation support yourself, as these properties only affect the SAXParser and emtpy constructor.


        super();

        this.reader = reader;

    
Methods Summary
public voidaddCallMethod(java.lang.String pattern, java.lang.String methodName)
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


        addRule(
                pattern,
                new CallMethodRule(methodName));

    
public voidaddCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount)
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


        addRule(pattern,
                new CallMethodRule(methodName, paramCount));

    
public voidaddCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount, java.lang.String[] paramTypes)
Add an "call method" rule for the specified parameters. If 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.

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 java.lang.Boolean for a boolean parameter)
see
CallMethodRule


        addRule(pattern,
                new CallMethodRule(
                                    methodName,
                                    paramCount, 
                                    paramTypes));

    
public voidaddCallMethod(java.lang.String pattern, java.lang.String methodName, int paramCount, java.lang.Class[] paramTypes)
Add an "call method" rule for the specified parameters. If 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.

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 java.lang.Boolean for a boolean parameter)
see
CallMethodRule


        addRule(pattern,
                new CallMethodRule(
                                    methodName,
                                    paramCount, 
                                    paramTypes));

    
public voidaddCallParam(java.lang.String pattern, int 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 body of this element)
see
CallParamRule


        addRule(pattern,
                new CallParamRule(paramIndex));

    
public voidaddCallParam(java.lang.String pattern, int paramIndex, java.lang.String attributeName)
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


        addRule(pattern,
                new CallParamRule(paramIndex, attributeName));

    
public voidaddCallParam(java.lang.String pattern, int paramIndex, boolean fromStack)
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

    
        addRule(pattern,
                new CallParamRule(paramIndex, fromStack));
      
    
public voidaddCallParam(java.lang.String pattern, int paramIndex, int stackIndex)
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

    
        addRule(pattern,
                new CallParamRule(paramIndex, stackIndex));
      
    
public voidaddCallParamPath(java.lang.String pattern, int paramIndex)
Add a "call parameter" rule that sets a parameter from the current 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

        addRule(pattern, new PathCallParamRule(paramIndex));
    
public voidaddFactoryCreate(java.lang.String pattern, java.lang.String className)
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


        addFactoryCreate(pattern, className, false);

    
public voidaddFactoryCreate(java.lang.String pattern, java.lang.Class clazz)
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


        addFactoryCreate(pattern, clazz, false);

    
public voidaddFactoryCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName)
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 className
see
FactoryCreateRule


        addFactoryCreate(pattern, className, attributeName, false);

    
public voidaddFactoryCreate(java.lang.String pattern, java.lang.Class clazz, java.lang.String attributeName)
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 className
see
FactoryCreateRule


        addFactoryCreate(pattern, clazz, attributeName, false);

    
public voidaddFactoryCreate(java.lang.String pattern, ObjectCreationFactory creationFactory)
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


        addFactoryCreate(pattern, creationFactory, false);

    
public voidaddFactoryCreate(java.lang.String pattern, java.lang.String className, boolean 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
ignoreCreateExceptions when true any exceptions thrown during object creation will be ignored.
see
FactoryCreateRule


        addRule(
                pattern,
                new FactoryCreateRule(className, ignoreCreateExceptions));

    
public voidaddFactoryCreate(java.lang.String pattern, java.lang.Class clazz, boolean 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 true any exceptions thrown during object creation will be ignored.
see
FactoryCreateRule


        addRule(
                pattern,
                new FactoryCreateRule(clazz, ignoreCreateExceptions));

    
public voidaddFactoryCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName, boolean 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 className
param
ignoreCreateExceptions when true any exceptions thrown during object creation will be ignored.
see
FactoryCreateRule


        addRule(
                pattern,
                new FactoryCreateRule(className, attributeName, ignoreCreateExceptions));

    
public voidaddFactoryCreate(java.lang.String pattern, java.lang.Class clazz, java.lang.String attributeName, boolean 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 className
param
ignoreCreateExceptions when true any exceptions thrown during object creation will be ignored.
see
FactoryCreateRule


        addRule(
                pattern,
                new FactoryCreateRule(clazz, attributeName, ignoreCreateExceptions));

    
public voidaddFactoryCreate(java.lang.String pattern, ObjectCreationFactory creationFactory, boolean 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 true any exceptions thrown during object creation will be ignored.
see
FactoryCreateRule


        creationFactory.setDigester(this);
        addRule(pattern,
                new FactoryCreateRule(creationFactory, ignoreCreateExceptions));

    
public voidaddObjectCreate(java.lang.String pattern, java.lang.String className)
Add an "object create" rule for the specified parameters.

param
pattern Element matching pattern
param
className Java class name to be created
see
ObjectCreateRule


        addRule(pattern,
                new ObjectCreateRule(className));

    
public voidaddObjectCreate(java.lang.String pattern, java.lang.Class clazz)
Add an "object create" rule for the specified parameters.

param
pattern Element matching pattern
param
clazz Java class to be created
see
ObjectCreateRule


        addRule(pattern,
                new ObjectCreateRule(clazz));

    
public voidaddObjectCreate(java.lang.String pattern, java.lang.String className, java.lang.String attributeName)
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


        addRule(pattern,
                new ObjectCreateRule(className, attributeName));

    
public voidaddObjectCreate(java.lang.String pattern, java.lang.String attributeName, java.lang.Class clazz)
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


        addRule(pattern,
                new ObjectCreateRule(attributeName, clazz));

    
public voidaddObjectParam(java.lang.String pattern, int paramIndex, java.lang.Object paramObj)
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.

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

    
        addRule(pattern,
                new ObjectParamRule(paramIndex, paramObj));
      
    
public voidaddRule(java.lang.String pattern, Rule rule)

Register a new Rule matching the specified pattern. This method sets the Digester property on the rule.

param
pattern Element matching pattern
param
rule Rule to be registered


        rule.setDigester(this);
        getRules().add(pattern, rule);

    
public voidaddRuleSet(RuleSet ruleSet)
Register a set of Rule instances defined in a RuleSet.

param
ruleSet The RuleSet instance to configure from


        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);

    
public voidaddSetNext(java.lang.String pattern, java.lang.String 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
see
SetNextRule


        addRule(pattern,
                new SetNextRule(methodName));

    
public voidaddSetNext(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
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 java.lang.Boolean for a boolean parameter)
see
SetNextRule


        addRule(pattern,
                new SetNextRule(methodName, paramType));

    
public voidaddSetProperties(java.lang.String pattern)
Add a "set properties" rule for the specified parameters.

param
pattern Element matching pattern
see
SetPropertiesRule


        addRule(pattern,
                new SetPropertiesRule());

    
public voidaddSetProperties(java.lang.String pattern, java.lang.String attributeName, java.lang.String propertyName)
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


        addRule(pattern,
                new SetPropertiesRule(attributeName, propertyName));

    
public voidaddSetProperties(java.lang.String pattern, java.lang.String[] attributeNames, java.lang.String[] propertyNames)
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


        addRule(pattern,
                new SetPropertiesRule(attributeNames, propertyNames));

    
public voidaddSetProperty(java.lang.String pattern, java.lang.String name, java.lang.String value)
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


        addRule(pattern,
                new SetPropertyRule(name, value));

    
public voidaddSetRoot(java.lang.String pattern, java.lang.String methodName)
Add {@link SetRootRule} with the specified parameters.

param
pattern Element matching pattern
param
methodName Method name to call on the root object
see
SetRootRule


        addRule(pattern,
                new SetRootRule(methodName));

    
public voidaddSetRoot(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
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


        addRule(pattern,
                new SetRootRule(methodName, paramType));

    
public voidaddSetTop(java.lang.String pattern, java.lang.String 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
see
SetTopRule


        addRule(pattern,
                new SetTopRule(methodName));

    
public voidaddSetTop(java.lang.String pattern, java.lang.String methodName, java.lang.String paramType)
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 java.lang.Boolean for a boolean parameter)
see
SetTopRule


        addRule(pattern,
                new SetTopRule(methodName, paramType));

    
public voidcharacters(char[] buffer, int start, int length)
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


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("characters(" + new String(buffer, start, length) + ")");
        }

        bodyText.append(buffer, start, length);

    
public voidclear()
Clear the current contents of the object stack.

Calling this method might allow another document of the same type to be correctly parsed. However this method was not intended for this purpose. In general, a separate Digester object should be created for each document to be parsed.


        match = "";
        bodyTexts.clear();
        params.clear();
        publicId = null;
        stack.clear();
        log = null;
        saxLog = null;
        configured = false;
        
    
protected voidconfigure()

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 {@link #initialize} or the code should take responsibility by checking and setting the {@link #configured} flag.


        // Do not configure more than once
        if (configured) {
            return;
        }

        log = LogFactory.getLog("org.apache.commons.digester.Digester");
        saxLog = LogFactory.getLog("org.apache.commons.digester.Digester.sax");

        // 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;

    
public org.xml.sax.SAXExceptioncreateSAXException(java.lang.String message, java.lang.Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occurs

return
the new exception

        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 (" + locator.getLineNumber() + ", " +
                    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);
        }
    
public org.xml.sax.SAXExceptioncreateSAXException(java.lang.Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occurs

return
the new exception

        if (e instanceof InvocationTargetException) {
            Throwable t = ((InvocationTargetException) e).getTargetException();
            if ((t != null) && (t instanceof Exception)) {
                e = (Exception) t;
            }
        }
        return createSAXException(e.getMessage(), e);
    
public org.xml.sax.SAXExceptioncreateSAXException(java.lang.String message)
Create a SAX exception which also understands about the location in the digester file where the exception occurs

return
the new exception

        return createSAXException(message, null);
    
public voidendDocument()
Process notification of the end of the document being reached.

exception
SAXException if a parsing error is to be reported


        if (saxLog.isDebugEnabled()) {
            if (getCount() > 1) {
                saxLog.debug("endDocument():  " + getCount() +
                             " elements left");
            } else {
                saxLog.debug("endDocument()");
            }
        }

        while (getCount() > 1) {
            pop();
        }

        // Fire "finish" events for all defined rules
        Iterator rules = getRules().rules().iterator();
        while (rules.hasNext()) {
            Rule rule = (Rule) rules.next();
            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();

    
public voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
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


        boolean debug = log.isDebugEnabled();

        if (debug) {
            if (saxLog.isDebugEnabled()) {
                saxLog.debug("endElement(" + namespaceURI + "," + localName +
                        "," + qName + ")");
            }
            log.debug("  match='" + match + "'");
            log.debug("  bodyText='" + bodyText + "'");
        }

        // Parse system properties
        bodyText = updateBodyText(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 rules = (List) matches.pop();
        if ((rules != null) && (rules.size() > 0)) {
            String bodyText = this.bodyText.toString();
            for (int i = 0; i < rules.size(); i++) {
                try {
                    Rule 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 = (StringBuffer) 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 = (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 = "";
        }

    
public voidendPrefixMapping(java.lang.String prefix)
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


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("endPrefixMapping(" + prefix + ")");
        }

        // Deregister this prefix mapping
        ArrayStack stack = (ArrayStack) 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");
        }

    
public voiderror(org.xml.sax.SAXParseException exception)
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


        log.error("Parse Error at line " + exception.getLineNumber() +
                " column " + exception.getColumnNumber() + ": " +
                exception.getMessage(), exception);
        if (errorHandler != null) {
            errorHandler.error(exception);
        }

    
public voidfatalError(org.xml.sax.SAXParseException 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


        log.error("Parse Fatal Error at line " + exception.getLineNumber() +
                " column " + exception.getColumnNumber() + ": " +
                exception.getMessage(), exception);
        if (errorHandler != null) {
            errorHandler.fatalError(exception);
        }

    
public java.lang.StringfindNamespaceURI(java.lang.String prefix)
Return the currently mapped namespace URI for the specified prefix, if any; otherwise return null. These mappings come and go dynamically as the document is parsed.

param
prefix Prefix to look up

    
    // ------------------------------------------------------------- Properties

                                          
        
        
        ArrayStack stack = (ArrayStack) namespaces.get(prefix);
        if (stack == null) {
            return (null);
        }
        try {
            return ((String) stack.peek());
        } catch (EmptyStackException e) {
            return (null);
        }

    
public java.lang.ClassLoadergetClassLoader()
Return the class loader to be used for instantiating application objects when required. This is determined based upon the following rules:
  • The class loader set by setClassLoader(), if any
  • The thread context class loader, if it exists and the useContextClassLoader property is set to true
  • The class loader used to load the Digester class itself.


        if (this.classLoader != null) {
            return (this.classLoader);
        }
        if (this.useContextClassLoader) {
            ClassLoader classLoader =
                    Thread.currentThread().getContextClassLoader();
            if (classLoader != null) {
                return (classLoader);
            }
        }
        return (this.getClass().getClassLoader());

    
public intgetCount()
Return the current depth of the element stack.


        return (stack.size());

    
public java.lang.StringgetCurrentElementName()
Return the name of the XML element that is currently being processed.


        String elementName = match;
        int lastSlash = elementName.lastIndexOf('/");
        if (lastSlash >= 0) {
            elementName = elementName.substring(lastSlash + 1);
        }
        return (elementName);

    
public intgetDebug()
Return the debugging detail level of our currently enabled logger.

deprecated
This method now always returns 0. Digester uses the apache jakarta commons-logging library; see the documentation for that library for more information.


        return (0);

    
public org.xml.sax.LocatorgetDocumentLocator()
Gets the document locator associated with our parser.

return
the Locator supplied by the document parser


        return locator;

    
public org.xml.sax.EntityResolvergetEntityResolver()
Return the Entity Resolver used by the SAX parser.

return
Return the Entity Resolver used by the SAX parser.

        return entityResolver;
    
public org.xml.sax.ErrorHandlergetErrorHandler()
Return the error handler for this Digester.


        return (this.errorHandler);

    
public javax.xml.parsers.SAXParserFactorygetFactory()
Return the SAXParserFactory we will use, creating one if necessary.


        if (factory == null) {
            factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(namespaceAware);
            factory.setValidating(validating);
        }
        return (factory);

    
public booleangetFeature(java.lang.String feature)
Returns a flag indicating whether the requested feature is supported by the underlying implementation of org.xml.sax.XMLReader. See for information about the standard SAX2 feature flags.

param
feature Name of the feature to inquire about
exception
ParserConfigurationException if a parser configuration error occurs
exception
SAXNotRecognizedException if the property name is not recognized
exception
SAXNotSupportedException if the property name is recognized but not supported


        return (getFactory().getFeature(feature));

    
public org.apache.juli.logging.LoggetLogger()
Return the current Logger associated with this instance of the Digester


        return log;

    
public java.lang.StringgetMatch()
Return the current rule match path


        return match;

    
public booleangetNamespaceAware()
Return the "namespace aware" flag for parsers we create.


        return (this.namespaceAware);

    
public javax.xml.parsers.SAXParsergetParser()
Return the SAXParser we will use to parse the input stream. If there is a problem creating the parser, return null.


        // Return the parser we already created (if any)
        if (parser != null) {
            return (parser);
        }

        // Create a new parser
        try {
            if (validating) {
                Properties properties = new Properties();
                properties.put("SAXParserFactory", getFactory());
                if (schemaLocation != null) {
                    properties.put("schemaLocation", schemaLocation);
                    properties.put("schemaLanguage", schemaLanguage);
                }
                parser = ParserFeatureSetterFactory.newSAXParser(properties);               } else {
                parser = getFactory().newSAXParser();
            }
        } catch (Exception e) {
            log.error("Digester.getParser: ", e);
            return (null);
        }

        return (parser);

    
public java.lang.ObjectgetProperty(java.lang.String property)
Return the current value of the specified property for the underlying XMLReader implementation. See for information about the standard SAX2 properties.

param
property Property name to be retrieved
exception
SAXNotRecognizedException if the property name is not recognized
exception
SAXNotSupportedException if the property name is recognized but not supported


        return (getParser().getProperty(property));

    
public java.lang.StringgetPublicId()
Return the public identifier of the DTD we are currently parsing under, if any.


        return (this.publicId);

    
public org.xml.sax.XMLReadergetReader()
By setting the reader in the constructor, you can bypass JAXP and be able to use digester in Weblogic 6.0.

deprecated
Use getXMLReader() instead, which can throw a SAXException if the reader cannot be instantiated


        try {
            return (getXMLReader());
        } catch (SAXException e) {
            log.error("Cannot get XMLReader", e);
            return (null);
        }

    
java.util.MapgetRegistrations()
Return the set of DTD URL registrations, keyed by public identifier.


        return (entityValidator);

    
public java.lang.ObjectgetRoot()
When the Digester is being used as a SAXContentHandler, this method allows you to access the root object that has been created after parsing.

return
the root object that has been created after parsing or null if the digester has not parsed any XML yet.

        return root;
    
public java.lang.StringgetRuleNamespaceURI()
Return the namespace URI that will be applied to all subsequently added Rule objects.


        return (getRules().getNamespaceURI());

    
java.util.ListgetRules(java.lang.String match)
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 match() on the Rules implementation returned by getRules()


        return (getRules().match(match));

    
public RulesgetRules()
Return the Rules implementation object containing our rules collection and associated matching policy. If none has been established, a default implementation will be created and returned.


        if (this.rules == null) {
            this.rules = new RulesBase();
            this.rules.setDigester(this);
        }
        return (this.rules);

    
public org.apache.juli.logging.LoggetSAXLogger()
Gets the logger used for logging SAX-related information. Note the output is finely grained.

since
1.6

        
        return saxLog;
    
public java.lang.StringgetSchema()
Return the XML Schema URI used for validating an XML instance.


        return (this.schemaLocation);

    
public java.lang.StringgetSchemaLanguage()
Return the XML Schema language used when parsing.


        return (this.schemaLanguage);

    
public booleangetUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.


        return useContextClassLoader;

    
public booleangetValidating()
Return the validating parser flag.


        return (this.validating);

    
public org.xml.sax.XMLReadergetXMLReader()
Return the XMLReader to be used for parsing the input document. FIX ME: there is a bug in JAXP/XERCES that prevent the use of a parser that contains a schema with a DTD.

exception
SAXException if no XMLReader can be instantiated

        if (reader == null){
            reader = getParser().getXMLReader();
        }        
                               
        reader.setDTDHandler(this);           
        reader.setContentHandler(this);        
        
        if (entityResolver == null){
            reader.setEntityResolver(this);
        } else {
            reader.setEntityResolver(entityResolver);           
        }
        
        reader.setErrorHandler(this);
        return reader;
    
public voidignorableWhitespace(char[] buffer, int start, int len)
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


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("ignorableWhitespace(" +
                    new String(buffer, start, len) + ")");
        }

        ;   // No processing required

    
protected voidinitialize()

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 {@link #configure} only when the {@link #configured} flag is false. Subclasses that override configure or who set configured may find that this method may be called more than once.

since
1.6


        // Perform lazy initialization as needed
        ; // Nothing required by default

    
public booleanisEmpty(java.lang.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.

param
stackName the name of the stack whose emptiness should be evaluated
return
true if the given stack if empty
since
1.6

        boolean result = true;
        ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName);
        if (namedStack != null ) {
            result = namedStack.isEmpty();
        }
        return result;
    
public voidlog(java.lang.String message)
Log a message to our associated logger.

param
message The message to be logged
deprecated
Call getLogger() and use it's logging methods


        log.info(message);

    
public voidlog(java.lang.String message, java.lang.Throwable exception)
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


        log.error(message, exception);

    
public voidnotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
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)


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("notationDecl(" + name + "," + publicId + "," +
                    systemId + ")");
        }

    
public java.lang.Objectparse(java.io.File file)
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


        configure();
        InputSource input = new InputSource(new FileInputStream(file));
        input.setSystemId("file://" + file.getAbsolutePath());
        getXMLReader().parse(input);
        return (root);

    
public java.lang.Objectparse(org.xml.sax.InputSource input)
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

 
        configure();
        getXMLReader().parse(input);
        return (root);

    
public java.lang.Objectparse(java.io.InputStream input)
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


        configure();
        InputSource is = new InputSource(input);
        getXMLReader().parse(is);
        return (root);

    
public java.lang.Objectparse(java.io.Reader reader)
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


        configure();
        InputSource is = new InputSource(reader);
        getXMLReader().parse(is);
        return (root);

    
public java.lang.Objectparse(java.lang.String uri)
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


        configure();
        InputSource is = new InputSource(uri);
        getXMLReader().parse(is);
        return (root);

    
public java.lang.Objectpeek()
Return the top object on the stack without removing it. If there are no objects on the stack, return null.


        try {
            return (stack.peek());
        } catch (EmptyStackException e) {
            log.warn("Empty stack (returning null)");
            return (null);
        }

    
public java.lang.Objectpeek(int n)
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 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.


        try {
            return (stack.peek(n));
        } catch (EmptyStackException e) {
            log.warn("Empty stack (returning null)");
            return (null);
        }

    
public java.lang.Objectpeek(java.lang.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.

param
stackName the name of the stack to be peeked
return
the top 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

        Object result = null;
        ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName);
        if (namedStack == null ) {
            if (log.isDebugEnabled()) {
                log.debug("Stack '" + stackName + "' is empty");
            }        
            throw new EmptyStackException();
        
        } else {
        
            result = namedStack.peek();
        }
        return result;
    
public java.lang.ObjectpeekParams()

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 {@link #params}.


        try {
            return (params.peek());
        } catch (EmptyStackException e) {
            log.warn("Empty stack (returning null)");
            return (null);
        }

    
public java.lang.ObjectpeekParams(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 {@link #params}.

param
n Index of the desired element, where 0 is the top of the stack, 1 is the next element down, and so on.


        try {
            return (params.peek(n));
        } catch (EmptyStackException e) {
            log.warn("Empty stack (returning null)");
            return (null);
        }

    
public java.lang.Objectpop()
Pop the top object off of the stack, and return it. If there are no objects on the stack, return null.


        try {
            return (stack.pop());
        } catch (EmptyStackException e) {
            log.warn("Empty stack (returning null)");
            return (null);
        }

    
public java.lang.Objectpop(java.lang.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.

param
stackName the name of the stack from which the top value is to be popped
return
the top 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

        Object result = null;
        ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName);
        if (namedStack == null) {
            if (log.isDebugEnabled()) {
                log.debug("Stack '" + stackName + "' is empty");
            }
            throw new EmptyStackException();
            
        } else {
        
            result = namedStack.pop();
        }
        return result;
    
public java.lang.ObjectpopParams()

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 {@link #params}.


        try {
            if (log.isTraceEnabled()) {
                log.trace("Popping params");
            }
            return (params.pop());
        } catch (EmptyStackException e) {
            log.warn("Empty stack (returning null)");
            return (null);
        }

    
public voidprocessingInstruction(java.lang.String target, java.lang.String data)
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


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("processingInstruction('" + target + "','" + data + "')");
        }

        ;   // No processing is required

    
public voidpush(java.lang.Object object)
Push a new object onto the top of the object stack.

param
object The new object


        if (stack.size() == 0) {
            root = object;
        }
        stack.push(object);

    
public voidpush(java.lang.String stackName, java.lang.Object value)
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

        ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName);
        if (namedStack == null) {
            namedStack = new ArrayStack();
            stacksByName.put(stackName, namedStack);
        }
        namedStack.push(value);
    
public voidpushParams(java.lang.Object object)

Push a new object onto the top of the parameters stack.

The parameters stack is used to store CallMethodRule parameters. See {@link #params}.

param
object The new object

        if (log.isTraceEnabled()) {
            log.trace("Pushing params");
        }
        params.push(object);

    
public voidregister(java.lang.String publicId, java.lang.String entityURL)

Register the specified DTD URL for the specified public identifier. This must be called before the first call to parse().

Digester contains an internal EntityResolver implementation. This maps PUBLICID's to URLs (from which the resource will be loaded). A common use case for this method is to register local URLs (possibly computed at runtime by a classloader) for DTDs. This allows the performance advantage of using a local version without having to ensure every SYSTEM URI on every processed xml document is local. This implementation provides only basic functionality. If more sophisticated features are required, using {@link #setEntityResolver} 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.)

param
publicId Public identifier of the DTD to be resolved
param
entityURL The URL to use for reading this DTD


        if (log.isDebugEnabled()) {
            log.debug("register('" + publicId + "', '" + entityURL + "'");
        }
        entityValidator.put(publicId, entityURL);

    
public voidreset()

        root = null;
        setErrorHandler(null);
        clear();
    
public org.xml.sax.InputSourceresolveEntity(java.lang.String publicId, java.lang.String systemId)
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

     
                
        if (saxLog.isDebugEnabled()) {
            saxLog.debug("resolveEntity('" + publicId + "', '" + systemId + "')");
        }
        
        if (publicId != null)
            this.publicId = publicId;
                                       
        // Has this system identifier been registered?
        String entityURL = null;
        if (publicId != null) {
            entityURL = (String) entityValidator.get(publicId);
        }
         
        // Redirect the schema location to a local destination
        if (schemaLocation != null && entityURL == null && systemId != null){
            entityURL = (String)entityValidator.get(systemId);
        } 

        if (entityURL == null) { 
            if (systemId == null) {
                // cannot resolve
                if (log.isDebugEnabled()) {
                    log.debug(" Cannot resolve entity: '" + entityURL + "'");
                }
                return (null);
                
            } else {
                // try to resolve using system ID
                if (log.isDebugEnabled()) {
                    log.debug(" Trying to resolve using system ID '" + systemId + "'");
                } 
                entityURL = systemId;
            }
        }
        
        // Return an input source to our alternative URL
        if (log.isDebugEnabled()) {
            log.debug(" Resolving to alternate DTD '" + entityURL + "'");
        }  
        
        try {
            return (new InputSource(entityURL));
        } catch (Exception e) {
            throw createSAXException(e);
        }
    
public voidsetClassLoader(java.lang.ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.

param
classLoader The new class loader to use, or null to revert to the standard rules


        this.classLoader = classLoader;

    
public voidsetDebug(int debug)
Set the debugging detail level of our currently enabled logger.

param
debug New debugging detail level (0=off, increasing integers for more detail)
deprecated
This method now has no effect at all. Digester uses the apache jakarta comons-logging library; see the documentation for that library for more information.


        ; // No action is taken

    
public voidsetDocumentLocator(org.xml.sax.Locator locator)
Sets the document locator associated with our parser.

param
locator The new locator


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("setDocumentLocator(" + locator + ")");
        }

        this.locator = locator;

    
public voidsetEntityResolver(org.xml.sax.EntityResolver entityResolver)
Set the EntityResolver used by SAX when resolving public id and system id. This must be called before the first call to parse().

param
entityResolver a class that implement the EntityResolver interface.

        this.entityResolver = entityResolver;
    
public voidsetErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Set the error handler for this Digester.

param
errorHandler The new error handler


        this.errorHandler = errorHandler;

    
public voidsetFeature(java.lang.String feature, boolean value)
Sets a flag indicating whether the requested feature is supported by the underlying implementation of org.xml.sax.XMLReader. See 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.

param
feature Name of the feature to set the status for
param
value The new value for this feature
exception
ParserConfigurationException if a parser configuration error occurs
exception
SAXNotRecognizedException if the property name is not recognized
exception
SAXNotSupportedException if the property name is recognized but not supported


        getFactory().setFeature(feature, value);

    
public voidsetLogger(org.apache.juli.logging.Log log)
Set the current logger for this Digester.


        this.log = log;

    
public voidsetNamespaceAware(boolean namespaceAware)
Set the "namespace aware" flag for parsers we create.

param
namespaceAware The new "namespace aware" flag


        this.namespaceAware = namespaceAware;

    
public voidsetProperty(java.lang.String property, java.lang.Object value)
Set the current value of the specified property for the underlying XMLReader implementation. See for information about the standard SAX2 properties.

param
property Property name to be set
param
value Property value to be set
exception
SAXNotRecognizedException if the property name is not recognized
exception
SAXNotSupportedException if the property name is recognized but not supported


        getParser().setProperty(property, value);

    
public voidsetPublicId(java.lang.String publicId)
Set the publid id of the current file being parse.

param
publicId the DTD/Schema public's id.

        this.publicId = publicId;
    
public voidsetRuleNamespaceURI(java.lang.String ruleNamespaceURI)
Set the namespace URI that will be applied to all subsequently added Rule objects.

param
ruleNamespaceURI Namespace URI that must match on all subsequently added rules, or null for matching regardless of the current namespace URI


        getRules().setNamespaceURI(ruleNamespaceURI);

    
public voidsetRules(Rules rules)
Set the Rules implementation object containing our rules collection and associated matching policy.

param
rules New Rules implementation


        this.rules = rules;
        this.rules.setDigester(this);

    
public voidsetSAXLogger(org.apache.juli.logging.Log saxLog)
Sets the logger used for logging SAX-related information. Note the output is finely grained.

param
saxLog Log, not null
since
1.6

    
        this.saxLog = saxLog;
    
public voidsetSchema(java.lang.String schemaLocation)
Set the XML Schema URI used for validating a XML Instance.

param
schemaLocation a URI to the schema.


        this.schemaLocation = schemaLocation;

    
public voidsetSchemaLanguage(java.lang.String schemaLanguage)
Set the XML Schema language used when parsing. By default, we use W3C.

param
schemaLanguage a URI to the schema language.


        this.schemaLanguage = schemaLanguage;

    
public voidsetUseContextClassLoader(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. If not using Context ClassLoader, then the class-loading defaults to using the calling-class' ClassLoader.

param
use determines whether to use Context ClassLoader.


        useContextClassLoader = use;

    
public voidsetValidating(boolean validating)
Set the validating parser flag. This must be called before parse() is called the first time.

param
validating The new validating parser flag.


        this.validating = validating;

    
public voidskippedEntity(java.lang.String name)
Process notification of a skipped entity.

param
name Name of the skipped entity
exception
SAXException if a parsing error is to be reported


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("skippedEntity(" + name + ")");
        }

        ; // No processing required

    
public voidstartDocument()
Process notification of the beginning of the document being reached.

exception
SAXException if a parsing error is to be reported


        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();
    
public voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes list)
Process notification of the start of an XML element being reached.

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

        boolean debug = log.isDebugEnabled();
        
        if (saxLog.isDebugEnabled()) {
            saxLog.debug("startElement(" + namespaceURI + "," + localName + "," +
                    qName + ")");
        }
        
        // Parse system properties
        list = updateAttributes(list);
        
        // 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 rules = getRules().match(namespaceURI, match);
        matches.push(rules);
        if ((rules != null) && (rules.size() > 0)) {
            for (int i = 0; i < rules.size(); i++) {
                try {
                    Rule 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 + "'.");
            }
        }

    
public voidstartPrefixMapping(java.lang.String prefix, java.lang.String namespaceURI)
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


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("startPrefixMapping(" + prefix + "," + namespaceURI + ")");
        }

        // Register this prefix mapping
        ArrayStack stack = (ArrayStack) namespaces.get(prefix);
        if (stack == null) {
            stack = new ArrayStack();
            namespaces.put(prefix, stack);
        }
        stack.push(namespaceURI);

    
public voidunparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notation)
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


        if (saxLog.isDebugEnabled()) {
            saxLog.debug("unparsedEntityDecl(" + name + "," + publicId + "," +
                    systemId + "," + notation + ")");
        }

    
private org.xml.sax.AttributesupdateAttributes(org.xml.sax.Attributes list)
Returns an attributes list which contains all the attributes passed in, with any text of form "${xxx}" in an attribute value replaced by the appropriate value from the system property.


        if (list.getLength() == 0) {
            return list;
        }
        
        AttributesImpl newAttrs = new AttributesImpl(list);
        int nAttributes = newAttrs.getLength();
        for (int i = 0; i < nAttributes; ++i) {
            String value = newAttrs.getValue(i);
            try {
                String newValue = 
                    IntrospectionUtils.replaceProperties(value, null, source);
                if (value != newValue) {
                    newAttrs.setValue(i, newValue);
                }
            }
            catch (Exception e) {
                // ignore - let the attribute have its original value
            }
        }

        return newAttrs;

    
private java.lang.StringBufferupdateBodyText(java.lang.StringBuffer bodyText)
Return a new StringBuffer containing the same contents as the input buffer, except that data of form ${varname} have been replaced by the value of that var as defined in the system property.

        String in = bodyText.toString();
        String out;
        try {
            out = IntrospectionUtils.replaceProperties(in, null, source);
        } catch(Exception e) {
            return bodyText; // return unchanged data
        }

        if (out == in)  {
            // No substitutions required. Don't waste memory creating
            // a new buffer
            return bodyText;
        } else {
            return new StringBuffer(out);
        }
    
public voidwarning(org.xml.sax.SAXParseException 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

         if (errorHandler != null) {
            log.warn("Parse Warning Error at line " + exception.getLineNumber() +
                " column " + exception.getColumnNumber() + ": " +
                exception.getMessage(), exception);
            
            errorHandler.warning(exception);
        }