LocalizedText { public static String[] separateLocale(String localeRepresentation) { List<String> ret = new ArrayList<String>(3); int start = 0; do { int end = localeRepresentation.indexOf(lang_sep, start); if(ret.size()==2 || end==-1) { if(start<localeRepresentation.length()) { ret.add(localeRepresentation.substring(start)); } break; } else { ret.add(localeRepresentation.substring(start,end)); } start = end + 1; } while(start!=0); return ret.toArray(new String[ret.size()]); } LocalizedText(String string, Locale l); String getValue(); void setValue(String content); Locale getLocale(); void setLocale(Locale locale); static String[] separateLocale(String localeRepresentation); static Locale forLanguageTag(String localeRepresentation); static boolean validateLanguage(String language); static boolean validateCountry(String country); static boolean validateVariant(String variant); static String toLanguageTag(Locale locale); LanguageStringType getJAXBType(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testLocaleSeparation() { String[] parts = LocalizedText.separateLocale("en-"); assertTrue("Invalid Locale parts size:"+parts.length, parts.length==1); parts = LocalizedText.separateLocale("en"); assertTrue("Invalid Locale parts size:"+parts.length, parts.length==1); parts = LocalizedText.separateLocale("en-US"); assertTrue("Invalid Locale parts size:"+parts.length, parts.length==2); parts = LocalizedText.separateLocale("en-US-x-twain"); assertTrue("Invalid Locale parts size:"+parts.length, parts.length==3); }