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

📄 xhtmlelementtowikitranslator.java

📁 wiki建站资源 java编写的 很好用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                    {
                                        print( e );
                                    }
                                    else
                                    {
                                        out.print( " [" );
                                        print( e );
                                        if( !e.getTextTrim().replaceAll( "\\s", "" ).equals( ref ) )
                                        {
                                            out.print( "|" );
                                            print( ref );
                                        }
                                        out.print( "]" );
                                    }
                                }
                            }
                            out.print( " " );
                        }
                    }
                }
                else if( n.equals( "b" ) )
                {
                    out.print( "__" );
                    print( e );
                    out.print( "__" );
                }
                else if( n.equals( "i" ) )
                {
                    out.print( "''" );
                    print( e );
                    out.print( "''" );
                }
                else if( n.equals( "ul" ) )
                {
                    out.println();
                    li.push( "*" );
                    print( e );
                    li.pop();
                }
                else if( n.equals( "ol" ) )
                {
                    out.println();
                    li.push( "#" );
                    print( e );
                    li.pop();
                }
                else if( n.equals( "li" ) )
                {
                    out.print( li + " " );
                    print( e );
                    out.println();
                }
                else if( n.equals( "pre" ) )
                {
                    out.print( "{{{" );
                    pre.push();
                    print( e );
                    pre.pop();
                    out.println( "}}}" );
                }
                else if( n.equals( "code" ) || n.equals( "tt" ) )
                {
                    out.print( "{{" );
                    pre.push();
                    print( e );
                    pre.pop();
                    out.println( "}}" );
                }
                else if( n.equals( "img" ) )
                {
                    if( !isIgnorableWikiMarkupLink( e ) )
                    {
                        out.print( "[" );
                        print( trimLink( e.getAttributeValue( "src" ) ) );
                        out.print( "]" );
                        out.print( " " );
                    }
                }
                else
                {
                    print( e );
                }
            }
            else
            {
                print( c );
            }
        }
    }

    private void printImage( Element base ) throws JDOMException
    {
        Element child = (Element)XPath.selectSingleNode( base, "TBODY/TR/TD/*" );
        if( child == null )
        {
            child = base;
        }
        Element img;
        String href;
        Map map = new ForgetNullValuesLinkedHashMap();
        if( child.getName().equals( "A" ) )
        {
            img = child.getChild( "IMG" );
            href = child.getAttributeValue( "href" );
        }
        else
        {
            img = child;
            href = null;
        }
        if( img == null )
        {
            return;
        }
        String src = trimLink( img.getAttributeValue( "src" ) );
        if( src == null )
        {
            return;
        }
        map.put( "align", base.getAttributeValue( "align" ) );
        map.put( "height", img.getAttributeValue( "height" ) );
        map.put( "width", img.getAttributeValue( "width" ) );
        map.put( "alt", img.getAttributeValue( "alt" ) );
        map.put( "caption", emptyToNull( XPath.newInstance( "CAPTION" ).valueOf( base ) ) );
        map.put( "link", href );
        map.put( "border", img.getAttributeValue( "border" ) );
        map.put( "style", base.getAttributeValue( "style" ) );
        if( map.size() > 0 )
        {
            out.print( "[{Image src='" + src + "'" );
            for( Iterator i = map.entrySet().iterator(); i.hasNext(); )
            {
                Map.Entry entry = (Map.Entry)i.next();
                out.print( " " + entry.getKey() + "='" + entry.getValue() + "'" );
            }
            out.print( "}]" );
        }
        else
        {
            out.print( "[" + src + "]" );
        }
    }

    private String emptyToNull( String s )
    {
        return s == null ? null : (s.replaceAll( "\\s", "" ).length() == 0 ? null : s);
    }

    private String propsToStyleString( Map styleProps )
    {
        StringBuffer style = new StringBuffer();
        for( Iterator i = styleProps.entrySet().iterator(); i.hasNext(); )
        {
            Map.Entry entry = (Map.Entry)i.next();
            style.append( " " ).append( entry.getKey() ).append( ": " ).append( entry.getValue() ).append( ";" );
        }
        return style.toString();
    }

    private boolean isIgnorableWikiMarkupLink( Element a )
    {
        String ref = a.getAttributeValue( "href" );
        String class_ = a.getAttributeValue( "class" );
        return (ref != null && ref.startsWith( config.getPageInfoJsp() ))
               || (class_ != null && class_.trim().equalsIgnoreCase( config.getOutlink() ));
    }

    private Map getStylePropertiesLowerCase( Element base ) throws IOException
    {
        //"font-weight: bold; font-style: italic;"
        String style = base.getAttributeValue( "style" );
        if( style == null )
        {
            return null;
        }
        else
        {
            style = style.replace( ';', '\n' ).toLowerCase();
            LinkedHashMap m = new LinkedHashMap();
            new PersistentMapDecorator( m ).load( new ByteArrayInputStream( style.getBytes() ) );
            return m;
        }
    }

    private String trimLink( String ref )
    {
        if( ref == null )
        {
            return null;
        }
        ref = URLDecoder.decode( ref );
        ref = ref.trim();
        if( ref.startsWith( config.getAttachPage() ) )
        {
            ref = ref.substring( config.getAttachPage().length() );
        }
        if( ref.startsWith( config.getWikiJspPage() ) )
        {
            ref = ref.substring( config.getWikiJspPage().length() );
        }
        if( config.getPageName() != null )
        {
            if( ref.startsWith( config.getPageName() ) )
            {
                ref = ref.substring( config.getPageName().length() );
            }
        }
        return ref;
    }

    // FIXME: These should probably be better used with java.util.Stack
    
    class LiStack
    {

        private String li = "";

        public void push( String c )
        {
            li += c;
        }

        public void pop()
        {
            li = li.substring( 0, li.length() - 1 );
        }

        public String toString()
        {
            return li;
        }

    }

    class PreStack
    {

        private int pre = 0;

        public boolean isPreMode()
        {
            return pre > 0;
        }

        public void push()
        {
            pre++;
            outTimmer.setWhitespaceTrimMode( !isPreMode() );
        }

        public void pop()
        {
            pre--;
            outTimmer.setWhitespaceTrimMode( !isPreMode() );
        }

    }

}

⌨️ 快捷键说明

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