⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saxdriver.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* SAXDriver.java --    Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception 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 gnu.xml.aelfred2;import java.io.*;import java.net.MalformedURLException;import java.net.URL;import java.util.Locale;import java.util.Stack;import java.util.ArrayList;import java.util.Collections;import java.util.Enumeration;import java.util.Iterator;import java.util.List;import org.xml.sax.*;import org.xml.sax.ext.*;import org.xml.sax.helpers.NamespaceSupport;/** * An enhanced SAX2 version of Microstar's &AElig;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. * * <table border="1" width='100%' cellpadding='3' cellspacing='0'> * <tr bgcolor='#ccccff'> *	<th><font size='+1'>Name</font></th> *	<th><font size='+1'>Notes</font></th></tr> * * <tr><td colspan=2><center><em>Features ... URL prefix is * <b>http://xml.org/sax/features/</b></em></center></td></tr> * * <tr><td>(URL)/external-general-entities</td> *	<td>Value defaults to <em>true</em></td></tr> * <tr><td>(URL)/external-parameter-entities</td> *	<td>Value defaults to <em>true</em></td></tr> * <tr><td>(URL)/is-standalone</td> *	<td>(PRELIMINARY) Returns true iff the document's parsing *	has started (some non-error event after <em>startDocument()</em> *	was reported) and the document's standalone flag is set.</td></tr> * <tr><td>(URL)/namespace-prefixes</td> *	<td>Value defaults to <em>false</em> (but XML 1.0 names are *		always reported)</td></tr> * <tr><td>(URL)/lexical-handler/parameter-entities</td> *	<td>Value is fixed at <em>true</em></td></tr> * <tr><td>(URL)/namespaces</td> *	<td>Value defaults to <em>true</em></td></tr> * <tr><td>(URL)/resolve-dtd-uris</td> *	<td>(PRELIMINARY) Value defaults to <em>true</em></td></tr> * <tr><td>(URL)/string-interning</td> *	<td>Value is fixed at <em>true</em></td></tr> * <tr><td>(URL)/use-attributes2</td> *	<td>(PRELIMINARY) Value is fixed at <em>true</em></td></tr> * <tr><td>(URL)/use-entity-resolver2</td> *	<td>(PRELIMINARY) Value defaults to <em>true</em></td></tr> * <tr><td>(URL)/validation</td> *	<td>Value is fixed at <em>false</em></td></tr> * * <tr><td colspan=2><center><em>Handler Properties ... URL prefix is * <b>http://xml.org/sax/properties/</b></em></center></td></tr> * * <tr><td>(URL)/declaration-handler</td> *	<td>A declaration handler may be provided.  </td></tr> * <tr><td>(URL)/lexical-handler</td> *	<td>A lexical handler may be provided.  </td></tr> * </table> * * <p>This parser currently implements the SAX1 Parser API, but * it may not continue to do so in the future. * * @author Written by David Megginson (version 1.2a from Microstar) * @author Updated by David Brownell &lt;dbrownell@users.sourceforge.net&gt; * @see org.xml.sax.Parser */final public class SAXDriver  implements Locator, Attributes2, XMLReader, Parser, AttributeList{    private final DefaultHandler2 base = new DefaultHandler2();  private XmlParser parser;    private EntityResolver entityResolver = base;  private EntityResolver2 resolver2 = null;  private ContentHandler contentHandler = base;  private DTDHandler dtdHandler = base;  private ErrorHandler errorHandler = base;  private DeclHandler declHandler = base;  private LexicalHandler lexicalHandler = base;    private String elementName;  private Stack entityStack;    // one vector (of object/struct): faster, smaller  private List attributesList;    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;    //  // Constructor.  //  /**   * Constructs a SAX Parser.   */  public SAXDriver()  {    reset();  }  private void reset()  {    elementName = null;    entityStack = new Stack();    attributesList = Collections.synchronizedList(new ArrayList());    attributeCount = 0;    attributes = false;    nsTemp = new String[3];    prefixStack = null;  }  //  // Implementation of org.xml.sax.Parser.  //  /**   * <b>SAX1</b>: Sets the locale used for diagnostics; currently,   * only locales using the English language are supported.   * @param locale The locale for which diagnostics will be generated   */  public void setLocale(Locale locale)    throws SAXException  {    if ("en".equals(locale.getLanguage()))      {        return;      }    throw new SAXException ("AElfred2 only supports English locales.");  }  /**   * <b>SAX2</b>: Returns the object used when resolving external   * entities during parsing (both general and parameter entities).   */  public EntityResolver getEntityResolver()  {    return (entityResolver == base) ? null : entityResolver;  }  /**   * <b>SAX1, SAX2</b>: Set the entity resolver for this parser.   * @param handler The object to receive entity events.   */  public void setEntityResolver(EntityResolver resolver)  {    if (resolver instanceof EntityResolver2)      {        resolver2 = (EntityResolver2) resolver;      }    else      {        resolver2 = null;      }    if (resolver == null)      {        resolver = base;      }    entityResolver = resolver;  }  /**   * <b>SAX2</b>: Returns the object used to process declarations related   * to notations and unparsed entities.   */  public DTDHandler getDTDHandler()  {    return (dtdHandler == base) ? null : dtdHandler;  }  /**   * <b>SAX1, SAX2</b>: Set the DTD handler for this parser.   * @param handler The object to receive DTD events.   */  public void setDTDHandler(DTDHandler handler)  {    if (handler == null)      {        handler = base;      }    this.dtdHandler = handler;  }  /**   * <b>SAX1</b>: 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.   *   * @param handler The object to receive document events.   */  public void setDocumentHandler(DocumentHandler handler)  {    contentHandler = new Adapter(handler);    xmlNames = true;  }  /**   * <b>SAX2</b>: Returns the object used to report the logical   * content of an XML document.   */  public ContentHandler getContentHandler()  {    return (contentHandler == base) ? null : contentHandler;  }  /**   * <b>SAX2</b>: 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 = base;      }    contentHandler = handler;  }  /**   * <b>SAX1, SAX2</b>: Set the error handler for this parser.   * @param handler The object to receive error events.   */  public void setErrorHandler(ErrorHandler handler)  {    if (handler == null)      {        handler = base;      }    this.errorHandler = handler;  }  /**   * <b>SAX2</b>: Returns the object used to receive callbacks for XML   * errors of all levels (fatal, nonfatal, warning); this is never null;   */  public ErrorHandler getErrorHandler()  {    return (errorHandler == base) ? null : errorHandler;  }  /**   * <b>SAX1, SAX2</b>: 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.   * @param source The XML input source.  Don't set 'encoding' unless   *  you know for a fact that it's correct.   * @see #setEntityResolver   * @see #setDTDHandler   * @see #setContentHandler   * @see #setErrorHandler   * @exception SAXException The handlers may throw any SAXException,   *  and the parser normally throws SAXParseException objects.   * @exception IOException IOExceptions are normally through through   *  the parser if there are problems reading the source document.   */  public void parse(InputSource source)    throws SAXException, IOException  {    synchronized (base)      {        parser = new XmlParser();        if (namespaces)          {            prefixStack = new NamespaceSupport();          }        else if (!xmlNames)          {            throw new IllegalStateException();          }        parser.setHandler(this);                try          {            Reader r = source.getCharacterStream();            InputStream in = source.getByteStream();                                    parser.doParse(source.getSystemId(),                           source.getPublicId(),                           r,                           in,                           source.getEncoding());          }        catch (SAXException e)          {            throw e;          }        catch (IOException e)          {            throw e;          }        catch (RuntimeException e)          {            throw e;          }        catch (Exception e)          {            throw new SAXParseException(e.getMessage(), this, e);          }        finally          {            contentHandler.endDocument();            reset();          }      }  }  /**   * <b>SAX1, SAX2</b>: Preferred API to parse an XML document, using a   * system identifier (URI).   */  public void parse(String systemId)    throws SAXException, IOException  {    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/";  /**   * <b>SAX2</b>: Tells the value of the specified feature flag.   *   * @exception SAXNotRecognizedException thrown if the feature flag   *  is neither built in, nor yet assigned.   */  public boolean getFeature(String featureId)    throws SAXNotRecognizedException, SAXNotSupportedException  {    if ((FEATURE + "validation").equals(featureId))      {        return false;      }    // external entities (both types) are optionally included    if ((FEATURE + "external-general-entities").equals(featureId))      {        return extGE;      }    if ((FEATURE + "external-parameter-entities").equals(featureId))      {        return extPE;      }        // element/attribute names are as written in document; no mangling    if ((FEATURE + "namespace-prefixes").equals(featureId))      {        return xmlNames;      }    // report element/attribute namespaces?    if ((FEATURE + "namespaces").equals(featureId))      {        return namespaces;      }    // all PEs and GEs are reported    if ((FEATURE + "lexical-handler/parameter-entities").equals(featureId))      {        return true;      }    // default is true    if ((FEATURE + "string-interning").equals(featureId))      {        return stringInterning;      }      // EXTENSIONS 1.1        // always returns isSpecified info    if ((FEATURE + "use-attributes2").equals(featureId))      {        return true;      }      // meaningful between startDocument/endDocument    if ((FEATURE + "is-standalone").equals(featureId))      {        if (parser == null)          {            throw new SAXNotSupportedException(featureId);          }        return parser.isStandalone();      }    // optionally don't absolutize URIs in declarations    if ((FEATURE + "resolve-dtd-uris").equals(featureId))      {        return resolveAll;      }    // optionally use resolver2 interface methods, if possible    if ((FEATURE + "use-entity-resolver2").equals(featureId))      {        return useResolver2;      }      throw new SAXNotRecognizedException(featureId);  }  // package private  DeclHandler getDeclHandler()  {    return declHandler;  }  // package private  boolean resolveURIs()  {    return resolveAll;  }  /**   * <b>SAX2</b>:  Returns the specified property.   *   * @exception SAXNotRecognizedException thrown if the property value   *  is neither built in, nor yet stored.   */  public Object getProperty(String propertyId)    throws SAXNotRecognizedException  {    if ((PROPERTY + "declaration-handler").equals(propertyId))      {        return (declHandler == base) ? null : declHandler;      }    if ((PROPERTY + "lexical-handler").equals(propertyId))      {        return (lexicalHandler == base) ? null : lexicalHandler;      }        // unknown properties    throw new SAXNotRecognizedException(propertyId);  }  /**   * <b>SAX2</b>:  Sets the state of feature flags in this parser.  Some   * built-in feature flags are mutable.   */  public void setFeature(String featureId, boolean value)    throws SAXNotRecognizedException, SAXNotSupportedException  {    boolean state;      // Features with a defined value, we just change it if we can.    state = getFeature (featureId);        if (state == value)      {        return;      }    if (parser != null)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -