HTML.Tmpl
Interface Filter


public interface Filter

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

SCALAR

public static final int SCALAR
Tells HTML.Template to call the parse(String) method of this filter.

ARRAY

public static final int ARRAY
Tells HTML.Template to call the parse(String []) method of this filter.
Method Detail

format

public int format()
Tells HTML.Template what kind of filter this is. Should return either SCALAR or ARRAY to indicate which parse method must be called.
Returns:
the values SCALAR or ARRAY indicating which parse method is to be called

parse

public java.lang.String parse(java.lang.String t)
parses the template as a single string, and returns the parsed template as a single string.

Should throw an UnsupportedOperationException if it isn't implemented

Parameters:
t - a string containing the entire template
Returns:
a string containing the template after you've parsed it
Throws:
UnsupportedOperationException - if this method isn't implemented

parse

public 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.

Should throw an UnsupportedOperationException if it isn't implemented

Parameters:
t - an array of strings containing the template - one line at a time
Returns:
an array of strings containing the parsed template - one line at a time
Throws:
UnsupportedOperationException - if this method isn't implemented