Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Minor typos

Wiki Markup
{scrollbar}

Excerpt
hiddentrue

Adding an Annotation and a Filter to customize Tapestry's page rendering

...

Most of the work has already been done for us: we just have to make a contribution to the MetaWorker service, which is already plugged into the component class transformation pipeline. MetaWorker spots the annotations we define and uses a second object, a MetaDataExtractor we provide, to convert the annotation into a meta-data value.

Code Block
languagejava
langjava
titleForbidFramingModule.java (partial)langjava
  @Contribute(MetaWorker.class)
  public static void mapAnnotationsToMetaDataValue(
      MappedConfiguration<Class, MetaDataExtractor> configuration) {
    configuration
        .add(ForbidFraming.class, new FixedExtractor<ForbidFraming>(
            FnordSymbols.FORBID_FRAMING));
  }

If the ForbidFraming annotation has had attributes, we would have provided an implementation of MetaDataExtractor that examined those attributes to set the meta-data value. Since it has no annotationsattributes, the FixedExtractor class can be used. The argument is the meta-data key, and the default value is "true".

...

We contribute into the pipeline; the order is important: since the filter will need to write JavaScript, it must be added after the built-in filter that provides the JavaScriptSupport environmental object.

Code Block
languagejava
langjava
titleForbidFramingModule.java (partial)langjava
  @Contribute(MarkupRenderer.class)
  public static void addFilter(
      OrderedConfiguration<MarkupRendererFilter> configuration) {
    configuration.addInstance("ForbidFraming", ForbidFramingFilter.class,
        "after:JavascriptSupport");
  }

...

This code makes one assumption: that the fnord application's Layout component added fnord.js to every page. That's necessary for the JavaScript that's added:

Code Block
languagejs
langjavascript
titlefnord.js (partial)langjavascript
Fnord = {
  popOutOfFrame : function() {
    if (top != self)
      top.location.replace(location);
  }
}

...