jjCode
Sample Usage
Using jjCode is very easy:
- First, create an instance of org.jjcode.RenderEngine
RenderEngine engine = new RenderEngine();
- Initialize the rendering engine by calling either registerAll() - which registers all command sequences, or by calling registerHandler() for each bbCode sequence that you want to be recognized.
engine.registerAll();
//
// or
//
registerHandler(new BoldCommand());
registerHandler(new ColorCommand());
...
- Register a message provider for the engine to retrieve internationalized messages. You can use the provided BundleMessageProvider if your messages are stored in a standard resource bundle, or you can write your own class descending from MessageProvider:
engine.setMessageProvider(
new BundleMessageProvider("messages")
)
- Add the smiley sequences that you want the rendering engine to recognize using the addIcon() method. For each smiley, you must provide the character sequence, the corresponding image, and the message key for the help text associated witht hat image:
engine.addIcon( new Icon( ":-)", "images/icon_biggrin.gif", "core.jjcodes.icon.biggrin" ) );
- And this is it. To render a string, simply use any of the render() methods:
String result =
engine.render( "Hello [b]there[/b] :-)" , RenderEngine.MODE_RENDER, Locale.US );
For a full example, see the included SampleUsage.java or CreateFullList.java files.