org.thymeleaf.processor.attr
Class AbstractAttrProcessor

Object
  extended by org.thymeleaf.processor.attr.AbstractAttrProcessor
All Implemented Interfaces:
Comparable<IAttrProcessor>, IAttrProcessor
Direct Known Subclasses:
AbstractAttributeModifierAttrProcessor, AbstractChildrenModifierAttrProcessor, AbstractConditionalFixedValueAttrProcessor, AbstractConditionalVisibilityAttrProcessor, AbstractIterationAttrProcessor, AbstractLocalVariableDefinitionAttrProcessor, AbstractNoOpAttrProcessor, AbstractRemovalAttrProcessor, AbstractSelectionTargetAttrProcessor, AbstractTextInlinerAttrProcessor

public abstract class AbstractAttrProcessor
extends Object
implements IAttrProcessor

Base convenience implementation of IAttrProcessor returning empty sets for all of the interface's methods and allowing easy access to internationalization features by providing methods for obtaining both template messages and processor messages.

This class provides a more convenient extension point for attribute processors, allowing the developer only to override the methods that are really needed.

Since:
1.0
Author:
Daniel Fernández

Constructor Summary
AbstractAttrProcessor()
           
 
Method Summary
 int compareTo(IAttrProcessor o)
           
protected  String getMessage(Arguments arguments, TemplateResolution templateResolution, String messageKey, Object[] messageParameters)
           Resolves a message, trying to resolve it first as a template message (see getMessageForTemplate(Arguments, TemplateResolution, 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, TemplateResolution templateResolution, String messageKey, Object[] messageParameters)
           Resolves the specified message as a template message.
 Set<Class<? extends IValueProcessor>> getValueProcessorDependencies()
           Return this processor's dependencies.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.thymeleaf.processor.attr.IAttrProcessor
getAttributeApplicabilities, getPrecedence, process
 

Constructor Detail

AbstractAttrProcessor

public AbstractAttrProcessor()
Method Detail

getValueProcessorDependencies

public Set<Class<? extends IValueProcessor>> getValueProcessorDependencies()
Description copied from interface: IAttrProcessor

Return this processor's dependencies.

The dependencies are the set of value processors (IValueProcessor objects) this attribute processor needs for being executed. This has to be declared for dialect validation purposes at configuration time.

Specified by:
getValueProcessorDependencies in interface IAttrProcessor
Returns:
the set of value processor dependencies.

getMessage

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

Resolves a message, trying to resolve it first as a template message (see getMessageForTemplate(Arguments, TemplateResolution, 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.
templateResolution - the result of resolving the template by the Template Resolvers.
messageKey - the message key
messageParameters - the (optional) message parameters
Returns:
the resolved message

getMessageForTemplate

protected String getMessageForTemplate(Arguments arguments,
                                       TemplateResolution templateResolution,
                                       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.
templateResolution - the result of resolving the template by the Template Resolvers.
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

compareTo

public int compareTo(IAttrProcessor o)
Specified by:
compareTo in interface Comparable<IAttrProcessor>


Copyright © 2011 The THYMELEAF team. All Rights Reserved.