I do not know ULocale, but if you mean java.util.Locale
, the following code may do:
public void setResources(String locale) {
// validate locale
Locale lo = parseLocale(locale);
if (isValid(lo) {
System.out.println(lo.getDisplayCountry());
} else {
System.out.println("invalid: " + locale);
}
}
private Locale parseLocale(String locale) {
String[] parts = locale.split("_");
switch (parts.length) {
case 3: return new Locale(parts[0], parts[1], parts[2]);
case 2: return new Locale(parts[0], parts[1]);
case 1: return new Locale(parts[0]);
default: throw new IllegalArgumentException("Invalid locale: " + locale);
}
}
private boolean isValid(Locale locale) {
try {
return locale.getISO3Language() != null && locale.getISO3Country() != null;
} catch (MissingResourceException e) {
return false;
}
}
EDIT: added validation