Pease Plate is hosted by
SourceForge.net Logo

Pease Plate

Uniform Integration Pattern

Adding Pease Plate to your project is quite simple.

1. Add the Library

Using Maven

If you use Maven just add the following dependency to your pom.xml:

  • <dependency>
    • <groupId>net.sourceforge.peaseplate</groupId>
    • <artifactId>peaseplate</artifactId>
    • <version>0.9alpha2</version>
  • </dependency>

If you have problems, here are some more details...

The Classic Way

You need to get the library and integrate it into your project. Download it from the download page and ensure that the peaseplate-0.9alpha2.jar is in your classpath when compiling and running your program.

If you don't know how to do this, have a look in the Java Tutorials.

Details to the Maven Integration

Usually the dependency should work, because the repository on peaseplate.sourceforge.net gets copied to the central Maven repository on a regular basis.

Sometimes it takes a while until the newest version is available there. To obtain the dependency from the repository on peaseplate.sourceforge.net add the following fragment to your pom.xml:

  • <project>
    • ...
    • <repositories>
      • <repository>
        • <id>peaseplate-repository</id>
        • <url>http://peaseplate.sourceforge.net/repository</url>
      • </repository>
    • </repositories>
    • ...
  • </project>

If you want to use SNAPSHOT versions, you can directly access the snapshot repository:

  • <project>
    • ...
    • <repositories>
      • <repository>
        • <id>peaseplate-snapshot-repository</id>
        • <url>http://peaseplate.sourceforge.net/snapshot-repository</url>
      • </repository>
    • </repositories>
    • ...
  • </project>

2. Initialize the Factory

Create one global instance of the PeasePlateEngine. There are various ways to do this. I recommend you create a public static instance.

public static final TemplateEngine ENGINE = new PeasePlateEngine();

It is important that you execute all renderings with the same instance of the PeasePlate engine, this is because the templates will be parsed once, and then stored in the cache of the instance. The engine is thread-safe.

3. Render a Template

To render a template use the following code:

try {
ENGINE.renderTemplate(writer, object, "my.template");
} catch (TemplateException e) {
...
}

This will render the template "my.template" to the writer using the object as data object.

If parsing of the template fails, a TemplateException will be thrown. You should handle it somehow.

This is a basic example. There are numerous other render methods in the TemplateEngine.

Additionally the TemplateEngine contains a lot of global settings you can adjust when instantiating the engine.

Check the API-Doc for more information.