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

📄 saxdriver.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
              {                attribute.nameSpace = nsTemp[0];                attribute.localName = nsTemp[1];              }          }      }        // save element name so attribute callbacks work    elementName = elname;    if (namespaces)      {        if (prefixStack.processName(elname, nsTemp, false) == null)          {            fatal("undeclared element prefix in: " + elname);            nsTemp[0] = nsTemp[1] = "";          }        handler.startElement(nsTemp[0], nsTemp[1], elname, this);      }    else      {        handler.startElement("", "", elname, this);      }    // elementName = null;        // elements with no attributes are pretty common!    if (attributes)      {        attributesList.clear();        attributeCount = 0;        attributes = false;      }  }    void endElement(String elname)    throws SAXException  {    ContentHandler handler = contentHandler;    if (!namespaces)      {        handler.endElement("", "", elname);        return;      }    prefixStack.processName(elname, nsTemp, false);    handler.endElement(nsTemp[0], nsTemp[1], elname);        Enumeration prefixes = prefixStack.getDeclaredPrefixes();        while (prefixes.hasMoreElements())      {        handler.endPrefixMapping((String) prefixes.nextElement());      }    prefixStack.popContext();  }  void startCDATA()    throws SAXException  {    lexicalHandler.startCDATA();  }  void charData(char[] ch, int start, int length)    throws SAXException  {    contentHandler.characters(ch, start, length);  }  void endCDATA()    throws SAXException  {    lexicalHandler.endCDATA();  }  void ignorableWhitespace(char[] ch, int start, int length)    throws SAXException  {    contentHandler.ignorableWhitespace(ch, start, length);  }  void processingInstruction(String target, String data)    throws SAXException  {    contentHandler.processingInstruction(target, data);  }  void comment(char[] ch, int start, int length)    throws SAXException  {    if (lexicalHandler != base)      {        lexicalHandler.comment(ch, start, length);      }  }  void fatal(String message)    throws SAXException  {    SAXParseException fatal;      fatal = new SAXParseException(message, this);    errorHandler.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 message)    throws SAXException  {    SAXParseException err;        err = new SAXParseException(message, this);    errorHandler.error(err);  }    void warn(String message)    throws SAXException  {    SAXParseException err;      err = new SAXParseException(message, this);    errorHandler.warning(err);  }  //  // Implementation of org.xml.sax.Attributes.  //  /**   * <b>SAX1 AttributeList, SAX2 Attributes</b> method   * (don't invoke on parser);   */  public int getLength()  {    return attributesList.size();  }  /**   * <b>SAX2 Attributes</b> method (don't invoke on parser);   */  public String getURI(int index)  {    if (index < 0 || index >= attributesList.size())      {        return null;      }    return ((Attribute) attributesList.get(index)).nameSpace;  }  /**   * <b>SAX2 Attributes</b> method (don't invoke on parser);   */  public String getLocalName(int index)  {    if (index < 0 || index >= attributesList.size())      {        return null;      }    Attribute attr = (Attribute) attributesList.get(index);    // FIXME attr.localName is sometimes null, why?    if (namespaces && 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;  }  /**   * <b>SAX2 Attributes</b> method (don't invoke on parser);   */  public String getQName(int index)  {    if (index < 0 || index >= attributesList.size())      {      return null;      }    Attribute attr = (Attribute) attributesList.get(index);    return (attr.name == null) ? "" : attr.name;  }  /**   * <b>SAX1 AttributeList</b> method (don't invoke on parser);   */  public String getName(int index)  {    return getQName(index);  }  /**   * <b>SAX1 AttributeList, SAX2 Attributes</b> method   * (don't invoke on parser);   */  public String getType(int index)  {    if (index < 0 || index >= attributesList.size())      {        return null;      }    String type = parser.getAttributeType(elementName, getQName(index));    if (type == null)      {        return "CDATA";      }    // ... use DeclHandler.attributeDecl to see enumerations    if (type == "ENUMERATION")      {        return "NMTOKEN";      }    return type;  }  /**   * <b>SAX1 AttributeList, SAX2 Attributes</b> method   * (don't invoke on parser);   */  public String getValue(int index)  {    if (index < 0 || index >= attributesList.size())      {        return null;      }    return ((Attribute) attributesList.get(index)).value;  }  /**   * <b>SAX2 Attributes</b> method (don't invoke on parser);   */  public int getIndex(String uri, String local)    {      int length = getLength();            for (int i = 0; i < length; i++)        {          if (!getURI(i).equals(uri))            {              continue;            }          if (getLocalName(i).equals(local))            {              return i;            }        }      return -1;  }  /**   * <b>SAX2 Attributes</b> method (don't invoke on parser);   */  public int getIndex(String xmlName)  {    int length = getLength();        for (int i = 0; i < length; i++)      {        if (getQName(i).equals(xmlName))          {            return i;          }      }    return -1;  }  /**   * <b>SAX2 Attributes</b> method (don't invoke on parser);   */  public String getType(String uri, String local)  {    int index = getIndex(uri, local);        if (index < 0)      {        return null;      }    return getType(index);  }  /**   * <b>SAX1 AttributeList, SAX2 Attributes</b> method   * (don't invoke on parser);   */  public String getType(String xmlName)  {    int index = getIndex(xmlName);        if (index < 0)      {        return null;      }    return getType(index);  }  /**   * <b>SAX Attributes</b> method (don't invoke on parser);   */  public String getValue(String uri, String local)  {    int index = getIndex(uri, local);        if (index < 0)      {        return null;      }    return getValue(index);  }  /**   * <b>SAX1 AttributeList, SAX2 Attributes</b> 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  //  /** @return 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 >= attributeCount)      {        throw new ArrayIndexOutOfBoundsException();      }    String type = parser.getAttributeType(elementName, getQName(index));    return (type != null);  }  /** @return 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 = parser.getAttributeType(elementName, qName);    return (type != null);  }  /** @return 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 uri, String localName)  {    int index = getIndex(uri, localName);    return isDeclared(index);  }  /**   * <b>SAX-ext Attributes2</b> method (don't invoke on parser);   */  public boolean isSpecified(int index)  {    return ((Attribute) attributesList.get(index)).specified;  }  /**   * <b>SAX-ext Attributes2</b> method (don't invoke on parser);   */  public boolean isSpecified(String uri, String local)  {    int index = getIndex (uri, local);    return isSpecified(index);  }  /**   * <b>SAX-ext Attributes2</b> method (don't invoke on parser);   */  public boolean isSpecified(String xmlName)  {    int index = getIndex (xmlName);    return isSpecified(index);  }  //  // Implementation of org.xml.sax.Locator.  //  /**   * <b>SAX Locator</b> method (don't invoke on parser);   */  public String getPublicId()  {    return null;   // FIXME track public IDs too  }  /**   * <b>SAX Locator</b> method (don't invoke on parser);   */  public String getSystemId()  {    if (entityStack.empty())      {        return null;      }    else      {        return (String) entityStack.peek();      }  }  /**   * <b>SAX Locator</b> method (don't invoke on parser);   */  public int getLineNumber()  {    return parser.getLineNumber();  }  /**   * <b>SAX Locator</b> method (don't invoke on parser);   */  public int getColumnNumber()  {    return parser.getColumnNumber();  }  // adapter between SAX2 content handler and SAX1 document handler callbacks  private static class Adapter    implements ContentHandler  {        private DocumentHandler docHandler;    Adapter(DocumentHandler dh)    {      docHandler = dh;    }    public void setDocumentLocator(Locator l)    {      docHandler.setDocumentLocator(l);    }      public void startDocument()      throws SAXException    {      docHandler.startDocument();    }      public void processingInstruction(String target, String data)      throws SAXException    {      docHandler.processingInstruction(target, data);    }      public void startPrefixMapping(String prefix, String uri)    {      /* ignored */    }    public void startElement(String namespace,                             String local,                             String name,                             Attributes attrs)      throws SAXException    {      docHandler.startElement(name, (AttributeList) attrs);    }    public void characters(char[] buf, int offset, int len)      throws SAXException    {      docHandler.characters(buf, offset, len);    }    public void ignorableWhitespace(char[] buf, int offset, int len)      throws SAXException    {      docHandler.ignorableWhitespace(buf, offset, len);    }    public void skippedEntity(String name)    {      /* ignored */    }    public void endElement(String u, String l, String name)      throws SAXException    {      docHandler.endElement(name);    }    public void endPrefixMapping(String prefix)    {      /* ignored */    }    public void endDocument()      throws SAXException    {      docHandler.endDocument();    }  }  private static class Attribute  {        String name;    String value;    String nameSpace;    String localName;    boolean specified;        Attribute(String name, String value, boolean specified)    {      this.name = name;      this.value = value;      this.nameSpace = "";      this.specified = specified;    }      }}

⌨️ 快捷键说明

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