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

📄 saxcontenthandler.java

📁 解决如何把XML应用到JAVA里问题
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * This method is called when a fatal error occurs during parsing. This
     * method rethrows the exception
     * 
     * @param exception
     *            DOCUMENT ME!
     * 
     * @throws SAXException
     *             DOCUMENT ME!
     */
    public void fatalError(SAXParseException exception) throws SAXException {
        throw exception;
    }

    // LexicalHandler interface
    // -------------------------------------------------------------------------
    public void startDTD(String name, String publicId, String systemId)
            throws SAXException {
        getDocument().addDocType(name, publicId, systemId);
        insideDTDSection = true;
        internalDTDsubset = true;
    }

    public void endDTD() throws SAXException {
        insideDTDSection = false;

        DocumentType docType = getDocument().getDocType();

        if (docType != null) {
            if (internalDTDDeclarations != null) {
                docType.setInternalDeclarations(internalDTDDeclarations);
            }

            if (externalDTDDeclarations != null) {
                docType.setExternalDeclarations(externalDTDDeclarations);
            }
        }

        internalDTDDeclarations = null;
        externalDTDDeclarations = null;
    }

    public void startEntity(String name) throws SAXException {
        ++entityLevel;

        // Ignore DTD references
        entity = null;

        if (!insideDTDSection) {
            if (!isIgnorableEntity(name)) {
                entity = name;
            }
        }

        // internal DTD subsets can only appear outside of a
        // startEntity/endEntity block
        // see the startDTD method in
        // http://dom4j.org/javadoc/org/xml/sax/ext/LexicalHandler.html
        internalDTDsubset = false;
    }

    public void endEntity(String name) throws SAXException {
        --entityLevel;
        entity = null;

        if (entityLevel == 0) {
            internalDTDsubset = true;
        }
    }

    public void startCDATA() throws SAXException {
        insideCDATASection = true;
        cdataText = new StringBuffer();
    }

    public void endCDATA() throws SAXException {
        insideCDATASection = false;
        currentElement.addCDATA(cdataText.toString());
    }

    public void comment(char[] ch, int start, int end) throws SAXException {
        if (!ignoreComments) {
            if (mergeAdjacentText && textInTextBuffer) {
                completeCurrentTextNode();
            }

            String text = new String(ch, start, end);

            if (!insideDTDSection && (text.length() > 0)) {
                if (currentElement != null) {
                    currentElement.addComment(text);
                } else {
                    getDocument().addComment(text);
                }
            }
        }
    }

    // DeclHandler interface
    // -------------------------------------------------------------------------

    /**
     * Report an element type declaration.
     * 
     * <p>
     * The content model will consist of the string "EMPTY", the string "ANY",
     * or a parenthesised group, optionally followed by an occurrence indicator.
     * The model will be normalized so that all parameter entities are fully
     * resolved and all whitespace is removed,and will include the enclosing
     * parentheses. Other normalization (such as removing redundant parentheses
     * or simplifying occurrence indicators) is at the discretion of the parser.
     * </p>
     * 
     * @param name
     *            The element type name.
     * @param model
     *            The content model as a normalized string.
     * 
     * @exception SAXException
     *                The application may raise an exception.
     */
    public void elementDecl(String name, String model) throws SAXException {
        if (internalDTDsubset) {
            if (includeInternalDTDDeclarations) {
                addDTDDeclaration(new ElementDecl(name, model));
            }
        } else {
            if (includeExternalDTDDeclarations) {
                addExternalDTDDeclaration(new ElementDecl(name, model));
            }
        }
    }

    /**
     * Report an attribute type declaration.
     * 
     * <p>
     * Only the effective (first) declaration for an attribute will be reported.
     * The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS",
     * "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", a parenthesized token group
     * with the separator "|" and all whitespace removed, or the word "NOTATION"
     * followed by a space followed by a parenthesized token group with all
     * whitespace removed.
     * </p>
     * 
     * <p>
     * Any parameter entities in the attribute value will be expanded, but
     * general entities will not.
     * </p>
     * 
     * @param eName
     *            The name of the associated element.
     * @param aName
     *            The name of the attribute.
     * @param type
     *            A string representing the attribute type.
     * @param valueDefault
     *            A string representing the attribute default ("#IMPLIED",
     *            "#REQUIRED", or "#FIXED") or null if none of these applies.
     * @param val
     *            A string representing the attribute's default value, or null
     *            if there is none.
     * 
     * @exception SAXException
     *                The application may raise an exception.
     */
    public void attributeDecl(String eName, String aName, String type,
            String valueDefault, String val) throws SAXException {
        if (internalDTDsubset) {
            if (includeInternalDTDDeclarations) {
                addDTDDeclaration(new AttributeDecl(eName, aName, type,
                        valueDefault, val));
            }
        } else {
            if (includeExternalDTDDeclarations) {
                addExternalDTDDeclaration(new AttributeDecl(eName, aName, type,
                        valueDefault, val));
            }
        }
    }

    /**
     * Report an internal entity declaration.
     * 
     * <p>
     * Only the effective (first) declaration for each entity will be reported.
     * All parameter entities in the value will be expanded, but general
     * entities will not.
     * </p>
     * 
     * @param name
     *            The name of the entity. If it is a parameter entity, the name
     *            will begin with '%'.
     * @param value
     *            The replacement text of the entity.
     * 
     * @exception SAXException
     *                The application may raise an exception.
     * 
     * @see #externalEntityDecl
     * @see org.xml.sax.DTDHandler#unparsedEntityDecl
     */
    public void internalEntityDecl(String name, String value)
            throws SAXException {
        if (internalDTDsubset) {
            if (includeInternalDTDDeclarations) {
                addDTDDeclaration(new InternalEntityDecl(name, value));
            }
        } else {
            if (includeExternalDTDDeclarations) {
                addExternalDTDDeclaration(new InternalEntityDecl(name, value));
            }
        }
    }

    /**
     * Report a parsed external entity declaration.
     * 
     * <p>
     * Only the effective (first) declaration for each entity will be reported.
     * </p>
     * 
     * @param name
     *            The name of the entity. If it is a parameter entity, the name
     *            will begin with '%'.
     * @param publicId
     *            The declared public identifier of the entity, or null if none
     *            was declared.
     * @param sysId
     *            The declared system identifier of the entity.
     * 
     * @exception SAXException
     *                The application may raise an exception.
     * 
     * @see #internalEntityDecl
     * @see org.xml.sax.DTDHandler#unparsedEntityDecl
     */
    public void externalEntityDecl(String name, String publicId, String sysId)
            throws SAXException {
        ExternalEntityDecl declaration = new ExternalEntityDecl(name, publicId,
                sysId);

        if (internalDTDsubset) {
            if (includeInternalDTDDeclarations) {
                addDTDDeclaration(declaration);
            }
        } else {
            if (includeExternalDTDDeclarations) {
                addExternalDTDDeclaration(declaration);
            }
        }
    }

    // DTDHandler interface
    // -------------------------------------------------------------------------

    /**
     * Receive notification of a notation declaration event.
     * 
     * <p>
     * It is up to the application to record the notation for later reference,
     * if necessary.
     * </p>
     * 
     * <p>
     * At least one of publicId and systemId must be non-null. If a system
     * identifier is present, and it is a URL, the SAX parser must resolve it
     * fully before passing it to the application through this event.
     * </p>
     * 
     * <p>
     * There is no guarantee that the notation declaration will be reported
     * before any unparsed entities that use it.
     * </p>
     * 
     * @param name
     *            The notation name.
     * @param publicId
     *            The notation's public identifier, or null if none was given.
     * @param systemId
     *            The notation's system identifier, or null if none was given.
     * 
     * @exception SAXException
     *                Any SAX exception, possibly wrapping another exception.
     * 
     * @see #unparsedEntityDecl
     * @see org.xml.sax.AttributeList
     */
    public void notationDecl(String name, String publicId, String systemId)
            throws SAXException {
        // #### not supported yet!
    }

    /**
     * Receive notification of an unparsed entity declaration event.
     * 
     * <p>
     * Note that the notation name corresponds to a notation reported by the
     * {@link #notationDecl notationDecl}event. It is up to the application to
     * record the entity for later reference, if necessary.
     * </p>
     * 
     * <p>
     * If the system identifier is a URL, the parser must resolve it fully
     * before passing it to the application.
     * </p>
     * 
     * @param name
     *            The unparsed entity's name.
     * @param publicId
     *            The entity's public identifier, or null if none was given.
     * @param systemId
     *            The entity's system identifier.
     * @param notationName
     *            The name of the associated notation.
     * 
     * @exception SAXException
     *                Any SAX exception, possibly wrapping another exception.
     * 
     * @see #notationDecl
     * @see org.xml.sax.AttributeList
     */
    public void unparsedEntityDecl(String name, String publicId,
            String systemId, String notationName) throws SAXException {
        // #### not supported yet!
    }

    // Properties
    // -------------------------------------------------------------------------
    public ElementStack getElementStack() {
        return elementStack;
    }

    public void setElementStack(ElementStack elementStack) {
        this.elementStack = elementStack;
    }

⌨️ 快捷键说明

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