1 2 23 24 package net.fenyo.gnetwatch; 25 26 import java.io.*; 27 import java.util.*; 28 import java.text.*; 29 import org.hibernate.cfg.*; 30 import org.apache.commons.logging.*; 31 32 37 38 public class Config { 39 private static Log log = LogFactory.getLog(Config.class); 40 41 private final Properties properties; 43 44 private Locale locale = null; 46 private ResourceBundle bundle = null; 47 48 private boolean needEnd = false; 49 50 57 public Config() throws IOException { 58 properties = new Properties(); 59 properties.loadFromXML(new FileInputStream("config.xml")); 60 61 locale = new Locale(getProperty("language"), getProperty("country")); 62 bundle = ResourceBundle.getBundle("i18n", locale); 63 } 64 65 71 public void setEnd() { 73 needEnd = true; 74 } 75 76 81 public boolean isEnd() { 83 return needEnd; 84 } 85 86 91 public String getProperty(final String key) { 92 return properties.getProperty("net.fenyo." + key); 93 } 94 95 101 public String getProperty(final String key, final String dflt) { 102 return properties.getProperty("net.fenyo." + key, dflt); 103 } 104 105 110 public Locale getLocale() { 111 return locale; 112 } 113 114 119 public ResourceBundle getBundle() { 120 return bundle; 121 } 122 123 128 public String getString(final String key) { 129 return bundle.getString(key); 130 } 131 132 138 public String getPattern(final String key, final Object [] params) { 139 final MessageFormat formatter = new MessageFormat(""); 140 formatter.setLocale(locale); 141 formatter.applyPattern(getString(key)); 142 return formatter.format(params); 143 } 144 145 151 public String getPattern(final String key, final Object arg) { 152 Object [] msgArgs = { arg }; 153 return getPattern(key, msgArgs); 154 } 155 156 163 public String getPattern(final String key, final Object arg1, final Object arg2) { 164 Object [] msgArgs = { arg1, arg2 }; 165 return getPattern(key, msgArgs); 166 } 167 168 176 public String getPattern(final String key, final Object arg1, final Object arg2, final Object arg3) { 177 Object [] msgArgs = { arg1, arg2, arg3 }; 178 return getPattern(key, msgArgs); 179 } 180 181 190 public String getPattern(final String key, final Object arg1, final Object arg2, final Object arg3, final Object arg4) { 191 Object [] msgArgs = { arg1, arg2, arg3, arg4 }; 192 return getPattern(key, msgArgs); 193 } 194 195 205 public String getPattern(final String key, final Object arg1, final Object arg2, 206 final Object arg3, final Object arg4, final Object arg5) { 207 Object [] msgArgs = { arg1, arg2, arg3, arg4, arg5 }; 208 return getPattern(key, msgArgs); 209 } 210 } 211 | Popular Tags |