]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/template/SprintfCommand.java
add: guide the user back when ttp request is missing.
[gigi.git] / src / org / cacert / gigi / output / template / SprintfCommand.java
index 24608d2ec030ea671b5d7b69281e2d6107b08470..8d42af44f4b76f5e7fff844a8e6d28f20604dff7 100644 (file)
@@ -1,29 +1,41 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
-import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
-import org.cacert.gigi.Language;
+import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.Outputable;
+import org.cacert.gigi.util.HTMLEncoder;
 
-final class SprintfCommand implements Outputable {
-       private final String text;
-       private final LinkedList<String> store;
+public final class SprintfCommand implements Outputable {
 
-       SprintfCommand(String text, LinkedList<String> store) {
-               this.text = text;
-               this.store = store;
-       }
+    private final String text;
 
-       @Override
-       public void output(PrintWriter out, Language l, Map<String, Object> vars) {
-               String[] parts = l.getTranslation(text).split("%s");
-               String[] myvars = store.toArray(new String[store.size()]);
-               out.print(parts[0]);
-               for (int j = 1; j < parts.length; j++) {
-                       Template.outputVar(out, l, vars, myvars[j - 1].substring(1));
-                       out.print(parts[j]);
-               }
-       }
-}
\ No newline at end of file
+    private final String[] store;
+
+    public SprintfCommand(String text, List<String> store) {
+        this.text = text;
+        this.store = store.toArray(new String[store.size()]);
+    }
+
+    @Override
+    public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+        String[] parts = l.getTranslation(text).split("%s", -1);
+        String[] myvars = store;
+        out.print(HTMLEncoder.encodeHTML(parts[0]));
+        for (int j = 1; j < parts.length; j++) {
+            String var = myvars[j - 1];
+            if (var.startsWith("$!")) {
+                Template.outputVar(out, l, vars, myvars[j - 1].substring(2), true);
+            } else if (var.startsWith("!\"")) {
+                out.print(var.substring(2));
+            } else if (var.startsWith("\"")) {
+                out.print(HTMLEncoder.encodeHTML(var.substring(1)));
+            } else {
+                Template.outputVar(out, l, vars, myvars[j - 1].substring(1), false);
+            }
+            out.print(HTMLEncoder.encodeHTML(parts[j]));
+        }
+    }
+}