com.instantbank.component.lettertemplate.util
Class Template

java.lang.Object
  |
  +--com.instantbank.component.lettertemplate.util.Template
All Implemented Interfaces:
LetterViewable, java.io.Serializable

public class Template
extends java.lang.Object
implements java.io.Serializable, LetterViewable

In memory representation of a letter template.

Author:
InstantBank (Rodrigo Lopez)
See Also:
Serialized Form

Field Summary
private  LetterComponent body
          The body component.
private  int bottomMargin
          Bottom margin (in twips = 1/1440 inches).
private  long category
          The category code (for the template) in the data base.
private  LetterComponent closing
          The closing component.
private  long code
          The Template code in the data base.
private  LetterComponent header
          The header component.
static int LASER
          Integer code for the LASER print type.
private  int leftMargin
          Left margin (in twips = 1/1440 inches).
private  java.lang.String name
          The name of the template
static int NEW_COMPONENT
          The template has changed one of its components.
static int OK
          The template can be saved without worrying about its components.
private  int printType
          The print type: LASER/TYPEWRITTER
private  int rightMargin
          Right margin (in twips = 1/1440 inches).
 int saveStatus
          Save status for the template: OK or NEW_COMPONENT.
private  java.lang.String stamp
          The time stamp of the last time the template was saved.
private  int topMargin
          Top margin (in twips = 1/1440 inches).
static int TYPEWRITTER
          Integer code for the TYPEWRITTER print type.
 
Constructor Summary
Template(int printType)
          Basic constructor used to initialize the Template when the editor starts.
Template(long code, java.lang.String name, long category, int printType, LetterComponent header, LetterComponent body, LetterComponent closing, java.lang.String timeStamp, int leftMargin, int rightMargin, int topMargin, int bottomMargin)
          Big constructor, defines explicitly all the attributes of the Template.
 
Method Summary
private  java.lang.String buildRtfMargins()
           
 java.lang.String codesToString()
          Produces a human readable/printable version of the code, name and stamp attributes of this template and its components.
 java.lang.String extractRtf()
          Produces the append of the rtf text contained in the header, body and closing of this template.
 java.util.ArrayList[] getAllImages()
          Produces an array with information of images, in ascending order through all the text.
 java.util.ArrayList[] getAllVariables()
          Produces an array with information of variables, in ascending order through all the text.
 LetterComponent getBody()
          Getter method for body
 int getBottomMargin()
          Getter method for bottomMargin
 long getCategory()
          Getter method for category
 LetterComponent getClosing()
          Getter method for closing
 long getCode()
          Getter method for code
 LetterComponent getComponent(int compType)
          Gets a component of the template from its type.
 LetterComponent getHeader()
          Getter method for header
 int getLeftMargin()
          Getter method for leftMargin
 java.lang.String getName()
          Getter method for name
 int getPrintType()
          Getter method for printType
 int getRightMargin()
          Getter method for rightMargin
 int getSaveStatus()
          Getter methos for saveStatus.
 java.lang.String getStamp()
          Getter method for stamp
 int getTopMargin()
          Getter method for topMargin
 boolean hasChanged()
          Test if this template has changed; i.e, if any of its components has changed.
 boolean hasImages()
          Tests if this template contains images.
 boolean hasVariables()
          Tests if this template contains variables.
 void outOfDate()
          Sets to true all of its component's "hasChanged" attribute.
 void setBody(LetterComponent cmp)
          Setter method for body
 void setBottomMargin(int twips)
          Setter method for Margin
 void setCategory(long c)
          Setter method for category
 void setClosing(LetterComponent cmp)
          Setter method for closing
 void setCode(long code)
          Setter method for code
 void setComponent(int compType, LetterComponent comp)
          Changes a template's component.
 void setHeader(LetterComponent cmp)
          Setter method for header
 void setLeftMargin(int twips)
          Setter method for leftMargin
 void setName(java.lang.String nm)
          Setter method for name
 java.util.ArrayList[] setOfVariables()
          Calculates the set --without repetitions-- of codes of variables mentioned in any of the components of this template.
 void setPrintType(int p)
          Setter method for printType
 void setRightMargin(int twips)
          Setter method for rightMargin
 void setSaveStatus(int status)
          Setter method for saveStatus
 void setStamp(java.lang.String s)
          Setter method for stamp
 void setTopMargin(int twips)
          Setter method for topMargin
 java.lang.String toFoTemplate()
          Transform this LetterTemplate in a "fo-template" without external references to image files.
 void upToDate()
          Sets to false all of its component's "hasChanged" attribute.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

LASER

public static final int LASER
Integer code for the LASER print type.

TYPEWRITTER

public static final int TYPEWRITTER
Integer code for the TYPEWRITTER print type.

OK

public static final int OK
The template can be saved without worrying about its components.

NEW_COMPONENT

public static final int NEW_COMPONENT
The template has changed one of its components.

header

private LetterComponent header
The header component.

body

private LetterComponent body
The body component.

closing

private LetterComponent closing
The closing component.

name

private java.lang.String name
The name of the template

code

private long code
The Template code in the data base.

category

private long category
The category code (for the template) in the data base.

printType

private int printType
The print type: LASER/TYPEWRITTER

stamp

private java.lang.String stamp
The time stamp of the last time the template was saved.

saveStatus

public int saveStatus
Save status for the template: OK or NEW_COMPONENT.

leftMargin

private int leftMargin
Left margin (in twips = 1/1440 inches).

rightMargin

private int rightMargin
Right margin (in twips = 1/1440 inches).

topMargin

private int topMargin
Top margin (in twips = 1/1440 inches).

bottomMargin

private int bottomMargin
Bottom margin (in twips = 1/1440 inches).
Constructor Detail

Template

public Template(int printType)
Basic constructor used to initialize the Template when the editor starts.
Parameters:
printType - The print type: LASER, TYPEWRITER.

Template

public Template(long code,
                java.lang.String name,
                long category,
                int printType,
                LetterComponent header,
                LetterComponent body,
                LetterComponent closing,
                java.lang.String timeStamp,
                int leftMargin,
                int rightMargin,
                int topMargin,
                int bottomMargin)
Big constructor, defines explicitly all the attributes of the Template.
Parameters:
code - Template's code
name - Template's description
category - Template's category
printType - Print type (lase, typewriter)
header - Header component
body - Body component
closing - Closing component
timeStamp - Time stamp when this template was saved for the last time.
leftMargin - Left margin when printed/previewed (in twips)
rightMargin - Left margin when printed/previewed (in twips)
topMargin - Left margin when printed/previewed (in twips)
bottomMargin - Left margin when printed/previewed (in twips)
Method Detail

getCode

public long getCode()
Getter method for code
Specified by:
getCode in interface LetterViewable
Returns:
The code value

setCode

public void setCode(long code)
Setter method for code
Parameters:
code - The new code value

getCategory

public long getCategory()
Getter method for category
Returns:
The category value

setCategory

public void setCategory(long c)
Setter method for category
Parameters:
c - The new category value

getPrintType

public int getPrintType()
Getter method for printType
Specified by:
getPrintType in interface LetterViewable
Returns:
The printType value

setPrintType

public void setPrintType(int p)
Setter method for printType
Parameters:
p - The new printType value

getName

public java.lang.String getName()
Getter method for name
Specified by:
getName in interface LetterViewable
Returns:
The name value

setName

public void setName(java.lang.String nm)
Setter method for name
Parameters:
nm - The new name value

getHeader

public LetterComponent getHeader()
Getter method for header
Returns:
The header value

setHeader

public void setHeader(LetterComponent cmp)
Setter method for header
Parameters:
cmp - The new header value

getBody

public LetterComponent getBody()
Getter method for body
Returns:
The body value

setBody

public void setBody(LetterComponent cmp)
Setter method for body
Parameters:
cmp - The new body value

getClosing

public LetterComponent getClosing()
Getter method for closing
Returns:
The closing value

setClosing

public void setClosing(LetterComponent cmp)
Setter method for closing
Parameters:
cmp - The new closing value

getStamp

public java.lang.String getStamp()
Getter method for stamp
Returns:
The stamp value

setStamp

public void setStamp(java.lang.String s)
Setter method for stamp
Parameters:
s - The new stamp value

getSaveStatus

public int getSaveStatus()
Getter methos for saveStatus.
Returns:
The saveStatus value

setSaveStatus

public void setSaveStatus(int status)
Setter method for saveStatus
Parameters:
status - The new saveStatus value

getComponent

public LetterComponent getComponent(int compType)
Gets a component of the template from its type.
Parameters:
compType - Type of the component: LetterComponent.HEADER, LetterComponent.BODY, LetterComponent.CLOSING.
Returns:
The component value

setComponent

public void setComponent(int compType,
                         LetterComponent comp)
Changes a template's component.
Parameters:
compType - The type of the component to be changed: LetterComponent.HEADER, LetterComponent.BODY, LetterComponent.CLOSING.
comp - The component that replaces the original one.

getLeftMargin

public int getLeftMargin()
Getter method for leftMargin
Returns:
The leftMargin value

setLeftMargin

public void setLeftMargin(int twips)
Setter method for leftMargin
Parameters:
twips - left margin (in twips).

getRightMargin

public int getRightMargin()
Getter method for rightMargin
Returns:
The rightMargin value

setRightMargin

public void setRightMargin(int twips)
Setter method for rightMargin
Parameters:
twips - right margin (in twips).

getTopMargin

public int getTopMargin()
Getter method for topMargin
Returns:
The topMargin value

setTopMargin

public void setTopMargin(int twips)
Setter method for topMargin
Parameters:
twips - margin (in twips).

getBottomMargin

public int getBottomMargin()
Getter method for bottomMargin
Returns:
The bottomMargin value

setBottomMargin

public void setBottomMargin(int twips)
Setter method for Margin
Parameters:
twips - margin (in twips).

codesToString

public java.lang.String codesToString()
Produces a human readable/printable version of the code, name and stamp attributes of this template and its components.
Returns:
String

setOfVariables

public java.util.ArrayList[] setOfVariables()
Calculates the set --without repetitions-- of codes of variables mentioned in any of the components of this template. Each variable will be paired with a list of formats.
Specified by:
setOfVariables in interface LetterViewable
Returns:
Array of [varCode, [format1, format2, ..]]. If there is no variables, returns an array with 0 entries.

getAllImages

public java.util.ArrayList[] getAllImages()
Produces an array with information of images, in ascending order through all the text. The position information is kept but is meaningless in this case.
Specified by:
getAllImages in interface LetterViewable
Returns:
An array of

getAllVariables

public java.util.ArrayList[] getAllVariables()
Produces an array with information of variables, in ascending order through all the text. The position information is kept but is meaningless in this case.
Returns:
An array of

hasVariables

public boolean hasVariables()
Tests if this template contains variables.
Specified by:
hasVariables in interface LetterViewable
Returns:
True if it has variables, False otherwise.

hasImages

public boolean hasImages()
Tests if this template contains images.
Returns:
True if it has images, False otherwise.

hasChanged

public boolean hasChanged()
Test if this template has changed; i.e, if any of its components has changed.
Returns:
True if it has changed, False otherwise.

upToDate

public void upToDate()
Sets to false all of its component's "hasChanged" attribute.

outOfDate

public void outOfDate()
Sets to true all of its component's "hasChanged" attribute.

extractRtf

public java.lang.String extractRtf()
Produces the append of the rtf text contained in the header, body and closing of this template. Due to a bug in swing's RTFEditorKit, here we also substitute the "\fnil" font family by actual font families. The current families in the system are "\fmodern, \froman and \fswiss". The substitution is guided by the equivalences established by FONT constants in class LetterOp. The central part of the algorithm replaces ocurrences of a font table like
 {\fonttbl\f0\fnil Monospaced;\f1\fnil Times New Roman;\f2\fnil Arial;}
 
by something with actual font families like:
 {\fonttbl\f0\fmodern Courier;\f1\froman Times;\f2\fswiss helvetica;}
 

Returns:
The appended rtf text of the three template components.

toFoTemplate

public java.lang.String toFoTemplate()
Transform this LetterTemplate in a "fo-template" without external references to image files.
Specified by:
toFoTemplate in interface LetterViewable
Returns:
The fo-template --as a String-- or null if something goes wrong.

buildRtfMargins

private java.lang.String buildRtfMargins()