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