com.gridsystems.config.tools
Class Template

java.lang.Object
  extended by com.gridsystems.config.tools.Template

public class Template
extends java.lang.Object

Simple template implementation.

Instances of this class use a template file as its source, with an optional default template located in the classpath.

Version:
1.0
Author:
Rodrigo Ruiz Aguayo

Constructor Summary
Template(java.io.File f)
          Creates a template using the specified file as the source.
Template(java.io.File f, java.lang.String resourceName)
          Creates a template using the specified file as the source.
Template(java.io.File f, java.net.URL url)
          Create a template using the specified file and URL as the template source, and its default source respectively.
 
Method Summary
 void printTo(java.util.Properties props, java.io.PrintWriter out)
          Writes the tamplate into the specified writer, replacing all found keys in the template text with the values in the props argument.
 void writeTo(java.util.Properties props, java.io.File f)
          Writes the template to the specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Template

public Template(java.io.File f)
         throws java.io.IOException
Creates a template using the specified file as the source. It will search for a default template with the same name as the file.

Parameters:
f - The source template file
Throws:
java.io.IOException - In case of error handling resources

Template

public Template(java.io.File f,
                java.lang.String resourceName)
         throws java.io.IOException
Creates a template using the specified file as the source.

Parameters:
f - The file of the template source
resourceName - The default template source as a resource name
Throws:
java.io.IOException - In case of error handling resources

Template

public Template(java.io.File f,
                java.net.URL url)
         throws java.io.IOException
Create a template using the specified file and URL as the template source, and its default source respectively.

If the file is not found, it will be created as a copy of the specified default. This way, anyone can modify the template, and turning back to the default will be as simple as deleting the file.

Parameters:
f - The template source file
url - The URL of the default template source
Throws:
java.io.IOException - In case of error handling resources
Method Detail

writeTo

public void writeTo(java.util.Properties props,
                    java.io.File f)
             throws java.io.IOException
Writes the template to the specified file. The props argument contains the list of replacements to apply to the template

Parameters:
props - The replacements to perform
f - The destination file
Throws:
java.io.IOException - In case of I/O error

printTo

public void printTo(java.util.Properties props,
                    java.io.PrintWriter out)
             throws java.io.IOException
Writes the tamplate into the specified writer, replacing all found keys in the template text with the values in the props argument.

A key in the template has the following syntax: ${key}

Parameters:
props - The replacement list
out - The writer
Throws:
java.io.IOException - In case of I/O error


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.