1 16 package org.apache.commons.net.ftp; 17 18 import java.text.DateFormatSymbols ; 19 import java.util.Collection ; 20 import java.util.Locale ; 21 import java.util.Map ; 22 import java.util.StringTokenizer ; 23 import java.util.TreeMap ; 24 25 140 public class FTPClientConfig 141 { 142 143 147 public static final String SYST_UNIX = "UNIX"; 148 149 153 public static final String SYST_VMS = "VMS"; 154 155 159 public static final String SYST_NT = "WINDOWS"; 160 161 165 public static final String SYST_OS2 = "OS/2"; 166 167 171 public static final String SYST_OS400 = "OS/400"; 172 173 177 public static final String SYST_MVS = "MVS"; 178 179 private final String serverSystemKey; 180 private String defaultDateFormatStr = null; 181 private String recentDateFormatStr = null; 182 private String serverLanguageCode = null; 183 private String shortMonthNames = null; 184 private String serverTimeZoneId = null; 185 186 187 192 public FTPClientConfig(String systemKey) { 193 this.serverSystemKey = systemKey; 194 } 195 196 200 public FTPClientConfig() { 201 this(SYST_UNIX); 202 } 203 204 220 public FTPClientConfig(String systemKey, 221 String defaultDateFormatStr, 222 String recentDateFormatStr, 223 String serverLanguageCode, 224 String shortMonthNames, 225 String serverTimeZoneId) 226 { 227 this(systemKey); 228 this.defaultDateFormatStr = defaultDateFormatStr; 229 this.recentDateFormatStr = recentDateFormatStr; 230 this.serverLanguageCode = serverLanguageCode; 231 this.shortMonthNames = shortMonthNames; 232 this.serverTimeZoneId = serverTimeZoneId; 233 } 234 235 private static Map LANGUAGE_CODE_MAP = new TreeMap (); 236 static { 237 238 241 242 243 LANGUAGE_CODE_MAP.put("en", Locale.ENGLISH); 246 LANGUAGE_CODE_MAP.put("de",Locale.GERMAN); 247 LANGUAGE_CODE_MAP.put("it",Locale.ITALIAN); 248 LANGUAGE_CODE_MAP.put("es", new Locale ("es", "", "")); LANGUAGE_CODE_MAP.put("pt", new Locale ("pt", "", "")); LANGUAGE_CODE_MAP.put("da", new Locale ("da", "", "")); LANGUAGE_CODE_MAP.put("sv", new Locale ("sv", "", "")); LANGUAGE_CODE_MAP.put("no", new Locale ("no", "", "")); LANGUAGE_CODE_MAP.put("nl", new Locale ("nl", "", "")); LANGUAGE_CODE_MAP.put("ro", new Locale ("ro", "", "")); LANGUAGE_CODE_MAP.put("sq", new Locale ("sq", "", "")); LANGUAGE_CODE_MAP.put("sh", new Locale ("sh", "", "")); LANGUAGE_CODE_MAP.put("sk", new Locale ("sk", "", "")); LANGUAGE_CODE_MAP.put("sl", new Locale ("sl", "", "")); 260 261 LANGUAGE_CODE_MAP.put("fr", 263 "jan|f\u00e9v|mar|avr|mai|jun|jui|ao\u00fb|sep|oct|nov|d\u00e9c"); 265 } 266 267 276 public String getServerSystemKey() { 277 return serverSystemKey; 278 } 279 280 285 public String getDefaultDateFormatStr() { 286 return defaultDateFormatStr; 287 } 288 289 293 294 public String getRecentDateFormatStr() { 295 return recentDateFormatStr; 296 } 297 298 302 public String getServerTimeZoneId() { 303 return serverTimeZoneId; 304 } 305 306 313 public String getShortMonthNames() { 314 return shortMonthNames; 315 } 316 317 323 public String getServerLanguageCode() { 324 return serverLanguageCode; 325 } 326 327 341 public void setDefaultDateFormatStr(String defaultDateFormatStr) { 342 this.defaultDateFormatStr = defaultDateFormatStr; 343 } 344 345 360 public void setRecentDateFormatStr(String recentDateFormatStr) { 361 this.recentDateFormatStr = recentDateFormatStr; 362 } 363 364 378 public void setServerTimeZoneId(String serverTimeZoneId) { 379 this.serverTimeZoneId = serverTimeZoneId; 380 } 381 382 399 public void setShortMonthNames(String shortMonthNames) { 400 this.shortMonthNames = shortMonthNames; 401 } 402 403 443 public void setServerLanguageCode(String serverLanguageCode) { 444 this.serverLanguageCode = serverLanguageCode; 445 } 446 447 459 public static DateFormatSymbols lookupDateFormatSymbols(String languageCode) 460 { 461 Object lang = LANGUAGE_CODE_MAP.get(languageCode); 462 if (lang != null) { 463 if (lang instanceof Locale ) { 464 return new DateFormatSymbols ((Locale ) lang); 465 } else if (lang instanceof String ){ 466 return getDateFormatSymbols((String ) lang); 467 } 468 } 469 return new DateFormatSymbols (Locale.US); 470 } 471 472 480 public static DateFormatSymbols getDateFormatSymbols(String shortmonths) 481 { 482 String [] months = splitShortMonthString(shortmonths); 483 DateFormatSymbols dfs = new DateFormatSymbols (Locale.US); 484 dfs.setShortMonths(months); 485 return dfs; 486 } 487 488 private static String [] splitShortMonthString(String shortmonths) { 489 StringTokenizer st = new StringTokenizer (shortmonths, "|"); 490 int monthcnt = st.countTokens(); 491 if (12 != monthcnt) { 492 throw new IllegalArgumentException ( 493 "expecting a pipe-delimited string containing 12 tokens"); 494 } 495 String [] months = new String [13]; 496 int pos = 0; 497 while(st.hasMoreTokens()) { 498 months[pos++] = st.nextToken(); 499 } 500 months[pos]=""; 501 return months; 502 } 503 504 512 public static Collection getSupportedLanguageCodes() { 513 return LANGUAGE_CODE_MAP.keySet(); 514 } 515 516 517 } 518 | Popular Tags |