]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/template/ForeachStatement.java
Merge "add: api for Test-memberid-lookup (addresses #4)"
[gigi.git] / src / org / cacert / gigi / output / template / ForeachStatement.java
index 38aad35f8f95d1d9573aaddb98807ccc546027f3..4c8b1027b5f7dfb3df420b309fffe699fad94d26 100644 (file)
@@ -1,30 +1,49 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.cacert.gigi.Language;
-import org.cacert.gigi.output.Outputable;
-
-final class ForeachStatement implements Outputable {
-       private final String variable;
-       private final TemplateBlock body;
-
-       ForeachStatement(String variable, TemplateBlock body) {
-               this.variable = variable;
-               this.body = body;
-       }
-
-       @Override
-       public void output(PrintWriter out, Language l, Map<String, Object> vars) {
-               Object o = vars.get(variable);
-               if (o instanceof IterableDataset) {
-                       IterableDataset id = (IterableDataset) o;
-                       Map<String, Object> subcontext = new HashMap<String, Object>(vars);
-                       while (id.next(l, subcontext)) {
-                               body.output(out, l, subcontext);
-                       }
-               }
-       }
-}
\ No newline at end of file
+import org.cacert.gigi.localisation.Language;
+
+/**
+ * Outputs an {@link Outputable} multiple times based on a given
+ * {@link IterableDataset}.
+ */
+public final class ForeachStatement implements Translatable {
+
+    private final String variable;
+
+    private final TemplateBlock body;
+
+    /**
+     * Creates a new {@link ForeachStatement}.
+     * 
+     * @param variable
+     *            the variable to take the {@link IterableDataset} from.
+     * @param body
+     *            the body to output multiple times.
+     */
+    public ForeachStatement(String variable, TemplateBlock body) {
+        this.variable = variable;
+        this.body = body;
+    }
+
+    @Override
+    public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+        Object o = vars.get(variable);
+        if (o instanceof IterableDataset) {
+            IterableDataset id = (IterableDataset) o;
+            Map<String, Object> subcontext = new HashMap<String, Object>(vars);
+            while (id.next(l, subcontext)) {
+                body.output(out, l, subcontext);
+            }
+        }
+    }
+
+    @Override
+    public void addTranslations(Collection<String> s) {
+        body.addTranslations(s);
+    }
+}