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

📄 wikiplugin.java

📁 这个weblogging 设计得比较精巧
💻 JAVA
字号:
package org.roller.presentation.velocity.plugins.jspwiki;
import com.ecyrd.jspwiki.FileUtil;
import com.ecyrd.jspwiki.TranslatorReader;
import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.WikiEngine;
import com.ecyrd.jspwiki.WikiPage;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.context.Context;
import org.roller.pojos.WeblogEntryData;
import org.roller.presentation.RollerRequest;
import org.roller.presentation.velocity.PagePlugin;

import java.io.StringReader;
import java.util.StringTokenizer;

/**
 * Wiki plugin using the JSPWiki WikiEngine. If you want Wiki links to point 
 * to your JSPWiki, then edit the jspwiki.properties fiel in Roller's WEB-INF
 * directory and set the jspwiki.baseURL appropriately. For example, if your
 * Wiki is on your localhost in the Servlet Context named 'wiki' then you'd
 * set jspwiki.baseURL like so:<br />
 * <br />
 *  jspwiki.baseURL=http://local:8080/wiki/<br />
 * 
 * @author David M Johnson
 */
public class WikiPlugin implements PagePlugin
{
    protected String name = "JSPWiki Syntax";
    public String description = "Allows use of JSPWiki formatting to easily " +
    "generate HTML. See the " +
    "<a href='http://www.jspwiki.org/Wiki.jsp?page=TextFormattingRules' target='jspwiki'>JSPWiki</a> site.";
    
    private static Log mLogger = 
       LogFactory.getFactory().getInstance(WikiPlugin.class);

    static WikiEngine mWikiEngine = null;
    static WikiContext mWikiContext = null;
    static WikiPage mWikiPage = new WikiPage("dummyPage");
    
    public WikiPlugin()
    {
        mLogger.debug("JSPWiki WikiPlugin instantiated.");
    }
    
    public String toString() { return name; }
    
    /** 
     * Initialize the JSPWiki Engine if not done so already.
     * Put the Plugin into the VelocityContex (is this still necessary?-Lance).
     */
    public void init(RollerRequest rreq, Context ctx)
    {
        try
        {
            if (WikiPlugin.mWikiEngine == null)
            {
                if (rreq != null && rreq.getPageContext() != null)
                {
                    WikiPlugin.mWikiEngine = WikiEngine.getInstance(
                        rreq.getPageContext().getServletConfig());
                }
            }
            if (WikiPlugin.mWikiContext == null && WikiPlugin.mWikiEngine != null)
            {
                WikiPlugin.mWikiContext = new WikiContext( 
                    WikiPlugin.mWikiEngine, WikiPlugin.mWikiPage );
            }

            if (WikiPlugin.mWikiContext != null && WikiPlugin.mWikiEngine != null)
            {
                ctx.put("wikiPlugin",this);
            }
        }
        catch (Exception e)
        {
            mLogger.error("ERROR initializing WikiPlugin",e);
        }
    }
    
    /** 
     * Convert an input string that contains text that uses JSPWiki
     * syntax to an output string in HTML format.
     * @param src Input string that uses JSPWiki syntax
     * @return Output string in HTML format.
     */
    public String render( String src )
    {
        String ret = null;        
        try
        {
            StringReader reader = new StringReader(src);            
            TranslatorReader tr = new TranslatorReader( mWikiContext, reader );
            ret = FileUtil.readContents( tr );        
        }
        catch (Exception e)
        {
            mLogger.error("ERROR rendering Wiki text",e);
        }
        return ret;
    }
    
    public String render( WeblogEntryData entry, boolean skipFlag)
    {
        return render(entry.getText());
    }
    /** Return URL to the Wiki page for a weblog entry, CamelCase style */
    public String makeCamelCaseWikiLink( WeblogEntryData wd, String prefix )
    {
        StringBuffer sb = new StringBuffer();
        StringTokenizer toker = new StringTokenizer(wd.getAnchor(),"_");
        while ( toker.hasMoreTokens() )
        {
            String token = toker.nextToken();
            sb.append( token.substring(0,1).toUpperCase() );
            sb.append( token.substring(1) );
        }
        return mWikiEngine.getBaseURL()+"Wiki.jsp?page="+prefix+sb.toString();
    }
    
    /** Return URL to the Wiki page for a weblog entry, spacey style */
    public String makeSpacedWikiLink( WeblogEntryData wd, String prefix )
    {
        StringBuffer sb = new StringBuffer();
        StringTokenizer toker = new StringTokenizer(wd.getAnchor(),"_");
        while ( toker.hasMoreTokens() )
        {
            sb.append( toker.nextToken() );
            if ( toker.hasMoreTokens() ) sb.append("%20");
        }
        return mWikiEngine.getBaseURL()+"Wiki.jsp?page="+prefix+sb.toString();
    }

    public String getName() { return name; }
    public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
}

⌨️ 快捷键说明

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