|
Dynamic Template in Java | ||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--cb.jdynamite.analyser.DefaultDynamicElement | +--cb.jdynamite.JDynamiTe
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.
{VARNAME}means you can use setVariable("VARNAME", aStringValue) in Java code.
<!-- BEGIN DYNAMIC : dynElemName -->or
<!-- BEGIN DYNAMIC BLOCK: dynElemName -->means the "dynElemName" Dynamic Element definition begins on the next line.
<!-- END DYNAMIC : dynElemName -->or
<!-- END DYNAMIC BLOCK: dynElemName -->means the "dynElemName" Dynamic Element definition ends on the previous line.
<!-- 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.
Constructor Summary | |
JDynamiTe()
Constructs an empty "JDynamiTe" (Java Dynamic Template) document. |
|
JDynamiTe(java.lang.String name)
Constructs an empty "JDynamiTe" (Java Dynamic Template) document. |
Method Summary | |
void |
clearAll()
Reset all Variables and all Dynamic Element values. |
void |
clearAllDynElemValues()
Reset all Dynamic Element values. |
void |
clearAllVariables()
Reset all Variables. |
ITemplateAnalyser |
getAnalyser()
Returns the analyser that parses template documents (Note: You do not need to directly call this method to use JDynamiTe). |
IDynamicElement |
getDynElem(java.lang.String key)
Returns the "Dynamic Element" identified by a string (Note: You do not need to directly call this method to use JDynamiTe). |
java.lang.String |
getTemplateDefinition()
For debugging purposes : get the result (structure of the template document) of the analyser parsing. |
java.lang.String |
getVariable(java.lang.String key)
Returns the value of a variable that was set by setVariable. |
java.util.Enumeration |
getVariableKeys()
Returns an enumeration of the template Variable keys in this JDynamiTe document. |
static void |
main(java.lang.String[] args)
Provides a simple (but sufficient) example of use. |
void |
parse()
Calls the parse method inherited from DefaultDynamicElement. |
void |
parseDynElem(java.lang.String elementName)
This is a "key" method you call to append elements to the current value of a Dynamic Element. |
void |
recordDynElem(java.lang.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). |
void |
setAnalyser(ITemplateAnalyser templateAnalyser)
Set the analyser that parses template documents (Note: You do not need to directly call this method to use JDynamiTe). |
void |
setDynElemValue(java.lang.String elementName,
java.lang.String value)
Set an arbitrary value to a Dynamic Element. |
void |
setInput(java.io.BufferedReader reader)
Starts the analysis of the input template document. |
void |
setInput(java.io.InputStream istream)
Starts the analysis of the input template document. |
void |
setInput(java.lang.String fileName)
Starts the analysis of the input template document. |
void |
setVariable(java.lang.String key,
java.lang.String value)
Set the value of a variable. |
java.lang.String |
toString()
Returns the value (after parsing) of this JDynamiTe document. |
Methods inherited from class cb.jdynamite.analyser.DefaultDynamicElement |
addElement, getDefinition, getValue, parse, setValue |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public JDynamiTe()
public JDynamiTe(java.lang.String name)
name
- The name of this "JDynamiTe" document, used for debugging purposes by the
"getTemplateDefinition" method.Method Detail |
public void setInput(java.io.BufferedReader reader) throws java.io.IOException
reader
- A BufferedReader to read the input template document.java.io.IOException
- If an I/O error occurs.setInput(java.io.InputStream)
,
setInput(java.lang.String)
,
DefaultAnalyser
,
setAnalyser(ITemplateAnalyser templateAnalyser)
public void setInput(java.io.InputStream istream) throws java.io.IOException
istream
- A stream to read the input template document.java.io.IOException
- If an I/O error occurs.setInput(java.io.BufferedReader)
,
setInput(java.lang.String)
,
DefaultAnalyser
,
setAnalyser(ITemplateAnalyser templateAnalyser)
public void setInput(java.lang.String fileName) throws java.io.IOException, java.io.FileNotFoundException
fileName
- The name of the file which contains the input template document.java.io.IOException
- If an I/O error occurs.java.io.FileNotFoundException
- Bad filename.setInput(java.io.BufferedReader)
,
setInput(java.io.InputStream)
,
DefaultAnalyser
,
setAnalyser(ITemplateAnalyser templateAnalyser)
public java.lang.String getVariable(java.lang.String key)
getVariable
in interface ITemplateDocument
key
- The key of the variable to retrieve.setVariable(java.lang.String, java.lang.String)
public void setVariable(java.lang.String key, java.lang.String value)
setVariable
in interface ITemplateDocument
key
- The key of the variable to set.value
- The new value of this variable.getVariable(java.lang.String)
public java.util.Enumeration getVariableKeys()
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. }
setVariable(java.lang.String, java.lang.String)
,
setInput(InputStream istream)
,
setInput(String fileName)
public IDynamicElement getDynElem(java.lang.String key)
key
- The "Dynamic Element" identifier. This is the string defined in the
template document in the "BEGIN DYNAMIC" tag. For example:<-- BEGIN DYNAMIC : myList -->Here "myList" identifies the Dynamic Element which begins.
public void recordDynElem(java.lang.String key, IDynamicElement value)
recordDynElem
in interface ITemplateDocument
key
- The "Dynamic Element" identifier.value
- An object that implements the IDynamicElement interface.public ITemplateAnalyser getAnalyser()
getAnalyser
in interface ITemplateDocument
setAnalyser(cb.jdynamite.analyser.ITemplateAnalyser)
public void setAnalyser(ITemplateAnalyser templateAnalyser)
setAnalyser
in interface ITemplateDocument
templateAnalyser
- The new analyser.getAnalyser()
public void parseDynElem(java.lang.String elementName)
elementName
- The "Dynamic Element" identifier. This is the string defined
in the template document in the "BEGIN DYNAMIC" tag. For example:<-- BEGIN DYNAMIC : myList -->Here "myList" identifies the Dynamic Element that begins.
public void setDynElemValue(java.lang.String elementName, java.lang.String value)
elementName
- The Dynamic Element identifier.value
- New value for The Dynamic Elementpublic void parse()
toString()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getTemplateDefinition()
public void clearAll()
public void clearAllVariables()
public void clearAllDynElemValues()
public static void main(java.lang.String[] args)
|
JDynamiTe | ||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |