1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.javadpkg.impl;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import net.sourceforge.javadpkg.Context;
25 import net.sourceforge.javadpkg.Script;
26 import net.sourceforge.javadpkg.ScriptVariableReplacer;
27 import net.sourceforge.javadpkg.replace.ReplacementException;
28 import net.sourceforge.javadpkg.replace.Replacements;
29 import net.sourceforge.javadpkg.replace.Replacer;
30 import net.sourceforge.javadpkg.replace.ReplacerImpl;
31
32
33
34
35
36
37
38
39
40
41 public class ScriptVariableReplacerImpl implements ScriptVariableReplacer {
42
43
44
45 private Replacer replacer;
46
47
48
49
50
51
52
53 public ScriptVariableReplacerImpl() {
54 super();
55
56 this.replacer = new ReplacerImpl();
57 }
58
59
60 @Override
61 public Script replaceScriptVariables(Script script, Replacements replacements, Context context)
62 throws ReplacementException {
63
64 Script result;
65 List<String> lines;
66 String replaced;
67
68
69 if (script == null)
70 throw new IllegalArgumentException("Argument script is null.");
71 if (replacements == null)
72 throw new IllegalArgumentException("Argument replacements is null.");
73 if (context == null)
74 throw new IllegalArgumentException("Argument context is null.");
75
76 lines = new ArrayList<>();
77 for (String line : script.getLines()) {
78 replaced = this.replacer.replace(line, replacements, context);
79 lines.add(replaced);
80 }
81 result = new ScriptImpl(lines);
82 return result;
83 }
84
85
86 }