How to use Confluence style wiki

Since release 2.4, a new set of features are now available with the Confluence wiki markup. Now we can use Jease as a wiki and have simple links between pages. A lot of the markup is taken care of by the renderer, however links are dependent on the system used. The idea is to keep the markup simple and compatible with Confluence.

A link in Confluence might look like the following:

[My page name], renders as "My page name"
[Some other name|My page name], renders as "Some other name"
[http://www.google.com], renders as http://www.google.com

So the links are kept to their simplest notation. External links are taken care of already, but we need some magic to make the internal one working.

Setup the default wiki markup

The first thing is to configure the default wiki markup. This is done by configuring a system parameter named JEASE_WIKI_LANGUAGE with a value of Confluence. Other values are available:

  • MediaWiki
  • Textile
  • TracWiki
  • TWiki

When a link get's rendered from wiki markup to HTML, the A anchor needs to have something to indicate how to process it. This is done by configuring another system parameter named *JEASE_WIKI_LINKS* with the value /display?pageName={0}. I selected display because it matches the one used in Confluence.

The {0} part will be replace dynamically by the name of the page between the square bracket.

This handler will be call when the user selects the link. The page name will be added to the handler call. The handler will query the database, retrieve the correct path to the page and forward the request, and the page gets displayed

At the root of the site, create a script object. Use display for the Id and the Title. Add the following code to it.

<%@page import="java.util.*,jfix.util.*,jfix.db4o.*,jfix.functor.*,jease.cms.domain.*,jease.site.*"%>

<%
  final String originalPageName = request.getParameter("pageName");

  int tokenPosition = originalPageName.indexOf ('#');
  
  final String pageName = (tokenPosition >= 0)? originalPageName.substring(0, tokenPosition): originalPageName ;
  
  String anchor = "";
    
 if (tokenPosition >=0)
    {
    anchor = originalPageName.substring(tokenPosition);
    }
    
  List<Content> contentList = Database.query(Content.class, 
    new Predicate<Content>() 
    {
      public boolean test(Content content) 
        {
        return pageName.equals(content.getTitle());
        }
    });

// Found one macthing result. Display page
if (contentList.size() == 1)
    {
    pageContext.forward(contentList.get(0).getPath() + anchor);
    }

// Found mulitple results or none. Display a pager list
else
    {
    request.setAttribute("contentList", contentList);
    pageContext.forward("/displayException");
    }
%>

There are two possible situation where the page cannot be located: when it does not exist and when there is more than one page with the same name. The exception handler will take care of this.

  • Page not found: Displays a nice message
  • Multiple pages: Show the list of pages and their paths. The user can then select the most appropriate one

At the root of the site, create a script object. Use displayException for the Id and the Title. Add the following code to it.

<%@page import="java.util.*,jfix.util.*,jfix.db4o.*,jfix.functor.*,jease.cms.domain.*,jease.site.*"%>

<%

List<Content> contentList = (List<Content>) request.getAttribute("contentList");

if (!contentList.isEmpty()) 
    {
    request.setAttribute("Pager.Scope", "search");
    request.setAttribute("Pager.Contents", contentList);
    request.setAttribute("Pager.Renderer",
        "/site/service/pager/Searchresult.jsp");    
    pageContext.include("/site/service/pager/Pager.jsp");
    }
    // No result found. Display error message    
   else 
    {
%>
<p><%=I18N.get("No_results")%>.</p>
<% } %>  

Try it!

Now you should have everything ready to try this.

Create a wiki page. In it add a link to any other page from your site (yup, it work with any type of page). Save it and click on the link...voila!

Last modified on 2011-09-13 by Patrick Boisclair

Java with Ease

Java is a very productive development environment if you choose and combine the right tools and patterns.

Jease is the result of my personal quest bringing tools and patterns together which make the life of a web-developer as simple as it can be.