com.wm.util.template
Class Reporter

java.lang.Object
  extended by com.wm.util.coder.Coder
      extended by com.wm.util.template.Reporter

public class Reporter
extends Coder

Extends the Coder class. This class contains the methods you use to apply an output template to a specified Codable object. An output template is a character string made up of literal text and one or more tags. A tag is an instruction that causes a prescribed substitution to be performed at run time. If a tag references a variable, that variable is pulled from the Codable object to which you are applying the output template.

For a complete list of tags that the Reporter class recognizes, see the DSPs & Output Templates Developer's Guide.

See Also:
Coder, Codable

Constructor Summary
Reporter(java.lang.String stringTemplate)
          Constructs a Reporter object using the output template in the specified String.
Reporter(java.lang.String templateFile, java.io.File templateDir)
          Constructs a Reporter object using the output template in the specified file.
Reporter(java.lang.String templateFile, java.io.File templateDir, Codable input)
          Deprecated. replaced by Reporter(String, File)
Reporter(java.lang.String templateFile, java.io.File templateDir, Codable input, boolean tryCache)
          Deprecated. No replacement.
Reporter(java.lang.String templateFile, java.io.File templateDir, Codable input, boolean tryCache, java.lang.String encoding)
          Deprecated. No replacement.
Reporter(java.lang.String templateFile, java.lang.String templateDir, Codable input)
          Deprecated. replaced by Reporter(String, File)
 
Method Summary
static TemplateToken createTemplateFromFile(java.io.File tmplFile, java.lang.String fileEncoding)
          Returns a TemplateToken object from the output template in the specified file.
static TemplateToken createTemplateFromString(java.lang.String tmplString, long modTime)
          Returns a TemplateToken object from the output template in the specified String.
 void encode(java.io.OutputStream os, Values val)
          Encodes a Values object to the specified OutputStream using the format specified by this Reporter object (i.e., the format specified by the template file.)
 java.lang.String getContentType()
          Returns a String indicating the content-type supported by this Reporter object (e.g., "text/html").
 byte[] report()
          Deprecated. replaced by report(Codable)
 byte[] report(Codable input)
          Applies the output template to the specified Codable object and returns a byte array containing the result of this process.
 void reportToFile(Codable input, java.io.File target)
          Applies the output template to the specified Codable object and writes the results to the specified File.
 void reportToOutput(Codable input, java.io.OutputStream os)
          Applies the output template to the specified Codable object and writes the results to the specified OutputStream.
 void setContentType(java.lang.String cType)
          Sets the content type supported by this Reporter object.
 
Methods inherited from class com.wm.util.coder.Coder
decode, decodeFromBytes, encodeToBytes, readFromFile, readFully, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reporter

public Reporter(java.lang.String templateFile,
                java.io.File templateDir)
         throws java.io.FileNotFoundException
Constructs a Reporter object using the output template in the specified file. Use this constructor when the template that you want to apply resides in a file.

Note: When you use this constructor, you use the report(Codable) method to apply the template to your Codable object.

Parameters:
templateFile - A String specifying the name of the file containing the output template that you want this Reporter object to use. Specify only the file name portion of the file in this parameter. At run time, the Reporter will look for this file in the path specified in templateDir
templateDir - A File object that specifies the directory in which the output template file resides.
Throws:
java.io.FileNotFoundException - If the specified template file does not exist.
See Also:
report(Codable)

Reporter

public Reporter(java.lang.String stringTemplate)
Constructs a Reporter object using the output template in the specified String. Use this constructor when the template that you want to apply resides in a String in memory.

Note: When you use this constructor, you use the report(Codable) method to apply the output template to your Codable object.

Parameters:
stringTemplate - A String containing the output template that you want this Reporter object to use.
See Also:
report(Codable)

Reporter

public Reporter(java.lang.String templateFile,
                java.lang.String templateDir,
                Codable input)
         throws java.io.FileNotFoundException
Deprecated. replaced by Reporter(String, File)

Constructs a Reporter object using the output template in the specified file. Use this constructor when the template you want to work with resides in a file.

Parameters:
templateFile - A String specifying the name of the file containing the output template that you want this Reporter object to use. Specify only the file name portion of the file in this parameter. At run time, the Reporter will look for this file in the path specified in templateDir.
templateDir - A String that specifies the directory in which the output template file resides.
input - The Codable object (for example, the Values or IData object) to which you want the output template applied.
Throws:
java.io.FileNotFoundException - If the specified template file does not exist.

Reporter

public Reporter(java.lang.String templateFile,
                java.io.File templateDir,
                Codable input)
         throws java.io.FileNotFoundException
Deprecated. replaced by Reporter(String, File)

Constructs a Reporter object using the output template in the specified file. Use this constructor when the template you want to work with resides in a file.

Parameters:
templateFile - A String specifying the name of the file containing the output template that you want this Reporter object to use. Specify only the file name portion of the file in this parameter. At run time, the Reporter will look for this file in the path specified in templateDir.
templateDir - A File object specifying the directory in which the output template file resides.
input - The Codable object (for example, the Values or IData object) to which you want the output template applied.
Throws:
java.io.FileNotFoundException - If the specified template file does not exist.

Reporter

public Reporter(java.lang.String templateFile,
                java.io.File templateDir,
                Codable input,
                boolean tryCache)
         throws java.io.FileNotFoundException
Deprecated. No replacement.

Constructs a Reporter object using the output template in the specified file or in cache, if a cached version exists. Use this constructor when the template you want to work with resides in a file and you want to keep a copy of that output template in cache. (If this template will be accessed often, caching it will save time by eliminating the need to fetch it from disk every time a Reporter object uses it.)

Note: If the template file is Unicode, the output encoding will be in Unicode.

Parameters:
templateFile - A String specifying the name of the file containing the output template that you want this Reporter object to use. Specify only the file name portion of the file in this parameter. At run time, the Reporter will look for this file in the path specified in templateDir.
templateDir - A File object specifying the directory in which the output template file resides.
input - The Codable object (for example, the Values or IData object) to which you want the template applied.
tryCache - A boolean specifying whether you want this Reporter object to use cache. If you set tryCache to true, this Reporter object will check cache before attempting to retrieve the output template from a file. If the output template already resides in cache, it uses that template. If the output template does not reside in cache, it fetches that template from the specified file and caches it.
Throws:
java.io.FileNotFoundException - If the specified template file does not exist.

Reporter

public Reporter(java.lang.String templateFile,
                java.io.File templateDir,
                Codable input,
                boolean tryCache,
                java.lang.String encoding)
         throws java.io.FileNotFoundException
Deprecated. No replacement.

Constructs a Reporter object using the specified output template file and the specified encoding. Use this constructor when the template you want to work with resides in a file. Use this constructor when the template you want to work with resides in a file and you want to keep a copy of that output template in cache. (If this template will be accessed often, caching it will save time by eliminating the need to fetch it from disk every time a Reporter object uses it.)

Parameters:
templateFile - A String specifying the name of the file containing the output template that you want this Reporter object to use. Specify only the file name portion of the file in this parameter. At run time, the Reporter will look for this file in the path specified in templateDir.
templateDir - A File object specifying the directory in which the output template file resides.
input - The Codable object (for example, the Values or IData object) to which you want the output template applied.
tryCache - A boolean specifying whether you want this Reporter object to use cache. If you set tryCache to true, this Reporter object will check cache before attempting to retrieve the output template from a file. If the template already resides in cache, it uses that template. If the template does not reside in cache, it fetches that template from the specified file and caches it.
encoding - A String specifying the format that you want this Reporter object to encode the output it generates. A Java or IANA encoding name may be specified. If this parameter is null and the template file is Unicode, then the output will be in Unicode.
Throws:
java.io.FileNotFoundException - If the specified template file does not exist.
Method Detail

createTemplateFromString

public static TemplateToken createTemplateFromString(java.lang.String tmplString,
                                                     long modTime)
Returns a TemplateToken object from the output template in the specified String. A TemplateToken object represents the root of the tree of tokens parsed from the template.

Parameters:
tmplString - The String containing the output template that you want to parse.
modTime - A long value specifying the value of the date stamp that will be inserted when the $lastmod system variable is referenced within the output template. If $lastmod is not used, you can set this to 0.
Returns:
A TemplateToken object representing the root of the tree of parsed tokens.

createTemplateFromFile

public static TemplateToken createTemplateFromFile(java.io.File tmplFile,
                                                   java.lang.String fileEncoding)
                                            throws java.io.FileNotFoundException
Returns a TemplateToken object from the output template in the specified file. A TemplateToken object represents the root of the tree of tokens parsed from the output template.

Parameters:
tmplFile - A File object specifying the file in which the output template resides.
fileEncoding - A String specifying the IANA format of the output template file.
Returns:
A TemplateToken object representing the root of the tree of parsed tokens.
Throws:
java.io.FileNotFoundException - If specified template file does not exist.

report

public byte[] report()
Deprecated. replaced by report(Codable)

Applies the output template to the Codable object that was specified when this Reporter object was constructed and returns a byte array containing the result of this process. You use this method if you instantiated the Reporter object using one of the constructors that take a Codable object as in input (e.g. Reporter(String, File, Codable).

Note: All constructors that use a Codable object as input have been deprecated.

Returns:
A byte array containing the results produced by applying the output template to the Codable object.

report

public byte[] report(Codable input)
Applies the output template to the specified Codable object and returns a byte array containing the result of this process.

Parameters:
input - The Codable object to which you want the output template applied.
Returns:
a byte array containing the results produced by applying the output template to the specified Codable object.
See Also:
reportToFile(Codable, File), reportToOutput(Codable, OutputStream)

reportToFile

public void reportToFile(Codable input,
                         java.io.File target)
                  throws java.io.IOException
Applies the output template to the specified Codable object and writes the results to the specified File.

Parameters:
input - The Codable object to which you want the output template applied.
target - A File specifying the file to which the results are to be written.
Throws:
java.io.IOException - If the results cannot be written to the specified file.
See Also:
report(Codable), reportToOutput(Codable, OutputStream)

reportToOutput

public void reportToOutput(Codable input,
                           java.io.OutputStream os)
                    throws java.io.IOException
Applies the output template to the specified Codable object and writes the results to the specified OutputStream.

Parameters:
input - The Codable object to which you want the output template applied.
os - The OutputStream to which you want the results written.
Throws:
java.io.IOException - If the results cannot be written to the specified OutputStream.
See Also:
report(Codable), reportToFile(Codable, File)

encode

public void encode(java.io.OutputStream os,
                   Values val)
            throws java.io.IOException
Encodes a Values object to the specified OutputStream using the format specified by this Reporter object (i.e., the format specified by the template file.)

Specified by:
encode in class Coder
Parameters:
os - The OutputStream to which you want the encoded Values written. object.
val - The Values object that you want to encode.
Throws:
java.io.IOException - If an error occurs while writing the OutputStream.
See Also:
Coder.encodeToBytes(com.wm.util.Values), Coder.writeToFile(java.io.File, com.wm.util.Values)

getContentType

public java.lang.String getContentType()
Returns a String indicating the content-type supported by this Reporter object (e.g., "text/html").

Specified by:
getContentType in class Coder
Returns:
A String that specifies the supported content-type.

setContentType

public void setContentType(java.lang.String cType)
Sets the content type supported by this Reporter object. This method allows for support of custom content types.

Parameters:
cType - A String specifying the content type supported by this Reporter object.