1 package org.enhydra.jawe.misc; 2 3 import java.util.*; 4 5 import org.enhydra.jawe.*; 6 7 14 public class PFLocale { 15 private Locale loc; 16 17 21 public static PFLocale createPFLocale (String pfExt) { 22 PFLocale pel=null; 23 try { 24 pfExt=pfExt.trim(); 25 if (pfExt.equals("default")) { 26 pel=new PFLocale(); 27 } else { 28 boolean hasCountry=pfExt.length()>2 && pfExt.substring(2,3).equals("_"); 29 if (hasCountry) { 30 boolean hasVariant=pfExt.length()>5 && pfExt.substring(5,6).equals("_"); 31 if (hasVariant) { 32 pel=new PFLocale(pfExt.substring(0,2), 33 pfExt.substring(3,5), 34 pfExt.substring(6,pfExt.length())); 35 } else { 36 if (pfExt.length()==5) { 37 pel=new PFLocale(pfExt.substring(0,2),pfExt.substring(3,5)); 38 } 39 } 40 } else { 41 if (pfExt.length()==2) { 42 pel=new PFLocale(pfExt); 43 } 44 } 45 } 46 } catch (Exception ex) {} 47 48 return pel; 49 } 50 51 public PFLocale () { 52 loc=ResourceManager.getDefaultLocale(); 53 } 54 55 public PFLocale (Locale l) { 56 loc=l; 57 } 58 59 public PFLocale (String lang) { 60 loc=new Locale(lang); 61 } 62 63 public PFLocale (String lang,String country) { 64 loc=new Locale(lang,country); 65 } 66 67 public PFLocale (String lang,String country,String variant) { 68 loc=new Locale(lang,country,variant); 69 } 70 71 public String toString () { 72 if (loc!=ResourceManager.getDefaultLocale()) { 73 return loc.getDisplayName(ResourceManager.getChoosenLocale()); 74 } else { 75 return ResourceManager.getLanguageDependentString("EnglishDefaultKey"); 76 } 77 } 78 79 public Locale getLocale () { 80 return loc; 81 } 82 83 public String getLanguage () { 84 return loc.getLanguage(); 85 } 86 87 public String getCountry () { 88 return loc.getCountry(); 89 } 90 91 public String getVariant () { 92 return loc.getVariant(); 93 } 94 95 public String getLocaleString () { 96 String locStr=""; 97 if (loc==ResourceManager.getDefaultLocale()) { 98 return "default"; 99 } else { 100 locStr=loc.getLanguage(); 101 if (loc.getCountry().length()>0){ 102 locStr+="_"+loc.getCountry(); 103 if (loc.getVariant().length()>0) { 104 locStr+="_"+loc.getVariant(); 105 } 106 } 107 } 108 return locStr; 109 } 110 111 public boolean equals(Object pfLoc) { 112 if (pfLoc instanceof PFLocale) { 113 return loc.equals(((PFLocale)pfLoc).loc); 114 } else { 115 return false; 116 } 117 } 118 119 } 120 121 | Popular Tags |