/**
* This example demonstrates the html-template features. For more
* information please see the example3.tlt file.
*/
import ee.mare.indrek.jtlt.*;
import ee.mare.indrek.jtlt.macros.*;
import java.util.*;
import java.io.*;
public class Example3 {
public static void main (String[] args) throws Exception
{
// Determine the language from argv, you are encouraged to try
// others aswell. We default to french, coded as FR.
String lang = args.length > 0 ? args[0] : "FR";
// We create our html templates context
HtmlTemplateContext my_ctx = new HtmlTemplateContext ();
// We add the special include macro that is not in it by default
my_ctx.registerMacro (new IncludeMacro("."));
// We load our filesystem based localization alias database
my_ctx.setAliasDatabase (FilebasedAliasDatabase.loadFilebasedAliasDatabase ("example3.adb"));
// Lets create a template
HtmlTemplate tlt = new HtmlTemplateGenerator("example3.tlt", my_ctx).createHtmlTemplate(lang);
// Try to insert HTML tags using replace
tlt.replace ("hello", "Hello there, <b>Mr. Babbage</b>.");
// Try to insert more evil HTML
tlt.replace ("input_value", "\"'<>&");
// This time we want the tags to get through intact
tlt.replace_raw ("hello_raw", "Hello there, <b>Mr. Babbage</b>.");
// Javascript demonstration
tlt.replace ("hello_js", "Hello there,\n'Mr. Babbage'!");
// Url encode
tlt.replace ("url_arg", "Sam&Max love to dance? Don't think so!");
System.out.println (tlt.toString());
}
}
syntax highlighted by Code2HTML, v. 0.9.1