| java.lang.Object cb.jdynamite.analyser.DefaultDynamicElement cb.jdynamite.JDynamiTe
JDynamiTe | public class JDynamiTe extends DefaultDynamicElement implements ITemplateDocument,Serializable(Code) | | JDynamiTe is the unique class you need to parse a template document.
This implementation extends the DefaultDynamicElement class (from package analyser),
so a JDynamiTe object is a "Dynamic Element".
The use is very simple :
First define the input file or input stream (for example an HTML template document)
with the "setInput" method.
Secondly fill and develop this document with a few methods such as "setVariable",
and "parseDynElem".
Finally, after calling the "parse" method to finalize building your dynamic document,
you simply obtain the result with the "toString" method.
See an example in the main method of this class.
JDynamiTe elements
There are (only) two elements which make a document a "template" document.
1) "Variable Element"
A "Variable Element" is defined by an identifier in the template document.
Its value can be changed with the JDynamiTe.setValue method.
Example of use: titles, values of cells in tables, etc.
2) "Dynamic Element"
A "Dynamic Element" is a "block" which can be dynamically developed.
It has an identifier, a template definition, and a value.
Its value can be set or developed with the JDynamiTe.parseDynElem and JDynamiTe.setDynElem methods.
Example of use: list, table, enumeration, etc.
Template document syntax
There are only 3 tags to use JDynamiTe : "Variable" tag, "Begin Dynamic Element" tag, and
"End Dynamic Element" tag. The tag syntax is defined by regular expressions, you can change it in the
analyser.
By default JDynamiTe uses the "DefaultAnalyser" to parse the template documents.
By default, this analyser uses HTML style tags.
1) "Variable" tag:
{VARNAME}
means you can use setVariable("VARNAME", aStringValue) in Java code.
2) "Begin Dynamic Element" tag:
<!-- BEGIN DYNAMIC : dynElemName -->
or
<!-- BEGIN DYNAMIC BLOCK: dynElemName -->
means the "dynElemName" Dynamic Element definition begins on the next line.
3) "End Dynamic Element" tag:
<!-- END DYNAMIC : dynElemName -->
or
<!-- END DYNAMIC BLOCK: dynElemName -->
means the "dynElemName" Dynamic Element definition ends on the previous line.
Identifiers syntax (for Variables and Dynamic Elements):
By default, it is a word made up of alphanumeric characters and these four characters:
'.', ':', '_' and '-'
New concept : "Ignored Element"
Since JDynamiTe 1.1, this optional element can be used in template documents. An "Ignored Element" is
a "block" which will be completly ignored (skipped during document analysis).
Example of use: it allows the HTML designer to build more realistic pages, with concrete data, giving a
better idea of the possible dynamic page look and feel. An "Ignored Element" can be inserted anywhere in
the template document, even inside "Dynamic Element".
"Ignored Element" tags
<!-- BEGIN IGNORED : ignoredElemName -->
means an ignored block (skipped during analysis and document output) begins on the next line.
<!-- END IGNORED : ignoredElemName -->
means this ignored block ends on the previous line.
JDynamiTe home page
JDynamiTe latest versions, news, examples ... at http://jdynamite.sourceforge.net
author: Christophe Bouleau |
Constructor Summary | |
public | JDynamiTe() Constructs an empty "JDynamiTe" (Java Dynamic Template) document. | public | JDynamiTe(String name) Constructs an empty "JDynamiTe" (Java Dynamic Template) document. |
Method Summary | |
public void | clearAll() Reset all Variables and all Dynamic Element values. | public void | clearAllDynElemValues() Reset all Dynamic Element values. | public void | clearAllVariables() Reset all Variables. | public ITemplateAnalyser | getAnalyser() Returns the analyser that parses template documents
(Note: You do not need to directly call this method to use JDynamiTe). | public IDynamicElement | getDynElem(String key) Returns the "Dynamic Element" identified by a string
(Note: You do not need to directly call this method to use JDynamiTe).
A "JDynamiTe" document maintains a list of "Dynamic Elements".
Parameters: key - The "Dynamic Element" identifier. | public String | getTemplateDefinition() For debugging purposes : get the result (structure of the template document) of the analyser parsing. | public String | getVariable(String key) Returns the value of a variable that was set by setVariable.
A "JDynamiTe" document maintains a list of key/value pairs, which is used when
Dynamic Elements are parsed.
Parameters: key - The key of the variable to retrieve. | public Enumeration | getVariableKeys() Returns an enumeration of the template Variable keys in this JDynamiTe document.
A "JDynamiTe" document maintains a list of key/value pairs, which is used when
Dynamic Elements are parsed.
The setInput method build this list (with an empty string as default value)
during the template document analysis. | public static void | main(String args) Provides a simple (but sufficient) example of use. | public void | parse() Calls the parse method inherited from DefaultDynamicElement. | public void | parseDynElem(String elementName) This is a "key" method you call to append elements to the current value of a Dynamic Element.
These elements are built from the template definition of this Dynamic Element and the current value
of variables (and possibly nested Dynamic Elements). | public void | recordDynElem(String key, IDynamicElement value) Records a "Dynamic Element" in this "JDynamiTe" Document
(Note: You do not need to directly call this method to use JDynamiTe). | public void | setAnalyser(ITemplateAnalyser templateAnalyser) Set the analyser that parses template documents
(Note: You do not need to directly call this method to use JDynamiTe). | public void | setDynElemValue(String elementName, String value) Set an arbitrary value to a Dynamic Element. | public void | setInput(BufferedReader reader) Starts the analysis of the input template document. | public void | setInput(InputStream istream) Starts the analysis of the input template document. | public void | setInput(String fileName) Starts the analysis of the input template document. | public void | setVariable(String key, String value) Set the value of a variable. | public String | toString() Returns the value (after parsing) of this JDynamiTe document. |
JDynamiTe | public JDynamiTe()(Code) | | Constructs an empty "JDynamiTe" (Java Dynamic Template) document.
|
JDynamiTe | public JDynamiTe(String name)(Code) | | Constructs an empty "JDynamiTe" (Java Dynamic Template) document.
Parameters: name - The name of this "JDynamiTe" document, used for debugging purposes by the"getTemplateDefinition" method. |
clearAll | public void clearAll()(Code) | | Reset all Variables and all Dynamic Element values.
|
clearAllDynElemValues | public void clearAllDynElemValues()(Code) | | Reset all Dynamic Element values.
|
clearAllVariables | public void clearAllVariables()(Code) | | Reset all Variables.
|
getAnalyser | public ITemplateAnalyser getAnalyser()(Code) | | Returns the analyser that parses template documents
(Note: You do not need to directly call this method to use JDynamiTe).
The current analyser. See Also: setAnalyser(cb.jdynamite.analyser.ITemplateAnalyser) |
getDynElem | public IDynamicElement getDynElem(String key)(Code) | | Returns the "Dynamic Element" identified by a string
(Note: You do not need to directly call this method to use JDynamiTe).
A "JDynamiTe" document maintains a list of "Dynamic Elements".
Parameters: key - The "Dynamic Element" identifier. This is the string defined in thetemplate document in the "BEGIN DYNAMIC" tag. For example:<-- BEGIN DYNAMIC : myList --> Here "myList" identifies the Dynamic Element which begins. The interface of the Dynamic Element. |
getTemplateDefinition | public String getTemplateDefinition()(Code) | | For debugging purposes : get the result (structure of the template document) of the analyser parsing.
Result (structure of the template document) of the analyser parsing. |
getVariable | public String getVariable(String key)(Code) | | Returns the value of a variable that was set by setVariable.
A "JDynamiTe" document maintains a list of key/value pairs, which is used when
Dynamic Elements are parsed.
Parameters: key - The key of the variable to retrieve. The value of the variable. See Also: setVariable(java.lang.String, java.lang.String) |
getVariableKeys | public Enumeration getVariableKeys()(Code) | | Returns an enumeration of the template Variable keys in this JDynamiTe document.
A "JDynamiTe" document maintains a list of key/value pairs, which is used when
Dynamic Elements are parsed.
The setInput method build this list (with an empty string as default value)
during the template document analysis. After this step, the setVariable method
is used to set a value to a Variable.
Example of use :
Enumeration keys = myJDynamiTeDoc.getVariableKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
System.err.println(keys);
String value = myDatabase.selectValue(key); // get the current value somewhere...
myJDynamiTeDoc.setVariable(key, value); // set the template Variable.
}
The value of the variable. See Also: setVariable(java.lang.String, java.lang.String) See Also: setInput(InputStream istream) See Also: setInput(String fileName) since: JDynamiTe 1.2 |
main | public static void main(String args)(Code) | | Provides a simple (but sufficient) example of use.
Needs "testTemplate.html" in current directory as a template file.
Writes the result on standard output.
|
parse | public void parse()(Code) | | Calls the parse method inherited from DefaultDynamicElement. As this object is the "top level"
dynamic element, this method enables obtaining the "final" value of this document.
You can use the "toString" method to get this value.
See Also: toString() |
parseDynElem | public void parseDynElem(String elementName)(Code) | | This is a "key" method you call to append elements to the current value of a Dynamic Element.
These elements are built from the template definition of this Dynamic Element and the current value
of variables (and possibly nested Dynamic Elements). See examples.
Parameters: elementName - The "Dynamic Element" identifier. This is the string definedin the template document in the "BEGIN DYNAMIC" tag. For example:<-- BEGIN DYNAMIC : myList --> Here "myList" identifies the Dynamic Element that begins. |
recordDynElem | public void recordDynElem(String key, IDynamicElement value)(Code) | | Records a "Dynamic Element" in this "JDynamiTe" Document
(Note: You do not need to directly call this method to use JDynamiTe).
A "JDynamiTe" document maintains a list of "Dynamic Elements".
It is called by the analyser.
Parameters: key - The "Dynamic Element" identifier. Parameters: value - An object that implements the IDynamicElement interface. |
setAnalyser | public void setAnalyser(ITemplateAnalyser templateAnalyser)(Code) | | Set the analyser that parses template documents
(Note: You do not need to directly call this method to use JDynamiTe).
Parameters: templateAnalyser - The new analyser. See Also: getAnalyser() |
setDynElemValue | public void setDynElemValue(String elementName, String value)(Code) | | Set an arbitrary value to a Dynamic Element. For example, enables emptying a
Dynamic Element if you give an empty string as argument.
Parameters: elementName - The Dynamic Element identifier. Parameters: value - New value for The Dynamic Element |
setInput | public void setInput(BufferedReader reader) throws IOException(Code) | | Starts the analysis of the input template document.
If no custom "ITemplateAnalyser" was defined, JDynamiTe uses the "DefaultAnalyser".
After this step, all the Variables and Dynamic Elements are identified,
so this JDynamiTe is ready to be developed.
By default all Variables are set to an empty string value.
In addition, Variable identifiers (keys) can be retreived by getVariablesKeys.
Parameters: reader - A BufferedReader to read the input template document. exception: java.io.IOException - If an I/O error occurs. See Also: setInput(java.io.InputStream) See Also: setInput(java.lang.String) See Also: cb.jdynamite.analyser.DefaultAnalyser See Also: setAnalyser(ITemplateAnalyser templateAnalyser) since: JDynamyTe 1.2 |
setInput | public void setInput(InputStream istream) throws IOException(Code) | | Starts the analysis of the input template document.
If no custom "ITemplateAnalyser" was defined, JDynamiTe uses the "DefaultAnalyser".
After this step, all the Variables and Dynamic Elements are identified,
so this JDynamiTe is ready to be developed.
By default all Variables are set to an empty string value.
In addition, Variable identifiers (keys) can be retreived by getVariablesKeys.
Parameters: istream - A stream to read the input template document. exception: java.io.IOException - If an I/O error occurs. See Also: setInput(java.io.BufferedReader) See Also: setInput(java.lang.String) See Also: cb.jdynamite.analyser.DefaultAnalyser See Also: setAnalyser(ITemplateAnalyser templateAnalyser) |
setInput | public void setInput(String fileName) throws IOException, FileNotFoundException(Code) | | Starts the analysis of the input template document.
If no custom "ITemplateAnalyser" was defined, JDynamiTe uses the "DefaultAnalyser".
After this step, all the Variables and Dynamic Elements are identified,
so this JDynamiTe is ready to be developed.
By default all Variables are set to an empty string value.
In addition, Variable identifiers (keys) can be retreived by getVariablesKeys.
Parameters: fileName - The name of the file which contains the input template document. exception: java.io.IOException - If an I/O error occurs. exception: java.io.FileNotFoundException - Bad filename. See Also: setInput(java.io.BufferedReader) See Also: setInput(java.io.InputStream) See Also: cb.jdynamite.analyser.DefaultAnalyser See Also: setAnalyser(ITemplateAnalyser templateAnalyser) |
setVariable | public void setVariable(String key, String value)(Code) | | Set the value of a variable.
Overrides its previous value if any.
A "JDynamiTe" document maintains a list of key/value pairs, which is used when
Dynamic Elements are parsed.
Parameters: key - The key of the variable to set. Parameters: value - The new value of this variable. See Also: getVariable(java.lang.String) |
toString | public String toString()(Code) | | Returns the value (after parsing) of this JDynamiTe document.
Value (after parsing) of this JDynamiTe document |
|
|