info.magnolia.module.templatingcomponents.freemarker
Class AbstractDirective

java.lang.Object
  extended by info.magnolia.module.templatingcomponents.freemarker.AbstractDirective
All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel, freemarker.template.TemplateModel
Direct Known Subclasses:
EditBarDirective, NewBarDirective, PageEditBarDirective, SingletonParagraphBarDirective

public abstract class AbstractDirective
extends Object
implements freemarker.template.TemplateDirectiveModel

A base class for freemarker directives used in Magnolia. Subclasses need to implement the prepareUIComponent(ServerConfiguration, AggregationState, Environment, Map, TemplateModel[], TemplateDirectiveBody) method.

Version:
$Revision: $ ($Author: $)
Author:
gjoseph

Field Summary
 
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
 
Constructor Summary
AbstractDirective()
           
 
Method Summary
protected
<MT extends freemarker.template.TemplateModel>
MT
_param(Map<String,freemarker.template.TemplateModel> params, String key, Class<MT> type, boolean isMandatory)
           
protected  boolean bool(Map<String,freemarker.template.TemplateModel> params, String key, boolean defaultValue)
           
protected  void checkBody(freemarker.template.TemplateDirectiveBody body, boolean needsBody)
          Utility method for directives who need to ensure they're used with or without a body.
protected  Content content(Map<String,freemarker.template.TemplateModel> params, String key, Content defaultValue)
           
protected  void doBody(freemarker.core.Environment env, freemarker.template.TemplateDirectiveBody body)
           
 void execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body)
           
protected  boolean mandatoryBool(Map<String,freemarker.template.TemplateModel> params, String key)
           
protected  Content mandatoryContent(Map<String,freemarker.template.TemplateModel> params, String key)
           
protected  String mandatoryString(Map<String,freemarker.template.TemplateModel> params, String key)
           
protected  List<String> mandatoryStringList(Map<String,freemarker.template.TemplateModel> params, String key)
           
protected abstract  AuthoringUiComponent prepareUIComponent(ServerConfiguration serverCfg, AggregationState aggState, freemarker.core.Environment env, Map<String,freemarker.template.TemplateModel> params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body)
          Implementations of this method should return a AuthoringUiComponent, prepared with the known parameters.
protected  String string(Map<String,freemarker.template.TemplateModel> params, String key, String defaultValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDirective

public AbstractDirective()
Method Detail

execute

public void execute(freemarker.core.Environment env,
                    Map params,
                    freemarker.template.TemplateModel[] loopVars,
                    freemarker.template.TemplateDirectiveBody body)
             throws freemarker.template.TemplateException,
                    IOException
Specified by:
execute in interface freemarker.template.TemplateDirectiveModel
Throws:
freemarker.template.TemplateException
IOException

prepareUIComponent

protected abstract AuthoringUiComponent prepareUIComponent(ServerConfiguration serverCfg,
                                                           AggregationState aggState,
                                                           freemarker.core.Environment env,
                                                           Map<String,freemarker.template.TemplateModel> params,
                                                           freemarker.template.TemplateModel[] loopVars,
                                                           freemarker.template.TemplateDirectiveBody body)
                                                    throws freemarker.template.TemplateModelException,
                                                           IOException
Implementations of this method should return a AuthoringUiComponent, prepared with the known parameters. If parameters have been grabbed using the methods provided by this class, they should be removed from the map, thus leaving an empty map once the method returns. execute(freemarker.core.Environment, java.util.Map, freemarker.template.TemplateModel[], freemarker.template.TemplateDirectiveBody) will throw a TemplateModelException if there are leftover parameters. note: The current FreeMarker implementation passes a "new" Map which we can safely manipulate. is thrown away after the execution of the directive. When no parameters are passed, the Map is readonly, but it is otherwise a regular HashMap which has been instantiated shortly before the execution of the directive. However, since this behavior is not mandated by their API, nor documented (at the time of writing, with FreeMarker 2.3.16), we should exert caution. Unit tests hopefully cover this, so we'll be safe when updating to newer FreeMarker versions.

Throws:
freemarker.template.TemplateModelException
IOException

doBody

protected void doBody(freemarker.core.Environment env,
                      freemarker.template.TemplateDirectiveBody body)
               throws freemarker.template.TemplateException,
                      IOException
Throws:
freemarker.template.TemplateException
IOException

checkBody

protected void checkBody(freemarker.template.TemplateDirectiveBody body,
                         boolean needsBody)
                  throws freemarker.template.TemplateModelException
Utility method for directives who need to ensure they're used with or without a body. If the body is *optional*, this method shouldn't be used.

Throws:
freemarker.template.TemplateModelException

mandatoryString

protected String mandatoryString(Map<String,freemarker.template.TemplateModel> params,
                                 String key)
                          throws freemarker.template.TemplateModelException
Throws:
freemarker.template.TemplateModelException

string

protected String string(Map<String,freemarker.template.TemplateModel> params,
                        String key,
                        String defaultValue)
                 throws freemarker.template.TemplateModelException
Throws:
freemarker.template.TemplateModelException

mandatoryBool

protected boolean mandatoryBool(Map<String,freemarker.template.TemplateModel> params,
                                String key)
                         throws freemarker.template.TemplateModelException
Throws:
freemarker.template.TemplateModelException

bool

protected boolean bool(Map<String,freemarker.template.TemplateModel> params,
                       String key,
                       boolean defaultValue)
                throws freemarker.template.TemplateModelException
Throws:
freemarker.template.TemplateModelException

mandatoryContent

protected Content mandatoryContent(Map<String,freemarker.template.TemplateModel> params,
                                   String key)
                            throws freemarker.template.TemplateModelException
Throws:
freemarker.template.TemplateModelException

content

protected Content content(Map<String,freemarker.template.TemplateModel> params,
                          String key,
                          Content defaultValue)
                   throws freemarker.template.TemplateModelException
Throws:
freemarker.template.TemplateModelException

mandatoryStringList

protected List<String> mandatoryStringList(Map<String,freemarker.template.TemplateModel> params,
                                           String key)
                                    throws freemarker.template.TemplateModelException
Throws:
freemarker.template.TemplateModelException

_param

protected <MT extends freemarker.template.TemplateModel> MT _param(Map<String,freemarker.template.TemplateModel> params,
                                                                   String key,
                                                                   Class<MT> type,
                                                                   boolean isMandatory)
                                                       throws freemarker.template.TemplateModelException
Throws:
freemarker.template.TemplateModelException


Copyright © 2003-2012 Magnolia International Ltd.. All Rights Reserved.