abstractsaxparser.java

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

JAVA
1,706
字号
     * responsible for parsing the data.     *     * @param target The target.     * @param data   The data or null if none specified.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void processingInstruction(String target, XMLString data, Augmentations augs)        throws XNIException {        //        // REVISIT - I keep running into SAX apps that expect        //   null data to be an empty string, which is contrary        //   to the comment for this method in the SAX API.        //        try {            // SAX1            if (fDocumentHandler != null) {                fDocumentHandler.processingInstruction(target,                                                       data.toString());            }            // SAX2            if (fContentHandler != null) {                fContentHandler.processingInstruction(target, data.toString());            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // processingInstruction(String,XMLString)    /**     * The end of the document.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endDocument(Augmentations augs) throws XNIException {        try {            // SAX1            if (fDocumentHandler != null) {                fDocumentHandler.endDocument();            }            // SAX2            if (fContentHandler != null) {                fContentHandler.endDocument();            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // endDocument()    //    // XMLDTDHandler methods    //    /**     * The start of the DTD external subset.     *     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startExternalSubset(XMLResourceIdentifier identifier,                                     Augmentations augs) throws XNIException {        startParameterEntity("[dtd]", null, null, augs);    }    /**     * The end of the DTD external subset.     *     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endExternalSubset(Augmentations augs) throws XNIException {        endParameterEntity("[dtd]", augs);    }    /**     * This method notifies of the start of parameter 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 parameter 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 startParameterEntity(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 && fLexicalHandlerParameterEntities) {                    fLexicalHandler.startEntity(name);                }            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // startParameterEntity(String,identifier,String,Augmentation)    /**     * 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 parameter entity.     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endParameterEntity(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 && fLexicalHandlerParameterEntities) {                    fLexicalHandler.endEntity(name);                }            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // endEntity(String)    /**     * An element declaration.     *     * @param name         The name of the element.     * @param contentModel The element content model.     *     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void elementDecl(String name, String contentModel, Augmentations augs)        throws XNIException {        try {            // SAX2 extension            if (fDeclHandler != null) {                fDeclHandler.elementDecl(name, contentModel);            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // elementDecl(String,String, Augmentations)    /**     * An attribute declaration.     *     * @param elementName   The name of the element that this attribute     *                      is associated with.     * @param attributeName The name of the attribute.     * @param type          The attribute type. This value will be one of     *                      the following: "CDATA", "ENTITY", "ENTITIES",     *                      "ENUMERATION", "ID", "IDREF", "IDREFS",     *                      "NMTOKEN", "NMTOKENS", or "NOTATION".     * @param enumeration   If the type has the value "ENUMERATION" or     *                      "NOTATION", this array holds the allowed attribute     *                      values; otherwise, this array is null.     * @param defaultType   The attribute default type. This value will be     *                      one of the following: "#FIXED", "#IMPLIED",     *                      "#REQUIRED", or null.     * @param defaultValue  The attribute default value, or null if no     *                      default value is specified.     *     * @param nonNormalizedDefaultValue  The attribute default value with no normalization      *                      performed, or null if no default value is specified.     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void attributeDecl(String elementName, String attributeName,                              String type, String[] enumeration,                              String defaultType, XMLString defaultValue,                              XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException {        try {            // SAX2 extension            if (fDeclHandler != null) {                // used as a key to detect duplicate attribute definitions.                String elemAttr = new StringBuffer(elementName).append("<").append(attributeName).toString();                if(fDeclaredAttrs.get(elemAttr) != null) {                    // we aren't permitted to return duplicate attribute definitions                    return;                }                fDeclaredAttrs.put(elemAttr, Boolean.TRUE);                if (type.equals("NOTATION") ||                     type.equals("ENUMERATION")) {                    StringBuffer str = new StringBuffer();                    if (type.equals("NOTATION")) {                      str.append(type);                      str.append(" (");                    }                    else {                      str.append("(");                    }                    for (int i = 0; i < enumeration.length; i++) {                        str.append(enumeration[i]);                        if (i < enumeration.length - 1) {                            str.append('|');                        }                    }                    str.append(')');                    type = str.toString();                }                String value = (defaultValue==null) ? null : defaultValue.toString();                fDeclHandler.attributeDecl(elementName, attributeName,                                           type, defaultType, value);            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // attributeDecl(String,String,String,String[],String,XMLString, XMLString, Augmentations)    /**     * An internal entity declaration.     *     * @param name The name of the entity. Parameter entity names start with     *             '%', whereas the name of a general entity is just the     *             entity name.     * @param text The value of the entity.     * @param nonNormalizedText The non-normalized value of the entity. This     *             value contains the same sequence of characters that was in     *             the internal entity declaration, without any entity     *             references expanded.     *     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void internalEntityDecl(String name, XMLString text,                                   XMLString nonNormalizedText,                                   Augmentations augs) throws XNIException {        try {            // SAX2 extensions            if (fDeclHandler != null) {                fDeclHandler.internalEntityDecl(name, text.toString());            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // internalEntityDecl(String,XMLString,XMLString)    /**     * An external entity declaration.     *     * @param name     The name of the entity. Parameter entity names start     *                 with '%', whereas the name of a general entity is just     *                 the entity name.     * @param identifier    An object containing all location information      *                      pertinent to this entity.     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void externalEntityDecl(String name, XMLResourceIdentifier identifier,                                   Augmentations augs) throws XNIException {        try {            // SAX2 extension            if (fDeclHandler != null) {                String publicId = identifier.getPublicId();                String systemId = fResolveDTDURIs ?                     identifier.getExpandedSystemId() : identifier.getLiteralSystemId();                fDeclHandler.externalEntityDecl(name, publicId, systemId);            }        }        catch (SAXException e) {            throw new XNIException(e);        }    } // externalEntityDecl(String,,XMLResourceIdentifier, Augmentations)    /**     * An unparsed entity declaration.     *

⌨️ 快捷键说明

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