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

📄 saxcontenthandler.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                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 value 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 value) throws SAXException {        if ( internalDTDsubset ) {            if ( includeInternalDTDDeclarations ) {                addDTDDeclaration( new AttributeDecl( eName, aName, type, valueDefault, value) );            }        }        else {            if ( includeExternalDTDDeclarations ) {                addExternalDTDDeclaration( new AttributeDecl( eName, aName, type, valueDefault, value) );            }        }    }    /**     * 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 systemID 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 systemID) throws SAXException {        if ( internalDTDsubset ) {            if ( includeInternalDTDDeclarations ) {                addDTDDeclaration( new ExternalEntityDecl( name, publicID, systemID ) );            }        }        else {            if ( includeExternalDTDDeclarations ) {                addExternalDTDDeclaration( new ExternalEntityDecl( name, publicID, systemID ) );            }        }    }    // 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 org.xml.sax.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>     *     * @exception org.xml.sax.SAXException Any SAX exception, possibly     *           wrapping another exception.     * @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.     * @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;    }    public EntityResolver getEntityResolver() {        return entityResolver;    }    public void setEntityResolver(EntityResolver entityResolver) {        this.entityResolver = entityResolver;    }    public InputSource getInputSource() {        return inputSource;    }    public void setInputSource(InputSource inputSource) {        this.inputSource = inputSource;    }    /** @return whether internal DTD declarations should be expanded into the DocumentType      * object or not.      */    public boolean isIncludeInternalDTDDeclarations() {        return includeInternalDTDDeclarations;    }    /** Sets whether internal DTD declarations should be expanded into the DocumentType      * object or not.      *      * @param includeInternalDTDDeclarations whether or not DTD declarations should be expanded      * and included into the DocumentType object.      */    public void setIncludeInternalDTDDeclarations(boolean includeInternalDTDDeclarations) {        this.includeInternalDTDDeclarations = includeInternalDTDDeclarations;    }    /** @return whether external DTD declarations should be expanded into the DocumentType      * object or not.      */    public boolean isIncludeExternalDTDDeclarations() {        return includeExternalDTDDeclarations;    }    /** Sets whether DTD external declarations should be expanded into the DocumentType      * object or not.      *      * @param includeExternalDTDDeclarations whether or not DTD declarations should be expanded      * and included into the DocumentType object.      */    public void setIncludeExternalDTDDeclarations(boolean includeExternalDTDDeclarations) {        this.includeExternalDTDDeclarations = includeExternalDTDDeclarations;    }    /** Returns whether adjacent text nodes should be merged together.      * @return Value of property mergeAdjacentText.      */    public boolean isMergeAdjacentText() {        return mergeAdjacentText;    }    /** Sets whether or not adjacent text nodes should be merged      * together when parsing.      * @param mergeAdjacentText New value of property mergeAdjacentText.      */    public void setMergeAdjacentText(boolean mergeAdjacentText) {        this.mergeAdjacentText = mergeAdjacentText;    }    /** Sets whether whitespace between element start and end tags should be ignored      *      * @return Value of property stripWhitespaceText.      */    public boolean isStripWhitespaceText() {        return stripWhitespaceText;    }    /** Sets whether whitespace between element start and end tags should be ignored.      *      * @param stripWhitespaceText New value of property stripWhitespaceText.      */    public void setStripWhitespaceText(boolean stripWhitespaceText) {        this.stripWhitespaceText = stripWhitespaceText;    }    /**     * Returns whether we should ignore comments or not.     * @return boolean     */    public boolean isIgnoreComments() {        return ignoreComments;    }    /**     * Sets whether we should ignore comments or not.     * @param ignoreComments whether we should ignore comments or not.     */    public void setIgnoreComments(boolean ignoreComments) {        this.ignoreComments = ignoreComments;    }    // Implementation methods    //-------------------------------------------------------------------------    /** If the current text buffer contains any text then create a new      * text node with it and add it to the current element      */    protected void completeCurrentTextNode() {        if ( stripWhitespaceText ) {            boolean whitespace = true;            for ( int i = 0, size = textBuffer.length(); i < size; i++ ) {                if ( ! Character.isWhitespace( textBuffer.charAt(i) ) ) {                    whitespace = false;                    break;                }            }            if ( ! whitespace ) {                currentElement.addText( textBuffer.toString() );            }        }        else {            currentElement.addText( textBuffer.toString() );        }        textBuffer.setLength(0);        textInTextBuffer = false;    }    /** @return the current document      */    protected Document createDocument() {        Document document = nodeFactory.createDocument();        // set the EntityResolver        document.setEntityResolver(entityResolver);        if ( inputSource != null ) {            document.setName( inputSource.getSystemId() );        }        return document;    }    /** a Strategy Method to determine if a given entity name is ignorable      */    protected boolean isIgnorableEntity(String name) {        return "amp".equals( name )            || "apos".equals( name )            || "gt".equals( name )            || "lt".equals( name )            || "quot".equals( name );    }    /** Add all namespaces declared before the startElement() SAX event      * to the current element so that they are available to child elements      * and attributes      */    protected void addDeclaredNamespaces(Element element) {        Namespace elementNamespace = element.getNamespace();        for ( int size = namespaceStack.size(); declaredNamespaceIndex < size; declaredNamespaceIndex++ ) {            AbstractNamespace namespace = namespaceStack.getNamespace(declaredNamespaceIndex);            if ( namespace != elementNamespace ) {                element.add( namespace );            }        }    }    /** Add all the attributes to the given elements      */    protected void addAttributes( Element element, Attributes attributes ) {        // XXXX: as an optimisation, we could deduce this value from the current        // SAX parser settings, the SAX namespaces-prefixes feature        boolean noNamespaceAttributes = false;        if ( element instanceof AbstractElement ) {            // optimised method            AbstractElement baseElement = (AbstractElement) element;            baseElement.setAttributes( attributes, namespaceStack, noNamespaceAttributes );        }        else {            int size = attributes.getLength();            for ( int i = 0; i < size; i++ ) {                String attributeQualifiedName = attributes.getQName(i);                if ( noNamespaceAttributes || ! attributeQualifiedName.startsWith( "xmlns" ) ) {                    String attributeURI = attributes.getURI(i);                    String attributeLocalName = attributes.getLocalName(i);                    String attributeValue = attributes.getValue(i);                    QName attributeQName = namespaceStack.getAttributeQName(                        attributeURI, attributeLocalName, attributeQualifiedName                    );                    element.addAttribute(attributeQName, attributeValue);                }            }        }    }    /** Adds an internal DTD declaration to the list of declarations */    protected void addDTDDeclaration(Object declaration) {        if ( internalDTDDeclarations == null ) {            internalDTDDeclarations = new ArrayList();        }        internalDTDDeclarations.add( declaration );    }    /** Adds an external DTD declaration to the list of declarations */    protected void addExternalDTDDeclaration(Object declaration) {        if ( externalDTDDeclarations == null ) {            externalDTDDeclarations = new ArrayList();        }        externalDTDDeclarations.add( declaration );    }    protected ElementStack createElementStack() {        return new ElementStack();    }}/* * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright *    statements and notices.  Redistributions must also contain a *    copy of this document. * * 2. Redistributions in binary form must reproduce the *    above copyright notice, this list of conditions and the *    following disclaimer in the documentation and/or other *    materials provided with the distribution. * * 3. The name "DOM4J" must not be used to endorse or promote *    products derived from this Software without prior written *    permission of MetaStuff, Ltd.  For written permission, *    please contact dom4j-info@metastuff.com. * * 4. Products derived from this Software may not be called "DOM4J" *    nor may "DOM4J" appear in their names without prior written *    permission of MetaStuff, Ltd. DOM4J is a registered *    trademark of MetaStuff, Ltd. * * 5. Due credit should be given to the DOM4J Project *    (http://dom4j.org/). * * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. * * $Id: SAXContentHandler.java,v 1.5 2003/11/02 18:04:59 per_nyfelt Exp $ */

⌨️ 快捷键说明

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