]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/template/SprintfCommand.java
UPD: Move some template classes to there reightful place.
[gigi.git] / src / org / cacert / gigi / output / template / SprintfCommand.java
1 package org.cacert.gigi.output.template;
2
3 import java.io.PrintWriter;
4 import java.util.List;
5 import java.util.Map;
6
7 import org.cacert.gigi.localisation.Language;
8 import org.cacert.gigi.util.HTMLEncoder;
9
10 public final class SprintfCommand implements Outputable {
11
12     private final String text;
13
14     private final String[] store;
15
16     public SprintfCommand(String text, List<String> store) {
17         this.text = text;
18         this.store = store.toArray(new String[store.size()]);
19     }
20
21     @Override
22     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
23         String[] parts = l.getTranslation(text).split("%s", -1);
24         String[] myvars = store;
25         out.print(HTMLEncoder.encodeHTML(parts[0]));
26         for (int j = 1; j < parts.length; j++) {
27             String var = myvars[j - 1];
28             if (var.startsWith("$!")) {
29                 Template.outputVar(out, l, vars, myvars[j - 1].substring(2), true);
30             } else if (var.startsWith("!\"")) {
31                 out.print(var.substring(2));
32             } else if (var.startsWith("\"")) {
33                 out.print(HTMLEncoder.encodeHTML(var.substring(1)));
34             } else {
35                 Template.outputVar(out, l, vars, myvars[j - 1].substring(1), false);
36             }
37             out.print(HTMLEncoder.encodeHTML(parts[j]));
38         }
39     }
40 }