| java.lang.Object de.anomic.http.httpTemplate
httpTemplate | final public class httpTemplate (Code) | | A template engine, which substitutes patterns in strings
The template engine supports four types of templates:
- Normal templates: the template will be replaced by a string.
- Multi templates: the template will be used more than one time.
i.e. for lists
- 3. Alternatives: the program chooses one of multiple alternatives.
- Includes: another file with templates will be included.
All these templates can be used recursivly.
HTML-Example
<html><head></head><body>
#{times}#
Good #(daytime)#morning::evening#(/daytime)#, #[name]#!(#[num]#. Greeting)<br>
#{/times}#
</body></html>
The corresponding Hashtable to use this Template:
Java Example
Hashtable pattern;
pattern.put("times", 10); //10 greetings
for(int i=0;i<=9;i++){
pattern.put("times_"+i+"_daytime", 1); //index: 1, second Entry, evening
pattern.put("times_"+i+"_name", "John Connor");
pattern.put("times_"+i+"_num", (i+1));
}
Recursion
If you use recursive templates, the templates will be used from
the external to the internal templates.
In our Example, the Template in #{times}##{/times}# will be repeated ten times.
Then the inner Templates will be applied.
The inner templates have a prefix, so they may have the same name as a template on another level,
or templates which are in another recursive template.
The Prefixes:
- Multi templates: multitemplatename_index_
- Alterantives: alternativename_
So the Names in the Hashtable are:
- Multi templates: multitemplatename_index_templatename
- Alterantives: alternativename_templatename
#(alternative)#::#{repeat}##[test]##{/repeat}##(/alternative)#
would be adressed as "alternative_repeat_"+number+"_test"
|
Method Summary | |
public static byte[] | appendBytes(byte[] b1, byte[] b2, byte[] b3, byte[] b4) | public static String | getPatternKey(byte[] prefix, byte[] key) | public static HashMap<String, String> | loadTemplates(File path) | public static void | main(String[] args) | public static byte[] | newPrefix(byte[] oldPrefix, byte[] key) | public static byte[] | newPrefix(byte[] oldPrefix, byte[] multi_key, int i) | public static byte[] | replacePattern(String key, HashMap<String, String> pattern, byte dflt) | public static List<serverByteBuffer> | splitQuotation(serverByteBuffer text, int qoff) | public static serverByteBuffer[] | splitQuotations(serverByteBuffer text) | public static void | writeTemplate(InputStream in, OutputStream out, HashMap<String, String> pattern, byte[] dflt) | public static byte[] | writeTemplate(InputStream in, OutputStream out, HashMap<String, String> pattern, byte[] dflt, byte[] prefix) |
dpdpa | final public static byte[] dpdpa(Code) | | |
hash | final public static byte hash(Code) | | |
meta_quotation | final public static Object[] meta_quotation(Code) | | |
slash | final public static byte[] slash(Code) | | |
appendBytes | public static byte[] appendBytes(byte[] b1, byte[] b2, byte[] b3, byte[] b4)(Code) | | |
getPatternKey | public static String getPatternKey(byte[] prefix, byte[] key)(Code) | | |
newPrefix | public static byte[] newPrefix(byte[] oldPrefix, byte[] key)(Code) | | |
newPrefix | public static byte[] newPrefix(byte[] oldPrefix, byte[] multi_key, int i)(Code) | | |
|
|