]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/template/IfStatement.java
0347a363db8798f3d98356fc68bbdea737c19d1f
[gigi.git] / src / org / cacert / gigi / output / template / IfStatement.java
1 package org.cacert.gigi.output.template;
2
3 import java.io.PrintWriter;
4 import java.util.Map;
5
6 import org.cacert.gigi.localisation.Language;
7
8 public final class IfStatement implements Outputable {
9
10     private final String variable;
11
12     private final TemplateBlock iftrue;
13
14     private final TemplateBlock iffalse;
15
16     public IfStatement(String variable, TemplateBlock body) {
17         this.variable = variable;
18         this.iftrue = body;
19         this.iffalse = null;
20     }
21
22     public IfStatement(String variable, TemplateBlock iftrue, TemplateBlock iffalse) {
23         this.variable = variable;
24         this.iftrue = iftrue;
25         this.iffalse = iffalse;
26     }
27
28     @Override
29     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
30         Object o = vars.get(variable);
31
32         if ( !(o == null || Boolean.FALSE.equals(o))) {
33             iftrue.output(out, l, vars);
34         } else if (iffalse != null) {
35             iffalse.output(out, l, vars);
36         }
37     }
38
39 }