de.fu_berlin.ties.util
Class VelocityService

java.lang.Object
  extended by de.fu_berlin.ties.util.VelocityService

public final class VelocityService
extends Object

A static class that provides a convenience interface to a Velocity singletons. No instances of this class can be created, only the static members should be used.

Version:
$Revision: 1.20 $, $Date: 2006/10/21 16:04:27 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
static String ANAKIA_TEMPLATE
          Name of the main template used for Anakia XML format.
static String CONFIG_TEMPLATE
          Name of the default template used to print configuration parameters.
static String GOAL_TEMPLATE
          Name of the default template used to print goals.
static String TEMPLATE_DIR
          The template directory.
static String TEMPLATE_EXT
          The extension of template files.
 
Method Summary
static String completeTemplateName(String shortName)
          Completes the short form of a template name, by prepending the TEMPLATE_DIR and appending the TEMPLATE_EXT.
static Properties getDefaultProperties()
          Returns properties listing the changes to the Velocity configuration made by default.
static void main(String[] args)
          Main methods: prints the list of config parameters and goals from the standard configuration to specified files (or standard out).
static void printConfigProperties(TiesConfiguration config, String templateName, String charset, Map<String,Object> contextObjects, Writer writer)
          Prints all properties contained in a configuration, using the specified template for rendering.
static void printConfigProperties(TiesConfiguration config, Writer writer)
          Prints all properties contained in a configuration, using the default template for printing them.
static void printGoals(TiesConfiguration config, String templateName, String charset, Map<String,Object> contextObjects, Writer writer)
          Prints the goals contained in a configuration, using the default template for printing them.
static void printGoals(TiesConfiguration config, Writer writer)
          Prints the goals contained in a configuration, using the default template for printing them.
static void renderTemplate(String templateName, Map contextObjects, Writer writer)
          Renders a template using the given context objects.
static void renderTemplate(String templateName, String charset, Map contextObjects, Writer writer)
          Renders a template using the given context objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMPLATE_DIR

public static final String TEMPLATE_DIR
The template directory.


TEMPLATE_EXT

public static final String TEMPLATE_EXT
The extension of template files.

See Also:
Constant Field Values

CONFIG_TEMPLATE

public static final String CONFIG_TEMPLATE
Name of the default template used to print configuration parameters.


GOAL_TEMPLATE

public static final String GOAL_TEMPLATE
Name of the default template used to print goals.


ANAKIA_TEMPLATE

public static final String ANAKIA_TEMPLATE
Name of the main template used for Anakia XML format.

Method Detail

completeTemplateName

public static String completeTemplateName(String shortName)
Completes the short form of a template name, by prepending the TEMPLATE_DIR and appending the TEMPLATE_EXT.

Parameters:
shortName - the short form of the template name (without directory and extension)
Returns:
the full form of the template name, which is assumed to be in the default directory and have the default extension

getDefaultProperties

public static Properties getDefaultProperties()
Returns properties listing the changes to the Velocity configuration made by default.

Returns:
a Properties object containing the changed parameters

main

public static void main(String[] args)
Main methods: prints the list of config parameters and goals from the standard configuration to specified files (or standard out). The generated files are in Anakia XML format and uses the platform's default character set.

Parameters:
args - the command-line arguments: should contain the filename for writing the config parameters as first element and the filename for writing the goals as second element; if no filenames are given, the corresponding output is written to standard out

printConfigProperties

public static void printConfigProperties(TiesConfiguration config,
                                         String templateName,
                                         String charset,
                                         Map<String,Object> contextObjects,
                                         Writer writer)
                                  throws IOException,
                                         org.apache.velocity.exception.VelocityException
Prints all properties contained in a configuration, using the specified template for rendering. In addition to the user-specified context objects (if any), the template has access to a collection $allParameters of all config parameters.

Parameters:
config - the configuration to print
templateName - name of template to be used in merge, either in short form (without directory and extension, when default directory and extension are used) or in complete form
charset - the character set used in the template
contextObjects - a map of objects that are made available in the context of the template; might be null
writer - the writer to write the output to; the writer is flushed but not closed by this method
Throws:
IOException - if an I/O error occurred
org.apache.velocity.exception.VelocityException - if rendering failed

printConfigProperties

public static void printConfigProperties(TiesConfiguration config,
                                         Writer writer)
                                  throws IOException,
                                         org.apache.velocity.exception.VelocityException
Prints all properties contained in a configuration, using the default template for printing them. This templates generates an (X)HTML fragment listing all configuration parameters with their types and default values in a table.

Parameters:
config - the configuration to print
writer - the writer to write the output to; the writer is flushed but not closed by this method
Throws:
IOException - if an I/O error occurred
org.apache.velocity.exception.VelocityException - if rendering failed

printGoals

public static void printGoals(TiesConfiguration config,
                              String templateName,
                              String charset,
                              Map<String,Object> contextObjects,
                              Writer writer)
                       throws IOException,
                              org.apache.velocity.exception.VelocityException
Prints the goals contained in a configuration, using the default template for printing them. In addition to the user-specified context objects (if any), the template has access to a collection $allParameters of all goals.

Parameters:
config - the configuration to print
templateName - name of template to be used in merge, either in short form (without directory and extension, when default directory and extension are used) or in complete form
charset - the character set used in the template
contextObjects - a map of objects that are made available in the context of the template; might be null
writer - the writer to write the output to; the writer is flushed but not closed by this method
Throws:
IOException - if an I/O error occurred
org.apache.velocity.exception.VelocityException - if rendering failed

printGoals

public static void printGoals(TiesConfiguration config,
                              Writer writer)
                       throws IOException,
                              org.apache.velocity.exception.VelocityException
Prints the goals contained in a configuration, using the default template for printing them. This templates generates an (X)HTML fragment listing all goals with their output extension (if given) and any further arguments in a table.

Parameters:
config - the configuration to print
writer - the writer to write the output to; the writer is flushed but not closed by this method
Throws:
IOException - if an I/O error occurred
org.apache.velocity.exception.VelocityException - if rendering failed

renderTemplate

public static void renderTemplate(String templateName,
                                  Map contextObjects,
                                  Writer writer)
                           throws IOException,
                                  org.apache.velocity.exception.VelocityException
Renders a template using the given context objects. The template must be in the standard Unicode character set (UFT-8).

Parameters:
templateName - name of template to be used in merge, either in short form (without directory and extension, when default directory and extension are used) or in complete form
contextObjects - a map of objects that are made available in the context of the template; mappings from "escapeTool" to a StringEscapeUtils and from "util" to a Util are added to allow XML entity escaping, String conversion etc.
writer - writer to write template into; the writer is flushed but not closed by this method
Throws:
IOException - if an I/O error occurred
org.apache.velocity.exception.VelocityException - if rendering failed

renderTemplate

public static void renderTemplate(String templateName,
                                  String charset,
                                  Map contextObjects,
                                  Writer writer)
                           throws IOException,
                                  org.apache.velocity.exception.VelocityException
Renders a template using the given context objects.

Parameters:
templateName - name of template to be used in merge, either in short form (without directory and extension, when default directory and extension are used) or in complete form
charset - the character set used in template
contextObjects - a map of objects that are made available in the context of the template; mappings from "escapeTool" to a StringEscapeUtils and from "util" to a Util are added to allow XML entity escaping, String conversion etc.
writer - writer to write template into; the writer is flushed but not closed by this method
Throws:
IOException - if an I/O error occurred
org.apache.velocity.exception.VelocityException - if rendering failed


Copyright © 2003-2007 Christian Siefkes. All Rights Reserved.