org.apache.shindig.gadgets.templates
Class DefaultTemplateProcessor

java.lang.Object
  extended by org.apache.shindig.gadgets.templates.DefaultTemplateProcessor
All Implemented Interfaces:
TemplateProcessor

public class DefaultTemplateProcessor
extends Object
implements TemplateProcessor

Implements a DOM-based OS templates compiler. Supports: - ${...} style expressions in content and attributes - @if attribute - @repeat attribute TODO: - Handle built-in/custom tags


Field Summary
static String ATTRIBUTE_CUR
           
static String ATTRIBUTE_IF
           
static String ATTRIBUTE_INDEX
           
static String ATTRIBUTE_REPEAT
           
static String ATTRIBUTE_VAR
           
static String PROPERTY_COUNT
           
static String PROPERTY_INDEX
           
 
Constructor Summary
DefaultTemplateProcessor(Expressions expressions)
           
 
Method Summary
<T> T
evaluate(String expression, Class<T> type, T defaultValue)
          Evaluates an expression within the scope of this processor's context.
 TemplateContext getTemplateContext()
           
 void processChildNodes(Node result, Node source)
          Process the children of an element or document.
 void processRepeat(Node result, Element element, Iterable<?> dataList, Runnable onEachLoop)
           
 DocumentFragment processTemplate(Element template, TemplateContext templateContext, javax.el.ELResolver globals, TagRegistry registry)
          Process an entire template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_INDEX

public static final String PROPERTY_INDEX
See Also:
Constant Field Values

PROPERTY_COUNT

public static final String PROPERTY_COUNT
See Also:
Constant Field Values

ATTRIBUTE_IF

public static final String ATTRIBUTE_IF
See Also:
Constant Field Values

ATTRIBUTE_INDEX

public static final String ATTRIBUTE_INDEX
See Also:
Constant Field Values

ATTRIBUTE_REPEAT

public static final String ATTRIBUTE_REPEAT
See Also:
Constant Field Values

ATTRIBUTE_VAR

public static final String ATTRIBUTE_VAR
See Also:
Constant Field Values

ATTRIBUTE_CUR

public static final String ATTRIBUTE_CUR
See Also:
Constant Field Values
Constructor Detail

DefaultTemplateProcessor

@Inject
public DefaultTemplateProcessor(Expressions expressions)
Method Detail

processTemplate

public DocumentFragment processTemplate(Element template,
                                        TemplateContext templateContext,
                                        javax.el.ELResolver globals,
                                        TagRegistry registry)
Process an entire template.

Specified by:
processTemplate in interface TemplateProcessor
Parameters:
template - the DOM template, typically a script element
templateContext - a template context providing top-level variables
globals - ELResolver providing global variables other than those in the templateContext
Returns:
a document fragment with the resolved content

processChildNodes

public void processChildNodes(Node result,
                              Node source)
Process the children of an element or document.

Specified by:
processChildNodes in interface TemplateProcessor
Parameters:
result - the node to which results should be appended
source - the node whose children should be processed

getTemplateContext

public TemplateContext getTemplateContext()
Specified by:
getTemplateContext in interface TemplateProcessor
Returns:
the current template context.

processRepeat

public void processRepeat(Node result,
                          Element element,
                          Iterable<?> dataList,
                          Runnable onEachLoop)
Specified by:
processRepeat in interface TemplateProcessor
Parameters:
result -
element -
dataList -

evaluate

public <T> T evaluate(String expression,
                      Class<T> type,
                      T defaultValue)
Evaluates an expression within the scope of this processor's context.

Specified by:
evaluate in interface TemplateProcessor
Parameters:
expression - The String expression
type - Expected result type
defaultValue - Default value to return in case of error


Copyright © 2007-2012. All Rights Reserved.