KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > velocity > plugins > textile > TextilePlugin


1
2 package org.roller.presentation.velocity.plugins.textile;
3
4 import org.apache.commons.lang.StringEscapeUtils;
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.apache.velocity.context.Context;
8 import org.roller.pojos.WeblogEntryData;
9 import org.roller.presentation.RollerRequest;
10 import org.roller.presentation.velocity.PagePlugin;
11
12 /**
13  * @author David M Johnson
14  */

15 public class TextilePlugin implements PagePlugin
16 {
17     public String JavaDoc name = "Textile Formatter";
18     public String JavaDoc description = "Allows use of Textile formatting to easily " +
19         "generate HTML. See the <a HREF='http://textism.com/tools/textile' target='textile'>Textile</a> site.";
20
21     public String JavaDoc toString() { return name; }
22     
23     private net.sf.textile4j.Textile mTextile = new net.sf.textile4j.Textile();
24     
25     private static Log mLogger =
26        LogFactory.getFactory().getInstance(TextilePlugin.class);
27     
28     public TextilePlugin()
29     {
30         mLogger.debug("Textile Plugin instantiated.");
31     }
32     
33     /**
34      * Put plugin into the page context so templates may access it.
35      */

36     public void init(RollerRequest rreq, Context ctx)
37     {
38         ctx.put("textileRenderer",this);
39     }
40     
41     /**
42      * Convert an input string that contains text that uses the Textile
43      * syntax to an output string in HTML format.
44      * @param src Input string that uses Textile syntax
45      * @return Output string in HTML format.
46      */

47     public String JavaDoc render( String JavaDoc src )
48     {
49         return mTextile.process(src);
50     }
51     
52     public String JavaDoc render( WeblogEntryData entry, boolean skipFlag )
53     {
54         return render( entry.getText() );
55     }
56
57     public String JavaDoc getName() { return name; }
58     public String JavaDoc getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
59 }
60
Popular Tags