aboutsummaryrefslogtreecommitdiff
path: root/java/pablotron/luigi/Template.java
blob: 2bf0bb74711502f688f9baa0176b8b24854c3d5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package pablotron.luigi;

import java.util.Map;
import pablotron.luigi.Parser;
import pablotron.luigi.Filter;
import pablotron.luigi.LuigiError;
import pablotron.luigi.actions.Action;

public final class Template {
  private static final String VERSION = "0.4.0";

  private final String template;
  private final Action actions[];
  private final Map<String, Filter.Handler> filters;

  public Template(
    final String template,
    final Map<String, Filter.Handler> filters
  ) throws LuigiError {
    this.template = template;
    this.filters = filters;
    this.actions = Parser.parse_template(template);
  }

  public Template(final String template) throws LuigiError {
    this(template, Filter.FILTERS);
  }

  public String run(Map<String, String> args) throws LuigiError {
    StringBuilder r = new StringBuilder();

    for (Action a: this.actions)
      r.append(a.run(this.filters, args));

    return r.toString();
  }
};