abstractsaxparser.java

来自「JAVA 所有包」· Java 代码 · 共 1,706 行 · 第 1/5 页

JAVA
1,706
字号
            fDeclaredAttrs = new SymbolHash();        }    } // doctypeDecl(String,String,String)        /**     * This method notifies of the start of an entity. The DTD has the     * pseudo-name of "[dtd]" parameter entity names start with '%'; and     * general entity names are just the entity name.     * <p>     * <strong>Note:</strong> Since the document is an entity, the handler     * will be notified of the start of the document entity by calling the     * startEntity method with the entity name "[xml]" <em>before</em> calling     * the startDocument method. When exposing entity boundaries through the     * SAX API, the document entity is never reported, however.     * <p>     * <strong>Note:</strong> This method is not called for entity references     * appearing as part of attribute values.     *     * @param name     The name of the entity.     * @param identifier The resource identifier.     * @param encoding The auto-detected IANA encoding name of the entity     *                 stream. This value will be null in those situations     *                 where the entity encoding is not auto-detected (e.g.     *                 internal parameter entities).     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startGeneralEntity(String name, XMLResourceIdentifier identifier,                                    String encoding, Augmentations augs)        throws XNIException {                try {            // Only report startEntity if this entity was actually read.            if (augs != null && Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) {                // report skipped entity to content handler                if (fContentHandler != null) {                    fContentHandler.skippedEntity(name);                }            }            else {                // SAX2 extension                if (fLexicalHandler != null) {                    fLexicalHandler.startEntity(name);                }            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // startGeneralEntity(String,String,String,String,String)    /**     * This method notifies the end of an entity. The DTD has the pseudo-name     * of "[dtd]" parameter entity names start with '%'; and general entity     * names are just the entity name.     * <p>     * <strong>Note:</strong> Since the document is an entity, the handler     * will be notified of the end of the document entity by calling the     * endEntity method with the entity name "[xml]" <em>after</em> calling     * the endDocument method. When exposing entity boundaries through the     * SAX API, the document entity is never reported, however.     * <p>     * <strong>Note:</strong> This method is not called for entity references     * appearing as part of attribute values.     *     * @param name The name of the entity.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endGeneralEntity(String name, Augmentations augs) throws XNIException {        try {            // Only report endEntity if this entity was actually read.            if (augs == null || !Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) {                // SAX2 extension                if (fLexicalHandler != null) {                    fLexicalHandler.endEntity(name);                }            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // endEntity(String)     /**     * The start of an element. If the document specifies the start element     * by using an empty tag, then the startElement method will immediately     * be followed by the endElement method, with no intervening methods.     *     * @param element    The name of the element.     * @param attributes The element attributes.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startElement(QName element, XMLAttributes attributes, Augmentations augs)        throws XNIException {        try {            // SAX1            if (fDocumentHandler != null) {                // REVISIT: should we support schema-normalized-value for SAX1 events                //                 fAttributesProxy.setAttributes(attributes);                fDocumentHandler.startElement(element.rawname, fAttributesProxy);            }            // SAX2            if (fContentHandler != null) {                                                if (fNamespaces) {                    // send prefix mapping events                    startNamespaceMapping();                    // REVISIT: It should not be necessary to iterate over the attribute                    // list when the set of [namespace attributes] is empty for this                    // element. This should be computable from the NamespaceContext, but                    // since we currently don't report the mappings for the xml prefix                    // we cannot use the declared prefix count for the current context                    // to skip this section. -- mrglavas                    int len = attributes.getLength();                    if (!fNamespacePrefixes) {                        for (int i = len - 1; i >= 0; --i) {                            attributes.getName(i, fQName);                                if ((fQName.prefix == XMLSymbols.PREFIX_XMLNS) ||                                (fQName.rawname == XMLSymbols.PREFIX_XMLNS)) {                                // remove namespace declaration attributes                                attributes.removeAttributeAt(i);                            }                        }                    }                    else if (!fXMLNSURIs) {                        for (int i = len - 1; i >= 0; --i) {                            attributes.getName(i, fQName);                                if ((fQName.prefix == XMLSymbols.PREFIX_XMLNS) ||                                (fQName.rawname == XMLSymbols.PREFIX_XMLNS)) {                                // localpart should be empty string as per SAX documentation:                                // http://www.saxproject.org/?selected=namespaces                                fQName.prefix = "";                                fQName.uri = "";                                fQName.localpart = "";                                attributes.setName(i, fQName);                            }                        }                    }                }                                fAugmentations = augs;                                String uri = element.uri != null ? element.uri : "";                String localpart = fNamespaces ? element.localpart : "";                fAttributesProxy.setAttributes(attributes);                fContentHandler.startElement(uri, localpart, element.rawname,                                             fAttributesProxy);            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // startElement(QName,XMLAttributes)    /**     * Character content.     *     * @param text The content.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void characters(XMLString text, Augmentations augs) throws XNIException {                // if type is union (XML Schema) it is possible that we receive        // character call with empty data        if (text.length == 0) {            return;        }        try {            // SAX1            if (fDocumentHandler != null) {                // REVISIT: should we support schema-normalized-value for SAX1 events                //                 fDocumentHandler.characters(text.ch, text.offset, text.length);            }            // SAX2            if (fContentHandler != null) {                fContentHandler.characters(text.ch, text.offset, text.length);            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // characters(XMLString)    /**     * Ignorable whitespace. For this method to be called, the document     * source must have some way of determining that the text containing     * only whitespace characters should be considered ignorable. For     * example, the validator can determine if a length of whitespace     * characters in the document are ignorable based on the element     * content model.     *     * @param text The ignorable whitespace.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {        try {            // SAX1            if (fDocumentHandler != null) {                fDocumentHandler.ignorableWhitespace(text.ch, text.offset, text.length);            }            // SAX2            if (fContentHandler != null) {                fContentHandler.ignorableWhitespace(text.ch, text.offset, text.length);            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // ignorableWhitespace(XMLString)    /**     * The end of an element.     *     * @param element The name of the element.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endElement(QName element, Augmentations augs) throws XNIException {                try {            // SAX1            if (fDocumentHandler != null) {                fDocumentHandler.endElement(element.rawname);            }            // SAX2            if (fContentHandler != null) {                fAugmentations = augs;                String uri = element.uri != null ? element.uri : "";                String localpart = fNamespaces ? element.localpart : "";                fContentHandler.endElement(uri, localpart,                                           element.rawname);                if (fNamespaces) {                    endNamespaceMapping();                }             }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // endElement(QName)        /**     * The start of a CDATA section.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startCDATA(Augmentations augs) throws XNIException {        try {            // SAX2 extension            if (fLexicalHandler != null) {                fLexicalHandler.startCDATA();            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // startCDATA()    /**     * The end of a CDATA section.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endCDATA(Augmentations augs) throws XNIException {        try {            // SAX2 extension            if (fLexicalHandler != null) {                fLexicalHandler.endCDATA();            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // endCDATA()    /**     * A comment.     *     * @param text The text in the comment.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by application to signal an error.     */    public void comment(XMLString text, Augmentations augs) throws XNIException {        try {            // SAX2 extension            if (fLexicalHandler != null) {                fLexicalHandler.comment(text.ch, 0, text.length);            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // comment(XMLString)    /**     * A processing instruction. Processing instructions consist of a     * target name and, optionally, text data. The data is only meaningful     * to the application.     * <p>     * Typically, a processing instruction's data will contain a series     * of pseudo-attributes. These pseudo-attributes follow the form of     * element attributes but are <strong>not</strong> parsed or presented     * to the application as anything other than text. The application is

⌨️ 快捷键说明

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