1 23 24 package org.infoglue.cms.util; 25 26 import java.text.MessageFormat ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.infoglue.cms.exception.Bug; 32 import org.infoglue.cms.exception.ConfigurationError; 33 34 35 38 class ChainedStringManager implements StringManager { 39 42 private List managers = new ArrayList (); 44 45 46 47 49 private static final StringManager sm = StringManagerFactory.getSystemStringManager(Constants.PACKAGE_NAME); 51 52 53 54 58 61 public final String getString(String key) { 62 for(Iterator iterator = this.managers.iterator(); iterator.hasNext(); ) { 63 SimpleStringManager manager = (SimpleStringManager) iterator.next(); 64 if(manager.containsKey(key)) { 65 return manager.getString(key); 66 } 67 } 68 throw new ConfigurationError(sm.getString("chain.getString.not_found_error", key)); 69 } 70 71 74 public final String getString(String key, Object args[]) { 75 return MessageFormat.format(getString(key), args); 76 } 77 78 81 public final String getString(String key, Object arg) { 82 return getString(key, new Object []{ arg }); 83 } 84 85 88 public final String getString(String key, Object arg1, Object arg2) { 89 return getString(key, new Object []{ arg1, arg2 }); 90 } 91 92 95 public final String getString(String key, Object arg1, Object arg2, Object arg3) { 96 return getString(key, new Object []{ arg1, arg2, arg3 }); 97 } 98 99 100 101 104 107 final void add(StringManager manager) { 108 if(manager == null) { 109 throw new Bug(sm.getString("chain.add.null_parameter_error")); 110 } 111 this.managers.add(manager); 112 } 113 114 115 116 } 120 | Popular Tags |