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

📄 jspwikimarkupparser.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                String ptrn = TextUtil.getStringProperty( props, name, null );                ptrnlist.add( ptrn );            }        }        if( ptrnlist.size() == 0 )        {            ptrnlist.add( DEFAULT_INLINEPATTERN );        }        return ptrnlist;    }    /**     *  Returns link name, if it exists; otherwise it returns null.     */    private String linkExists( String page )    {        try        {            if( page == null || page.length() == 0 ) return null;            return m_engine.getFinalPageName( page );        }        catch( ProviderException e )        {            log.warn("TranslatorReader got a faulty page name!",e);            return page;  // FIXME: What would be the correct way to go back?        }    }    /**     *  Calls a transmutator chain.     *     *  @param list Chain to call     *  @param text Text that should be passed to the mutate() method     *              of each of the mutators in the chain.     *  @return The result of the mutation.     */    protected String callMutatorChain( Collection list, String text )    {        if( list == null || list.size() == 0 )        {            return text;        }        for( Iterator i = list.iterator(); i.hasNext(); )        {            StringTransmutator m = (StringTransmutator) i.next();            text = m.mutate( m_context, text );        }        return text;    }    /**     * Calls the heading listeners.     *     * @param param A Heading object.     */    protected void callHeadingListenerChain( Heading param )    {        List list = m_headingListenerChain;        for( Iterator i = list.iterator(); i.hasNext(); )        {            HeadingListener h = (HeadingListener) i.next();            h.headingAdded( m_context, param );        }    }    /**     *  Creates a JDOM anchor element.  Can be overridden to change the URL creation,     *  if you really know what you are doing.     *     *  @param type One of the types above     *  @param link URL to which to link to     *  @param text Link text     *  @param section If a particular section identifier is required.     *  @return An A element.     *  @since 2.4.78     */    protected Element createAnchor(int type, String link, String text, String section)    {        text = escapeHTMLEntities( text );        section = escapeHTMLEntities( section );        Element el = new Element("a");        el.setAttribute("class",CLASS_TYPES[type]);        el.setAttribute("href",link+section);        el.addContent(text);        return el;    }    private Element makeLink( int type, String link, String text, String section, Iterator attributes )    {        Element el = null;        if( text == null ) text = link;        text = callMutatorChain( m_linkMutators, text );        section = (section != null) ? ("#"+section) : "";        // Make sure we make a link name that can be accepted        // as a valid URL.        if( link.length() == 0 )        {            type = EMPTY;        }        ResourceBundle rb = m_context.getBundle(InternationalizationManager.CORE_BUNDLE);        Object[] args = { link };        switch(type)        {            case READ:                el = createAnchor( READ, m_context.getURL(WikiContext.VIEW, link), text, section );                break;            case EDIT:                el = createAnchor( EDIT, m_context.getURL(WikiContext.EDIT,link), text, "" );                el.setAttribute("title", MessageFormat.format( rb.getString( "markupparser.link.create" ), args ) );                break;            case EMPTY:                el = new Element("u").addContent(text);                break;                //                //  These two are for local references - footnotes and                //  references to footnotes.                //  We embed the page name (or whatever WikiContext gives us)                //  to make sure the links are unique across Wiki.                //            case LOCALREF:                el = createAnchor( LOCALREF, "#ref-"+m_context.getName()+"-"+link, "["+text+"]", "" );                break;            case LOCAL:                el = new Element("a").setAttribute("class","footnote");                el.setAttribute("name", "ref-"+m_context.getName()+"-"+link.substring(1));                el.addContent("["+text+"]");                break;                //                //  With the image, external and interwiki types we need to                //  make sure nobody can put in Javascript or something else                //  annoying into the links themselves.  We do this by preventing                //  a haxor from stopping the link name short with quotes in                //  fillBuffer().                //            case IMAGE:                el = new Element("img").setAttribute("class","inline");                el.setAttribute("src",link);                el.setAttribute("alt",text);                break;            case IMAGELINK:                el = new Element("img").setAttribute("class","inline");                el.setAttribute("src",link);                el.setAttribute("alt",text);                el = createAnchor(IMAGELINK,text,"","").addContent(el);                break;            case IMAGEWIKILINK:                String pagelink = m_context.getURL(WikiContext.VIEW,text);                el = new Element("img").setAttribute("class","inline");                el.setAttribute("src",link);                el.setAttribute("alt",text);                el = createAnchor(IMAGEWIKILINK,pagelink,"","").addContent(el);                break;            case EXTERNAL:                el = createAnchor( EXTERNAL, link, text, section );                if( m_useRelNofollow ) el.setAttribute("rel","nofollow");                break;            case INTERWIKI:                el = createAnchor( INTERWIKI, link, text, section );                break;            case ATTACHMENT:                String attlink = m_context.getURL( WikiContext.ATTACH,                                                   link );                String infolink = m_context.getURL( WikiContext.INFO,                                                    link );                String imglink = m_context.getURL( WikiContext.NONE,                                                   "images/attachment_small.png" );                el = createAnchor( ATTACHMENT, attlink, text, "" );                pushElement(el);                popElement(el.getName());                if( m_useAttachmentImage )                {                    el = new Element("img").setAttribute("src",imglink);                    el.setAttribute("border","0");                    el.setAttribute("alt","(info)");                    el = new Element("a").setAttribute("href",infolink).addContent(el);                    el.setAttribute("class","infolink");                }                else                {                    el = null;                }                break;            default:                break;        }        if( el != null && attributes != null )        {            while( attributes.hasNext() )            {                Attribute attr = (Attribute)attributes.next();                if( attr != null )                {                    el.setAttribute(attr);                }            }        }        if( el != null )        {            flushPlainText();            m_currentElement.addContent( el );        }        return el;    }    /**     *  Figures out if a link is an off-site link.  This recognizes     *  the most common protocols by checking how it starts.     *     *  @param link The link to check.     *  @return true, if this is a link outside of this wiki.     *  @since 2.4     */    public static boolean isExternalLink( String link )    {        int idx = Arrays.binarySearch( EXTERNAL_LINKS, link,                                       c_startingComparator );        //        //  We need to check here once again; otherwise we might        //  get a match for something like "h".        //        if( idx >= 0 && link.startsWith(EXTERNAL_LINKS[idx]) ) return true;        return false;    }    /**     *  Returns true, if the link in question is an access     *  rule.     */    private static boolean isAccessRule( String link )    {        return link.startsWith("{ALLOW") || link.startsWith("{DENY");    }    /**     *  Matches the given link to the list of image name patterns     *  to determine whether it should be treated as an inline image     *  or not.     */    private boolean isImageLink( String link )    {        if( m_inlineImages )        {            link = link.toLowerCase();            for( Iterator i = m_inlineImagePatterns.iterator(); i.hasNext(); )            {                if( m_inlineMatcher.matches( link, (Pattern) i.next() ) )                    return true;            }        }        return false;    }    private static boolean isMetadata( String link )    {        return link.startsWith("{SET");    }    /**     *  These are all of the HTML 4.01 block-level elements.     */    private static final String[] BLOCK_ELEMENTS = {        "address", "blockquote", "div", "dl", "fieldset", "form",        "h1", "h2", "h3", "h4", "h5", "h6",        "hr", "noscript", "ol", "p", "pre", "table", "ul"    };    private static final boolean isBlockLevel( String name )    {        return Arrays.binarySearch( BLOCK_ELEMENTS, name ) >= 0;    }    /**     *  This method peeks ahead in the stream until EOL and returns the result.     *  It will keep the buffers untouched.     *     *  @return The string from the current position to the end of line.     */    // FIXME: Always returns an empty line, even if the stream is full.    private String peekAheadLine()        throws IOException    {        String s = readUntilEOL().toString();        if( s.length() > PUSHBACK_BUFFER_SIZE )        {            log.warn("Line is longer than maximum allowed size ("+PUSHBACK_BUFFER_SIZE+" characters.  Attempting to recover...");            pushBack( s.substring(0,PUSHBACK_BUFFER_SIZE-1) );        }        else        {            try            {                pushBack( s );            }            catch( IOException e )            {                log.warn("Pushback failed: the line is probably too long.  Attempting to recover.");            }        }        return s;    }    /**     *  Writes HTML for error message.  Does not add it to the document, you     *  have to do it yourself.     *       *  @param error The error string.     *  @return An Element containing the error.     */    public static Element makeError( String error )    {        return new Element("span").setAttribute("class","error").addContent(error);    }    private int flushPlainText()    {        int numChars = m_plainTextBuf.length();        if( numChars > 0 )        {            String buf;            if( !m_allowHTML )            {                buf = escapeHTMLEntities(m_plainTextBuf.toString());            }            else            {                buf = m_plainTextBuf.toString();            }            //            //  We must first empty the buffer because the side effect of            //  calling makeCamelCaseLink() is to call this routine.            //            m_plainTextBuf = new StringBuilder(20);            try            {                //                //  This is the heaviest part of parsing, and therefore we can                //  do some optimization here.                //                //  1) Only when the length of the buffer is big enough, we try to do the match                //                if( m_camelCaseLinks && !m_isEscaping && buf.length() > 3 )                {                    // System.out.println("Buffer="+buf);                    while( m_camelCaseMatcher.contains( buf, m_camelCasePattern ) )                    {                        MatchResult result = m_camelCaseMatcher.getMatch();                        String firstPart = buf.substring(0,result.beginOffset(0));                        String prefix = result.group(1);                        if( prefix == null ) prefix = "";                        String camelCase = result.group(2);                        String protocol  = result.group(3);                        String uri       = protocol+result.group(4);

⌨️ 快捷键说明

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