|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Pre-parse filters for HTML.Template templates.
The HTML.Tmpl.Filter interface allows you to write Filters for your templates. The filter is called after the template is read and before it is parsed.
You can use a filter to make changes in the template file before it is parsed by HTML.Template, so for example, use it to replace constants, or to translate your own tags to HTML.Template tags.
A common usage would be to do what you think you're doing when you
do <TMPL_INCLUDE file="<TMPL_VAR name="the_file">">
:
myTemplate.tmpl:
<TMPL_INCLUDE file="<%the_file%>">
myFilter.java:
class myFilter implements HTML.Tmpl.Filter { private String myFile; private int type=SCALAR public myFilter(String myFile) { this.myFile = myFile; } public int format() { return this.type; } public String parse(String t) { // replace all <%the_file%> with myFile return t; } public String [] parse(String [] t) { throw new UnsupportedOperationException(); } }
myClass.java:
Hashtable params = new Hashtable(); params.put("filename", "myTemplate.tmpl"); params.put("filter", new myFilter("myFile.tmpl")); Template t = new Template(params);
Field Summary | |
static int |
ARRAY
Tells HTML.Template to call the parse(String []) method of this filter. |
static int |
SCALAR
Tells HTML.Template to call the parse(String) method of this filter. |
Method Summary | |
int |
format()
Tells HTML.Template what kind of filter this is. |
java.lang.String |
parse(java.lang.String t)
parses the template as a single string, and returns the parsed template as a single string. |
java.lang.String[] |
parse(java.lang.String[] t)
parses the template as an array of strings, and returns the parsed template as an array of strings. |
Field Detail |
public static final int SCALAR
public static final int ARRAY
Method Detail |
public int format()
public java.lang.String parse(java.lang.String t)
Should throw an UnsupportedOperationException if it isn't implemented
t
- a string containing the entire templateUnsupportedOperationException
- if this method isn't
implementedpublic java.lang.String[] parse(java.lang.String[] t)
Should throw an UnsupportedOperationException if it isn't implemented
t
- an array of strings containing the template - one line
at a timeUnsupportedOperationException
- if this method isn't
implemented
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |