X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Foutput%2Ftemplate%2FTemplate.java;h=15f3408d28ce41d10d55b4f9491fdaf223cb0d84;hp=84727f25758dfd6b6f795c40c17d5064284c9331;hb=78aea4e2c6a8e99ba546c4189d7071d57c1aaf3b;hpb=c0d62ad52b65d78806431b34ed2ae24bf58c1ada diff --git a/src/org/cacert/gigi/output/template/Template.java b/src/org/cacert/gigi/output/template/Template.java index 84727f25..15f3408d 100644 --- a/src/org/cacert/gigi/output/template/Template.java +++ b/src/org/cacert/gigi/output/template/Template.java @@ -10,6 +10,7 @@ import java.io.Reader; import java.net.URISyntaxException; import java.net.URL; import java.text.SimpleDateFormat; +import java.util.Collection; import java.util.Date; import java.util.LinkedList; import java.util.Map; @@ -21,6 +22,9 @@ import org.cacert.gigi.output.DateSelector; import org.cacert.gigi.util.DayDate; import org.cacert.gigi.util.HTMLEncoder; +/** + * Represents a loaded template file. + */ public class Template implements Outputable { private static class ParseResult { @@ -62,6 +66,14 @@ public class Template implements Outputable { private static final Pattern ELSE_PATTERN = Pattern.compile(" ?\\} ?else ?\\{ ?"); + /** + * Creates a new template by parsing the contents from the given URL. This + * constructor will fail on syntax error. When the URL points to a file, + * {@link File#lastModified()} is monitored for changes of the template. + * + * @param u + * the URL to load the template from. UTF-8 is chosen as charset. + */ public Template(URL u) { try { Reader r = new InputStreamReader(u.openStream(), "UTF-8"); @@ -80,6 +92,13 @@ public class Template implements Outputable { } } + /** + * Creates a new template by parsing the contents from the given reader. + * This constructor will fail on syntax error. + * + * @param r + * the Reader containing the data. + */ public Template(Reader r) { try { data = parse(r).getBlock(null); @@ -91,7 +110,7 @@ public class Template implements Outputable { private ParseResult parse(Reader r) throws IOException { LinkedList splitted = new LinkedList(); - LinkedList commands = new LinkedList(); + LinkedList commands = new LinkedList(); StringBuffer buf = new StringBuffer(); String blockType = null; outer: @@ -144,14 +163,14 @@ public class Template implements Outputable { } } splitted.add(buf.toString()); - return new ParseResult(new TemplateBlock(splitted.toArray(new String[splitted.size()]), commands.toArray(new Outputable[commands.size()])), blockType); + return new ParseResult(new TemplateBlock(splitted.toArray(new String[splitted.size()]), commands.toArray(new Translatable[commands.size()])), blockType); } private boolean endsWith(StringBuffer buf, String string) { return buf.length() >= string.length() && buf.substring(buf.length() - string.length(), buf.length()).equals(string); } - private Outputable parseCommand(String s2) { + private Translatable parseCommand(String s2) { if (s2.startsWith("=_")) { final String raw = s2.substring(2); if ( !s2.contains("$") && !s2.contains("!'")) { @@ -194,11 +213,17 @@ public class Template implements Outputable { } else if (s instanceof DayDate) { out.print(DateSelector.getDateFormat().format(((DayDate) s).toDate())); } else if (s instanceof Date) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - out.print(sdf.format(s)); - out.print(" UTC"); + SimpleDateFormat sdfUI = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + out.print(""); } else { out.print(s == null ? "null" : (unescaped ? s.toString() : HTMLEncoder.encodeHTML(s.toString()))); } } + + public void addTranslations(Collection s) { + data.addTranslations(s); + } }