|
|||||||||
| Home >> All >> jsd >> ftp >> [ tpl overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
jsd.ftp.tpl
Class Template

java.lang.Objectjsd.ftp.tpl.Template
- public class Template
- extends java.lang.Object
This class is used to load files into OutputStream
after parsing the template file. It supports variables,
for block, if-then-else block and iterator block. It has
only one public method - loadFile(OutputStream, Map).
It also supports vector indexing. It stores the file data in a
byte array. We may face some problems later due to character
encoding. But for the time being it works fine.
Template syntax.
| Field Summary | |
private static java.lang.String |
EQ
|
private static int |
FOR
|
private static int |
IF
|
private static java.lang.String |
IN
|
private static int |
ITR
|
private static java.lang.String |
LAST
|
private byte[] |
mbyContent
|
private java.io.File |
mFile
|
private long |
mModifiedTime
|
private static java.lang.String[] |
mstKeywords
|
private static java.lang.String |
mstWhitespaces
|
private static java.lang.String |
NE
|
private static int |
NULL
|
private static java.lang.String |
SIZE
|
private static java.lang.String |
THRU
|
private static int |
VAR
|
private static int |
VARKEY
|
| Constructor Summary | |
Template(java.io.File file)
Constructor. |
|
| Method Summary | |
private java.lang.Object |
elementAt(java.lang.Object obj,
int index)
Returns an element at a particular element. |
private java.lang.String |
getActualVarString(java.util.Map hash,
java.lang.String initVar)
Variable name can be formed dynamically. |
private Block |
getBlock(int start)
Get block from index start. |
private java.lang.String |
getBlock(java.lang.String str,
int start)
Get block - this function is used to form the variable name dynamically. |
private java.lang.Object |
getCondVarObject(java.util.Map hash,
java.lang.String str)
Get conditional variable object. |
private java.util.List |
getForList(java.util.Map hash,
java.lang.StringBuffer sb,
Block block)
Get for vector and init variable name. |
private java.lang.Object |
getIndexedObject(java.lang.Object obj,
java.lang.String indexBlock)
Get vector element at a particular index. |
private int |
getIntegerValue(java.util.Map hash,
java.util.StringTokenizer st)
Get the integer value from StringTokenizer. |
private java.lang.Object |
getLastVar(java.util.Map hash,
java.lang.String sb)
Returns the last element of a vector. |
private java.lang.Object |
getVarObject(java.util.Map hash,
java.lang.String var)
Get variable object. |
private java.lang.Integer |
getVarSize(java.util.Map hash,
java.lang.String sb)
Returns the size of a variable as an Integer
object. |
private boolean |
ifObjExists(java.lang.Object left,
java.lang.Object right)
Check object existance. |
private int |
ignoreWhitespace(int start)
Ignore whitespace. |
private boolean |
isTrueCondition(java.util.Map hash,
Block block)
Evaluate condition block in IF statement. |
void |
loadFile(java.io.OutputStream out,
java.util.Map hash)
Load file - it reads the file and process the block as normal block. |
private int |
processBlock(java.io.OutputStream out,
java.util.Map hash,
Block block)
Process block. |
private int |
processBlock(java.io.OutputStream out,
java.util.Map hash,
Block block,
int type)
Process block - call respective functions. |
private int |
processForBlock(java.io.OutputStream out,
java.util.Map hash,
int index)
Process FOR block. |
private int |
processIfBlock(java.io.OutputStream out,
java.util.Map hash,
int start)
Process IF block. |
private int |
processItrBlock(java.io.OutputStream out,
java.util.Map hash,
int index)
Process iterator block. |
private int |
processNormalBlock(java.io.OutputStream out,
java.util.Map hash,
Block block)
Process normal block. |
private int |
processNullBlock(java.io.OutputStream out,
Block block)
Process null block - returns nothing |
private int |
processVarBlock(java.io.OutputStream out,
java.util.Map hash,
Block block)
Process variable block. |
private int |
processVarkeyBlock(java.io.OutputStream out,
Block block)
Process varkey. |
private void |
readFile()
Read file (if modified) into a byte array. |
java.lang.String |
toString()
Get template file name |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
mstWhitespaces
private static final java.lang.String mstWhitespaces
- See Also:
- Constant Field Values
mstKeywords
private static final java.lang.String[] mstKeywords
IF
private static final int IF
- See Also:
- Constant Field Values
FOR
private static final int FOR
- See Also:
- Constant Field Values
ITR
private static final int ITR
- See Also:
- Constant Field Values
VARKEY
private static final int VARKEY
- See Also:
- Constant Field Values
NULL
private static final int NULL
- See Also:
- Constant Field Values
VAR
private static final int VAR
- See Also:
- Constant Field Values
SIZE
private static final java.lang.String SIZE
- See Also:
- Constant Field Values
LAST
private static final java.lang.String LAST
- See Also:
- Constant Field Values
THRU
private static final java.lang.String THRU
- See Also:
- Constant Field Values
EQ
private static final java.lang.String EQ
- See Also:
- Constant Field Values
NE
private static final java.lang.String NE
- See Also:
- Constant Field Values
IN
private static final java.lang.String IN
- See Also:
- Constant Field Values
mFile
private java.io.File mFile
mModifiedTime
private long mModifiedTime
mbyContent
private byte[] mbyContent
| Constructor Detail |
Template
public Template(java.io.File file)
- Constructor.
| Method Detail |
readFile
private void readFile()
throws java.io.IOException
- Read file (if modified) into a byte array.
This function is
Synchronizedto make this class thread safe.
processBlock
private int processBlock(java.io.OutputStream out, java.util.Map hash, Block block) throws java.io.IOException
- Process block. First find the block type and then process.
processBlock
private int processBlock(java.io.OutputStream out, java.util.Map hash, Block block, int type) throws java.io.IOException
- Process block - call respective functions. Each of these
functions returns the next index from where the next
processing starts.
processNullBlock
private int processNullBlock(java.io.OutputStream out, Block block)
- Process null block - returns nothing
processVarkeyBlock
private int processVarkeyBlock(java.io.OutputStream out, Block block) throws java.io.IOException
- Process varkey.
It is used to write ${ in the
OutputStream.
processNormalBlock
private int processNormalBlock(java.io.OutputStream out, java.util.Map hash, Block block) throws java.io.IOException
- Process normal block. Normal block may contain other variables,
keywords and other normal blocks. Search for "${". If found,
get the block and process it.
processVarBlock
private int processVarBlock(java.io.OutputStream out, java.util.Map hash, Block block) throws java.io.IOException
- Process variable block. Get variable object from the
Mapand write the string representation of the object.
getVarObject
private java.lang.Object getVarObject(java.util.Map hash, java.lang.String var) throws java.io.IOException
- Get variable object.
Returns null if not available in the Map
getCondVarObject
private java.lang.Object getCondVarObject(java.util.Map hash, java.lang.String str) throws java.io.IOException
- Get conditional variable object. If not a variable returns
the string itself. Else returns the equivalent object from
the hashtable. If it is not available in the hashtable
returns null.
getVarSize
private java.lang.Integer getVarSize(java.util.Map hash, java.lang.String sb) throws java.io.IOException
- Returns the size of a variable as an
Integerobject. In case of Scalar returns 1. If object is null, returns 0 and in case ofListreturns the list size.
getLastVar
private java.lang.Object getLastVar(java.util.Map hash, java.lang.String sb) throws java.io.IOException
- Returns the last element of a vector. In case of scalar,
returns the object itself. In case of null returns null
and in case of vector returns null if size is zero or the
last element.
getIndexedObject
private java.lang.Object getIndexedObject(java.lang.Object obj, java.lang.String indexBlock)
- Get vector element at a particular index. Tokenize
indexBlockstring and returns the element.
elementAt
private java.lang.Object elementAt(java.lang.Object obj, int index)
- Returns an element at a particular element. If the object
is null, returns null. If the object is a
Listreturns null if the index is out of range or the element at that index.
getActualVarString
private java.lang.String getActualVarString(java.util.Map hash, java.lang.String initVar) throws java.io.IOException
- Variable name can be formed dynamically. This function is
used to get the actual variable name - by resolving inner
variable name. Keywords will be treated as variables. The
variable within '{' and '}' will be replaced by its string
representation.
processIfBlock
private int processIfBlock(java.io.OutputStream out, java.util.Map hash, int start) throws java.io.IOException
- Process IF block. Returns the index of the next char.
isTrueCondition
private boolean isTrueCondition(java.util.Map hash, Block block) throws java.io.IOException
- Evaluate condition block in IF statement.
ifObjExists
private boolean ifObjExists(java.lang.Object left, java.lang.Object right)
- Check object existance. If any vector element is null,
that element is ignored.
processItrBlock
private int processItrBlock(java.io.OutputStream out, java.util.Map hash, int index) throws java.io.IOException
- Process iterator block. Here
indexis the starting index of the iterator initialization block.
getIntegerValue
private int getIntegerValue(java.util.Map hash, java.util.StringTokenizer st) throws java.io.IOException
- Get the integer value from
StringTokenizer. This function is used to get the start index and iteration count in ITR block. It returns -1 in case of error (NumberFormatException).
processForBlock
private int processForBlock(java.io.OutputStream out, java.util.Map hash, int index) throws java.io.IOException
- Process FOR block. Here
indexis the start index of the FOR initialization block.
getForList
private java.util.List getForList(java.util.Map hash, java.lang.StringBuffer sb, Block block) throws java.io.IOException
- Get for vector and init variable name. It passes the
name of the FOR temporary variable name in
StringBuffer sb
getBlock
private Block getBlock(int start)
- Get block from index
start. It starts just after the '{' character. It reads till it reaches the corresponding '}'.
getBlock
private java.lang.String getBlock(java.lang.String str, int start)
- Get block - this function is used to form the
variable name dynamically.
ignoreWhitespace
private int ignoreWhitespace(int start)
- Ignore whitespace. Returns the first
non-whitespace char index.
loadFile
public void loadFile(java.io.OutputStream out, java.util.Map hash) throws java.io.IOException
- Load file - it reads the file and process the block as
normal block.
toString
public java.lang.String toString()
- Get template file name
|
|||||||||
| Home >> All >> jsd >> ftp >> [ tpl overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
jsd.ftp.tpl.Template