@header@
Blog Entry Decorators

Blog entry decorators are a type of Pebble plugin that allow you to extend the way that blog entries are displayed in the HTML pages of your blog and the XML newsfeeds that are generated. The following features have been externalized into decorators and are included in the distribution.

  • pebble.decorator.HtmlDecorator - filters the HTML comments/TrackBacks and allows blog entries to be rendered as HTML.
  • pebble.decorator.EscapeMarkupDecorator - escapes HTML markup between <escape> tags (like this except that the tags are maintained and simply decorated out at runtime)
  • pebble.decorator.RelativeUriDecorator - replaces relative URIs with absolute URLs so that they are rendered properly in browsers and newsreaders (Pebble currently does this but it's hardcoded)
  • pebble.decorator.DisableResponseDecorator - disables comments and TrackBacks for the blog entry (useful if you are worried about spam when you don't have access to your blog, such as on holiday)

To write your own custom decorator, you need to write a Java class that implements the pebble.decorator.BlogEntryDecorator interface. A default implementation is also available to subclass from called pebble.decorator.BlogEntryDecoratorSupport.

The code for the DisableResponseDecorator is shown here as an example.

  package pebble.decorator;

  import pebble.blog.BlogEntry;

  /**
   * Disables comments and TrackBacks for the blog entry.
   *
   * @author Simon Brown
   */
  public class DisableResponseDecorator extends BlogEntryDecoratorSupport {

    /**
     * Executes the logic associated with this decorator.
     *
     * @param chain   the chain of BlogEntryDecorators to apply
     * @param context     the context in which the decoration is running
     * @throws BlogEntryDecoratorException
     *          if something goes wrong when running the decorator
     */
    public void decorate(BlogEntryDecoratorChain chain, BlogEntryDecoratorContext context)
        throws BlogEntryDecoratorException {
      BlogEntry blogEntry = context.getBlogEntry();
      blogEntry.setCommentsEnabled(false);
      blogEntry.setTrackBacksEnabled(false);

      chain.decorate(context);
    }

    /**
     * Gets the name of this decorator.
     *
     * @return the name of this decorator as a String
     */
    public String getName() {
      return "Disable response decorator";
    }

  }

@footer@