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

📄 beanwriter.java

📁 JAVA 文章管理系统源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }
    
    
    
    // New API
    //------------------------------------------------------------------------------

    
    /**
     * Writes the start tag for an element.
     *
     * @param uri the element's namespace uri
     * @param localName the element's local name 
     * @param qualifiedName the element's qualified name
     * @param attr the element's attributes
     * @throws IOException if an IO problem occurs during writing 
     * @throws SAXException if an SAX problem occurs during writing 
     * @since 0.5
     */
    protected void startElement(
                                WriteContext context,
                                String uri, 
                                String localName, 
                                String qualifiedName, 
                                Attributes attr)
                                    throws
                                        IOException,
                                        SAXException {
        if ( !closedStartTag ) {
            writer.write( '>' );
            printLine();
        }
        
        indentLevel++;
        
        indent();
        writer.write( '<' );
        writer.write( qualifiedName );
        
        for ( int i=0; i< attr.getLength(); i++ ) {
            writer.write( ' ' );
            writer.write( attr.getQName(i) );
            writer.write( "=\"" );
            writer.write( XMLUtils.escapeAttributeValue( attr.getValue(i) ) );
            writer.write( '\"' );
        }
        closedStartTag = false;
        currentElementIsEmpty = true;
        currentElementHasBodyText = false;
    }
    
    /**
     * Writes the end tag for an element
     *
     * @param uri the element's namespace uri
     * @param localName the element's local name 
     * @param qualifiedName the element's qualified name
     *
     * @throws IOException if an IO problem occurs during writing 
     * @throws SAXException if an SAX problem occurs during writing 
     * @since 0.5
     */
    protected void endElement(
                                WriteContext context,
                                String uri, 
                                String localName, 
                                String qualifiedName)
                                    throws
                                        IOException,
                                        SAXException {
        if ( 
            !addEndTagForEmptyElement
            && !closedStartTag 
            && currentElementIsEmpty ) {
        
            writer.write( "/>" );
            closedStartTag = true;
            
        } else {
            if (!currentElementHasBodyText) {
                indent();
            }
            if (
                    addEndTagForEmptyElement
                    && !closedStartTag ) {
                 writer.write( ">" );
                 closedStartTag = true;                 
            }
            writer.write( "</" );
            writer.write( qualifiedName );
            writer.write( '>' );
            
        }
        
        indentLevel--;
        printLine();
        
        currentElementHasBodyText = false;
    }

    /** 
     * Write element body text 
     *
     * @param text write out this body text
     * @throws IOException when the stream write fails
     * @since 0.5
     */
    protected void bodyText(WriteContext context, String text) throws IOException {
        if ( text == null ) {
            // XXX This is probably a programming error
            log.error( "[expressBodyText]Body text is null" );
            
        } else {
            if ( !closedStartTag ) {
                writer.write( '>' );
                closedStartTag = true;
            }
            writer.write( 
                mixedContentEncodingStrategy.encode(
                    text, 
                    context.getCurrentDescriptor()) );
            currentElementIsEmpty = false;
            currentElementHasBodyText = true;
        }
    }
    
    /** Writes out an empty line.
     * Uses current <code>endOfLine</code>.
     *
     * @throws IOException when stream write fails
     */
    private void printLine() throws IOException {
        if ( endOfLine != null ) {
            writer.write( endOfLine );
        }
    }
    
    /** 
     * Writes out <code>indent</code>'s to the current <code>indentLevel</code>
     *
     * @throws IOException when stream write fails
     */
    private void indent() throws IOException {
        if ( indent != null ) {
            for ( int i = 0; i < indentLevel; i++ ) {
                writer.write( getIndent() );
            }
        }
    }

    // OLD API (DEPRECATED)
    //----------------------------------------------------------------------------

            
    /** Writes out an empty line.
     * Uses current <code>endOfLine</code>.
     *
     * @throws IOException when stream write fails
     * @deprecated 0.5 replaced by new SAX inspired API
     */
    protected void writePrintln() throws IOException {
        if ( endOfLine != null ) {
            writer.write( endOfLine );
        }
    }
    
    /** 
     * Writes out <code>indent</code>'s to the current <code>indentLevel</code>
     *
     * @throws IOException when stream write fails
     * @deprecated 0.5 replaced by new SAX inspired API
     */
    protected void writeIndent() throws IOException {
        if ( indent != null ) {
            for ( int i = 0; i < indentLevel; i++ ) {
                writer.write( getIndent() );
            }
        }
    }
    
    /** 
     * <p>Escape the <code>toString</code> of the given object.
     * For use as body text.</p>
     *
     * @param value escape <code>value.toString()</code>
     * @return text with escaped delimiters 
     * @deprecated 0.5 moved into utility class {@link XMLUtils#escapeBodyValue}
     */
    protected String escapeBodyValue(Object value) {
        return XMLUtils.escapeBodyValue(value);
    }

    /** 
     * <p>Escape the <code>toString</code> of the given object.
     * For use in an attribute value.</p>
     *
     * @param value escape <code>value.toString()</code>
     * @return text with characters restricted (for use in attributes) escaped
     *
     * @deprecated 0.5 moved into utility class {@link XMLUtils#escapeAttributeValue}
     */
    protected String escapeAttributeValue(Object value) {
        return XMLUtils.escapeAttributeValue(value);
    }  

    /** 
     * Express an element tag start using given qualified name 
     *
     * @param qualifiedName the fully qualified name of the element to write
     * @throws IOException when stream write fails
     * @deprecated 0.5 replaced by new SAX inspired API
     */
    protected void expressElementStart(String qualifiedName) throws IOException {
        if ( qualifiedName == null ) {
            // XXX this indicates a programming error
            log.fatal( "[expressElementStart]Qualified name is null." );
            throw new RuntimeException( "Qualified name is null." );
        }
        
        writePrintln();
        writeIndent();
        writer.write( '<' );
        writer.write( qualifiedName );
    }
    
    /** 
     * Write a tag close to the stream
     *
     * @throws IOException when stream write fails
     * @deprecated 0.5 replaced by new SAX inspired API
     */
    protected void expressTagClose() throws IOException {
        writer.write( '>' );
    }
    
    /** 
     * Write an element end tag to the stream
     *
     * @param qualifiedName the name of the element
     * @throws IOException when stream write fails
     * @deprecated 0.5 replaced by new SAX inspired API
     */
    protected void expressElementEnd(String qualifiedName) throws IOException {
        if (qualifiedName == null) {
            // XXX this indicates a programming error
            log.fatal( "[expressElementEnd]Qualified name is null." );
            throw new RuntimeException( "Qualified name is null." );
        }
        
        writer.write( "</" );
        writer.write( qualifiedName );
        writer.write( '>' );
    }    
    
    /**  
     * Write an empty element end to the stream
     *
     * @throws IOException when stream write fails
     * @deprecated 0.5 replaced by new SAX inspired API
     */
    protected void expressElementEnd() throws IOException {
        writer.write( "/>" );
    }

    /** 
     * Write element body text 
     *
     * @param text write out this body text
     * @throws IOException when the stream write fails
     * @deprecated 0.5 replaced by new SAX inspired API
     */
    protected void expressBodyText(String text) throws IOException {
        if ( text == null ) {
            // XXX This is probably a programming error
            log.error( "[expressBodyText]Body text is null" );
            
        } else {
            writer.write( XMLUtils.escapeBodyValue(text) );
        }
    }
    
    /** 
     * Writes an attribute to the stream.
     *
     * @param qualifiedName fully qualified attribute name
     * @param value attribute value
     * @throws IOException when the stream write fails
     * @deprecated 0.5 replaced by new SAX inspired API
     */
    protected void expressAttribute(
                                String qualifiedName, 
                                String value) 
                                    throws
                                        IOException{
        if ( value == null ) {
            // XXX probably a programming error
            log.error( "Null attribute value." );
            return;
        }
        
        if ( qualifiedName == null ) {
            // XXX probably a programming error
            log.error( "Null attribute value." );
            return;
        }
                
        writer.write( ' ' );
        writer.write( qualifiedName );
        writer.write( "=\"" );
        writer.write( XMLUtils.escapeAttributeValue(value) );
        writer.write( '\"' );
    }


}

⌨️ 快捷键说明

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