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

📄 saxdriver.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    if (state == value)      {        return;      }    if (parser != null)      {        throw new SAXNotSupportedException("not while parsing");      }    if ((FEATURE + "namespace-prefixes").equals(featureId))      {        // in this implementation, this only affects xmlns reporting        xmlNames = value;        // forcibly prevent illegal parser state        if (!xmlNames)          {            namespaces = true;          }        return;      }    if ((FEATURE + "namespaces").equals(featureId))      {        namespaces = value;        // forcibly prevent illegal parser state        if (!namespaces)          {            xmlNames = true;          }        return;      }    if ((FEATURE + "external-general-entities").equals(featureId))      {        extGE = value;        return;      }    if ((FEATURE + "external-parameter-entities").equals(featureId))      {        extPE = value;        return;      }    if ((FEATURE + "resolve-dtd-uris").equals(featureId))      {        resolveAll = value;        return;      }    if ((FEATURE + "use-entity-resolver2").equals(featureId))      {        useResolver2 = value;        return;      }    throw new SAXNotRecognizedException(featureId);  }  /**   * <b>SAX2</b>:  Assigns the specified property.  Like SAX1 handlers,   * these may be changed at any time.   */  public void setProperty(String propertyId, Object value)    throws SAXNotRecognizedException, SAXNotSupportedException  {    // see if the property is recognized    getProperty(propertyId);        // Properties with a defined value, we just change it if we can.        if ((PROPERTY + "declaration-handler").equals(propertyId))      {        if (value == null)          {            declHandler = base;          }        else if (!(value instanceof DeclHandler))          {            throw new SAXNotSupportedException(propertyId);          }        else          {            declHandler = (DeclHandler) value;          }        return ;      }        if ((PROPERTY + "lexical-handler").equals(propertyId))      {        if (value == null)          {            lexicalHandler = base;          }        else if (!(value instanceof LexicalHandler))          {            throw new SAXNotSupportedException(propertyId);          }        else          {            lexicalHandler = (LexicalHandler) value;          }        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  {    contentHandler.setDocumentLocator(this);    contentHandler.startDocument();    attributesList.clear();  }  void skippedEntity(String name)    throws SAXException  {    contentHandler.skippedEntity(name);  }  InputSource getExternalSubset(String name, String baseURI)    throws SAXException, IOException  {    if (resolver2 == null || !useResolver2 || !extPE)      {        return null;      }    return resolver2.getExternalSubset(name, baseURI);  }  InputSource resolveEntity(boolean isPE, String name,                            InputSource in, String baseURI)    throws SAXException, IOException  {    InputSource  source;        // external entities might be skipped    if (isPE && !extPE)      {        return null;      }    if (!isPE && !extGE)      {        return null;      }    // ... or not    lexicalHandler.startEntity(name);    if (resolver2 != null && useResolver2)      {        source = resolver2.resolveEntity(name, in.getPublicId(),                                         baseURI, in.getSystemId());        if (source == null)          {            in.setSystemId(absolutize(baseURI,                                      in.getSystemId(), false));            source = in;          }      }    else      {        in.setSystemId(absolutize(baseURI,                                  in.getSystemId(),                                  entityResolver != base));        source = entityResolver.resolveEntity(in.getPublicId(),                                              in.getSystemId());        if (source == null)          {            source = in;          }      }    startExternalEntity(name, source.getSystemId(), true);    return source;  }  // absolutize a system ID relative to the specified base URI  // (temporarily) package-visible for external entity decls  String absolutize(String baseURI, String systemId, boolean nice)    throws MalformedURLException, SAXException  {    // FIXME normalize system IDs -- when?    // - Convert to UTF-8    // - Map reserved and non-ASCII characters to %HH        try      {        if (baseURI == null)          {            if (XmlParser.uriWarnings)              {                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 name, String systemId, boolean 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      {        lexicalHandler.startEntity(name);      }    entityStack.push(systemId);  }  void endExternalEntity(String name)    throws SAXException  {    if (!"[document]".equals(name))      {        lexicalHandler.endEntity(name);      }    entityStack.pop();  }  void startInternalEntity(String name)    throws SAXException  {    lexicalHandler.startEntity(name);  }  void endInternalEntity(String name)    throws SAXException  {    lexicalHandler.endEntity(name);  }  void doctypeDecl(String name, String publicId, String systemId)    throws SAXException  {    lexicalHandler.startDTD(name, publicId, systemId);      // ... 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 name, String publicId, String systemId,                    String baseUri)    throws SAXException  {    try      {        dtdHandler.notationDecl(name, publicId,                                (resolveAll && systemId != null)                                ? absolutize(baseUri, systemId, true)                                : systemId);      }    catch (IOException e)      {        // "can't happen"        throw new SAXParseException(e.getMessage(), this, e);      }  }  void unparsedEntityDecl(String name, String publicId, String systemId,                          String baseUri, String notation)    throws SAXException  {    try      {        dtdHandler.unparsedEntityDecl(name, publicId,                                      resolveAll                                      ? absolutize(baseUri, systemId, true)                                      : systemId,                                      notation);      }    catch (IOException e)      {        // "can't happen"        throw new SAXParseException(e.getMessage(), this, e);      }  }  void endDoctype()    throws SAXException  {    lexicalHandler.endDTD();  }  private void declarePrefix(String prefix, String uri)    throws SAXException  {    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);      }    // FIXME:  char [0] must be ascii alpha; chars [1..index]    // must be ascii alphanumeric or in "+-." [RFC 2396]        //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();    prefixStack.declarePrefix(prefix, uri);    contentHandler.startPrefixMapping(prefix, uri);  }  void attribute(String qname, String value, boolean isSpecified)    throws SAXException  {    if (!attributes)      {        attributes = true;        if (namespaces)          {            prefixStack.pushContext();          }      }        // process namespace decls immediately;    // then maybe forget this as an attribute    if (namespaces)      {        int index;                // default NS declaration?        if (stringInterning)          {            if ("xmlns" == qname)              {                declarePrefix("", value);                if (!xmlNames)                  {                    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(prefix, value);                  }                if (!xmlNames)                  {                    return;                  }              }          }        else          {            if ("xmlns".equals(qname))              {                declarePrefix("", value);                if (!xmlNames)                  {                    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(prefix, value);                  }                if (!xmlNames)                  {                    return;                  }              }          }      }    // remember this attribute ...    attributeCount++;        // attribute type comes from querying parser's DTD records    attributesList.add(new Attribute(qname, value, isSpecified));      }    void startElement(String elname)    throws SAXException  {    ContentHandler handler = contentHandler;    //    // 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 (!attributes)      {        if (namespaces)          {            prefixStack.pushContext();          }      }    else if (namespaces)      {              // now we can patch up namespace refs; we saw all the        // declarations, so now we'll do the Right Thing        Iterator itt = attributesList.iterator();        while (itt.hasNext())          {            Attribute attribute = (Attribute) itt.next();            String qname = attribute.name;            int index;                        // default NS declaration?            if (stringInterning)              {                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 (prefixStack.processName(qname, nsTemp, true) == null)              {                fatal("undeclared attribute prefix in: " + qname);              }            else

⌨️ 快捷键说明

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