Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /* SAXDriver.java -- 
    Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.
    Portions Copyright 2006-2007 Henri Sivonen
    Portions Copyright 2007-2008 Mozilla Foundation
   
    This file is part of GNU JAXP.
   
    GNU JAXP is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.
  
   GNU JAXP is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.
  
   You should have received a copy of the GNU General Public License
   along with GNU JAXP; see the file COPYING.  If not, write to the
   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.
  
   Linking this library statically or dynamically with other modules is
   making a combined work based on this library.  Thus, the terms and
   conditions of the GNU General Public License cover the whole
   combination.
  
   As a special exception, the copyright holders of this library give you
   permission to link this library with independent modules to produce an
   executable, regardless of the license terms of these independent
   modules, and to copy and distribute the resulting executable under
   terms of your choice, provided that you also meet, for each linked
   independent module, the terms and conditions of the license of that
   module.  An independent module is a module which is not derived from
   or based on this library.  If you modify this library, you may extend
   this exception to your version of the library, but you are not
   obligated to do so.  If you do not wish to do so, delete this
   exception statement from your version.
  
   Portions derived from code which carried the following notice:
  
   Copyright (c) 1997, 1998 by Microstar Software Ltd.
  
   AElfred is free for both commercial and non-commercial use and
   redistribution, provided that Microstar's copyright and disclaimer are
   retained intact.  You are free to modify AElfred for your own use and
   to redistribute AElfred with your modifications, provided that the
   modifications are clearly documented.
  
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   merchantability or fitness for a particular purpose.  Please use it AT
   YOUR OWN RISK.
   */
  
  package nu.validator.gnu.xml.aelfred2;
  
  import java.io.Reader;
  import java.net.URL;
  import java.util.List;
  import java.util.Locale;
  import java.util.Stack;
  
  
An enhanced SAX2 version of Microstar's Ælfred XML parser. The enhancements primarily relate to significant improvements in conformance to the XML specification, and SAX2 support. Performance has been improved. See the package level documentation for more information.
NameNotes
Features ... URL prefix is http://xml.org/sax/features/
(URL)/external-general-entitiesValue defaults to true
(URL)/external-parameter-entitiesValue defaults to true
(URL)/is-standalone(PRELIMINARY) Returns true iff the document's parsing has started (some non-error event after startDocument() was reported) and the document's standalone flag is set.
(URL)/namespace-prefixesValue defaults to false (but XML 1.0 names are always reported)
(URL)/lexical-handler/parameter-entitiesValue is fixed at true
(URL)/namespacesValue defaults to true
(URL)/resolve-dtd-uris(PRELIMINARY) Value defaults to true
(URL)/string-interningValue is fixed at true
(URL)/use-attributes2(PRELIMINARY) Value is fixed at true
(URL)/use-entity-resolver2(PRELIMINARY) Value defaults to true
(URL)/validationValue is fixed at false
Handler Properties ... URL prefix is http://xml.org/sax/properties/
(URL)/declaration-handlerA declaration handler may be provided.
(URL)/lexical-handlerA lexical handler may be provided.

This parser currently implements the SAX1 Parser API, but it may not continue to do so in the future.

Author(s):
Written by David Megginson (version 1.2a from Microstar)
Updated by David Brownell <dbrownell@users.sourceforge.net>
See also:
org.xml.sax.Parser
 
 final public class SAXDriver implements Locator2Attributes2XMLReader,
         ParserAttributeList {
 
     private final DefaultHandler2 base = new DefaultHandler2();
 
     private XmlParser parser;
 
     private EntityResolver entityResolver = ;
 
     private EntityResolver2 resolver2 = null;
 
     private ContentHandler contentHandler = ;
 
     private DTDHandler dtdHandler = ;
 
     private ErrorHandler errorHandler = ;
 
     private DeclHandler declHandler = ;
 
     private LexicalHandler lexicalHandler = ;
 
     private String elementName;
 
     private Stack<StringentityStack;
 
     // one vector (of object/struct): faster, smaller
     private List<AttributeattributesList;
 
     private boolean namespaces = true;
 
     private boolean xmlNames = false;
 
     private boolean extGE = true;
 
     private boolean extPE = true;
 
     private boolean resolveAll = true;
 
     private boolean useResolver2 = true;
 
     // package private to allow (read-only) access in XmlParser
     boolean stringInterning = true;
 
     private int attributeCount;
 
     private boolean attributes;
 
     private String[] nsTemp;
 
     private NamespaceSupport prefixStack;
 
     boolean checkNormalization = false;
     
     private boolean errorHandlerLocked = false;
 
     
     //
     // Constructor.
     //
 
    
Constructs a SAX Parser.
 
     public SAXDriver() {
         reset();
     }
 
     private void reset() {
          = null;
          = new Stack<String>();
          = Collections.synchronizedList(new ArrayList<Attribute>());
          = 0;
          = false;
          = new String[3];
          = null;
     }
 
     //
     // Implementation of org.xml.sax.Parser.
     //
 
    
SAX1: Sets the locale used for diagnostics; currently, only locales using the English language are supported.

Parameters:
locale The locale for which diagnostics will be generated
 
     public void setLocale(Locale localethrows SAXException {
         if ("en".equals(locale.getLanguage())) {
             return;
         }
         throw new SAXException("AElfred2 only supports English locales.");
     }

    
SAX2: Returns the object used when resolving external entities during parsing (both general and parameter entities).
 
     public EntityResolver getEntityResolver() {
         return ( == ) ? null : ;
     }

    
SAX1, SAX2: Set the entity resolver for this parser.

Parameters:
resolver
 
     public void setEntityResolver(EntityResolver resolver) {
         if (resolver instanceof EntityResolver2) {
              = (EntityResolver2resolver;
         } else {
              = null;
         }
         if (resolver == null) {
             resolver = ;
         }
          = resolver;
     }

    
SAX2: Returns the object used to process declarations related to notations and unparsed entities.
 
     public DTDHandler getDTDHandler() {
         return ( == ) ? null : ;
     }

    
SAX1, SAX2: Set the DTD handler for this parser.

Parameters:
handler The object to receive DTD events.
 
     public void setDTDHandler(DTDHandler handler) {
         if (handler == null) {
             handler = ;
         }
         this. = handler;
     }

    
SAX1: Set the document handler for this parser. If a content handler was set, this document handler will supplant it. The parser is set to report all XML 1.0 names rather than to filter out "xmlns" attributes (the "namespace-prefixes" feature is set to true).

Deprecated:
SAX2 programs should use the XMLReader interface and a ContentHandler.
Parameters:
handler The object to receive document events.
 
     public void setDocumentHandler(DocumentHandler handler) {
          = new Adapter(handler);
          = true;
     }

    
SAX2: Returns the object used to report the logical content of an XML document.
 
     public ContentHandler getContentHandler() {
         return ( == ) ? null : ;
     }

    
SAX2: Assigns the object used to report the logical content of an XML document. If a document handler was set, this content handler will supplant it (but XML 1.0 style name reporting may remain enabled).
 
     public void setContentHandler(ContentHandler handler) {
         if (handler == null) {
             handler = ;
         }
          = handler;
     }
 
     public void lockErrorHandler() {
          = true;
     }
    
    
SAX1, SAX2: Set the error handler for this parser.

Parameters:
handler The object to receive error events.
 
     public void setErrorHandler(ErrorHandler handler) {
         if () {
             return;
         }
         if (handler == null) {
             handler = ;
         }
         this. = handler;
     }

    
SAX2: Returns the object used to receive callbacks for XML errors of all levels (fatal, nonfatal, warning); this is never null;
 
     public ErrorHandler getErrorHandler() {
         return ( == ) ? null : ;
     }

    
SAX1, SAX2: Auxiliary API to parse an XML document, used mostly when no URI is available. If you want anything useful to happen, you should set at least one type of handler.

Parameters:
source The XML input source. Don't set 'encoding' unless you know for a fact that it's correct.
Throws:
org.xml.sax.SAXException The handlers may throw any SAXException, and the parser normally throws SAXParseException objects.
java.io.IOException IOExceptions are normally through through the parser if there are problems reading the source document.
See also:
setEntityResolver(org.xml.sax.EntityResolver)
setDTDHandler(org.xml.sax.DTDHandler)
setContentHandler(org.xml.sax.ContentHandler)
setErrorHandler(org.xml.sax.ErrorHandler)
 
     public void parse(InputSource sourcethrows SAXExceptionIOException {
         synchronized () {
              = new XmlParser();
             if () {
                  = new NamespaceSupport();
             } else if (!) {
                 throw new IllegalStateException();
             }
             .setHandler(this);
 
             try {
                 Reader r = source.getCharacterStream();
                 InputStream in = source.getByteStream();
 
                 .doParse(source.getSystemId(), source.getPublicId(), r,
                         insource.getEncoding());
             } catch (SAXException e) {
                 throw e;
             } catch (IOException e) {
                 throw e;
             } catch (RuntimeException e) {
                 throw e;
             } catch (Exception e) {
                 throw new SAXParseException(e.getMessage(), thise);
             } finally {
                 .endDocument();
                 reset();
             }
         }
     }

    
SAX1, SAX2: Preferred API to parse an XML document, using a system identifier (URI).
 
     public void parse(String systemIdthrows SAXExceptionIOException {
         parse(new InputSource(systemId));
     }
 
     //
     // Implementation of SAX2 "XMLReader" interface
     //
     static final String FEATURE = "http://xml.org/sax/features/";
 
     static final String PROPERTY = "http://xml.org/sax/properties/";

    
SAX2: Tells the value of the specified feature flag.

Throws:
org.xml.sax.SAXNotRecognizedException thrown if the feature flag is neither built in, nor yet assigned.
 
     public boolean getFeature(String featureId)
             throws SAXNotRecognizedExceptionSAXNotSupportedException {
         if (( + "validation").equals(featureId)) {
             return false;
         }
 
         // external entities (both types) are optionally included
         if (( + "external-general-entities").equals(featureId)) {
             return ;
         }
         if (( + "external-parameter-entities").equals(featureId)) {
             return ;
         }
 
         // element/attribute names are as written in document; no mangling
         if (( + "namespace-prefixes").equals(featureId)) {
             return ;
         }
 
         // report element/attribute namespaces?
         if (( + "namespaces").equals(featureId)) {
             return ;
         }
 
         // all PEs and GEs are reported
         if (( + "lexical-handler/parameter-entities").equals(featureId)) {
             return true;
         }
 
         // default is true
         if (( + "string-interning").equals(featureId)) {
             return ;
         }
 
         // EXTENSIONS 1.1
 
         // always returns isSpecified info
         if (( + "use-attributes2").equals(featureId)) {
             return true;
         }
 
         // meaningful between startDocument/endDocument
         if (( + "is-standalone").equals(featureId)) {
             if ( == null) {
                 throw new SAXNotSupportedException(featureId);
             }
             return .isStandalone();
         }
 
         // optionally don't absolutize URIs in declarations
         if (( + "resolve-dtd-uris").equals(featureId)) {
             return ;
         }
 
         // optionally use resolver2 interface methods, if possible
         if (( + "use-entity-resolver2").equals(featureId)) {
             return ;
         }
 
         if ("http://xml.org/sax/features/unicode-normalization-checking".equals(featureId)) {
             return ;
         }
 
         throw new SAXNotRecognizedException(featureId);
     }
 
     // package private
         return ;
     }
 
     // package private
     boolean resolveURIs() {
         return ;
     }

    
SAX2: Returns the specified property.

Throws:
org.xml.sax.SAXNotRecognizedException thrown if the property value is neither built in, nor yet stored.
 
     public Object getProperty(String propertyId)
             throws SAXNotRecognizedException {
         if (( + "declaration-handler").equals(propertyId)) {
             return ( == ) ? null : ;
         }
 
         if (( + "lexical-handler").equals(propertyId)) {
             return ( == ) ? null : ;
         }
 
         // unknown properties
         throw new SAXNotRecognizedException(propertyId);
     }

    
SAX2: Sets the state of feature flags in this parser. Some built-in feature flags are mutable.
 
     public void setFeature(String featureIdboolean value)
             throws SAXNotRecognizedExceptionSAXNotSupportedException {
         boolean state;
 
         // Features with a defined value, we just change it if we can.
         state = getFeature(featureId);
 
         if (state == value) {
             return;
         }
         if ( != null) {
             throw new SAXNotSupportedException("not while parsing");
         }
 
         if (( + "namespace-prefixes").equals(featureId)) {
             // in this implementation, this only affects xmlns reporting
              = value;
             // forcibly prevent illegal parser state
             if (!) {
                  = true;
             }
             return;
         }
 
         if (( + "namespaces").equals(featureId)) {
              = value;
             // forcibly prevent illegal parser state
             if (!) {
                  = true;
             }
             return;
         }
 
         if (( + "external-general-entities").equals(featureId)) {
              = value;
             return;
         }
         if (( + "external-parameter-entities").equals(featureId)) {
              = value;
             return;
         }
         if (( + "resolve-dtd-uris").equals(featureId)) {
              = value;
             return;
         }
 
         if (( + "use-entity-resolver2").equals(featureId)) {
              = value;
             return;
         }
 
         if ("http://xml.org/sax/features/unicode-normalization-checking".equals(featureId)) {
              = value;
             return;
         }
 
         throw new SAXNotRecognizedException(featureId);
     }

    
SAX2: Assigns the specified property. Like SAX1 handlers, these may be changed at any time.
 
     public void setProperty(String propertyIdObject value)
             throws SAXNotRecognizedExceptionSAXNotSupportedException {
         // see if the property is recognized
         getProperty(propertyId);
 
         // Properties with a defined value, we just change it if we can.
 
         if (( + "declaration-handler").equals(propertyId)) {
             if (value == null) {
                  = ;
             } else if (!(value instanceof DeclHandler)) {
                 throw new SAXNotSupportedException(propertyId);
             } else {
                  = (DeclHandlervalue;
             }
             return;
         }
 
         if (( + "lexical-handler").equals(propertyId)) {
             if (value == null) {
                  = ;
             } else if (!(value instanceof LexicalHandler)) {
                 throw new SAXNotSupportedException(propertyId);
             } else {
                  = (LexicalHandlervalue;
             }
             return;
         }
 
         throw new SAXNotSupportedException(propertyId);
     }
 
     //
     // This is where the driver receives XmlParser callbacks and translates
     // them into SAX callbacks. Some more callbacks have been added for
     // SAX2 support.
     //
 
     void startDocument() throws SAXException {
         .setDocumentLocator(this);
         .startDocument();
         .clear();
     }
 
     void skippedEntity(String namethrows SAXException {
         .skippedEntity(name);
     }
 
     InputSource getExternalSubset(String nameString baseURI)
             throws SAXExceptionIOException {
         if ( == null || ! || !) {
             return null;
         }
         return .getExternalSubset(namebaseURI);
     }
 
     InputSource resolveEntity(boolean isPEString nameInputSource in,
             String baseURIthrows SAXExceptionIOException {
         InputSource source;
 
         // external entities might be skipped
         if (isPE && !) {
             return null;
         }
         if (!isPE && !) {
             return null;
         }
 
         // ... or not
         .startEntity(name);
         if ( != null && ) {
             source = .resolveEntity(namein.getPublicId(), baseURI,
                     in.getSystemId());
             if (source == null) {
                 in.setSystemId(absolutize(baseURIin.getSystemId(), false));
                 source = in;
             }
         } else {
             in.setSystemId(absolutize(baseURIin.getSystemId(), false));
             source = .resolveEntity(in.getPublicId(),
                     in.getSystemId());
             if (source == null) {
                 source = in;
             }
         }
         startExternalEntity(namesource.getSystemId(), true);
         return source;
     }
 
     // absolutize a system ID relative to the specified base URI
     // (temporarily) package-visible for external entity decls
     String absolutize(String baseURIString systemIdboolean nice)
             throws MalformedURLExceptionSAXException {
         // FIXME normalize system IDs -- when?
         // - Convert to UTF-8
         // - Map reserved and non-ASCII characters to %HH
 
         try {
             if (baseURI == null) {
                 if (.) {
                     warn("No base URI; hope this SYSTEM id is absolute: "
                             + systemId);
                 }
                 return new URL(systemId).toString();
             } else {
                 return new URL(new URL(baseURI), systemId).toString();
             }
         } catch (MalformedURLException e) {
             // Let unknown URI schemes pass through unless we need
             // the JVM to map them to i/o streams for us...
             if (!nice) {
                 throw e;
             }
 
             // sometimes sysids for notations or unparsed entities
             // aren't really URIs...
             warn("Can't absolutize SYSTEM id: " + e.getMessage());
             return systemId;
         }
     }
 
     void startExternalEntity(String nameString systemIdboolean stackOnly)
             throws SAXException {
         // The following warning was deleted because the application has the
         // option of not setting systemId. Sun's JAXP or Xerces seems to
         // ignore this case.
         /*
          * if (systemId == null) warn ("URI was not reported to parser for
          * entity " + name);
          */
         if (!stackOnly// spliced [dtd] needs startEntity
         {
             .startEntity(name);
         }
         .push(systemId);
     }
 
     void endExternalEntity(String namethrows SAXException {
         if (!"[document]".equals(name)) {
             .endEntity(name);
         }
         .pop();
     }
 
     void startInternalEntity(String namethrows SAXException {
         .startEntity(name);
     }
 
     void endInternalEntity(String namethrows SAXException {
         .endEntity(name);
     }
 
     void doctypeDecl(String nameString publicIdString systemId)
             throws SAXException {
         .startDTD(namepublicIdsystemId);
 
         // ... the "name" is a declaration and should be given
         // to the DeclHandler (but sax2 doesn't).
 
         // the IDs for the external subset are lexical details,
         // as are the contents of the internal subset; but sax2
         // doesn't provide the internal subset "pre-parse"
     }
 
     void notationDecl(String nameString publicIdString systemId,
             String baseUrithrows SAXException {
         try {
             .notationDecl(namepublicId,
                     ( && systemId != null) ? absolutize(baseUri,
                             systemIdtrue) : systemId);
         } catch (IOException e) {
             // "can't happen"
             throw new SAXParseException(e.getMessage(), thise);
         }
     }
 
     void unparsedEntityDecl(String nameString publicIdString systemId,
             String baseUriString notationthrows SAXException {
         try {
             .unparsedEntityDecl(
                     name,
                     publicId,
                      ? absolutize(baseUrisystemIdtrue) : systemId,
                     notation);
         } catch (IOException e) {
             // "can't happen"
             throw new SAXParseException(e.getMessage(), thise);
         }
     }
 
     void endDoctype() throws SAXException {
         .endDTD();
     }
 
     private void declarePrefix(String prefixString urithrows SAXException {
         // NOTE: uri may be the empty string
 
         int index = uri.indexOf(':');
 
         // many versions of nwalsh docbook stylesheets
         // have bogus URLs; so this can't be an error...
         if (index < 1 && uri.length() != 0) {
             warn("relative URI for namespace: " + uri);
         }
 
         // char [0] must be ascii alpha [RFC 2396]
         if (uri.length() != 0 && !isAlpha(uri.charAt(0))) {
             fatal("First character of the URI must be ascii alpha");
         }
 
         // chars [1..index] must be ascii alphanumeric or in "+-." [RFC 2396]
         for (int i = 1; i < indexi++) {
             if (!isAlphanumericOrPlusMinusPoint(uri.charAt(i))) {
                 fatal("Character " + i
                         + " of the URI must be ascii alpha or in \"+-.\"");
             }
         }
 
         // Namespace Constraints
         // name for xml prefix must be http://www.w3.org/XML/1998/namespace
         boolean prefixEquality = prefix.equals("xml");
         boolean uriEquality = uri.equals("http://www.w3.org/XML/1998/namespace");
         if ((prefixEquality || uriEquality) && !(prefixEquality && uriEquality)) {
             fatal("xml is by definition bound to the namespace name "
                     + "http://www.w3.org/XML/1998/namespace");
         }
 
         // xmlns prefix declaration is illegal but xml prefix declaration is
         // llegal...
         if (prefixEquality && uriEquality) {
             return;
         }
 
         // name for xmlns prefix must be http://www.w3.org/2000/xmlns/
         prefixEquality = prefix.equals("xmlns");
         uriEquality = uri.equals("http://www.w3.org/2000/xmlns/");
         if ((prefixEquality || uriEquality) && !(prefixEquality && uriEquality)) {
             fatal("http://www.w3.org/2000/xmlns/ is by definition bound"
                     + " to prefix xmlns");
         }
 
         // even if the uri is http://www.w3.org/2000/xmlns/
         // it is illegal to declare it
         if (prefixEquality && uriEquality) {
             fatal("declaring the xmlns prefix is illegal");
         }
 
         uri = uri.intern();
         .declarePrefix(prefixuri);
         .startPrefixMapping(prefixuri);
     }
 
     void attribute(String qnameString valueboolean isSpecified)
             throws SAXException {
         if (!) {
              = true;
             if () {
                 .pushContext();
             }
         }
 
         // process namespace decls immediately;
         // then maybe forget this as an attribute
         if () {
             int index;
 
             // default NS declaration?
             if () {
                 if ("xmlns" == qname) {
                     declarePrefix(""value);
                     if (!) {
                         return;
                     }
                 }
                 // NS prefix declaration?
                 else if ((index = qname.indexOf(':')) == 5
                         && qname.startsWith("xmlns")) {
                     String prefix = qname.substring(6);
 
                     if (prefix.equals("")) {
                         fatal("missing prefix "
                                 + "in namespace declaration attribute");
                     }
                     if (value.length() == 0) {
                         verror("missing URI in namespace declaration attribute: "
                                 + qname);
                     } else {
                         declarePrefix(prefixvalue);
                     }
                     if (!) {
                         return;
                     }
                 }
             } else {
                 if ("xmlns".equals(qname)) {
                     declarePrefix(""value);
                     if (!) {
                         return;
                     }
                 }
                 // NS prefix declaration?
                 else if ((index = qname.indexOf(':')) == 5
                         && qname.startsWith("xmlns")) {
                     String prefix = qname.substring(6);
 
                     if (value.length() == 0) {
                         verror("missing URI in namespace decl attribute: "
                                 + qname);
                     } else {
                         declarePrefix(prefixvalue);
                     }
                     if (!) {
                         return;
                     }
                 }
             }
         }
         // remember this attribute ...
         ++;
 
         // attribute type comes from querying parser's DTD records
         .add(new Attribute(qnamevalueisSpecified));
 
     }
 
     void startElement(String elnamethrows SAXException {
         ContentHandler handler = ;
 
         //
         // NOTE: this implementation of namespace support adds something
         // like six percent to parsing CPU time, in a large (~50 MB)
         // document that doesn't use namespaces at all. (Measured by PC
         // sampling, with a bug where endElement processing was omitted.)
         // [Measurement referred to older implementation, older JVM ...]
         //
         // It ought to become notably faster in such cases. Most
         // costs are the prefix stack calling Hashtable.get() (2%),
         // String.hashCode() (1.5%) and about 1.3% each for pushing
         // the context, and two chunks of name processing.
         //
 
         if (!) {
             if () {
                 .pushContext();
             }
         } else if () {
 
             // now we can patch up namespace refs; we saw all the
             // declarations, so now we'll do the Right Thing
             Iterator<Attributeitt = .iterator();
             while (itt.hasNext()) {
                 Attribute attribute = itt.next();
                 String qname = attribute.name;
                 int index;
 
                 // default NS declaration?
                 if () {
                     if ("xmlns" == qname) {
                         continue;
                     }
                 } else {
                     if ("xmlns".equals(qname)) {
                         continue;
                     }
                 }
                 // Illegal in the new Namespaces Draft
                 // should it be only in 1.1 docs??
                 if (qname.equals(":")) {
                     fatal("namespace names consisting of a single colon "
                             + "character are invalid");
                 }
                 index = qname.indexOf(':');
 
                // NS prefix declaration?
                if (index == 5 && qname.startsWith("xmlns")) {
                    continue;
                }
                // it's not a NS decl; patch namespace info items
                if (.processName(qnametrue) == null) {
                    fatal("undeclared attribute prefix in: " + qname);
                } else {
                    attribute.nameSpace = [0];
                    attribute.localName = [1];
                }
            }
        }
        // save element name so attribute callbacks work
         = elname;
        if () {
            if (.processName(elnamefalse) == null) {
                fatal("undeclared element prefix in: " + elname);
                [0] = [1] = "";
            }
            handler.startElement([0], [1], elnamethis);
        } else {
            handler.startElement(""""elnamethis);
        }
        // elementName = null;
        // elements with no attributes are pretty common!
        if () {
            .clear();
             = 0;
             = false;
        }
    }
    void endElement(String elnamethrows SAXException {
        ContentHandler handler = ;
        if (!) {
            handler.endElement(""""elname);
            return;
        }
        .processName(elnamefalse);
        handler.endElement([0], [1], elname);
        Enumeration prefixes = .getDeclaredPrefixes();
        while (prefixes.hasMoreElements()) {
            handler.endPrefixMapping((Stringprefixes.nextElement());
        }
        .popContext();
    }
    void startCDATA() throws SAXException {
        .startCDATA();
    }
    void charData(char[] chint startint lengththrows SAXException {
        .characters(chstartlength);
    }
    void endCDATA() throws SAXException {
        .endCDATA();
    }
    void ignorableWhitespace(char[] chint startint length)
            throws SAXException {
        .ignorableWhitespace(chstartlength);
    }
    void processingInstruction(String targetString datathrows SAXException {
        .processingInstruction(targetdata);
    }
    void comment(char[] chint startint lengththrows SAXException {
        if ( != ) {
            .comment(chstartlength);
        }
    }
    void fatal(String messagethrows SAXException {
        SAXParseException fatal;
        fatal = new SAXParseException(messagethis);
        .fatalError(fatal);
        // Even if the application can continue ... we can't!
        throw fatal;
    }
    // We can safely report a few validity errors that
    // make layered SAX2 DTD validation more conformant
    void verror(String messagethrows SAXException {
        SAXParseException err;
        err = new SAXParseException(messagethis);
        .error(err);
    }
    void warn(String messagethrows SAXException {
        SAXParseException err;
        err = new SAXParseException(messagethis);
        .warning(err);
    }

    
Checks whether a given character is an ASCII alpha or not.

Parameters:
character The character to check.
Returns:
true if the character is an ASCII alpha.
    private boolean isAlpha(char character) {
        // Range of alpha characters in ASCII, should be the same for
        // Unicode according to "The Unicode Standard 4.0", section 5.2
        return (character >= 'A' && character <= 'Z'// Unicode A..Z
                || (character >= 'a' && character <= 'z'); // Unicode a..z
    }

    
Checks whether a given character is in "+-." or an ASCII alphanumeric. This is useful for a check related to [RFC 2396]

Parameters:
character The character to check.
Returns:
true if the character is in "+-." or an ASCII alphanumeric.
    private boolean isAlphanumericOrPlusMinusPoint(char character) {
        return (character >= 'A' && character <= 'Z'// Unicode A..Z
                || (character >= 'a' && character <= 'z'// Unicode a..z
                || (character >= '0' && character <= '9'// Unicode 0..9
                || character == '+' || character == '-' || character == '.';
    }
    
    //
    // Implementation of org.xml.sax.Attributes.
    //

    
SAX1 AttributeList, SAX2 Attributes method (don't invoke on parser);
    public int getLength() {
        return .size();
    }

    
SAX2 Attributes method (don't invoke on parser);
    public String getURI(int index) {
        if (index < 0 || index >= .size()) {
            return null;
        }
        return .get(index).;
    }

    
SAX2 Attributes method (don't invoke on parser);
    public String getLocalName(int index) {
        if (index < 0 || index >= .size()) {
            return null;
        }
        Attribute attr = .get(index);
        // FIXME attr.localName is sometimes null, why?
        if ( && attr.localName == null) {
            // XXX fix this here for now
            int ci = attr.name.indexOf(':');
            attr.localName = (ci == -1) ? attr.name
                    : attr.name.substring(ci + 1);
        }
        return (attr.localName == null) ? "" : attr.localName;
    }

    
SAX2 Attributes method (don't invoke on parser);
    public String getQName(int index) {
        if (index < 0 || index >= .size()) {
            return null;
        }
        Attribute attr = .get(index);
        return (attr.name == null) ? "" : attr.name;
    }

    
SAX1 AttributeList method (don't invoke on parser);
    public String getName(int index) {
        return getQName(index);
    }

    
SAX1 AttributeList, SAX2 Attributes method (don't invoke on parser);
    public String getType(int index) {
        if (index < 0 || index >= .size()) {
            return null;
        }
        String type = .getAttributeType(getQName(index));
        if (type == null) {
            return "CDATA";
        }
        // ... use DeclHandler.attributeDecl to see enumerations
        if (type == "ENUMERATION") {
            return "NMTOKEN";
        }
        return type;
    }

    
SAX1 AttributeList, SAX2 Attributes method (don't invoke on parser);
    public String getValue(int index) {
        if (index < 0 || index >= .size()) {
            return null;
        }
        return .get(index).;
    }

    
SAX2 Attributes method (don't invoke on parser);
    public int getIndex(String uriString local) {
        int length = getLength();
        for (int i = 0; i < lengthi++) {
            if (!getURI(i).equals(uri)) {
                continue;
            }
            if (getLocalName(i).equals(local)) {
                return i;
            }
        }
        return -1;
    }

    
SAX2 Attributes method (don't invoke on parser);
    public int getIndex(String xmlName) {
        int length = getLength();
        for (int i = 0; i < lengthi++) {
            if (getQName(i).equals(xmlName)) {
                return i;
            }
        }
        return -1;
    }

    
SAX2 Attributes method (don't invoke on parser);
    public String getType(String uriString local) {
        int index = getIndex(urilocal);
        if (index < 0) {
            return null;
        }
        return getType(index);
    }

    
SAX1 AttributeList, SAX2 Attributes method (don't invoke on parser);
    public String getType(String xmlName) {
        int index = getIndex(xmlName);
        if (index < 0) {
            return null;
        }
        return getType(index);
    }

    
SAX Attributes method (don't invoke on parser);
    public String getValue(String uriString local) {
        int index = getIndex(urilocal);
        if (index < 0) {
            return null;
        }
        return getValue(index);
    }

    
SAX1 AttributeList, SAX2 Attributes method (don't invoke on parser);
    public String getValue(String xmlName) {
        int index = getIndex(xmlName);
        if (index < 0) {
            return null;
        }
        return getValue(index);
    }
    //
    // Implementation of org.xml.sax.ext.Attributes2
    //

    

Returns:
false unless the attribute was declared in the DTD.
Throws:
java.lang.ArrayIndexOutOfBoundsException When the supplied index does not identify an attribute.
    public boolean isDeclared(int index) {
        if (index < 0 || index >= ) {
            throw new ArrayIndexOutOfBoundsException();
        }
        String type = .getAttributeType(getQName(index));
        return (type != null);
    }

    

Returns:
false unless the attribute was declared in the DTD.
Throws:
java.lang.IllegalArgumentException When the supplied names do not identify an attribute.
    public boolean isDeclared(String qName) {
        int index = getIndex(qName);
        if (index < 0) {
            throw new IllegalArgumentException();
        }
        String type = .getAttributeType(qName);
        return (type != null);
    }

    

Returns:
false unless the attribute was declared in the DTD.
Throws:
java.lang.IllegalArgumentException When the supplied names do not identify an attribute.
    public boolean isDeclared(String uriString localName) {
        int index = getIndex(urilocalName);
        return isDeclared(index);
    }

    
SAX-ext Attributes2 method (don't invoke on parser);
    public boolean isSpecified(int index) {
        return .get(index).;
    }

    
SAX-ext Attributes2 method (don't invoke on parser);