X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Foutput%2Ftemplate%2FTemplate.java;h=1705159514c02846432da50e6e4da76569f41861;hb=ec155eec51606c19970c9099ef23f700fb6aa53a;hp=8bcbc8f24ebe156a98d5cdd38918e494e94c004d;hpb=95840660b28dce27a38ed7de0b66634ec7f38ba2;p=gigi.git diff --git a/src/org/cacert/gigi/output/template/Template.java b/src/org/cacert/gigi/output/template/Template.java index 8bcbc8f2..17051595 100644 --- a/src/org/cacert/gigi/output/template/Template.java +++ b/src/org/cacert/gigi/output/template/Template.java @@ -9,17 +9,22 @@ import java.io.PrintWriter; 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; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.DateSelector; +import org.cacert.gigi.util.DayDate; import org.cacert.gigi.util.HTMLEncoder; public class Template implements Outputable { - class ParseResult { + private static class ParseResult { TemplateBlock block; @@ -87,7 +92,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: @@ -140,14 +145,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("!'")) { @@ -187,8 +192,18 @@ public class Template implements Outputable { } if (s instanceof Outputable) { ((Outputable) s).output(out, l, vars); + } 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"); } else { out.print(s == null ? "null" : (unescaped ? s.toString() : HTMLEncoder.encodeHTML(s.toString()))); } } + + public void addTranslations(Collection s) { + data.addTranslations(s); + } }