abstractsaxparser.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,695 行 · 第 1/5 页

JAVA
1,695
字号
    public void xmlDecl(String version, String encoding, String standalone, Augmentations augs)    throws XNIException {                // the version need only be set once; if        // document's XML 1.0|1.1, that's how it'll stay        fVersion = version;        if(standalone != null && standalone.equalsIgnoreCase("yes"))            isStandalone = true;        else            isStandalone = false;    } // xmlDecl(String,String,String)        /**     * Notifies of the presence of the DOCTYPE line in the document.     *     * @param rootElement The name of the root element.     * @param publicId    The public identifier if an external DTD or null     *                    if the external DTD is specified using SYSTEM.     * @param systemId    The system identifier if an external DTD, null     *                    otherwise.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void doctypeDecl(String rootElement,    String publicId, String systemId, Augmentations augs)    throws XNIException {        fInDTD = true;                try {            // SAX2 extension            if (fLexicalHandler != null) {                fLexicalHandler.startDTD(rootElement, publicId, systemId);            }        }        catch (SAXException e) {            throw new XNIException(e);        }                // is there a DeclHandler?        if(fDeclHandler != null) {            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();                    for (int i = len - 1; i >= 0; --i) {                        attributes.getName(i, fQName);                        if ((fQName.prefix == XMLSymbols.PREFIX_XMLNS) ||                        (fQName.rawname == XMLSymbols.PREFIX_XMLNS)) {                            if (!fNamespacePrefixes) {                                // remove namespace declaration attributes                                attributes.removeAttributeAt(i);                            }                            else {                                // 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();            }

⌨️ 快捷键说明

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