1 30 31 34 package com.nightlabs.l10n; 35 36 import java.text.DateFormat ; 37 import java.text.DateFormatSymbols ; 38 import java.text.SimpleDateFormat ; 39 import java.util.Locale ; 40 41 import com.nightlabs.config.ConfigModule; 42 import com.nightlabs.config.InitException; 43 44 47 public class DefaultDateFormatCfMod extends ConfigModule 48 { 49 private String dateLong; 50 private String dateShort; 51 private String dateLongWeekday; 52 private String dateShortWeekday; 53 private String timeHM; 54 private String timeHMS; 55 private String timeHMSms; 56 private String [] weekDaysLong; 57 private String [] weekDaysShort; 58 private String [] monthsLong; 59 private String [] monthsShort; 60 private String [] amPmStrings; 61 private String [] eras; 62 63 public DefaultDateFormatCfMod() 64 { 65 } 66 67 70 public String getIdentifier() 71 { 72 return super.getIdentifier(); 73 } 74 77 public void setIdentifier(String _identifier) 78 { 79 super.setIdentifier(_identifier); 80 } 81 82 85 public void init() throws InitException 86 { 87 String identifier = getIdentifier(); 88 if (identifier == null) 89 throw new IllegalStateException ("identifier of this ConfigModule is null! It should be the language/country-code (e.g. en_US)!"); 90 91 String [] sa = identifier.split("_"); 92 if (sa.length < 1) 93 throw new IllegalStateException ("identifier of this ConfigModule is invalid (empty?!)! It should be the language/country-code (e.g. en_US)!"); 94 95 String language = sa[0]; 96 String country = null; 97 if (sa.length > 1) 98 country = sa[1]; 99 100 Locale locale = new Locale (language, country); 101 102 if (dateShort == null) { 103 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); 104 if (df instanceof SimpleDateFormat ) { 105 SimpleDateFormat sdf = (SimpleDateFormat )df; 106 setDateShort(sdf.toPattern()); 107 } 108 else 109 setDateShort("yyyy-MM-dd"); 110 } 111 112 if (dateShortWeekday == null) 113 setDateShortWeekday("EE, " + dateShort); 114 115 DateFormatSymbols dfs = new DateFormatSymbols (locale); 116 117 if (dateLong == null) { 118 DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, locale); 119 if (df instanceof SimpleDateFormat ) { 120 SimpleDateFormat sdf = (SimpleDateFormat )df; 121 setDateLong(sdf.toPattern()); 122 } 123 else 124 setDateLong("yyyy MMMM dd"); 125 } 126 127 if (dateLongWeekday == null) 128 setDateLongWeekday("EEEE, " + dateLong); 129 130 if (timeHM == null) { 131 DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT, locale); 132 if (df instanceof SimpleDateFormat ) { 133 SimpleDateFormat sdf = (SimpleDateFormat )df; 134 setTimeHM(sdf.toPattern()); 135 } 136 else 137 setTimeHM("HH:mm"); 138 } 139 140 if (timeHMS == null) { 141 DateFormat df = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); 142 if (df instanceof SimpleDateFormat ) { 143 SimpleDateFormat sdf = (SimpleDateFormat )df; 144 setTimeHMS(sdf.toPattern()); 145 } 146 else 147 setTimeHMS("HH:mm:ss"); 148 } 149 150 if (timeHMSms == null) 151 setTimeHMSms("HH:mm:ss.SSS"); 152 153 if (weekDaysLong == null) 154 weekDaysLong = dfs.getWeekdays(); 155 156 if (weekDaysShort == null) 157 weekDaysShort = dfs.getShortWeekdays(); 158 159 if (monthsLong == null) 160 monthsLong = dfs.getMonths(); 161 162 if (monthsShort == null) 163 monthsShort = dfs.getShortMonths(); 164 165 if (amPmStrings == null) 166 amPmStrings = dfs.getAmPmStrings(); 167 168 if (eras == null) 169 eras = dfs.getEras(); 170 } 171 172 175 public String getDateLong() 176 { 177 return dateLong; 178 } 179 182 public void setDateLong(String dateLong) 183 { 184 this.dateLong = dateLong; 185 setChanged(); 186 } 187 190 public String getDateLongWeekday() 191 { 192 return dateLongWeekday; 193 } 194 197 public void setDateLongWeekday(String dateLongWeekday) 198 { 199 this.dateLongWeekday = dateLongWeekday; 200 setChanged(); 201 } 202 205 public String getDateShort() 206 { 207 return dateShort; 208 } 209 212 public void setDateShort(String dateShort) 213 { 214 this.dateShort = dateShort; 215 setChanged(); 216 } 217 220 public String getDateShortWeekday() 221 { 222 return dateShortWeekday; 223 } 224 227 public void setDateShortWeekday(String dateShortWeekday) 228 { 229 this.dateShortWeekday = dateShortWeekday; 230 setChanged(); 231 } 232 235 public String getTimeHM() 236 { 237 return timeHM; 238 } 239 242 public void setTimeHM(String timeHM) 243 { 244 this.timeHM = timeHM; 245 setChanged(); 246 } 247 250 public String getTimeHMS() 251 { 252 return timeHMS; 253 } 254 257 public void setTimeHMS(String timeHMS) 258 { 259 this.timeHMS = timeHMS; 260 setChanged(); 261 } 262 265 public String getTimeHMSms() 266 { 267 return timeHMSms; 268 } 269 272 public void setTimeHMSms(String timeHMSms) 273 { 274 this.timeHMSms = timeHMSms; 275 setChanged(); 276 } 277 280 public String [] getAmPmStrings() 281 { 282 return amPmStrings; 283 } 284 287 public void setAmPmStrings(String [] amPmStrings) 288 { 289 this.amPmStrings = amPmStrings; 290 setChanged(); 291 } 292 295 public String [] getEras() 296 { 297 return eras; 298 } 299 302 public void setEras(String [] eras) 303 { 304 this.eras = eras; 305 setChanged(); 306 } 307 310 public String [] getMonthsLong() 311 { 312 return monthsLong; 313 } 314 317 public void setMonthsLong(String [] monthsLong) 318 { 319 this.monthsLong = monthsLong; 320 setChanged(); 321 } 322 325 public String [] getMonthsShort() 326 { 327 return monthsShort; 328 } 329 332 public void setMonthsShort(String [] monthsShort) 333 { 334 this.monthsShort = monthsShort; 335 setChanged(); 336 } 337 340 public String [] getWeekDaysLong() 341 { 342 return weekDaysLong; 343 } 344 347 public void setWeekDaysLong(String [] weekDaysLong) 348 { 349 this.weekDaysLong = weekDaysLong; 350 setChanged(); 351 } 352 355 public String [] getWeekDaysShort() 356 { 357 return weekDaysShort; 358 } 359 362 public void setWeekDaysShort(String [] weekDaysShort) 363 { 364 this.weekDaysShort = weekDaysShort; 365 setChanged(); 366 } 367 } 368 | Popular Tags |