[{TableOfContents}]

!!How does it all work?

To utilize the JSPWiki rendering code (i.e. the TranslatorReader), you need three things:

# __A WikiEngine instance.__  It contains all of the configuration, PageProviders, etc.
# __A WikiContext.__ The WikiContext tells the TranslatorReader things like the current page name, version, stores some WikiVariables, etc.
# __A TranslatorReader.__ This is the heavy lifter that does all of the translating.

!!How to get a WikiEngine?

{{{
public WikiEngine getEngine( HttpServletRequest request )
{
    ServletConfig config = request.getSession().getServletContext().getServletConfig();
    WikiEngine my_engine = WikiEngine.getInstance( config );
    return my_engine;
}
}}}

You can instantiate a WikiEngine through
{{{
    Properties properties = new Properties();
    // set properties
    WikiEngine my_engine = new WikiEngine( properties );
}}}

but this is not recommended, since WikiEngines should really be singletons across your application (or context - if you have different applications running in the same JVM).

After you have created a WikiEngine, you can then reuse this object all over again.  Note that there is a significant penalty in creating a WikiEngine, so you definitely want to cache this object.

!!How do I get a WikiContext?

Simple.  If you have a HttpServletRequest handy, you can just go
{{{
    WikiContext wikiContext = myWikiEngine.createContext( request, WikiContext.VIEW );
}}}

Another option is to create one for yourself with:

{{{
    WikiPage page = myWikiEngine.getPage( "SamplePage" );
    WikiContext wikiContext = new WikiContext( my_engine, page );
    wikiContext.setRequestContext( WikiContext.VIEW );
}}}

Alternatively, you can use the WikiPage constructor -method to get the WikiPage.  This is not recommended, however, because using getPage() gives you the benefits of the built-in caches.

The WikiContext holds the current rendering context.  The WikiContext is created at the beginning of the request, and discarded after the response has been sent back to the client program.  It is probably not a good idea to reuse this object.

!!How to get rendered page data?

If your page data is stored inside a JSPWiki repository, you can use the JSPWiki rendering code directly via the method ~WikiEngine.getHTML():

{{{
    String rendereddata = myWikiEngine.getHTML( wikiContext, page );
}}}

The reason why you need to respecify the WikiPage you want to render is that in some occasions you may want to render a page within the context of another page, for example, the LeftMenu wants the ReferringPagesPlugin to get the referring pages of the page are viewing, not LeftMenu.

!!How to use the TranslatorReader?

If you have just a chunk of WikiMarkup, you don't want to store it in the Wiki page repository, but you want to render it directly.  This can be accomplished by directly accessing a TranslatorReader.  After you have the WikiContext, you can simply create a new TranslatorReader by using
{{{
    TranslatorReader my_reader = new TranslatorReader( wikiContext,
                                                       new StringReader( my_page_data );
}}}

Now you can use the TranslatorReader just as if you were using any other {{java.io.Reader}}.

See the {{~FileUtil.copyContents( Reader in, Writer out)}} if you don't want to copy it all manually.

%%note
Note: You will need to call any PageFilters manually, if you are directly accessing the TranslatorReader, as normally this is done by the WikiEngine.
%%

!!How can I vary the rendering?

Take a look at the Javadoc of TranslatorReader to get the most up-to-date information, but here are some things you can do.  You can control some features by setting variables in the WikiContext before rendering, and some others by directly accessing the TranslatorReader.

!Switching off the plugin rendering

Say 
{{{
wikiContext.setVariable( TranslatorReader.PROP_RUNPLUGINS, "false" );
}}}

Alternatively, use
{{{
translatorReader.enablePlugins( false );
}}}

!Turn off image inlining

No matter what jspwiki.properties says, this turns off any image inlining.
{{{
translatorReader.enableImageInlining( false );
}}}

!!What other information can I get from the TranslatorReader?

TranslatorReader has a bunch of places where you can hook.  I'm calling them hooks, because, well, I'm an old Amiga guy, and that word just sits better with me than "Listener".  (This is a stub, more info needed.)

!Modifying link text

Hook to {{{ addLinkTransmutator() }}}

!Collecting local links

Add a listener with {{{addLocalLinkHook()}}}.

!Collecting external hyperlinks

Add a listener with {{{addExternalLinkHook()}}}.

!Collecting attachment links

Add a listener with {{{addAttachmentLinkHook()}}}.

!!What libraries (Jars) do I need?

TBA

!!How do I make JSPWiki's logging play nice with my app's Log4j setup?

TBA


;:''BTW, I am not very adept at [log4j] config, so if someone else can help me out here, it would be cool. --[JanneJalkanen].''

!!!Current known JSPWiki embedders:

* [Roller Weblogger|http://rollerweblogger.org/wiki/Wiki.jsp?page=RollerWikiPlugin]. [Sample code|http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/roller/roller/src/org/roller/presentation/velocity/plugins/jspwiki/WikiPlugin.java?rev=1.4&content-type=text/vnd.viewcvs-markup]
* [JabberMessageArchiving]
* [The Ceryle Project|http://purl.org/ceryle/]