FileDocCategorySizeDatePackage
DocumentTracer.javaAPI DocApache Xerces 3.0.150992Fri Sep 14 20:33:58 BST 2007xni

DocumentTracer

public class DocumentTracer extends org.apache.xerces.parsers.XMLDocumentParser implements org.apache.xerces.xni.parser.XMLErrorHandler
Provides a complete trace of XNI document and DTD events for files parsed.
author
Andy Clark, IBM
author
Arnaud Le Hors, IBM
version
$Id: DocumentTracer.java 447690 2006-09-19 02:41:53Z mrglavas $

Fields Summary
protected static final String
NAMESPACES_FEATURE_ID
Namespaces feature id (http://xml.org/sax/features/namespaces).
protected static final String
VALIDATION_FEATURE_ID
Validation feature id (http://xml.org/sax/features/validation).
protected static final String
SCHEMA_VALIDATION_FEATURE_ID
Schema validation feature id (http://apache.org/xml/features/validation/schema).
protected static final String
SCHEMA_FULL_CHECKING_FEATURE_ID
Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking).
protected static final String
HONOUR_ALL_SCHEMA_LOCATIONS_ID
Honour all schema locations feature id (http://apache.org/xml/features/honour-all-schemaLocations).
protected static final String
NOTIFY_CHAR_REFS_FEATURE_ID
Character ref notification feature id (http://apache.org/xml/features/scanner/notify-char-refs).
protected static final String
DEFAULT_PARSER_CONFIG
Default parser configuration (org.apache.xerces.parsers.XIncludeAwareParserConfiguration).
protected static final boolean
DEFAULT_NAMESPACES
Default namespaces support (true).
protected static final boolean
DEFAULT_VALIDATION
Default validation support (false).
protected static final boolean
DEFAULT_SCHEMA_VALIDATION
Default Schema validation support (false).
protected static final boolean
DEFAULT_SCHEMA_FULL_CHECKING
Default Schema full checking support (false).
protected static final boolean
DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS
Default honour all schema locations (false).
protected static final boolean
DEFAULT_NOTIFY_CHAR_REFS
Default character notifications (false).
private org.apache.xerces.xni.QName
fQName
Temporary QName.
protected PrintWriter
fOut
Print writer.
protected int
fIndent
Indent level.
protected org.apache.xerces.xni.NamespaceContext
fNamespaceContext
Constructors Summary
public DocumentTracer()
Default constructor.


    //
    // Constructors
    //

       
      
        this(null);
    
public DocumentTracer(org.apache.xerces.xni.parser.XMLParserConfiguration config)
Default constructor.

        super(config);
        setOutput(new PrintWriter(System.out));
        fConfiguration.setErrorHandler(this);
    
Methods Summary
public voidany(org.apache.xerces.xni.Augmentations augs)
Any.


        printIndent();
        fOut.print("any(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidattributeDecl(java.lang.String elementName, java.lang.String attributeName, java.lang.String type, java.lang.String[] enumeration, java.lang.String defaultType, org.apache.xerces.xni.XMLString defaultValue, org.apache.xerces.xni.XMLString nonNormalizedDefaultValue, org.apache.xerces.xni.Augmentations augs)
Attribute declaration.


        printIndent();
        fOut.print("attributeDecl(");
        fOut.print("elementName=");
        printQuotedString(elementName);
        fOut.print(',");
        fOut.print("attributeName=");
        printQuotedString(attributeName);
        fOut.print(',");
        fOut.print("type=");
        printQuotedString(type);
        fOut.print(',");
        fOut.print("enumeration=");
        if (enumeration == null) {
            fOut.print("null");
        }
        else {
            fOut.print('{");
            for (int i = 0; i < enumeration.length; i++) {
                printQuotedString(enumeration[i]);
                if (i < enumeration.length - 1) {
                    fOut.print(',");
                }
            }
            fOut.print('}");
        }
        fOut.print(',");
        fOut.print("defaultType=");
        printQuotedString(defaultType);
        fOut.print(',");
        fOut.print("defaultValue=");
        if (defaultValue == null) {
            fOut.print("null");
        }
        else {
            printQuotedString(defaultValue.ch, defaultValue.offset,
                              defaultValue.length);
        }
        fOut.print(',");
        fOut.print("nonNormalizedDefaultValue=");
        if (nonNormalizedDefaultValue == null) {
            fOut.print("null");
        }
        else {
            printQuotedString(nonNormalizedDefaultValue.ch, nonNormalizedDefaultValue.offset,
                              nonNormalizedDefaultValue.length);
        }
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidcharacters(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)


        printIndent();
        fOut.print("characters(");
        fOut.print("text=");
        printQuotedString(text.ch, text.offset, text.length);
        /***
        if (augs != null) {
            ElementPSVI element = (ElementPSVI)augs.getItem(Constants.ELEMENT_PSVI);
            fOut.print(",schemaNormalized=");
            printQuotedString(element.getSchemaNormalizedValue());
        }
        /***/
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidcomment(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
Comment.


        printIndent();
        fOut.print("comment(");
        fOut.print("text=");
        printQuotedString(text.ch, text.offset, text.length);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voiddoctypeDecl(java.lang.String rootElement, java.lang.String publicId, java.lang.String systemId, org.apache.xerces.xni.Augmentations augs)
Doctype declaration.


        printIndent();
        fOut.print("doctypeDecl(");
        fOut.print("rootElement=");
        printQuotedString(rootElement);
        fOut.print(',");
        fOut.print("publicId=");
        printQuotedString(publicId);
        fOut.print(',");
        fOut.print("systemId=");
        printQuotedString(systemId);
        fOut.println(')");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.flush();

    
public voidelement(java.lang.String elementName, org.apache.xerces.xni.Augmentations augs)
Element.


        printIndent();
        fOut.print("element(");
        fOut.print("elementName=");
        printQuotedString(elementName);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidelementDecl(java.lang.String name, java.lang.String contentModel, org.apache.xerces.xni.Augmentations augs)
Element declaration.


        printIndent();
        fOut.print("elementDecl(");
        fOut.print("name=");
        printQuotedString(name);
        fOut.print(',");
        fOut.print("contentModel=");
        printQuotedString(contentModel);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidempty(org.apache.xerces.xni.Augmentations augs)
Empty.


        printIndent();
        fOut.print("empty(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidemptyElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs)
Empty element.

        printInScopeNamespaces();
        printIndent();
        fOut.print("emptyElement(");
        printElement(element, attributes);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        printEndNamespaceMapping();
    
public voidendAttlist(org.apache.xerces.xni.Augmentations augs)
End attribute list.


        fIndent--;
        printIndent();
        fOut.print("endAttlist(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendCDATA(org.apache.xerces.xni.Augmentations augs)
End CDATA section.


        fIndent--;
        printIndent();
        fOut.print("endCDATA(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendConditional(org.apache.xerces.xni.Augmentations augs)
End conditional section.


        fIndent--;
        printIndent();
        fOut.print("endConditional(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendContentModel(org.apache.xerces.xni.Augmentations augs)
End content model.


        fIndent--;
        printIndent();
        fOut.print("endContentModel(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendDTD(org.apache.xerces.xni.Augmentations augs)
End DTD.


        fIndent--;
        printIndent();
        fOut.print("endDTD(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendDocument(org.apache.xerces.xni.Augmentations augs)
End document.


        fIndent--;
        printIndent();
        fOut.print("endDocument(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.Augmentations augs)
End element.


        fIndent--;
        printIndent();
        fOut.print("endElement(");
        fOut.print("element=");
        fOut.print('{");
        fOut.print("prefix=");
        printQuotedString(element.prefix);
        fOut.print(',");
        fOut.print("localpart=");
        printQuotedString(element.localpart);
        fOut.print(',");
        fOut.print("rawname=");
        printQuotedString(element.rawname);
        fOut.print(',");
        fOut.print("uri=");
        printQuotedString(element.uri);
        fOut.print('}");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
		fOut.flush();

        printEndNamespaceMapping();

    
public voidendExternalSubset(org.apache.xerces.xni.Augmentations augs)
End external subset.


        fIndent--;
        printIndent();
        fOut.print("endExternalSubset(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendGeneralEntity(java.lang.String name, org.apache.xerces.xni.Augmentations augs)
End entity.


        fIndent--;
        printIndent();
        fOut.print("endGeneralEntity(");
        fOut.print("name=");
        printQuotedString(name);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendGroup(org.apache.xerces.xni.Augmentations augs)
End group.


        fIndent--;
        printIndent();
        fOut.print("endGroup(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidendParameterEntity(java.lang.String name, org.apache.xerces.xni.Augmentations augs)
End entity.


        fIndent--;
        printIndent();
        fOut.print("endParameterEntity(");
        fOut.print("name=");
        printQuotedString(name);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voiderror(java.lang.String domain, java.lang.String key, org.apache.xerces.xni.parser.XMLParseException ex)
Error.

        printError("Error", ex);
    
public voidexternalEntityDecl(java.lang.String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, org.apache.xerces.xni.Augmentations augs)
External entity declaration.


        printIndent();
        fOut.print("externalEntityDecl(");
        fOut.print("name=");
        printQuotedString(name);
        fOut.print(',");
        fOut.print("publicId=");
        printQuotedString(identifier.getPublicId());
        fOut.print(',");
        fOut.print("systemId=");
        printQuotedString(identifier.getLiteralSystemId());
        fOut.print(',");
        fOut.print("baseSystemId=");
        printQuotedString(identifier.getBaseSystemId());
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidfatalError(java.lang.String domain, java.lang.String key, org.apache.xerces.xni.parser.XMLParseException ex)
Fatal error.

        printError("Fatal Error", ex);
        throw ex;
    
public voidignorableWhitespace(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
Ignorable whitespace.


        printIndent();
        fOut.print("ignorableWhitespace(");
        fOut.print("text=");
        printQuotedString(text.ch, text.offset, text.length);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidignoredCharacters(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
Characters.


        printIndent();
        fOut.print("ignoredCharacters(");
        fOut.print("text=");
        printQuotedString(text.ch, text.offset, text.length);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidinternalEntityDecl(java.lang.String name, org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.XMLString nonNormalizedText, org.apache.xerces.xni.Augmentations augs)
Internal entity declaration.


        printIndent();
        fOut.print("internalEntityDecl(");
        fOut.print("name=");
        printQuotedString(name);
        fOut.print(',");
        fOut.print("text=");
        printQuotedString(text.ch, text.offset, text.length);
        fOut.print(',");
        fOut.print("nonNormalizedText=");
        printQuotedString(nonNormalizedText.ch, nonNormalizedText.offset,
                          nonNormalizedText.length);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public static voidmain(java.lang.String[] argv)
Main.


        // is there anything to do?
        if (argv.length == 0) {
            printUsage();
            System.exit(1);
        }

        // variables
        XMLDocumentParser parser = null;
        XMLParserConfiguration parserConfig = null;
        boolean namespaces = DEFAULT_NAMESPACES;
        boolean validation = DEFAULT_VALIDATION;
        boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION;
        boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING;
        boolean honourAllSchemaLocations = DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS;
        boolean notifyCharRefs = DEFAULT_NOTIFY_CHAR_REFS;

        // process arguments
        for (int i = 0; i < argv.length; i++) {
            String arg = argv[i];
            if (arg.startsWith("-")) {
                String option = arg.substring(1);
                if (option.equals("p")) {
                    // get parser name
                    if (++i == argv.length) {
                        System.err.println("error: Missing argument to -p option.");
                        continue;
                    }
                    String parserName = argv[i];

                    // create parser
                    try {
                        parserConfig = (XMLParserConfiguration)ObjectFactory.newInstance(parserName,
                            ObjectFactory.findClassLoader(), true);
                        parser = null;
                    }
                    catch (Exception e) {
                        parserConfig = null;
                        System.err.println("error: Unable to instantiate parser configuration ("+parserName+")");
                    }
                    continue;
                }
                if (option.equalsIgnoreCase("n")) {
                    namespaces = option.equals("n");
                    continue;
                }
                if (option.equalsIgnoreCase("v")) {
                    validation = option.equals("v");
                    continue;
                }
                if (option.equalsIgnoreCase("s")) {
                    schemaValidation = option.equals("s");
                    continue;
                }
                if (option.equalsIgnoreCase("f")) {
                    schemaFullChecking = option.equals("f");
                    continue;
                }
                if (option.equalsIgnoreCase("hs")) {
                    honourAllSchemaLocations = option.equals("hs");
                    continue;
                }
                if (option.equalsIgnoreCase("c")) {
                    notifyCharRefs = option.equals("c");
                    continue;
                }
                if (option.equals("h")) {
                    printUsage();
                    continue;
                }
            }

            // use default parser?
            if (parserConfig == null) {

                // create parser
                try {
                    parserConfig = (XMLParserConfiguration)ObjectFactory.newInstance(DEFAULT_PARSER_CONFIG,
                        ObjectFactory.findClassLoader(), true);
                }
                catch (Exception e) {
                    System.err.println("error: Unable to instantiate parser configuration ("+DEFAULT_PARSER_CONFIG+")");
                    continue;
                }
            }

            // set parser features
            if (parser == null) {
                parser = new DocumentTracer(parserConfig);
            }
            try {
                parserConfig.setFeature(NAMESPACES_FEATURE_ID, namespaces);
            }
            catch (XMLConfigurationException e) {
                System.err.println("warning: Parser does not support feature ("+NAMESPACES_FEATURE_ID+")");
            }
            try {
                parserConfig.setFeature(VALIDATION_FEATURE_ID, validation);
            }
            catch (XMLConfigurationException e) {
                System.err.println("warning: Parser does not support feature ("+VALIDATION_FEATURE_ID+")");
            }
            try {
                parserConfig.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation);
            }
            catch (XMLConfigurationException e) {
                if (e.getType() == XMLConfigurationException.NOT_SUPPORTED) {
                    System.err.println("warning: Parser does not support feature ("+SCHEMA_VALIDATION_FEATURE_ID+")");
                }
            }
            try {
                parserConfig.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking);
            }
            catch (XMLConfigurationException e) {
                if (e.getType() == XMLConfigurationException.NOT_SUPPORTED) {
                    System.err.println("warning: Parser does not support feature ("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
                }
            }
            try {
                parserConfig.setFeature(HONOUR_ALL_SCHEMA_LOCATIONS_ID, honourAllSchemaLocations);
            }
            catch (XMLConfigurationException e) {
                if (e.getType() == XMLConfigurationException.NOT_SUPPORTED) {
                    System.err.println("warning: Parser does not support feature ("+HONOUR_ALL_SCHEMA_LOCATIONS_ID+")");
                }
            }
            try {
                parserConfig.setFeature(NOTIFY_CHAR_REFS_FEATURE_ID, notifyCharRefs);
            }
            catch (XMLConfigurationException e) {
                if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
                    //e.printStackTrace();
                    System.err.println("warning: Parser does not recognize feature ("+NOTIFY_CHAR_REFS_FEATURE_ID+")");
                }
                else {
                    System.err.println("warning: Parser does not support feature ("+NOTIFY_CHAR_REFS_FEATURE_ID+")");
                }
            }

            // parse file
            try {
                parser.parse(new XMLInputSource(null, arg, null));
            }
            catch (XMLParseException e) {
                // ignore
            }
            catch (Exception e) {
                System.err.println("error: Parse error occurred - "+e.getMessage());
                if (e instanceof XNIException) {
                    e = ((XNIException)e).getException();
                }
                e.printStackTrace(System.err);
            }
        }

    
protected voidnormalizeAndPrint(char c)
Normalize and print.


        switch (c) {
            case '\n": {
                fOut.print("\\n");
                break;
            }
            case '\r": {
                fOut.print("\\r");
                break;
            }
            case '\t": {
                fOut.print("\\t");
                break;
            }
            case '\\": {
                fOut.print("\\\\");
                break;
            }
            case '"": {
                fOut.print("\\\"");
                break;
            }
            default: {
                fOut.print(c);
            }
        }

    
public voidnotationDecl(java.lang.String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, org.apache.xerces.xni.Augmentations augs)
Notation declaration.


        printIndent();
        fOut.print("notationDecl(");
        fOut.print("name=");
        printQuotedString(name);
        fOut.print(',");
        fOut.print("publicId=");
        printQuotedString(identifier.getPublicId());
        fOut.print(',");
        fOut.print("systemId=");
        printQuotedString(identifier.getLiteralSystemId());
        fOut.print(',");
        fOut.print("baseSystemId=");
        printQuotedString(identifier.getBaseSystemId());
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidoccurrence(short occurrence, org.apache.xerces.xni.Augmentations augs)
Occurrence.


        printIndent();
        fOut.print("occurrence(");
        fOut.print("occurrence=");
        switch (occurrence) {
            case XMLDTDContentModelHandler.OCCURS_ONE_OR_MORE: {
                fOut.print("OCCURS_ONE_OR_MORE");
                break;
            }
            case XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE: {
                fOut.print("OCCURS_ZERO_OR_MORE");
                break;
            }
            case XMLDTDContentModelHandler.OCCURS_ZERO_OR_ONE: {
                fOut.print("OCCURS_ZERO_OR_ONE");
                break;
            }
            default: {
                fOut.print("??? ("+occurrence+')");
            }
        }
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidpcdata(org.apache.xerces.xni.Augmentations augs)
#PCDATA.


        printIndent();
        fOut.print("pcdata(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
protected voidprintAugmentations(org.apache.xerces.xni.Augmentations augs)
Prints augmentations.

        fOut.print("augs={");
        java.util.Enumeration keys = augs.keys();
        while (keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            Object value = augs.getItem(key);
            fOut.print(key);
            fOut.print('#");
            fOut.print(String.valueOf(value));
        }
        fOut.print('}");
    
protected voidprintElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes)
Prints an element.


        fOut.print("element=");
        fOut.print('{");
        fOut.print("prefix=");
        printQuotedString(element.prefix);
        fOut.print(',");
        fOut.print("localpart=");
        printQuotedString(element.localpart);
        fOut.print(',");
        fOut.print("rawname=");
        printQuotedString(element.rawname);
        fOut.print(',");
        fOut.print("uri=");
        printQuotedString(element.uri);
        fOut.print('}");
        fOut.print(',");
        fOut.print("attributes=");
        if (attributes == null) {
            fOut.println("null");
        }
        else {
            fOut.print('{");
            int length = attributes.getLength();
            for (int i = 0; i < length; i++) {
                if (i > 0) {
                    fOut.print(',");
                }
                attributes.getName(i, fQName);
                String attrType = attributes.getType(i);
                String attrValue = attributes.getValue(i);
                String attrNonNormalizedValue = attributes.getNonNormalizedValue(i);
                Augmentations augs = attributes.getAugmentations(i);
                fOut.print("name=");
                fOut.print('{");
                fOut.print("prefix=");
                printQuotedString(fQName.prefix);
                fOut.print(',");
                fOut.print("localpart=");
                printQuotedString(fQName.localpart);
                fOut.print(',");
                fOut.print("rawname=");
                printQuotedString(fQName.rawname);
                fOut.print(',");
                fOut.print("uri=");
                printQuotedString(fQName.uri);
                fOut.print('}");
                fOut.print(',");
                fOut.print("type=");
                printQuotedString(attrType);
                fOut.print(',");
                fOut.print("value=");
                printQuotedString(attrValue);
                fOut.print(',");
                fOut.print("nonNormalizedValue=");
                printQuotedString(attrNonNormalizedValue);
                if (attributes.isSpecified(i) == false ) {
                   fOut.print("(default)");
                }
                if (augs != null) {
                    fOut.print(',");
                    printAugmentations(augs);
                }
                fOut.print('}");
            }
            fOut.print('}");
        }

    
protected voidprintEndNamespaceMapping()

        int count = fNamespaceContext.getDeclaredPrefixCount();
        if (count > 0) {
            for (int i = 0; i < count; i++) {
                printIndent();
                fOut.print("endPrefix(");
                fOut.print("prefix=");
                String prefix = fNamespaceContext.getDeclaredPrefixAt(i);
                printQuotedString(prefix);
                fOut.println(')");
                fOut.flush();
            }
        }

   
protected voidprintError(java.lang.String type, org.apache.xerces.xni.parser.XMLParseException ex)
Prints the error message.


        System.err.print("[");
        System.err.print(type);
        System.err.print("] ");
        String systemId = ex.getExpandedSystemId();
        if (systemId != null) {
            int index = systemId.lastIndexOf('/");
            if (index != -1)
                systemId = systemId.substring(index + 1);
            System.err.print(systemId);
        }
        System.err.print(':");
        System.err.print(ex.getLineNumber());
        System.err.print(':");
        System.err.print(ex.getColumnNumber());
        System.err.print(": ");
        System.err.print(ex.getMessage());
        System.err.println();
        System.err.flush();

    
protected voidprintInScopeNamespaces()

        int count = fNamespaceContext.getDeclaredPrefixCount();
        if (count>0){
            for (int i = 0; i < count; i++) {
                printIndent();
                fOut.print("declaredPrefix(");
                fOut.print("prefix=");
                String prefix = fNamespaceContext.getDeclaredPrefixAt(i);
                printQuotedString(prefix);
                fOut.print(',");
                fOut.print("uri=");
                printQuotedString(fNamespaceContext.getURI(prefix));
                fOut.println(')");
                fOut.flush();
            }
        }
   
protected voidprintIndent()
Prints the indent.


        for (int i = 0; i < fIndent; i++) {
            fOut.print(' ");
        }

    
protected voidprintQuotedString(java.lang.String s)
Print quoted string.


        if (s == null) {
            fOut.print("null");
            return;
        }

        fOut.print('"");
        int length = s.length();
        for (int i = 0; i < length; i++) {
            char c = s.charAt(i);
            normalizeAndPrint(c);
        }
        fOut.print('"");

    
protected voidprintQuotedString(char[] ch, int offset, int length)
Print quoted string.


        fOut.print('"");
        for (int i = 0; i < length; i++) {
            normalizeAndPrint(ch[offset + i]);
        }
        fOut.print('"");

    
private static voidprintUsage()
Prints the usage.


        System.err.println("usage: java xni.DocumentTracer (options) uri ...");
        System.err.println();

        System.err.println("options:");
        System.err.println("  -p name     Specify parser configuration by name.");
        System.err.println("  -n | -N     Turn on/off namespace processing.");
        System.err.println("  -v | -V     Turn on/off validation.");
        System.err.println("  -s | -S     Turn on/off Schema validation support.");
        System.err.println("              NOTE: Not supported by all parser configurations.");
        System.err.println("  -f  | -F    Turn on/off Schema full checking.");
        System.err.println("              NOTE: Requires use of -s and not supported by all parsers.");
        System.err.println("  -hs | -HS   Turn on/off honouring of all schema locations.");
        System.err.println("              NOTE: Requires use of -s and not supported by all parsers.");
        System.err.println("  -c | -C     Turn on/off character notifications");
        System.err.println("  -h          This help screen.");
        System.err.println();

        System.err.println("defaults:");
        System.err.println("  Config:     "+DEFAULT_PARSER_CONFIG);
        System.err.print("  Namespaces: ");
        System.err.println(DEFAULT_NAMESPACES ? "on" : "off");
        System.err.print("  Validation: ");
        System.err.println(DEFAULT_VALIDATION ? "on" : "off");
        System.err.print("  Schema:     ");
        System.err.println(DEFAULT_SCHEMA_VALIDATION ? "on" : "off");
        System.err.print("  Schema full checking:     ");
        System.err.println(DEFAULT_SCHEMA_FULL_CHECKING ? "on" : "off");
        System.err.print("  Honour all schema locations:     ");
        System.err.println(DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS ? "on" : "off");
        System.err.print("  Char refs:  ");
        System.err.println(DEFAULT_NOTIFY_CHAR_REFS ? "on" : "off" );

    
public voidprocessingInstruction(java.lang.String target, org.apache.xerces.xni.XMLString data, org.apache.xerces.xni.Augmentations augs)
Processing instruction.


        printIndent();
        fOut.print("processingInstruction(");
        fOut.print("target=");
        printQuotedString(target);
        fOut.print(',");
        fOut.print("data=");
        printQuotedString(data.ch, data.offset, data.length);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidseparator(short separator, org.apache.xerces.xni.Augmentations augs)
separator.


        printIndent();
        fOut.print("separator(");
        fOut.print("separator=");
        switch (separator) {
            case XMLDTDContentModelHandler.SEPARATOR_CHOICE: {
                fOut.print("SEPARATOR_CHOICE");
                break;
            }
            case XMLDTDContentModelHandler.SEPARATOR_SEQUENCE: {
                fOut.print("SEPARATOR_SEQUENCE");
                break;
            }
            default: {
                fOut.print("??? ("+separator+')");
            }
        }
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidsetOutput(java.io.OutputStream stream, java.lang.String encoding)
Sets the output stream for printing.


        if (encoding == null) {
            encoding = "UTF8";
        }

        Writer writer = new OutputStreamWriter(stream, encoding);
        fOut = new PrintWriter(writer);

    
public voidsetOutput(java.io.Writer writer)
Sets the output writer.


        fOut = writer instanceof PrintWriter
             ? (PrintWriter)writer : new PrintWriter(writer);

    
public voidstartAttlist(java.lang.String elementName, org.apache.xerces.xni.Augmentations augs)
Start attribute list.


        printIndent();
        fOut.print("startAttlist(");
        fOut.print("elementName=");
        printQuotedString(elementName);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartCDATA(org.apache.xerces.xni.Augmentations augs)
Start CDATA section.


        printIndent();
        fOut.print("startCDATA(");
        if (augs != null) {
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartConditional(short type, org.apache.xerces.xni.Augmentations augs)
Start conditional section.


        printIndent();
        fOut.print("startConditional(");
        fOut.print("type=");
        switch (type) {
            case XMLDTDHandler.CONDITIONAL_IGNORE: {
                fOut.print("CONDITIONAL_IGNORE");
                break;
            }
            case XMLDTDHandler.CONDITIONAL_INCLUDE: {
                fOut.print("CONDITIONAL_INCLUDE");
                break;
            }
            default: {
                fOut.print("??? ("+type+')");
            }
        }
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartContentModel(java.lang.String elementName, org.apache.xerces.xni.Augmentations augs)
Start content model.


        printIndent();
        fOut.print("startContentModel(");
        fOut.print("elementName=");
        printQuotedString(elementName);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartDTD(org.apache.xerces.xni.XMLLocator locator, org.apache.xerces.xni.Augmentations augs)
Start DTD.


        printIndent();
        fOut.print("startDTD(");
        fOut.print("locator=");
        if (locator == null) {
            fOut.print("null");
        }
        else {
            fOut.print('{");
            fOut.print("publicId=");
            printQuotedString(locator.getPublicId());
            fOut.print(',");
            fOut.print("literal systemId=");
            printQuotedString(locator.getLiteralSystemId());
            fOut.print(',");
            fOut.print("baseSystemId=");
            printQuotedString(locator.getBaseSystemId());
            fOut.print(',");
            fOut.print("expanded systemId=");
            printQuotedString(locator.getExpandedSystemId());
            fOut.print(',");
            fOut.print("lineNumber=");
            fOut.print(locator.getLineNumber());
            fOut.print(',");
            fOut.print("columnNumber=");
            fOut.print(locator.getColumnNumber());
            fOut.print('}");
        }
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartDocument(org.apache.xerces.xni.XMLLocator locator, java.lang.String encoding, org.apache.xerces.xni.NamespaceContext namespaceContext, org.apache.xerces.xni.Augmentations augs)
The start of the document.

param
systemId The system identifier of the entity if the entity is external, null otherwise.
param
encoding The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).
throws
XNIException Thrown by handler to signal an error.

        fNamespaceContext = namespaceContext;
        fIndent = 0;
        printIndent();
        fOut.print("startDocument(");
        fOut.print("locator=");
        if (locator == null) {
            fOut.print("null");
        }
        else {
            fOut.print('{");
            fOut.print("publicId=");
            printQuotedString(locator.getPublicId());
            fOut.print(',");
            fOut.print("literal systemId=");
            printQuotedString(locator.getLiteralSystemId());
            fOut.print(',");
            fOut.print("baseSystemId=");
            printQuotedString(locator.getBaseSystemId());
            fOut.print(',");
            fOut.print("expanded systemId=");
            printQuotedString(locator.getExpandedSystemId());
            fOut.print(',");
            fOut.print("lineNumber=");
            fOut.print(locator.getLineNumber());
            fOut.print(',");
            fOut.print("columnNumber=");
            fOut.print(locator.getColumnNumber());
            fOut.print('}");
        }
        fOut.print(',");
        fOut.print("encoding=");
        printQuotedString(encoding);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs)
Start element.


        printInScopeNamespaces();

        printIndent();
        fOut.print("startElement(");
        printElement(element, attributes);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartExternalSubset(org.apache.xerces.xni.XMLResourceIdentifier identifier, org.apache.xerces.xni.Augmentations augs)
Start external subset.


        printIndent();
        fOut.print("startExternalSubset(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartGeneralEntity(java.lang.String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, java.lang.String encoding, org.apache.xerces.xni.Augmentations augs)
Start entity.


        printIndent();
        fOut.print("startGeneralEntity(");
        fOut.print("name=");
        printQuotedString(name);
        fOut.print(',");
        fOut.print("identifier=");
        fOut.print(identifier);
        fOut.print(',");
        fOut.print("encoding=");
        printQuotedString(encoding);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartGroup(org.apache.xerces.xni.Augmentations augs)
Start group.


        printIndent();
        fOut.print("startGroup(");
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidstartParameterEntity(java.lang.String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, java.lang.String encoding, org.apache.xerces.xni.Augmentations augs)
Start entity.


        printIndent();
        fOut.print("startParameterEntity(");
        fOut.print("name=");
        printQuotedString(name);
        fOut.print(',");
        fOut.print("identifier=");
        fOut.print(identifier);
        fOut.print(',");
        fOut.print("encoding=");
        printQuotedString(encoding);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();
        fIndent++;

    
public voidtextDecl(java.lang.String version, java.lang.String encoding, org.apache.xerces.xni.Augmentations augs)
Text declaration.


        printIndent();
        fOut.print("textDecl(");
        fOut.print("version=");
        printQuotedString(version);
        fOut.print(',");
        fOut.print("encoding=");
        printQuotedString(encoding);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidunparsedEntityDecl(java.lang.String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, java.lang.String notation, org.apache.xerces.xni.Augmentations augs)
Unparsed entity declaration.


        printIndent();
        fOut.print("unparsedEntityDecl(");
        fOut.print("name=");
        printQuotedString(name);
        fOut.print(',");
        fOut.print("publicId=");
        printQuotedString(identifier.getPublicId());
        fOut.print(',");
        fOut.print("systemId=");
        printQuotedString(identifier.getLiteralSystemId());
        fOut.print(',");
        fOut.print("baseSystemId=");
        printQuotedString(identifier.getBaseSystemId());
        fOut.print(',");
        fOut.print("notation=");
        printQuotedString(notation);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");
        fOut.flush();

    
public voidwarning(java.lang.String domain, java.lang.String key, org.apache.xerces.xni.parser.XMLParseException ex)
Warning.

        printError("Warning", ex);
    
public voidxmlDecl(java.lang.String version, java.lang.String encoding, java.lang.String standalone, org.apache.xerces.xni.Augmentations augs)
XML Declaration.


        printIndent();
        fOut.print("xmlDecl(");
        fOut.print("version=");
        printQuotedString(version);
        fOut.print(',");
        fOut.print("encoding=");
        printQuotedString(encoding);
        fOut.print(',");
        fOut.print("standalone=");
        printQuotedString(standalone);
        if (augs != null) {
            fOut.print(',");
            printAugmentations(augs);
        }
        fOut.println(')");