X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Foutput%2Ftemplate%2FIfStatement.java;h=f2248bcc72fd3a3987b87cc22f7192d5c2883bdc;hb=449f75a2b5d97ebf34bec2df715b71aa7e31afb0;hp=adb9099251038215f21c6f8a6e1bf11cb6acf42c;hpb=480cb29387c76ccc19f8fa8fb0abe8ae1b069730;p=gigi.git
diff --git a/src/org/cacert/gigi/output/template/IfStatement.java b/src/org/cacert/gigi/output/template/IfStatement.java
index adb90992..f2248bcc 100644
--- a/src/org/cacert/gigi/output/template/IfStatement.java
+++ b/src/org/cacert/gigi/output/template/IfStatement.java
@@ -1,27 +1,70 @@
package org.cacert.gigi.output.template;
import java.io.PrintWriter;
+import java.util.Collection;
import java.util.Map;
import org.cacert.gigi.localisation.Language;
-import org.cacert.gigi.output.Outputable;
-public final class IfStatement implements Outputable {
+/**
+ * One ore two {@link Outputable}s that are emitted conditionally if a given
+ * variable is neither null
nor {@link Boolean#FALSE}.
+ */
+public final class IfStatement implements Translatable {
private final String variable;
- private final TemplateBlock body;
+ private final TemplateBlock iftrue;
+ private final TemplateBlock iffalse;
+
+ /**
+ * Creates a new {@link IfStatement} with an empty else-part.
+ *
+ * @param variable
+ * the variable to check
+ * @param body
+ * the body to emit conditionally.
+ */
public IfStatement(String variable, TemplateBlock body) {
this.variable = variable;
- this.body = body;
+ this.iftrue = body;
+ this.iffalse = null;
+ }
+
+ /**
+ * Creates a new {@link IfStatement} with an else-block.
+ *
+ * @param variable
+ * the variable to check
+ * @param iftrue
+ * the block to emit if the check succeeds.
+ * @param iffalse
+ * the block to emit if the check fails
+ */
+ public IfStatement(String variable, TemplateBlock iftrue, TemplateBlock iffalse) {
+ this.variable = variable;
+ this.iftrue = iftrue;
+ this.iffalse = iffalse;
}
@Override
public void output(PrintWriter out, Language l, Map vars) {
Object o = vars.get(variable);
- if ( !(o == Boolean.FALSE || o == null)) {
- body.output(out, l, vars);
+
+ if ( !(o == null || Boolean.FALSE.equals(o))) {
+ iftrue.output(out, l, vars);
+ } else if (iffalse != null) {
+ iffalse.output(out, l, vars);
}
}
+
+ @Override
+ public void addTranslations(Collection s) {
+ iftrue.addTranslations(s);
+ if (iffalse != null) {
+ iffalse.addTranslations(s);
+ }
+ }
+
}