org.thymeleaf.processor
Class AbstractProcessor

Object
  extended by org.thymeleaf.processor.AbstractProcessor
All Implemented Interfaces:
Comparable<IProcessor>, IProcessor
Direct Known Subclasses:
AbstractAttrProcessor, AbstractElementProcessor, AbstractTextNodeProcessor

public abstract class AbstractProcessor
extends Object
implements IProcessor

Common abstract superclass for all processors, including utility methods for easily resolving template- and class-based externalized messages. This class also takes care of processor precedence.

Since:
2.0.0
Author:
Daniel Fernández

Constructor Summary
AbstractProcessor()
           
 
Method Summary
 int compareTo(IProcessor o)
           Compare (and therefore order) processors according to their precedence.
protected abstract  ProcessorResult doProcess(Arguments arguments, ProcessorMatchingContext processorMatchingContext, Node node)
           
protected  String getMessage(Arguments arguments, String messageKey, Object[] messageParameters)
           Resolves a message, trying to resolve it first as a template message (see getMessageForTemplate(Arguments, String, Object[])) and, if not found, as a processor message (see getMessageForProcessor(Arguments, String, Object[]).
protected  String getMessageForProcessor(Arguments arguments, String messageKey, Object[] messageParameters)
           Resolves the specified message as a processor message.
protected  String getMessageForTemplate(Arguments arguments, String messageKey, Object[] messageParameters)
           Resolves the specified message as a template message.
abstract  int getPrecedence()
           
 ProcessorResult process(Arguments arguments, ProcessorMatchingContext processorMatchingContext, Node node)
           Processes a node.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.thymeleaf.processor.IProcessor
getMatcher
 

Constructor Detail

AbstractProcessor

public AbstractProcessor()
Method Detail

getMessage

protected String getMessage(Arguments arguments,
                            String messageKey,
                            Object[] messageParameters)

Resolves a message, trying to resolve it first as a template message (see getMessageForTemplate(Arguments, String, Object[])) and, if not found, as a processor message (see getMessageForProcessor(Arguments, String, Object[]).

This method always returns a result: if no message is found for the specified key, a default placeholder message is returned (as a String).

Parameters:
arguments - the execution arguments, containing Template Engine configuration and execution context.
messageKey - the message key
messageParameters - the (optional) message parameters
Returns:
the resolved message

getMessageForTemplate

protected String getMessageForTemplate(Arguments arguments,
                                       String messageKey,
                                       Object[] messageParameters)

Resolves the specified message as a template message.

Template messages are resolved by the Message Resolver (IMessageResolver) instances configured at the Template Engine (executed in chain) in exactly the same way as, for example, a #{...} expression would when using the Standard Dialect or the SpringStandard Dialect.

This method always returns a result: if no message is found for the specified key, a default placeholder message is returned (as a String).

Parameters:
arguments - the execution arguments, containing Template Engine configuration and execution context.
messageKey - the message key
messageParameters - the (optional) message parameters
Returns:
the resolved message

getMessageForProcessor

protected String getMessageForProcessor(Arguments arguments,
                                        String messageKey,
                                        Object[] messageParameters)

Resolves the specified message as a processor message.

Processor messages appear on .properties files that usually live in the same package (i.e. source folder) as the processor class itself, and have the same base name (for example, for a com.something.MyProc processor we can have com/something/MyProc_en.properties, com/something/MyProc_es.properties, com/something/MyProc.properties (for defaults), etc.). This allows the encapsulation and packing of processors along with all of its required internationalization resources.

If no message is found for the specified key in a .properties file with the same base name as the attribute processor, then its superclasses are also examined.

This method always returns a result: if at the end no message is found for the specified key, a default placeholder message is returned (as a String).

Parameters:
arguments - the execution arguments, containing Template Engine configuration and execution context.
messageKey - the message key
messageParameters - the (optional) message parameters
Returns:
the resolved message

getPrecedence

public abstract int getPrecedence()

compareTo

public int compareTo(IProcessor o)

Compare (and therefore order) processors according to their precedence.

Be careful: This implementation of compareTo breaks (o1.compareTo(o2) == 0) == (o1.equals(o2)), as two different processors can have the same precedence.

Specified by:
compareTo in interface Comparable<IProcessor>
Parameters:
o - the object to compare to
Returns:
the comparison result

process

public final ProcessorResult process(Arguments arguments,
                                     ProcessorMatchingContext processorMatchingContext,
                                     Node node)
Description copied from interface: IProcessor

Processes a node. This node is supposed to have already positively matched this processor's applicability.

Specified by:
process in interface IProcessor
Parameters:
arguments - the Arguments object to be applied.
processorMatchingContext - the matching context.
node - the node to be processed.
Returns:
the processor result.

doProcess

protected abstract ProcessorResult doProcess(Arguments arguments,
                                             ProcessorMatchingContext processorMatchingContext,
                                             Node node)


Copyright © 2012 The THYMELEAF team. All Rights Reserved.