1 15 package org.apache.tapestry.script; 16 17 import java.util.Iterator ; 18 import java.util.Map ; 19 20 import org.apache.hivemind.Location; 21 22 33 34 class ForeachToken extends AbstractToken 35 { 36 private String _key; 37 38 private String _index; 39 40 private String _expression; 41 42 ForeachToken(String key, String index, String expression, Location location) 43 { 44 super(location); 45 46 _key = key; 47 _index = index; 48 _expression = expression; 49 } 50 51 public void write(StringBuffer buffer, ScriptSession session) 52 { 53 Iterator i = (Iterator ) session.evaluate(_expression, Iterator .class); 54 55 if (i == null) 56 return; 57 58 Map symbols = session.getSymbols(); 59 60 int index = 0; 61 62 while (i.hasNext()) 63 { 64 Object newValue = i.next(); 65 66 symbols.put(_key, newValue); 67 68 if (_index != null) 69 symbols.put(_index, String.valueOf(index)); 70 71 writeChildren(buffer, session); 72 73 index++; 74 } 75 76 } 79 } | Popular Tags |