1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package tools.gsf.facade.runtag.xlat;
18
19 import COM.FutureTense.Interfaces.ICS;
20 import tools.gsf.facade.runtag.AbstractTagRunner;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25
26
27
28
29
30
31 public final class Lookup extends AbstractTagRunner {
32
33 public Lookup() {
34 super("XLAT.LOOKUP");
35 }
36
37
38
39
40
41
42 public void setKey(String s) {
43
44 if (s == null || s.length() == 0) {
45 throw new IllegalArgumentException("Invalid key string: " + s);
46 }
47 this.set("KEY", s);
48 }
49
50
51
52
53
54
55 public void setVarname(String s) {
56
57 if (s == null || s.length() == 0) {
58 throw new IllegalArgumentException("Invalid varname string: " + s);
59 }
60 this.set("VARNAME", s);
61 }
62
63
64
65
66
67
68 public void setLocale(String s) {
69
70 if (s == null || s.length() == 0) {
71 throw new IllegalArgumentException("Invalid locale string: " + s);
72 }
73 this.set("LOCALE", s);
74 }
75
76
77
78
79
80
81 public void setEncode(String s) {
82
83 if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
84 throw new IllegalArgumentException("Invalid encode string: " + s);
85 }
86 this.set("ENCODE", s);
87 }
88
89
90
91
92
93
94 public void setEscape(String s) {
95
96 if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
97 throw new IllegalArgumentException("Invalid escape string: " + s);
98 }
99 this.set("ESCAPE", s);
100 }
101
102
103
104
105
106
107 public void setEvalAll(String s) {
108
109 if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
110 throw new IllegalArgumentException("Invalid evalall string: " + s);
111 }
112 this.set("EVALALL", s);
113 }
114
115
116
117
118
119
120
121
122 public void setArgument(String argname, String argvalue) {
123
124 if (argname == null || argname.length() == 0) {
125 throw new IllegalArgumentException("Invalid argname string: " + argname);
126 }
127 if (argvalue == null || argvalue.length() == 0) {
128 throw new IllegalArgumentException("Invalid argvalue string: " + argvalue);
129 }
130 this.set(argname, argvalue);
131 }
132
133 protected void preExecute(ICS ics) {
134
135
136 super.preExecute(ics);
137
138 List<String> newVars = new ArrayList<String>();
139 for (Object oKey : list.keySet()) {
140 String sKey = (String) oKey;
141 if (ics.GetVar(sKey) == null) {
142 newVars.add(sKey);
143 ics.SetVar(sKey, list.getValString(sKey));
144 }
145 }
146 ics.SetObj("NewVars", newVars);
147 }
148
149 @SuppressWarnings("unchecked")
150 protected void postExecute(ICS ics) {
151 super.postExecute(ics);
152 List<String> newVars = (List<String>) ics.GetObj("NewVars");
153 for (String toRemove : newVars) {
154 ics.RemoveVar(toRemove);
155 }
156 ics.SetObj("NewVars", null);
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171 public static String lookup(ICS ics, String key, String locale, boolean encode) {
172 Lookup l = new Lookup();
173 l.setKey(key);
174 l.setEncode(encode ? "true" : "false");
175 l.setLocale(locale);
176 String var = ics.genID(true);
177 l.setVarname(var);
178 String result = null;
179 try {
180 l.execute(ics);
181 result = ics.GetVar(var);
182 } finally {
183 ics.RemoveVar(var);
184 }
185 return result;
186 }
187
188 }