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

📄 translatorreader.java

📁 wiki建站资源 java编写的 很好用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            else if ( ch == closing )             {                braceLevel--;                if (braceLevel==0) {                  break;                }            }            sb.append( (char)ch );        }            return sb.toString();    }    /**     *  Reads the stream until it meets one of the specified     *  ending characters, or stream end.  The ending character will be left     *  in the stream.     */    private String readUntil( String endChars )        throws IOException    {        StringBuffer sb = new StringBuffer();        int ch = nextToken();        while( ch != -1 )        {            if( ch == '\\' )             {                ch = nextToken();                 if( ch == -1 )                 {                    break;                }            }            else            {                if( endChars.indexOf((char)ch) != -1 )                {                    pushBack( ch );                    break;                }            }            sb.append( (char) ch );            ch = nextToken();        }        return sb.toString();    }    /**     *  Reads the stream while the characters that have been specified are     *  in the stream, returning then the result as a String.     */    private String readWhile( String endChars )        throws IOException    {        StringBuffer sb = new StringBuffer();        int ch = nextToken();        while( ch != -1 )        {            if( endChars.indexOf((char)ch) == -1 )            {                pushBack( ch );                break;            }                        sb.append( (char) ch );            ch = nextToken();        }        return sb.toString();    }        /**     *  Handles constructs of type %%(style) and %%class     * @param newLine     * @return     * @throws IOException     */    private String handleDiv( boolean newLine )        throws IOException    {        int ch = nextToken();        if( ch == '%' )        {            StringBuffer sb = new StringBuffer();            String style = null;            String clazz = null;            ch = nextToken();            boolean isspan = false;                        //            //  Style or class?            //            if( ch == '(' )            {                                style = readBraceContent('(',')');            }            else if( Character.isLetter( (char) ch ) )            {                pushBack( ch );                clazz = readUntil( " \t\n\r" );                ch = nextToken();                                //                //  Pop out only spaces, so that the upcoming EOL check does not check the                //  next line.                //                if( ch == '\n' || ch == '\r' )                {                    pushBack(ch);                }            }            else            {                //                // Anything else stops.                //                pushBack(ch);                                try                {                    Boolean isSpan = (Boolean)m_styleStack.pop();                                    if( isSpan == null )                    {                        // Fail quietly                    }                    else if( isSpan.booleanValue() )                    {                        sb.append( m_renderer.closeSpan() );                    }                    else                    {                        sb.append( m_renderer.closeDiv() );                    }                }                catch( EmptyStackException e )                {                    log.debug("Page '"+m_context.getPage().getName()+"' closes a %%-block that has not been opened.");                }                                return sb.toString();            }            //            //  Decide if we should open a div or a span?            //            String eol = peekAheadLine();                        if( eol.trim().length() > 0 )            {                // There is stuff after the class                                sb.append( m_renderer.openSpan( style, clazz ) );                                m_styleStack.push( Boolean.TRUE );            }            else            {                sb.append( startBlockLevel() );                sb.append( m_renderer.openDiv( style, clazz ) );                m_styleStack.push( Boolean.FALSE );            }                        return sb.toString();        }        pushBack(ch);        return "%";    }    private String handleBar( boolean newLine )        throws IOException    {        StringBuffer sb = new StringBuffer();        if( !m_istable && !newLine )        {            return "|";        }        if( newLine )        {            if( !m_istable )            {                sb.append( startBlockLevel() );                sb.append( m_renderer.openTable() );                m_istable = true;            }            sb.append( m_renderer.openTableRow() );            m_closeTag = m_renderer.closeTableItem()+m_renderer.closeTableRow();        }                int ch = nextToken();        if( ch == '|' )        {            if( !newLine )             {                sb.append( m_renderer.closeTableHeading() );            }            sb.append( m_renderer.openTableHeading() );            m_closeTag = m_renderer.closeTableHeading()+m_renderer.closeTableRow();        }        else        {            if( !newLine )             {                sb.append( m_renderer.closeTableItem() );            }            sb.append( m_renderer.openTableItem() );            pushBack( ch );        }        return sb.toString();    }    /**     *  Generic escape of next character or entity.     */    private String handleTilde()        throws IOException    {        int ch = nextToken();        if( ch == '|' || ch == '~' || ch == '\\' || ch == '*' || ch == '#' ||             ch == '-' || ch == '!' || ch == '\'' || ch == '_' || ch == '[' ||            ch == '{' || ch == ']' || ch == '}' )        {            StringBuffer sb = new StringBuffer();            sb.append( (char)ch );            sb.append(readWhile( ""+(char)ch ));            return sb.toString();        }                if( Character.isUpperCase( (char) ch ) )        {            pushBack( ch );            return "";        }        // No escape.        pushBack( ch );        return "~";    }    private void fillBuffer()        throws IOException    {        StringBuffer buf = new StringBuffer();        StringBuffer word = null;        int previousCh = -2;        int start = 0;                boolean quitReading = false;        boolean newLine     = true; // FIXME: not true if reading starts in middle of buffer        while(!quitReading)        {            int ch = nextToken();            String s = null;            //            //  Check if we're actually ending the preformatted mode.            //  We still must do an entity transformation here.            //            if( m_isEscaping )            {                if( ch == '}' )                {                    buf.append( handleClosebrace() );                }                                else if( ch == -1 )                {                    quitReading = true;                }                else                 {                    m_renderer.doChar( buf, (char)ch );                }                continue;            }            //            //  CamelCase detection, a non-trivial endeavour.            //  We keep track of all white-space separated entities, which we            //  hereby refer to as "words".  We then check for an existence            //  of a CamelCase format text string inside the "word", and            //  if one exists, we replace it with a proper link.            //                        if( m_camelCaseLinks )            {                // Quick parse of start of a word boundary.                if( word == null &&                                        (Character.isWhitespace( (char)previousCh ) ||                     WORD_SEPARATORS.indexOf( (char)previousCh ) != -1 ||                     newLine ) &&                    !Character.isWhitespace( (char) ch ) )                {                    word = new StringBuffer();                }                // Are we currently tracking a word?                if( word != null )                {                    //                    //  Check for the end of the word.                    //                    if( Character.isWhitespace( (char)ch ) ||                         ch == -1 ||                        WORD_SEPARATORS.indexOf( (char) ch ) != -1 )                    {                        String potentialLink = word.toString();                        String camelCase = checkForCamelCaseLink(potentialLink);                        if( camelCase != null )                        {                            // System.out.println("Buffer is "+buf);                            // System.out.println("  Replacing "+camelCase+" with proper link.");                            start = buf.toString().lastIndexOf( camelCase );                            buf.replace(start,                                        start+camelCase.length(),                                        makeCamelCaseLink(camelCase) );                            // System.out.println("  Resulting with "+buf);                        }                        else                        {                            // System.out.println("Checking for potential URI: "+potentialLink);                            if( isExternalLink( potentialLink ) )                            {                                // System.out.println("buf="+buf);                                start = buf.toString().lastIndexOf( potentialLink );                                if( start >= 0 )                                {                                    String link = readUntil(" \t()[]{}!\"'\n|");                                    link = potentialLink + (char)ch + link; // Do not forget the start.                                    // System.out.println("start="+start+", pl="+potentialLink);                                    buf.replace( start,                                                 start + potentialLink.length(),                                                 makeDirectURILink( link ) );                                    // System.out.println("Resulting with "+buf);                                    ch = nextToken();                                }                            }                        }                        // We've ended a word boundary, so time to reset.                        word = null;                    }                    else                    {                        // This should only be appending letters and digits.                        word.append( (char)ch );                    } // if end of word                } // if word's not null                // Always set the previous character to test for word starts.                previousCh = ch;		             } // if m_camelCaseLinks            //            //  An empty line stops a list            //            if( newLine && ch != '*' && ch != '#' && ch != ' ' && m_genlistlevel > 0 )            {                buf.append(unwindGeneralList());            }            if( newLine && ch != '|' && m_istable )            {                buf.append( m_renderer.closeTable() );                m_istable = false;                m_closeTag = null;            }            //            //  Now, check the incoming token.            //            switch( ch )            {              case '\r':                // DOS linefeeds we forget                s = null;                break;              case '\n':                //                //  Close things like headings, etc.                //                if( m_closeTag != null )                 {                    buf.append( m_closeTag );                    m_closeTag = null;                }                m_isdefinition = false;                if( newLine )                {                    // Paragraph change.                    buf.append( startBlockLevel() );                    //                    //  Figure out which elements cannot be enclosed inside                    //  a <p></p> pair according to XHTML rules.                    //                    String nextLine = peekAheadLine();                    if( nextLine.length() == 0 ||                         (nextLine.length() > 0 &&                         !nextLine.startsWith("{{{") &&                         !nextLine.startsWith("-

⌨️ 快捷键说明

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