1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.ediknight.edifact.setup;
21
22 import java.io.File;
23 import java.util.HashMap;
24 import java.util.Map;
25
26
27 /***
28 * @author Holger Joest
29 */
30 public final class AnalyzerContext {
31
32 private File targetDirectory;
33
34 private Map<String, String> parameterValues =
35 new HashMap<String, String>();
36
37
38 /***
39 * Returns a parameter value.
40 *
41 * @param parameter the parameter name
42 * @return the value of the specified parameter
43 */
44 public String getValue(String parameter) {
45 return parameterValues.get(parameter);
46 }
47
48
49 /***
50 * Sets a parameter value.
51 *
52 * @param parameter the parameter name
53 * @param value the value to set
54 */
55 public void setValue(String parameter, String value) {
56 parameterValues.put(parameter, value);
57 }
58
59
60 /***
61 * Expands parameter values in a given string.
62 *
63 * @param string the value to expand
64 * @return the expanded value
65 */
66 public String expandValues(String string) {
67 int p1 = string.indexOf("${");
68 while (p1 > -1) {
69 int p2 = string.indexOf("}", p1);
70 if (p2 < 0) {
71 return string;
72 }
73 String parameter = string.substring(p1 + 2, p2);
74 string = string.substring(0, p1)
75 + getValue(parameter)
76 + string.substring(p2 + 1);
77 p1 = string.indexOf("${");
78 }
79 return string;
80 }
81
82
83 /***
84 * Returns the target directory.
85 *
86 * @return the target directory
87 */
88 public File getTargetDirectory() {
89 return targetDirectory;
90 }
91
92
93 /***
94 * Sets the target directory.
95 *
96 * @param targetDirectory the directory to set
97 */
98 public void setTargetDirectory(File targetDirectory) {
99 this.targetDirectory = targetDirectory;
100 }
101
102 }
103