]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/template/Template.java
Adding fetch for tag 1.4.0
[gigi.git] / src / org / cacert / gigi / output / template / Template.java
index 2702f6c108fcb36b939ec9c77f3bcc4ec9bf61a4..0bd9cce170096b4d4088ed158edca8c4f9dfb459 100644 (file)
@@ -15,16 +15,16 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.cacert.gigi.DevelLauncher;
-import org.cacert.gigi.Language;
-import org.cacert.gigi.output.Outputable;
+import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.util.HTMLEncoder;
 
 public class Template implements Outputable {
 
-    TemplateBlock data;
+    private TemplateBlock data;
 
-    long lastLoaded;
+    private long lastLoaded;
 
-    File source;
+    private File source;
 
     private static final Pattern CONTROL_PATTERN = Pattern.compile(" ?([a-z]+)\\(\\$([^)]+)\\) ?\\{ ?");
 
@@ -120,9 +120,15 @@ public class Template implements Outputable {
         } else if (s2.startsWith("=s,")) {
             String command = s2.substring(3);
             final LinkedList<String> store = new LinkedList<String>();
-            while (command.startsWith("$")) {
-                int idx = command.indexOf(",");
-                store.add(command.substring(0, idx));
+            while (command.startsWith("$") || command.startsWith("\"") || command.startsWith("!\"")) {
+                int idx;
+                if (command.startsWith("\"") || command.startsWith("!\"")) {
+                    idx = command.indexOf("\"", command.charAt(0) == '!' ? 2 : 1) + 1;
+                    store.add(command.substring(0, idx - 1));
+                } else {
+                    idx = command.indexOf(",");
+                    store.add(command.substring(0, idx));
+                }
                 command = command.substring(idx + 1);
             }
             final String text = command;
@@ -133,6 +139,7 @@ public class Template implements Outputable {
         return null;
     }
 
+    @Override
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
         if (source != null && DevelLauncher.DEVEL) {
             if (lastLoaded < source.lastModified()) {
@@ -150,7 +157,7 @@ public class Template implements Outputable {
         data.output(out, l, vars);
     }
 
-    protected static void outputVar(PrintWriter out, Language l, Map<String, Object> vars, String varname) {
+    protected static void outputVar(PrintWriter out, Language l, Map<String, Object> vars, String varname, boolean unescaped) {
         Object s = vars.get(varname);
 
         if (s == null) {
@@ -159,7 +166,7 @@ public class Template implements Outputable {
         if (s instanceof Outputable) {
             ((Outputable) s).output(out, l, vars);
         } else {
-            out.print(s);
+            out.print(s == null ? "null" : (unescaped ? s.toString() : HTMLEncoder.encodeHTML(s.toString())));
         }
     }
 }