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