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

📄 saxdriver.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        // in this implementation, this only affects xmlns reporting        xmlNames = state;        return;        }        if ((FEATURE + "namespaces").equals (featureId)) {        // XXX if not currently parsing ...        if (true) {            namespaces = state;            return;        }        // if in mid-parse, critical info hasn't been computed/saved        }        // can't change builtins        if (features == null || !features.containsKey (featureId))        throw new SAXNotSupportedException (featureId);    } catch (SAXNotRecognizedException e) {        // as-yet unknown features        if (features == null)        features = new HashMap (5);    }    // record first value, or modify existing one    features.put (featureId,         state        ? Boolean.TRUE        : Boolean.FALSE);    }    /**     * <b>SAX2</b>:  Assigns the specified property.  Like SAX1 handlers,     * these may be changed at any time.     */    public void setProperty (String propertyId, Object property)    throws SAXNotRecognizedException, SAXNotSupportedException    {    Object  value;        try {        // Properties with a defined value, we just change it if we can.        value = getProperty (propertyId);        if ((HANDLER + "declaration-handler").equals (propertyId)) {            if (property == null)                declHandler = base;            else if (! (property instanceof DeclHandler))                throw new SAXNotSupportedException (propertyId);            else                declHandler = (DeclHandler) property;            return ;        }        if ((HANDLER + "lexical-handler").equals (propertyId)) {            if (property == null)                lexicalHandler = base;            else if (! (property instanceof LexicalHandler))                throw new SAXNotSupportedException (propertyId);            else                lexicalHandler = (LexicalHandler) property;            return ;        }        // can't change builtins        if (properties == null || !properties.containsKey (propertyId))        throw new SAXNotSupportedException (propertyId);    } catch (SAXNotRecognizedException e) {        // as-yet unknown properties        if (properties == null)        properties = new HashMap (5);    }    // record first value, or modify existing one    properties.put (propertyId, property);    }    //    // This is where the driver receives AElfred callbacks and translates    // them into SAX callbacks.  Some more callbacks have been added for    // SAX2 support.    //    // NOTE:  in some cases, local copies of handlers are    // created and used, to work around codegen bugs in at    // least one snapshot version of GCJ.    void startDocument () throws SAXException    {        contentHandler.setDocumentLocator (this);        contentHandler.startDocument ();        attributeNames.clear ();        attributeValues.clear ();    }    void endDocument () throws SAXException    {        // SAX says endDocument _must_ be called (handy to close        // files etc) so it's in a "finally" clause    }    Object resolveEntity (String publicId, String systemId)    throws SAXException, IOException    {        InputSource source = entityResolver.resolveEntity (publicId,                     systemId);        if (source == null) {            return null;        } else if (source.getCharacterStream () != null) {            return source.getCharacterStream ();        } else if (source.getByteStream () != null) {            if (source.getEncoding () == null)            return source.getByteStream ();            else try {            return new InputStreamReader (                source.getByteStream (),                source.getEncoding ()                );            } catch (IOException e) {            return source.getByteStream ();            }        } else {            return source.getSystemId ();        }        // XXX no way to tell AElfred about new public        // or system ids ... so relative URL resolution        // through that entity could be less than reliable.    }    void startExternalEntity (String systemId)    throws SAXException    {        entityStack.add (systemId);    }    void endExternalEntity (String systemId)    throws SAXException    {        entityStack.remove ( entityStack.size() - 1 );    }    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 beta doesn't).        // the IDs for the external subset are lexical details,        // as are the contents of the internal subset; but sax2        // beta only provides the external subset "pre-parse"    }    void endDoctype () throws SAXException    {        // NOTE:  some apps may care that comments and PIs,        // are stripped from their DTD declaration context,        // and that those declarations are themselves quite        // thoroughly reordered here.        deliverDTDEvents ();        lexicalHandler.endDTD ();    }    void attribute (String aname, String value, boolean isSpecified)    throws SAXException    {        if (attributeCount++ == 0) {            if (namespaces)                prefixStack.pushContext ();        }        // set nsTemp [0] == namespace URI (or empty)        // set nsTemp [1] == local name (or empty)        if (value != null) {            if (namespaces) {                int index = aname.indexOf (':');                // prefixed name?                if (index > 0) {                    // prefix declaration?                    if (index == 5 && aname.startsWith ("xmlns")) {                        String      prefix = aname.substring (index + 1);                        if (value.length () == 0) {                            errorHandler.error (new SAXParseException (                                "missing URI in namespace decl attribute: "                                + aname,                                this));                        } else {                            prefixStack.declarePrefix (prefix, value);                            contentHandler.startPrefixMapping (prefix, value);                        }                        if (!xmlNames)                            return;                        nsTemp [0] = "";                        nsTemp [1] = aname;                    // prefix reference                    } else {                        if (prefixStack.processName (aname, nsTemp, true)                            == null) {                            // start of MHK code                                nsTemp[0] = "";                                nsTemp[1] = aname;    // defer checking till later                                nspending = true;                            // end of MHK code                            // start of previous code                                // errorHandler.error (new SAXParseException (                            //    "undeclared name prefix in: " + aname,                            //    this));                            // nsTemp [0] = nsTemp [1] = "";                            // end of previous code                            } // else nsTemp [0, 1] received { uri, local }                    }                // no prefix                } else {                    // default declaration?                    if ("xmlns".equals (aname)) {                    prefixStack.declarePrefix ("", value);                    contentHandler.startPrefixMapping ("", value);                    if (!xmlNames)                        return;                    }                    nsTemp [0] = "";                    nsTemp [1] = aname;                }            } else                nsTemp [0] = nsTemp [1] = "";            attributeNamespaces.add (nsTemp [0]);            attributeLocalNames.add (nsTemp [1]);            attributeNames.add (aname);            // attribute type comes from querying parser's DTD records            attributeValues.add (value);        }    }    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.)        //        // 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 (attributeCount == 0)            prefixStack.pushContext ();        // save element name so attribute callbacks work        elementName = elname;        if (namespaces) {            // START MHK CODE            // Check that namespace prefixes for attributes are valid            if (attributeCount > 0 && nspending) {                for (int i=0; i<attributeLocalNames.size(); i++) {                    String aname = (String)attributeLocalNames.get(i);                    if (aname.indexOf(':')>0) {                        if (prefixStack.processName (aname, nsTemp, true) == null) {                            errorHandler.error (new SAXParseException (                                "undeclared name prefix in: " + aname,                                this));                        } else {                            attributeNamespaces.set(i, nsTemp[0]);                            attributeLocalNames.set(i, nsTemp[1]);                        }                    }                }            }            // END MHK CODE            if (prefixStack.processName (elname, nsTemp, false) == null) {            errorHandler.error (new SAXParseException (                "undeclared name prefix in: " + elname,                this));            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 (attributeCount != 0) {            attributeNames.clear ();            attributeNamespaces.clear ();            attributeLocalNames.clear ();            attributeValues.clear ();            attributeCount = 0;        }        nspending = false;    }    void endElement (String elname)    throws SAXException    {        ContentHandler  handler = contentHandler;        handler.endElement ("", "", elname);        if (!namespaces)            return;        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    {        // XXX if within DTD, perhaps it's best to discard        // PIs since the decls to which they (usually)        // apply get significantly rearranged        contentHandler.processingInstruction (target, data);    }    void comment (char ch[], int start, int length)    throws SAXException    {        // XXX if within DTD, perhaps it's best to discard        // comments since the decls to which they (usually)        // apply get significantly rearranged        if (lexicalHandler != base)            lexicalHandler.comment (ch, start, length);    }        // AElfred only has fatal errors        void error (String message, String url, int line, int column)        throws SAXException        {        SAXParseException fatal;            fatal = new SAXParseException (message, null, url, line, column);        errorHandler.fatalError (fatal);        // Even if the application can continue ... we can't!        throw fatal;    }    //    // Before the endDtd event, deliver all non-PE declarations.    //    private void deliverDTDEvents ()    throws SAXException    {    String  ename;    String  nname;    String publicId;    String  systemId;    // First, report all notations.    if (dtdHandler != base) {        Iterator    notationNames = parser.declaredNotations ();        while (notationNames.hasNext ()) {        nname = (String) notationNames.next ();        publicId = parser.getNotationPublicId (nname);        systemId = parser.getNotationSystemId (nname);        dtdHandler.notationDecl (nname, publicId, systemId);        }    }    // Next, report all entities.    if (dtdHandler != base || declHandler != base) {        Iterator    entityNames = parser.declaredEntities ();        int type;        while (entityNames.hasNext ()) {        ename = (String) entityNames.next ();        type = parser.getEntityType (ename);        if (ename.charAt (0) == '%')

⌨️ 快捷键说明

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