1 package org.apache.velocity.test.provider;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Hashtable;
24 import java.util.List;
25 import java.util.Stack;
26 import java.util.Vector;
27
28
29
30
31
32
33
34
35
36 public class TestProvider
37 {
38 String title = "lunatic";
39 boolean state;
40 Object ob = null;
41
42 public static String PUB_STAT_STRING = "Public Static String";
43
44 int stateint = 0;
45
46
47 public String getName()
48 {
49 return "jason";
50 }
51
52 public Stack getStack()
53 {
54 Stack stack = new Stack();
55 stack.push("stack element 1");
56 stack.push("stack element 2");
57 stack.push("stack element 3");
58 return stack;
59 }
60
61 public List getEmptyList()
62 {
63 List list = new ArrayList();
64 return list;
65 }
66
67 public List getList()
68 {
69 List list = new ArrayList();
70 list.add("list element 1");
71 list.add("list element 2");
72 list.add("list element 3");
73
74 return list;
75 }
76
77 public Hashtable getSearch()
78 {
79 Hashtable h = new Hashtable();
80 h.put("Text", "this is some text");
81 h.put("EscText", "this is escaped text");
82 h.put("Title", "this is the title");
83 h.put("Index", "this is the index");
84 h.put("URL", "http://periapt.com");
85
86 ArrayList al = new ArrayList();
87 al.add(h);
88
89 h.put("RelatedLinks", al);
90
91 return h;
92 }
93
94 public Hashtable getHashtable()
95 {
96 Hashtable h = new Hashtable();
97 h.put("key0", "value0");
98 h.put("key1", "value1");
99 h.put("key2", "value2");
100
101 return h;
102 }
103
104 public ArrayList getRelSearches()
105 {
106 ArrayList al = new ArrayList();
107 al.add(getSearch());
108
109 return al;
110 }
111
112 public String getTitle()
113 {
114 return title;
115 }
116
117 public void setTitle(String title)
118 {
119 this.title = title;
120 }
121
122 public Object[] getMenu()
123 {
124
125 Object[] menu = new Object[3];
126 for (int i = 0; i < 3; i++)
127 {
128 Hashtable item = new Hashtable();
129 item.put("id", "item" + Integer.toString(i+1));
130 item.put("name", "name" + Integer.toString(i+1));
131 item.put("label", "label" + Integer.toString(i+1));
132
133 menu[i] = item;
134 }
135
136
137 return menu;
138 }
139
140 public ArrayList getCustomers()
141 {
142 ArrayList list = new ArrayList();
143
144 list.add("ArrayList element 1");
145 list.add("ArrayList element 2");
146 list.add("ArrayList element 3");
147 list.add("ArrayList element 4");
148
149 return list;
150 }
151
152 public ArrayList getCustomers2()
153 {
154 ArrayList list = new ArrayList();
155
156 list.add(new TestProvider());
157 list.add(new TestProvider());
158 list.add(new TestProvider());
159 list.add(new TestProvider());
160
161 return list;
162 }
163
164 public Object me()
165 {
166 return this;
167 }
168
169 public String toString()
170 {
171 return ("test provider");
172 }
173
174 public Vector getVector()
175 {
176 Vector list = new Vector();
177
178 list.addElement("vector element 1");
179 list.addElement("vector element 2");
180
181 return list;
182 }
183
184 public String[] getArray()
185 {
186 String[] strings = new String[2];
187 strings[0] = "first element";
188 strings[1] = "second element";
189 return strings;
190 }
191
192 public boolean theAPLRules()
193 {
194 return true;
195 }
196
197 public boolean getStateTrue()
198 {
199 return true;
200 }
201
202 public boolean getStateFalse()
203 {
204 return false;
205 }
206
207 public String objectArrayMethod(Object[] o)
208 {
209 return "result of objectArrayMethod";
210 }
211
212 public String concat(Object[] strings)
213 {
214 StringBuffer result = new StringBuffer();
215
216 for (int i = 0; i < strings.length; i++)
217 {
218 result.append((String) strings[i]).append(' ');
219 }
220
221 return result.toString();
222 }
223
224 public String concat(List strings)
225 {
226 StringBuffer result = new StringBuffer();
227
228 for (int i = 0; i < strings.size(); i++)
229 {
230 result.append((String) strings.get(i)).append(' ');
231 }
232
233 return result.toString();
234 }
235
236 public String objConcat(List objects)
237 {
238 StringBuffer result = new StringBuffer();
239
240 for (int i = 0; i < objects.size(); i++)
241 {
242 result.append(objects.get(i)).append(' ');
243 }
244
245 return result.toString();
246 }
247
248 public String parse(String a, Object o, String c, String d)
249 {
250 return a + o.toString() + c + d;
251 }
252
253 public String concat(String a, String b)
254 {
255 return a + b;
256 }
257
258
259
260 public Person getPerson()
261 {
262 return new Person();
263 }
264
265 public Child getChild()
266 {
267 return new Child();
268 }
269
270 public String showPerson(Person person)
271 {
272 return person.getName();
273 }
274
275
276
277
278
279
280
281
282 public String chop(String string, int i)
283 {
284 return(string.substring(0, string.length() - i));
285 }
286
287 public boolean allEmpty(Object[] list)
288 {
289 int size = list.length;
290
291 for (int i = 0; i < size; i++)
292 if (list[i].toString().length() > 0)
293 return false;
294
295 return true;
296 }
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314 public void setState(Boolean state)
315 {
316 }
317
318 public void setBangStart( Integer i )
319 {
320 System.out.println("SetBangStart() : called with val = " + i );
321 stateint = i.intValue();
322 }
323 public Integer bang()
324 {
325 System.out.println("Bang! : " + stateint );
326 Integer ret = new Integer( stateint );
327 stateint++;
328 return ret;
329 }
330
331
332
333
334
335
336 public String get(String key)
337 {
338 return key;
339 }
340
341
342
343
344
345
346 public String put(String key, Object o)
347 {
348 ob = o;
349 return key;
350 }
351
352 public String getFoo()
353 throws Exception
354 {
355 throw new Exception("From getFoo()");
356 }
357
358 public String getThrow()
359 throws Exception
360 {
361 throw new Exception("From getThrow()");
362 }
363 }