Integration with Velocity or FreeMarker

Velocity and FreeMarker are quite similar and serve similar needs, they are discussed together in this section.

Hint:
This part of the documentation is just for those who are familiar with Velocity or FreeMarker. It's just a hint for an approach on how to use the Java Integration Pack with these template engines!

The required jars are velocity-1.x.x.jar or freemarker-2.x.jar in order to work with Velocity or FreeMarker respectively and commons-collections.jar also has to be available for Velocity. Drop the required jar files in your classpath (usually WEB-INF/lib).

The main class that builds the HTML for the editor is net.fckeditor.FCKeditor. We propose to write a wrapper object to initialize the FCKeditor object.
Take a look at this very simple example:

public class FCKeditorWrapper {
  private HttpServletRequest request;

  public FCKeditorWrapper(final HttpServletRequest request) {
    this.request = request;
  }

  public String get(final String instanceName, final String value) {
    FCKeditor editor = new FCKeditor(request, instanceName);
    editor.setValue(value);
    return editor.createHtml();
  }
}

Let's assume you add a FCKeditorWrapper instance called editor to your context objects, then you just need the following minimal template example (Velocity):

<form method="post" action="[servlet path]">
   $editor.get("DefaultEditor", "Some text");
   <input type="submit" value="OK" />
</form>