Clone wiki / WikiModels

How to use the WikiModel


For this page we assume that we use the following code snippet with a MyWikiModel which is derived from the class or interface:

  MyWikiModel wikiModel = new MyWikiModel("${image}",
  String wikiText = "some wiki text we would like to convert to HTML";
  String htmlStr = wikiModel.render(wikiText);

How to expand templates found in a wiki text

If our model should support Transclusion (i.e. expanding templates within a document) we have to implement the IWikiModel#getRawWikiContent() method.

If we would like to expand the my template template with the text "foo" in the following string:

  wikiText = "This is a simple [[Hello World]] wiki tag {{my template}}";

our implementation method MyWikiModel#getRawWikiContent() looks something like this:

    public final static String MY_TEMPLATE = "foo";

        public String getRawWikiContent(String namespace, String articleName, Map<String, String> map) {
        String result = super.getRawWikiContent(namespace, articleName, map);
        if (result != null) {
            // found magic word template
            return result;
                // replace SPACES with underscore('_') and first character as uppercase
        String name = encodeTitleToUrl(articleName, true);
        if (isTemplateNamespace(namespace)) {
            if (name.equals("My_template")) {
                return MY_TEMPLATE;
        return null;

In the class you can find a more sophisticated example in the method getRawWikiContent(). There the template content is cached in an internal Apache Derby database. If the template is not available in the database we import it directly from a wiki which supports the Mediawiki API with the info.bliki.api.User#queryContent(String[] listOfTitleStrings) method.

The [ Magic words Variables] are not completely supported. In the you can find the currently implemented magic words variables.

How to substitute template calls

If the model should support a special substituting or extracting of template calls, which differs from the default implementation, we have to implement the IWikiModel#substituteTemplateCall(templateName, parameterTreeMap, writer) method.

Simply override the default implementation of the (or, to get your own behaviour inside your wiki model.

For example it's useful, if you would like to extract an Infobox template like this one from the Tom Hanks Wikipedia page:

{{Infobox Actor
| image         = TomHanksApr09.jpg
| caption       = Hanks in April 2009
| birthname     = Thomas Jeffrey Hanks
| birthdate     = {{birth date and age|1956|7|9}}
| birthplace = [[Concord, California]], [[United States|U.S.]]
| yearsactive   = 1979present
| occupation    = Actor, producer, director, voice over artist, writer, speaker
| spouse        = Samantha Lewes (19781987)<br>[[Rita Wilson]] (1988present)