1 13 package info.magnolia.cms.i18n; 14 15 import java.util.ArrayList ; 16 import java.util.HashSet ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 import java.util.Set ; 20 21 import org.apache.commons.collections.IteratorUtils; 22 23 24 29 public class MessagesChain extends AbstractMessagesImpl { 30 31 34 private List chain = new ArrayList (); 35 36 39 public MessagesChain(Messages head) { 40 super(head.getBasename(), head.getLocale()); 41 chain.add(head); 42 } 43 44 49 public Messages chain(Messages messages) { 50 chain.add(messages); 51 return this; 52 } 53 54 57 public String get(String key) { 58 for (Iterator iter = chain.iterator(); iter.hasNext();) { 59 Messages msgs = (Messages) iter.next(); 60 String str = msgs.get(key); 61 if (!str.startsWith("???")) { 62 return str; 63 } 64 } 65 return "???" + key + "???"; 66 } 67 68 71 public Iterator keys() { 72 Set keys = new HashSet (); 73 for (Iterator iter = chain.iterator(); iter.hasNext();) { 74 Messages msgs = (Messages) iter.next(); 75 List current = IteratorUtils.toList(msgs.keys()); 76 keys.addAll(current); 77 } 78 return keys.iterator(); 79 } 80 81 84 public void reload() throws Exception { 85 for (Iterator iter = chain.iterator(); iter.hasNext();) { 86 Messages msgs = (Messages) iter.next(); 87 msgs.reload(); 88 } 89 } 90 } 91 | Popular Tags |