]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/template/Scope.java
700ccfe7e9b717229869720ebc61f3eb387a5a41
[gigi.git] / src / org / cacert / gigi / output / template / Scope.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.localisation.Language;
8
9 /**
10  * Builds a variable scope around another {@link Outputable}, statically filling
11  * variables.
12  */
13 public class Scope implements Outputable {
14
15     private Map<String, Object> vars;
16
17     private Outputable out;
18
19     /**
20      * Creates a new {@link Scope}.
21      * 
22      * @param out
23      *            the enclosed {@link Outputable}.
24      * @param vars
25      *            the variables to assign in the inner scope.
26      */
27     public Scope(Outputable out, Map<String, Object> vars) {
28         this.out = out;
29         this.vars = vars;
30     }
31
32     @Override
33     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
34         HashMap<String, Object> map = new HashMap<>();
35         map.putAll(vars);
36         map.putAll(this.vars);
37         this.out.output(out, l, map);
38     }
39
40 }