]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/template/Template.java
Suggestion to display datetimes in local format
[gigi.git] / src / org / cacert / gigi / output / template / Template.java
index 1705159514c02846432da50e6e4da76569f41861..15f3408d28ce41d10d55b4f9491fdaf223cb0d84 100644 (file)
@@ -22,6 +22,9 @@ import org.cacert.gigi.output.DateSelector;
 import org.cacert.gigi.util.DayDate;
 import org.cacert.gigi.util.HTMLEncoder;
 
 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 {
 public class Template implements Outputable {
 
     private static class ParseResult {
@@ -63,6 +66,14 @@ public class Template implements Outputable {
 
     private static final Pattern ELSE_PATTERN = Pattern.compile(" ?\\} ?else ?\\{ ?");
 
 
     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");
     public Template(URL u) {
         try {
             Reader r = new InputStreamReader(u.openStream(), "UTF-8");
@@ -81,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);
     public Template(Reader r) {
         try {
             data = parse(r).getBlock(null);
@@ -195,9 +213,11 @@ public class Template implements Outputable {
         } else if (s instanceof DayDate) {
             out.print(DateSelector.getDateFormat().format(((DayDate) s).toDate()));
         } else if (s instanceof Date) {
         } 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("<time datetime=\"" + sdf.format(s) + "\">");
+            out.print(sdfUI.format(s));
+            out.print(" UTC</time>");
         } else {
             out.print(s == null ? "null" : (unescaped ? s.toString() : HTMLEncoder.encodeHTML(s.toString())));
         }
         } else {
             out.print(s == null ? "null" : (unescaped ? s.toString() : HTMLEncoder.encodeHTML(s.toString())));
         }