1 23 24 package org.infoglue.cms.util; 25 26 import java.util.HashMap ; 27 import java.util.Locale ; 28 import java.util.Map ; 29 30 import org.apache.log4j.Logger; 31 32 33 38 public class StringManagerFactory 39 { 40 41 private final static Logger logger = Logger.getLogger(StringManagerFactory.class.getName()); 42 43 private static final String SYSTEM = ".SystemStrings"; 44 private static final String PRESENTATION = ".PresentationStrings"; 45 46 private static Map managers = new HashMap (); 48 49 50 53 private StringManagerFactory() {} 54 55 56 57 59 62 public static synchronized StringManager getSystemStringManager(String packageName) { 63 return getStringManager(packageName, SYSTEM, Locale.ENGLISH); 64 } 65 66 69 public static synchronized StringManager getPresentationStringManager(String packageName, Locale locale) { 70 return getStringManager(packageName, PRESENTATION, locale); 71 } 72 73 76 public static synchronized StringManager getPresentationStringManager(String packageNames[], Locale locale) 77 { 78 logger.info("Getting stringManager"); 79 final ChainedStringManager chain = new ChainedStringManager(); 80 for(int i=0; i<packageNames.length; ++i) { 81 chain.add(getPresentationStringManager(packageNames[i], locale)); 82 } 83 return chain; 84 } 85 86 87 88 93 96 private static StringManager getStringManager(String packageName, String suffix, Locale locale) { 97 logger.info("packageName:" + packageName); 98 final String name = getName(packageName, suffix, locale); 99 final String bundleName = getBundleName(packageName, suffix); 100 101 StringManager manager = (StringManager) managers.get(name); 102 if(manager == null) { 103 manager = new SimpleStringManager(bundleName, locale); 104 managers.put(name, manager); 105 } 106 return manager; 107 } 108 109 112 113 private final static String getName(String packageName, String suffix, Locale locale) 114 { 115 return packageName + suffix + "_" + locale.toString() + ".properties"; 116 } 117 118 121 private final static String getBundleName(String packageName, String suffix) { 122 return packageName + suffix; 123 } 124 125 126 127 } | Popular Tags |