com.instantbank.component.lettertemplate.util
Class LetterComponent

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

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

In memory representation of a letter component.

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

Field Summary
static int BODY
          Identifies the "body type" of the component.
static int CLOSING
          Identifies the "closing type" of the component.
private  long code
          Unique code in the data base.
 boolean hasChanged
          Indicates if this component is up to date with respect to the database.
static int HEADER
          Identifies the "header type" of the component.
static java.lang.String IMGTYPE
          Identifies the image attribute for a character.
private  java.lang.String name
          Component description.
private  int printType
          Component print type: LASER, TYPEWRITTER
private  java.lang.String rtfText
          The text contained in the template in RTF format.
private  java.lang.String stamp
          Time stamp of the last time the component was saved.
private  java.util.ArrayList traceImages
          ArrayList containing < position,image> pairs.
private  java.util.ArrayList traceVariables
          ArrayList containing < position,fieldId, formatCode, offset> tuple.
private  int type
          Component type : HEADER, BODY, CLOSING
static java.lang.String VARTYPE
          Identifies the variable attribute for a character.
 
Constructor Summary
LetterComponent(int type, int printType)
          Simple constructor from type and printType.
LetterComponent(long code, int type, int printType, java.lang.String name, java.lang.String rtfText, java.util.ArrayList traceVariables, java.util.ArrayList traceImages, java.lang.String stamp)
          Big constructor.
 
Method Summary
 java.lang.String codesToString()
          Produces a human readable/printable version of the code, name and stamp attributes of this LetterComponent.
 java.lang.String extractRtf()
          Fixes the rtf text of this component.
 java.util.ArrayList[] getAllImages()
          Delivers an array with images' information, in ascending order by position:
 java.util.ArrayList[] getAllVariables()
          Delivers an array with variables' information, in ascending order by position.
 long getCode()
          Getter method for code
 java.lang.String getName()
          Getter method for name
 int getPrintType()
          Getter method for printType
 java.lang.String getRtfText()
          Getter method for rtfText
 java.lang.String getStamp()
          Getter method for stamp
 java.util.ArrayList getTraceImages()
          Getter method for traceImages
 java.util.ArrayList getTraceVariables()
          Getter method for traceVariables
 int getType()
          Getter method for type
 boolean hasVariables()
          Answers whether or not this component has variables.
 java.lang.String mergeToString(java.util.ArrayList[] merge)
          Delivers a String representation of a merge structure for variables and images.
 java.util.ArrayList[] mergeVarsImages()
          Calculates the "merge" of this component's variables and images, in descending order by their position in the text.
 void setCode(long code)
          Setter method for code
 void setName(java.lang.String name)
          Setter method for name
 java.util.ArrayList[] setOfVariables()
          Calculates the set --without repetitions-- of codes of variables mentioned in this components.
 void setPrintType(int printType)
          Setter method for printType
 void setRtfText(java.lang.String rtfText)
          Setter method for rtfText
 void setStamp(java.lang.String st)
          Setter method for stamp
 void setTraceImages(java.util.ArrayList traceImages)
          Setter method for traceImages
 void setTraceVariables(java.util.ArrayList traceVariables)
          Setter method for traceVariables
 void setType(int type)
          Setter method for type
 java.lang.String toFoTemplate()
          Transform this LetterComponent in a "fo-template" without external references to image files.
 java.lang.String traceImgToString()
          traceImgToStringod
 java.lang.String traceImgToString(java.util.ArrayList trace)
          traceImgToString
 java.lang.String traceVarsToString()
          traceVarsToString
 java.lang.String traceVarsToString(java.util.ArrayList trace)
          traceVarsToString
static java.lang.String typeToPlural(int type)
          Produces a human readable version of the plural of a component type code.
static java.lang.String typeToPlural(java.lang.String type)
          Produces a human readable version of the plural of a component type code.
static java.lang.String typeToString(int type)
          Produces a human readable version of a component type code.
 boolean wellFormed(java.util.ArrayList trace)
          Verifies if the trace is in descending order --by variable or image position.
 boolean wellFormed(java.util.ArrayList[] merge)
          Verifies if the merge is in descending order --by variable or image position--.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

HEADER

public static final int HEADER
Identifies the "header type" of the component.

BODY

public static final int BODY
Identifies the "body type" of the component.

CLOSING

public static final int CLOSING
Identifies the "closing type" of the component.

IMGTYPE

public static final java.lang.String IMGTYPE
Identifies the image attribute for a character.

VARTYPE

public static final java.lang.String VARTYPE
Identifies the variable attribute for a character.

hasChanged

public boolean hasChanged
Indicates if this component is up to date with respect to the database. True if it is out of date, False if it is up to date.

type

private int type
Component type : HEADER, BODY, CLOSING

printType

private int printType
Component print type: LASER, TYPEWRITTER

code

private long code
Unique code in the data base.

name

private java.lang.String name
Component description.

traceImages

private java.util.ArrayList traceImages
ArrayList containing < position,image> pairs. "Position" is stored as an Integer objet and "image" is stored as a byte[] object. They are in descending order, by position.

traceVariables

private java.util.ArrayList traceVariables
ArrayList containing < position,fieldId, formatCode, offset> tuple. "Position" is stored as an Integer objet "fieldId", "formatCode" and "offset" are stored as Long objects. They are in descending order, by position.

rtfText

private java.lang.String rtfText
The text contained in the template in RTF format. Positions of the images and variables are not directly related to this text (see traceImages and traceVariables). Those positions are related to the document resulting from this text after it is read by the corresponding swing component.

stamp

private java.lang.String stamp
Time stamp of the last time the component was saved. It is used as "version Id" for the component.
Constructor Detail

LetterComponent

public LetterComponent(int type,
                       int printType)
Simple constructor from type and printType. Moreover, code, name, and stamp are initialized to "undefined".
Parameters:
type - The component type: BODY, HEADER, CLOSING.
printType - The component print type: LASER, TYPEWITTER.

LetterComponent

public LetterComponent(long code,
                       int type,
                       int printType,
                       java.lang.String name,
                       java.lang.String rtfText,
                       java.util.ArrayList traceVariables,
                       java.util.ArrayList traceImages,
                       java.lang.String stamp)
Big constructor. Defines all attributes from parameters.
Parameters:
code - Component's code.
type - Component's type: HEADER, BODY, CLOSING.
printType - Component's print type: LASER, TYPEWRITTER.
name - Component's name.
rtfText - Component's rtf text.
traceVariables - Variables in the component.
traceImages - Images in the component.
stamp - Time stamp of the last time the component was saved.
Method Detail

getType

public int getType()
Getter method for type
Returns:
The type value

setType

public void setType(int type)
Setter method for type
Parameters:
type - The new type value

getPrintType

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

setPrintType

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

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

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 name)
Setter method for name
Parameters:
name - The new name value

getTraceImages

public java.util.ArrayList getTraceImages()
Getter method for traceImages
Returns:
The traceImages value

setTraceImages

public void setTraceImages(java.util.ArrayList traceImages)
Setter method for traceImages
Parameters:
traceImages - The new traceImages value

getTraceVariables

public java.util.ArrayList getTraceVariables()
Getter method for traceVariables
Returns:
The traceVariables value

setTraceVariables

public void setTraceVariables(java.util.ArrayList traceVariables)
Setter method for traceVariables
Parameters:
traceVariables - The new traceVariables value

getRtfText

public java.lang.String getRtfText()
Getter method for rtfText
Returns:
The rtfText value

setRtfText

public void setRtfText(java.lang.String rtfText)
Setter method for rtfText
Parameters:
rtfText - The new rtfText value

getStamp

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

setStamp

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

codesToString

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

typeToString

public static java.lang.String typeToString(int type)
Produces a human readable version of a component type code.
Parameters:
type - The component type code.
Returns:
String representing component type cod

typeToPlural

public static java.lang.String typeToPlural(int type)
Produces a human readable version of the plural of a component type code.
Parameters:
type - The component type code.
Returns:
String representing the plural of the component type code

typeToPlural

public static java.lang.String typeToPlural(java.lang.String type)
Produces a human readable version of the plural of a component type code.
Parameters:
type - The component type name.
Returns:
String representing the plural of the component type code

mergeVarsImages

public java.util.ArrayList[] mergeVarsImages()
Calculates the "merge" of this component's variables and images, in descending order by their position in the text.
Returns:
An array of ArrayLists. Each entry is an ArrayList of size=2:
  • The first position contains the "type" of the second position, coded as "V" = variable, "I"=image.
  • The second position contains an ArrayList coming from traceVariables or traceImages, according to the type.

mergeToString

public java.lang.String mergeToString(java.util.ArrayList[] merge)
Delivers a String representation of a merge structure for variables and images.
Parameters:
merge - The merge structure.
Returns:
String representing merge structure for variables and images.

traceVarsToString

public java.lang.String traceVarsToString()
traceVarsToString
Returns:
String

traceVarsToString

public java.lang.String traceVarsToString(java.util.ArrayList trace)
traceVarsToString
Parameters:
trace -  
Returns:
String

traceImgToString

public java.lang.String traceImgToString()
traceImgToStringod
Returns:
String

traceImgToString

public java.lang.String traceImgToString(java.util.ArrayList trace)
traceImgToString
Parameters:
trace -  
Returns:
String

wellFormed

public boolean wellFormed(java.util.ArrayList trace)
Verifies if the trace is in descending order --by variable or image position. Can be used on a variable trace as well as on an images trace.
Parameters:
trace -  
Returns:
boolean

wellFormed

public boolean wellFormed(java.util.ArrayList[] merge)
Verifies if the merge is in descending order --by variable or image position--.
Parameters:
merge - A structure resulting from mergeVarsImages().
Returns:
boolean

getAllVariables

public java.util.ArrayList[] getAllVariables()
Delivers an array with variables' information, in ascending order by position.
Returns:
An array of < position,fieldId, formatCode>

getAllImages

public java.util.ArrayList[] getAllImages()
Delivers an array with images' information, in ascending order by position:
Specified by:
getAllImages in interface LetterViewable
Returns:
An Array of < position,image>

extractRtf

public java.lang.String extractRtf()
Fixes the rtf text of this component. Due to a bug in swing's RTFEditorKit, here we must 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 fontable 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 fixed rtf text .

hasVariables

public boolean hasVariables()
Answers whether or not this component has variables.
Specified by:
hasVariables in interface LetterViewable
Returns:
True if it has variables, False otherwise.

toFoTemplate

public java.lang.String toFoTemplate()
Transform this LetterComponent 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.

setOfVariables

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