]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/template/ForeachStatement.java
Implement a Template-Foreach (and use in "new email certificate")
[gigi.git] / src / org / cacert / gigi / output / template / ForeachStatement.java
1 package org.cacert.gigi.output.template;
2
3 import java.io.PrintWriter;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import org.cacert.gigi.Language;
8 import org.cacert.gigi.output.Outputable;
9
10 final class ForeachStatement implements Outputable {
11         private final String variable;
12         private final TemplateBlock body;
13
14         ForeachStatement(String variable, TemplateBlock body) {
15                 this.variable = variable;
16                 this.body = body;
17         }
18
19         @Override
20         public void output(PrintWriter out, Language l, Map<String, Object> vars) {
21                 Object o = vars.get(variable);
22                 if (o instanceof IterableDataset) {
23                         IterableDataset id = (IterableDataset) o;
24                         Map<String, Object> subcontext = new HashMap<String, Object>(vars);
25                         while (id.next(subcontext)) {
26                                 body.output(out, l, subcontext);
27                         }
28                 }
29         }
30 }