Collaboration API Documentation

com.filenet.bso.api.collaboration
Class TextTemplate

java.lang.Object
  |
  +--com.filenet.bso.api.collaboration.TextTemplate
All Implemented Interfaces:
com.filenet.bso.api.collaboration.impl.templates.TemplateInclude

public class TextTemplate
extends java.lang.Object
implements com.filenet.bso.api.collaboration.impl.templates.TemplateInclude

The TextTemplate class uses a text template and a map of parameters, interprets the template looking for special template instructions, and returns the result either as a stream, string or message.

To use it, use code like this

      // set up parameters for template

      HashMap params = new HashMap();
      params.put("doc", doc);
      params.put("folder", folder);
      params.put("time", time());

      TextTemplate tt = new TextTemplate(store, null, null);

      // interpret the template

      InputStream in = tt.getStream("mytemplate", params);
 

The application ID and time zone information are not required; if not available, the application ID is determined from the store's session and the time zone from either the application ID, or, if not found, from the server. Normally, the application ID affects which localized template file is selected and both the locale and the time zone affect some formatting, but certain installations might all be in the same locale and time zone or the template might be written in such a way that this is not significant.


Constructor Summary
TextTemplate(com.filenet.wcm.api.ObjectStore store, java.lang.String applicationID, java.util.TimeZone timeZone)
          Construct a TextTemplate instance.
 
Method Summary
 java.lang.String getApplicationID()
          Return the current application ID.
 BsoByteArrayWithCharset getInclude(java.lang.String name, java.lang.String applicationID)
          Return a byte array representing the text of a template include.
 boolean getIsDebug()
          Return whether debugging mode is currently set or not.
 byte[] getMessageBytes()
          Return an array of bytes for the raw form of the message.
 com.filenet.wcm.api.TransportInputStream getStream()
          Return a JavaAPI TransportInputStream for a recently parsed template.
 com.filenet.wcm.api.TransportInputStream getStream(int templateCode, java.util.Map parameters)
          Return a JavaAPI TransportInputStream representing the interpretation of a template given its template code and parameters.
 com.filenet.wcm.api.TransportInputStream getStream(java.lang.String templateName, java.util.Map parameters)
          Return a JavaAPI TransportInputStream representing the interpretation of a template given its template name and parameters.
 java.lang.String getString()
          Return a string from the parsed template.
 java.lang.String getString(int templateCode, java.util.Map parameters)
          Return a string created using a template code and parameters.
 java.lang.String getString(java.lang.String templateName, java.util.Map parameters)
          Return a string created using a template name and parameters.
 void parse(BsoByteArrayWithCharset templ, java.lang.String templateName, java.util.Map parameters, java.util.Map extra, java.util.TimeZone timeZone, java.util.Map appMap)
          Parse the template given its byte array.
 void parse(int templateCode, java.util.Map parameters, java.util.Map extra, java.util.TimeZone timeZone, java.util.Map appMap)
          Parse the template represented by a template code.
 void parse(java.lang.String templateName, java.util.Map parameters, java.util.Map extra, java.util.TimeZone timeZone, java.util.Map appMap)
          Parse the template given its name.
 void setApplicationID(java.lang.String applicationID)
          Set the application ID, which is used in looking up the correct template and also to find "localized" versions of the same application for locale lookups.
 void setIsDebug(boolean isDebug)
          Set or clear debugging mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextTemplate

public TextTemplate(com.filenet.wcm.api.ObjectStore store,
                    java.lang.String applicationID,
                    java.util.TimeZone timeZone)
Construct a TextTemplate instance.
Parameters:
store - the object store where collaboration email information can be found
applicationID - the name of the application. This will also be used to find different localized versions of the same application. This may be null, in which case the appID of the store's JavaAPI session is used instead.
Method Detail

getApplicationID

public java.lang.String getApplicationID()
Return the current application ID.
Returns:
the application ID

setApplicationID

public void setApplicationID(java.lang.String applicationID)
Set the application ID, which is used in looking up the correct template and also to find "localized" versions of the same application for locale lookups. This also gets the group of this appID as well as the default time zone. If the appID is null, then the appID of the object store's JavaAPI session is used instead.
Parameters:
applicationID - the new application ID to use

getIsDebug

public boolean getIsDebug()
Return whether debugging mode is currently set or not.
Returns:
true if in debugging mode, false otherwise

setIsDebug

public void setIsDebug(boolean isDebug)
Set or clear debugging mode.
Parameters:
isDebug - if true, sets debugging mode; if false, resets it

getInclude

public BsoByteArrayWithCharset getInclude(java.lang.String name,
                                          java.lang.String applicationID)
Return a byte array representing the text of a template include. This method is a callback, used whenever the template encounters an {$include:"xyz.txt"} command.
Specified by:
getInclude in interface com.filenet.bso.api.collaboration.impl.templates.TemplateInclude
Parameters:
name - the name of the include/template file
applicationID - the name of the application (used during template lookup)
Returns:
the byte array for the template include

parse

public void parse(int templateCode,
                  java.util.Map parameters,
                  java.util.Map extra,
                  java.util.TimeZone timeZone,
                  java.util.Map appMap)
           throws TemplateException
Parse the template represented by a template code. After parsing, use one of getString, getStream or getMessage to retrieve the parsed template.
Parameters:
templateCode - the code number for the template (see Collaboration are a list of the codes)
parameters - the parameters to use with the template
extra - extra parameters that will be combined with parameters (may be null)
timeZone - the time zone to use (may be null if the default should be used)
appMap - the application map to use (may be null)

parse

public void parse(java.lang.String templateName,
                  java.util.Map parameters,
                  java.util.Map extra,
                  java.util.TimeZone timeZone,
                  java.util.Map appMap)
           throws TemplateException
Parse the template given its name. After parsing, use one of getString, getStream or getMessage to retrieve the parsed template.
Parameters:
templateName - the code number for the template (see Collaboration are a list of the codes)
parameters - the parameters to use with the template
extra - extra parameters that will be combined with parameters (may be null)
timeZone - the time zone to use (may be null)
appMap - the application map to use (may be null)

parse

public void parse(BsoByteArrayWithCharset templ,
                  java.lang.String templateName,
                  java.util.Map parameters,
                  java.util.Map extra,
                  java.util.TimeZone timeZone,
                  java.util.Map appMap)
           throws TemplateException
Parse the template given its byte array. After parsing, use one of getString, getStream or getMessage to retrieve the parsed template.
Parameters:
templ - the byte array for this template with its charset, if known
templateName - the name of the template (may be null)
parameters - the parameters to use with the template
extra - extra parameters that will be combined with parameters (may be null)
timeZone - the time zone to use (may be null)
appMap - the application map to use (may be null)

getStream

public com.filenet.wcm.api.TransportInputStream getStream(int templateCode,
                                                          java.util.Map parameters)
Return a JavaAPI TransportInputStream representing the interpretation of a template given its template code and parameters. This is a convenience routine that first calls parse before getting the stream.
Parameters:
templateCode - the code for this template
parameters - values to use when interpreting the template
Returns:
a stream generated by interpreting the template
Throws:
TemplateException - if anything goes awry

getStream

public com.filenet.wcm.api.TransportInputStream getStream(java.lang.String templateName,
                                                          java.util.Map parameters)
Return a JavaAPI TransportInputStream representing the interpretation of a template given its template name and parameters. This is a convenience routine that first calls parse before getting the stream.
Parameters:
templateName - the name of the template on the CE
parameters - values to use when interpreting the template
Returns:
a stream generated by interpreting the template
Throws:
TemplateException - if anything goes awry

getStream

public com.filenet.wcm.api.TransportInputStream getStream()
Return a JavaAPI TransportInputStream for a recently parsed template. One of the parse methods must be called before calling this method. The template must only generate a single section (plain, HTML or attachment) or an exception will be thrown.
Returns:
a stream for the results of the template
Throws:
TemplateException - if anything goes awry

getString

public java.lang.String getString(int templateCode,
                                  java.util.Map parameters)
Return a string created using a template code and parameters. This is a convenience routine that first calls parse before getting the string.
Parameters:
templateCode - the template code to use
parameters - values to use when interpreting the template
Returns:
a string created from the template

getString

public java.lang.String getString(java.lang.String templateName,
                                  java.util.Map parameters)
Return a string created using a template name and parameters. This is a convenience routine that first calls parse before getting the string.
Parameters:
templateName - the name of the template to use
parameters - values to use when interpreting the template
Returns:
a string created from the template

getString

public java.lang.String getString()
Return a string from the parsed template. One of the parse methods must be called before using this method. The template must only generate a single section (plain, HTML or attachment) or an exception will be thrown.
Returns:
a string created from the template

getMessageBytes

public byte[] getMessageBytes()
Return an array of bytes for the raw form of the message. The from and message-id headers will be filled in, but the to, cc, date, reply-to and possibly the subject mail headers will not be set in this raw message. One of the parse methods should be called before calling this method.
Returns:
the array of bytes for the raw message derived from the template

Collaboration API Documentation

Copyright ?2002 - 2005 FileNet Corporation. All rights reserved.