|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object fr.gedeon.telnetservice.OutputFormatDefaultImpl fr.gedeon.telnetservice.OutputFormatVT100Impl fr.gedeon.telnetservice.OutputFormatVelocityImpl
public abstract class OutputFormatVelocityImpl
This implementation of the OutputFormat
interface formats a given subject using a
selected Apache Velocity Engine template. For more information on the Apache Velocity Engine and
the Apache Software Foundation, please refer to the 'See Also' section below.
The template selection process is based on the class structure of the subject to be represented.
This class is abstract but does not require any method implementation, the extension mechanism is
used to provide bundle specific templates as follows:
If a class custompackage.MyOutputFormatVelocityImpl
extends
OutputFormatVelocityImpl
, the templates that are provided by this class are
located under: custompackage/vms/
in the custom bundle's domain. Subject classes
or interfaces that require a template must have a template in that location, the template for a
class or interface would be named: [package].[classname].vm. For example, the template for
java.util.List.class
in the above situation would be named in:
custompackage/vms/java.util.List.vm
The search order is as follows:
When a template is found, it is cached against all the classes and interfaces that were visited
to arrive to it, and when a lookup fails for a class that class is cached as a failed lookup
class. The caches are checked before a lengthy search operation to improve performance.
If a different template source is to be used, it is strongly recommended to override
findClassTemplate(Package, Class)
, this would allow to load the templates from a
different location while still having the caching mechanism. The same Package
/Class
pair will not be requested twice.
The template is merged with the following context entries:
sessionState.getSession().getOutputFormat()
Please be sure to read VTL (Velocity Template Language) documentation to write a template.
The following is an example template, this one is for java.lang.Iterable
:
#foreach ( $item in $subject ) $indent o $format.format($sessionState, $item, "${indent} ") #endThe template lays each item in the iterable each on a new line, and puts an indent and a bullet before it. However, it doesnt impose a format on the item, it delegates the item's representation back to the format search engine.
o
in the above with
${format.style( [ $vt100.ATTRS_FORE_RED ])}o${format.style( [ ] )}
would make the
bullet plain red on black background.$format.style()
takes an array of color attributes, those correspond to the
STYLE_*
and ATTRS_*
constants declared in
OutputFormatVT100Constants
. It is important to reset the style once it's no longer
wanted (by having a ${format.style( [ ] )}
that matches each
${format.style( [ $vt100.ATTRS_FORE_RED ])}
to avoid colors running out of the
subject's boundaries.
OutputFormatVT100Constants
,
Apache Velocity Engine site,
Apache Software Foundation siteField Summary |
---|
Fields inherited from interface fr.gedeon.telnetservice.OutputFormatVT100Constants |
---|
_DONE, _MORE, _RESET, ATTRS_BACK_BLACK, ATTRS_BACK_BLUE, ATTRS_BACK_CYAN, ATTRS_BACK_GREEN, ATTRS_BACK_MAGENTA, ATTRS_BACK_RED, ATTRS_BACK_WHITE, ATTRS_BACK_YELLOW, ATTRS_DEFAULT, ATTRS_FORE_BLACK, ATTRS_FORE_BLUE, ATTRS_FORE_CYAN, ATTRS_FORE_GREEN, ATTRS_FORE_MAGENTA, ATTRS_FORE_RED, ATTRS_FORE_WHITE, ATTRS_FORE_YELLOW, STYLE_BLINK, STYLE_BOLD, STYLE_DIM, STYLE_HIDDEN, STYLE_REVERSE, STYLE_UNDERSCORE |
Constructor Summary | |
---|---|
OutputFormatVelocityImpl()
|
Method Summary | |
---|---|
protected org.apache.velocity.Template |
findClassTemplate(Package base,
Class clazz)
|
StringBuffer |
format(SessionState sessionState,
StringBuffer buffer,
Object subject,
String indent)
Uses the velocity template associated with the given subject to append this subject's representation to the buffer. The template is given the following context: outputFormat holds this instance,
subject the subject to be represented, and
indent the suggested indent to affect each lined
|
boolean |
formats(Object subject)
Called to check if the implementation of this interface knows how to format the given subject. |
String |
toString()
|
Methods inherited from class fr.gedeon.telnetservice.OutputFormatVT100Impl |
---|
resetAttrs, resetAttrs, setAttrs, setAttrs, setAttrs, setAttrs, style, style |
Methods inherited from class fr.gedeon.telnetservice.OutputFormatDefaultImpl |
---|
format, format, format, getPriority |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface fr.gedeon.telnetservice.OutputFormatSpi |
---|
getPriority |
Methods inherited from interface fr.gedeon.telnetservice.OutputFormat |
---|
format, format, format |
Constructor Detail |
---|
public OutputFormatVelocityImpl()
Method Detail |
---|
protected org.apache.velocity.Template findClassTemplate(Package base, Class clazz)
public boolean formats(Object subject)
OutputFormatSpi
formats
in interface OutputFormatSpi
formats
in class OutputFormatDefaultImpl
true
public StringBuffer format(SessionState sessionState, StringBuffer buffer, Object subject, String indent) throws OutputFormatException
outputFormat
holds this instance,subject
the subject to be represented, andindent
the suggested indent to affect each lined
format
in interface OutputFormat
format
in class OutputFormatDefaultImpl
sessionState
- the current session statebuffer
- the caller's current buffersubject
- the subject to be representedindent
- a hint to the indent expected by the caller at the beginning of each line.
OutputFormatException
- for any errors that occur in the formatting process.public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |