basemarkupserializer.java

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

JAVA
1,946
字号
        // ???    }    public void endEntity( String name )    {        // ???    }    public void setDocumentLocator( Locator locator )    {        // Nothing to do    }    //-----------------------------------------//    // SAX content handler serializing methods //    //-----------------------------------------//    public void skippedEntity ( String name )        throws SAXException    {        try {        endCDATA();        content();        _printer.printText( '&' );        _printer.printText( name );        _printer.printText( ';' );        } catch ( IOException except ) {            throw new SAXException( except );    }    }    public void startPrefixMapping( String prefix, String uri )        throws SAXException    {        if ( _prefixes == null )            _prefixes = new Hashtable();        _prefixes.put( uri, prefix == null ? "" : prefix );    }    public void endPrefixMapping( String prefix )        throws SAXException    {    }    //------------------------------------------//    // SAX DTD/Decl handler serializing methods //    //------------------------------------------//    public final void startDTD( String name, String publicId, String systemId )        throws SAXException    {        try {        _printer.enterDTD();        _docTypePublicId = publicId;        _docTypeSystemId = systemId;                } catch ( IOException except ) {            throw new SAXException( except );        }    }    public void endDTD()    {        // Nothing to do here, all the magic occurs in startDocument(String).    }    public void elementDecl( String name, String model )        throws SAXException    {        try {        _printer.enterDTD();        _printer.printText( "<!ELEMENT " );        _printer.printText( name );        _printer.printText( ' ' );        _printer.printText( model );        _printer.printText( '>' );        if ( _indenting )            _printer.breakLine();        } catch ( IOException except ) {            throw new SAXException( except );        }    }    public void attributeDecl( String eName, String aName, String type,                               String valueDefault, String value )        throws SAXException    {        try {        _printer.enterDTD();        _printer.printText( "<!ATTLIST " );        _printer.printText( eName );        _printer.printText( ' ' );        _printer.printText( aName );        _printer.printText( ' ' );        _printer.printText( type );        if ( valueDefault != null ) {            _printer.printText( ' ' );            _printer.printText( valueDefault );        }        if ( value != null ) {            _printer.printText( " \"" );            printEscaped( value );            _printer.printText( '"' );        }        _printer.printText( '>' );        if ( _indenting )            _printer.breakLine();        } catch ( IOException except ) {            throw new SAXException( except );    }    }    public void internalEntityDecl( String name, String value )        throws SAXException    {        try {        _printer.enterDTD();        _printer.printText( "<!ENTITY " );        _printer.printText( name );        _printer.printText( " \"" );        printEscaped( value );        _printer.printText( "\">" );        if ( _indenting )            _printer.breakLine();        } catch ( IOException except ) {            throw new SAXException( except );        }    }    public void externalEntityDecl( String name, String publicId, String systemId )        throws SAXException    {        try {        _printer.enterDTD();        unparsedEntityDecl( name, publicId, systemId, null );        } catch ( IOException except ) {            throw new SAXException( except );        }    }    public void unparsedEntityDecl( String name, String publicId,                                    String systemId, String notationName )        throws SAXException    {        try {        _printer.enterDTD();        if ( publicId == null ) {            _printer.printText( "<!ENTITY " );            _printer.printText( name );            _printer.printText( " SYSTEM " );            printDoctypeURL( systemId );        } else {            _printer.printText( "<!ENTITY " );            _printer.printText( name );            _printer.printText( " PUBLIC " );            printDoctypeURL( publicId );            _printer.printText( ' ' );            printDoctypeURL( systemId );        }        if ( notationName != null ) {            _printer.printText( " NDATA " );            _printer.printText( notationName );        }        _printer.printText( '>' );        if ( _indenting )            _printer.breakLine();        } catch ( IOException except ) {            throw new SAXException( except );    }    }    public void notationDecl( String name, String publicId, String systemId )        throws SAXException    {        try {        _printer.enterDTD();        if ( publicId != null ) {            _printer.printText( "<!NOTATION " );            _printer.printText( name );            _printer.printText( " PUBLIC " );            printDoctypeURL( publicId );            if ( systemId != null ) {                _printer.printText( ' ' );                printDoctypeURL( systemId );            }        } else {            _printer.printText( "<!NOTATION " );            _printer.printText( name );            _printer.printText( " SYSTEM " );            printDoctypeURL( systemId );        }        _printer.printText( '>' );        if ( _indenting )            _printer.breakLine();        } catch ( IOException except ) {            throw new SAXException( except );        }    }    //------------------------------------------//    // Generic node serializing methods methods //    //------------------------------------------//    /**     * Serialize the DOM node. This method is shared across XML, HTML and XHTML     * serializers and the differences are masked out in a separate {@link     * #serializeElement}.     *     * @param node The node to serialize     * @see #serializeElement     * @throws IOException An I/O exception occured while     *   serializing     */    protected void serializeNode( Node node )        throws IOException    {        fCurrentNode = node;        // Based on the node type call the suitable SAX handler.        // Only comments entities and documents which are not        // handled by SAX are serialized directly.        switch ( node.getNodeType() ) {        case Node.TEXT_NODE : {            String text;            text = node.getNodeValue();            if ( text != null ) {                if (fDOMFilter !=null &&                     (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_TEXT)!= 0) {                    short code = fDOMFilter.acceptNode(node);                    switch (code) {                        case NodeFilter.FILTER_REJECT:                        case NodeFilter.FILTER_SKIP: {                             break;                        }                        default: {                            characters(text);                        }                    }                }                else if ( !_indenting || getElementState().preserveSpace                     || (text.replace('\n',' ').trim().length() != 0))                    characters( text );                        }                            break;        }        case Node.CDATA_SECTION_NODE : {            String text = node.getNodeValue();            if ((features & DOMSerializerImpl.CDATA) != 0) {                if (text != null) {                    if (fDOMFilter != null                        && (fDOMFilter.getWhatToShow()                            & NodeFilter.SHOW_CDATA_SECTION)                            != 0) {                        short code = fDOMFilter.acceptNode(node);                        switch (code) {                            case NodeFilter.FILTER_REJECT :                            case NodeFilter.FILTER_SKIP :                                {                                    // skip the CDATA node                                    return;                                }                            default :                                {                                    //fall through..                                }                        }                    }                    startCDATA();                    characters(text);                    endCDATA();                }            } else {                // transform into a text node                characters(text);            }            break;        }        case Node.COMMENT_NODE : {            String text;            if ( ! _format.getOmitComments() ) {                text = node.getNodeValue();                if ( text != null ) {                                    if (fDOMFilter !=null &&                           (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_COMMENT)!= 0) {                          short code = fDOMFilter.acceptNode(node);                          switch (code) {                              case NodeFilter.FILTER_REJECT:                              case NodeFilter.FILTER_SKIP: {                                   // skip the comment node                                  return;                              }                              default: {                                   // fall through                              }                          }                                          }                    comment( text );                }                                }            break;        }        case Node.ENTITY_REFERENCE_NODE : {            Node         child;            endCDATA();            content();                        if (((features & DOMSerializerImpl.ENTITIES) != 0)                || (node.getFirstChild() == null)) {                if (fDOMFilter !=null &&                       (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ENTITY_REFERENCE)!= 0) {                      short code = fDOMFilter.acceptNode(node);                      switch (code) {                        case NodeFilter.FILTER_REJECT:{                            return; // remove the node                          }                          case NodeFilter.FILTER_SKIP: {                               child = node.getFirstChild();                              while ( child != null ) {                                  serializeNode( child );                                  child = child.getNextSibling();                              }                              return;                          }                          default: {                               // fall through                          }                      }                  }                         checkUnboundNamespacePrefixedNode(node);                              _printer.printText("&");                _printer.printText(node.getNodeName());                _printer.printText(";");            }            else {                child = node.getFirstChild();                while ( child != null ) {                    serializeNode( child );                    child = child.getNextSibling();                }            }            break;        }        case Node.PROCESSING_INSTRUCTION_NODE : {                    if (fDOMFilter !=null &&                   (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_PROCESSING_INSTRUCTION)!= 0) {                  short code = fDOMFilter.acceptNode(node);                  switch (code) {                    case NodeFilter.FILTER_REJECT:                                          case NodeFilter.FILTER_SKIP: {                           return;  // skip this node                                          }                    default: { // fall through                    }                  }            }            processingInstructionIO( node.getNodeName(), node.getNodeValue() );            break;        }        case Node.ELEMENT_NODE :  {            if (fDOMFilter !=null && 

⌨️ 快捷键说明

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