private static final String WIKI_START_TAG = "<wiki>";
private static final String WIKI_END_TAG = "</wiki>";
public static String wikify(String content) {
InitialRenderContext renderContext = new BaseInitialRenderContext();
RenderEngine renderEngine = new RadeoxWikiRenderEngine(renderContext);
// is there work to do?
if (content == null || content.length() == 0) {
return "";
}
// this pattern says "take the shortest match you can find where there are
// one or more characters between wiki tags"
// - the match is case insensitive and DOTALL means that newlines are
// - considered as a character match
Pattern p = Pattern.compile(WIKI_START_TAG + ".+?" + WIKI_END_TAG,
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(content);
// while there are blocks to be escaped
while (m.find()) {
int start = m.start();
int end = m.end();
// grab the text, strip off the escape tags and transform it
String textToWikify = content.substring(start, end);
textToWikify = textToWikify.substring(WIKI_START_TAG.length(), textToWikify.length() - WIKI_END_TAG.length());
textToWikify = renderEngine.render(textToWikify, renderContext);
// now add it back into the original text
content = content.substring(0, start) + textToWikify + content.substring(end, content.length());
m = p.matcher(content);
}