]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/template/IfStatement.java
Implement template if-else statements
[gigi.git] / src / org / cacert / gigi / output / template / IfStatement.java
index db0cbe11f07f20132ebdad1503ed82695686f849..fbd83bcfc799c70059b6f226f225dd84f5bab6e2 100644 (file)
@@ -9,18 +9,29 @@ public final class IfStatement implements Outputable {
 
     private final String variable;
 
-    private final TemplateBlock body;
+    private final TemplateBlock iftrue;
+
+    private final TemplateBlock iffalse;
 
     public IfStatement(String variable, TemplateBlock body) {
         this.variable = variable;
-        this.body = body;
+        this.iftrue = body;
+        iffalse = null;
+    }
+
+    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<String, Object> vars) {
         Object o = vars.get(variable);
         if ( !(o == Boolean.FALSE || o == null)) {
-            body.output(out, l, vars);
+            iftrue.output(out, l, vars);
+        } else if (iffalse != null) {
+            iffalse.output(out, l, vars);
         }
     }
 }