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

📄 saxparser.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      {        SAXParseException e2 = new SAXParseException(e.getMessage(), this);        e2.initCause(e);        try          {            if (!startDocumentDone && contentHandler != null)              contentHandler.startDocument();            if (errorHandler != null)              errorHandler.fatalError(e2);            if (contentHandler != null)              contentHandler.endDocument();          }        catch (SAXException sex)          {            // Ignored, we will rethrow the original exception.          }        reset();        if (opened)          in.close();        if (e instanceof SAXException)          throw (SAXException) e;        if (e instanceof IOException)          throw (IOException) e;        else          throw e2;      }  }  /**   * Indicates whether the specified characters are ignorable whitespace.   */  private boolean isIgnorableWhitespace(XMLParser reader, char[] b,                                        boolean testCharacters)    throws XMLStreamException  {    XMLParser.Doctype doctype = reader.doctype;    if (doctype == null)      return false;    String currentElement = reader.getCurrentElement();    // check for xml:space    int ac = reader.getAttributeCount();    for (int i = 0; i < ac; i++)      {        QName aname = reader.getAttributeName(i);        if ("space".equals(aname.getLocalPart()) &&            XMLConstants.XML_NS_URI.equals(aname.getNamespaceURI()))          {            if ("preserve".equals(reader.getAttributeValue(i)))              return false;          }      }    XMLParser.ContentModel model = doctype.getElementModel(currentElement);    if (model == null || model.type != XMLParser.ContentModel.ELEMENT)      return false;    if (model.external && xmlStandalone)      return false;    boolean white = true;    if (testCharacters)      {        for (int i = 0; i < b.length; i++)          {            if (b[i] != ' ' && b[i] != '\t' && b[i] != '\n' && b[i] != '\r')              {                white = false;                break;              }          }      }    return white;  }  public void parse(String systemId)    throws IOException, SAXException  {    parse(new InputSource(systemId));  }  // -- Attributes2 --  public int getIndex(String qName)  {    int len = reader.getAttributeCount();    for (int i = 0; i < len; i++)      {        QName q = reader.getAttributeName(i);        String localName = q.getLocalPart();        String prefix = q.getPrefix();        String qn = ("".equals(prefix)) ? localName : prefix + ":" + localName;        if (qName.equals(qn))          return i;      }    return -1;  }  public int getIndex(String uri, String localName)  {    int len = reader.getAttributeCount();    for (int i = 0; i < len; i++)      {        QName q = reader.getAttributeName(i);        String ln = q.getLocalPart();        String u = q.getNamespaceURI();        if (u == null && uri != null)          continue;        if (u != null && !u.equals(uri))          continue;        if (ln.equals(localName))          return i;      }    return -1;  }  public int getLength()  {    return reader.getAttributeCount();  }  public String getLocalName(int index)  {    return reader.getAttributeLocalName(index);  }  public String getQName(int index)  {    QName q = reader.getAttributeName(index);    String localName = q.getLocalPart();    String prefix = q.getPrefix();    return ("".equals(prefix)) ? localName : prefix + ":" + localName;  }  public String getType(int index)  {    String ret = reader.getAttributeType(index);    // SAX doesn't permit ENUMERATION?    return ("ENUMERATION".equals(ret)) ? "NMTOKEN" : ret;  }  public String getType(String qName)  {    int index = getIndex(qName);    return (index == -1) ? null : getType(index);  }  public String getType(String uri, String localName)  {    int index = getIndex(uri, localName);    return (index == -1) ? null : getType(index);  }  public String getURI(int index)  {    String ret = reader.getAttributeNamespace(index);    return (ret == null) ? "" : ret;  }  public String getValue(int index)  {    return reader.getAttributeValue(index);  }  public String getValue(String qName)  {    int index = getIndex(qName);    return (index == -1) ? null : getValue(index);  }  public String getValue(String uri, String localName)  {    int index = getIndex(uri, localName);    return (index == -1) ? null : getValue(index);  }  public boolean isDeclared(int index)  {    return parser.isAttributeDeclared(index);  }  public boolean isDeclared(String qName)  {    int index = getIndex(qName);    return (index == -1) ? false : isDeclared(index);  }  public boolean isDeclared(String uri, String localName)  {    int index = getIndex(uri, localName);    return (index == -1) ? false : isDeclared(index);  }  public boolean isSpecified(int index)  {    return reader.isAttributeSpecified(index);  }  public boolean isSpecified(String qName)  {    int index = getIndex(qName);    return (index == -1) ? false : isSpecified(index);  }  public boolean isSpecified(String uri, String localName)  {    int index = getIndex(uri, localName);    return (index == -1) ? false : isSpecified(index);  }  // -- Locator2 --    public int getColumnNumber()  {    Location l = reader.getLocation();    return l.getColumnNumber();  }  public int getLineNumber()  {    Location l = reader.getLocation();    return l.getLineNumber();  }  public String getPublicId()  {    Location l = reader.getLocation();    return l.getPublicId();  }  public String getSystemId()  {    Location l = reader.getLocation();    return l.getSystemId();  }    public String getEncoding()  {    return encoding;  }  public String getXMLVersion()  {    return xmlVersion;  }  // -- XMLResolver --    public Object resolveEntity(String publicId, String systemId,                              String baseURI, String namespace)    throws XMLStreamException  {    if (entityResolver != null)      {        try          {            InputSource input =              entityResolver.resolveEntity(publicId, systemId);            if (input != null)              {                InputStream in = input.getByteStream();                if (in == null)                  {                    String newSystemId = input.getSystemId();                    if (newSystemId != null && !newSystemId.equals(systemId))                      in = XMLParser.resolve(newSystemId);                  }                return in;              }          }        catch (SAXException e)          {            XMLStreamException e2 = new XMLStreamException(e.getMessage());            e2.initCause(e);            throw e2;          }        catch (IOException e)          {            XMLStreamException e2 = new XMLStreamException(e.getMessage());            e2.initCause(e);            throw e2;          }      }    return null;  }  public XMLEventReader resolveAsXMLEventReader(String uri)    throws XMLStreamException  {    // unused    return null;  }  public XMLStreamReader resolveAsXMLStreamReader(String uri)    throws XMLStreamException  {    // unused    return null;  }  // -- XMLReporter --  public void report(String message, String errorType,                     Object relatedInformation, Location location)    throws XMLStreamException  {    if (errorHandler != null)      {        try          {            errorHandler.warning(new SAXParseException(message, this));          }        catch (SAXException e)          {            XMLStreamException e2 = new XMLStreamException(e.getMessage());            e2.initCause(e);            throw e2;          }      }  }  public static void main(String[] args)    throws Exception  {    SAXParser parser = new SAXParser();    InputSource input = new InputSource(args[0]);    parser.parse(input, new org.xml.sax.helpers.DefaultHandler());      }  }

⌨️ 快捷键说明

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