@Test public void testNormalizeLanguage() { Assert.assertNull(Util.normalizeLanguage(null)); Assert.assertEquals("", Util.normalizeLanguage("")); Assert.assertEquals("", Util.normalizeLanguage(" ")); Assert.assertEquals("default", Util.normalizeLanguage("default")); Assert.assertEquals("default", Util.normalizeLanguage("DeFault")); Assert.assertEquals("default", Util.normalizeLanguage("invalid code")); Assert.assertEquals("en", Util.normalizeLanguage("en")); Assert.assertEquals("en", Util.normalizeLanguage("En_")); Assert.assertEquals("de_AT", Util.normalizeLanguage("DE_at")); }
public static String normalizeLanguage(String languageCode) { if (languageCode == null) { return null; } if (StringUtils.isBlank(languageCode)) { return ""; } final String separator = "_"; String[] parts = StringUtils.split(languageCode.toLowerCase(), "_-."); String result = parts[0]; if (parts.length > 1) { parts[1] = parts[1].toUpperCase(); result = parts[0] + separator + parts[1]; } final String defaultLanguage = "default"; if (defaultLanguage.equals(result)) { return defaultLanguage; } try { Locale l = new Locale(parts[0], parts.length > 1 ? parts[1] : ""); l.getISO3Language(); return result; } catch (MissingResourceException ex) { LOGGER.warn("Invalid language: " + languageCode); } return defaultLanguage; }
Util { public static String normalizeLanguage(String languageCode) { if (languageCode == null) { return null; } if (StringUtils.isBlank(languageCode)) { return ""; } final String separator = "_"; String[] parts = StringUtils.split(languageCode.toLowerCase(), "_-."); String result = parts[0]; if (parts.length > 1) { parts[1] = parts[1].toUpperCase(); result = parts[0] + separator + parts[1]; } final String defaultLanguage = "default"; if (defaultLanguage.equals(result)) { return defaultLanguage; } try { Locale l = new Locale(parts[0], parts.length > 1 ? parts[1] : ""); l.getISO3Language(); return result; } catch (MissingResourceException ex) { LOGGER.warn("Invalid language: " + languageCode); } return defaultLanguage; } }
Util { public static String normalizeLanguage(String languageCode) { if (languageCode == null) { return null; } if (StringUtils.isBlank(languageCode)) { return ""; } final String separator = "_"; String[] parts = StringUtils.split(languageCode.toLowerCase(), "_-."); String result = parts[0]; if (parts.length > 1) { parts[1] = parts[1].toUpperCase(); result = parts[0] + separator + parts[1]; } final String defaultLanguage = "default"; if (defaultLanguage.equals(result)) { return defaultLanguage; } try { Locale l = new Locale(parts[0], parts.length > 1 ? parts[1] : ""); l.getISO3Language(); return result; } catch (MissingResourceException ex) { LOGGER.warn("Invalid language: " + languageCode); } return defaultLanguage; }  }
Util { public static String normalizeLanguage(String languageCode) { if (languageCode == null) { return null; } if (StringUtils.isBlank(languageCode)) { return ""; } final String separator = "_"; String[] parts = StringUtils.split(languageCode.toLowerCase(), "_-."); String result = parts[0]; if (parts.length > 1) { parts[1] = parts[1].toUpperCase(); result = parts[0] + separator + parts[1]; } final String defaultLanguage = "default"; if (defaultLanguage.equals(result)) { return defaultLanguage; } try { Locale l = new Locale(parts[0], parts.length > 1 ? parts[1] : ""); l.getISO3Language(); return result; } catch (MissingResourceException ex) { LOGGER.warn("Invalid language: " + languageCode); } return defaultLanguage; }  String substitute(String pattern, String text); boolean match(String pattern, String text); boolean matched(); String substitute(String pattern, String substitution, String text); Perl5Matcher getMatcher(); Perl5Util getP5util(); List<String> getAllMatches(String content, String spattern, int group); List<String> getUniqueMatches(String content, String spattern, int group); static String cleanValue(String value); static String restoreValue(String value); static Hashtable<String, String> keyValueToHashtable(String mapString); static PatternCache getPatterns(); static Map<String, String[]> getObject(XWikiRequest request, String prefix); static Map<String, T> getSubMap(Map<String, T> map, String prefix); static String getWeb(String fullname); Vector<String> split(String pattern, String text); static boolean contains(String name, String list, String sep); static String noaccents(String text); static boolean isAlphaNumeric(String text); static String getName(String name); static String getName(String name, XWikiContext context); static Cookie getCookie(String cookieName, XWikiContext context); static Cookie getCookie(String cookieName, HttpServletRequest request); static String getHTMLExceptionMessage(XWikiException xe, XWikiContext context); static MonitorPlugin getMonitorPlugin(XWikiContext context); org.w3c.dom.Document getDOMForString(String str); org.w3c.dom.Document getDOMDocument(); @Deprecated static String escapeText(String text); @Deprecated static String escapeURL(String url); static String encodeURI(String text, XWikiContext context); static String decodeURI(String text, XWikiContext context); static String convertToAlphaNumeric(String text); static Date getFileLastModificationDate(String path); static boolean isValidXMLElementName(String elementName); static InputStream getResourceAsStream(String resource); static URL getResource(String resource); static String normalizeLanguage(String languageCode); static long getHash(String uid); }
Util { public static String normalizeLanguage(String languageCode) { if (languageCode == null) { return null; } if (StringUtils.isBlank(languageCode)) { return ""; } final String separator = "_"; String[] parts = StringUtils.split(languageCode.toLowerCase(), "_-."); String result = parts[0]; if (parts.length > 1) { parts[1] = parts[1].toUpperCase(); result = parts[0] + separator + parts[1]; } final String defaultLanguage = "default"; if (defaultLanguage.equals(result)) { return defaultLanguage; } try { Locale l = new Locale(parts[0], parts.length > 1 ? parts[1] : ""); l.getISO3Language(); return result; } catch (MissingResourceException ex) { LOGGER.warn("Invalid language: " + languageCode); } return defaultLanguage; }  String substitute(String pattern, String text); boolean match(String pattern, String text); boolean matched(); String substitute(String pattern, String substitution, String text); Perl5Matcher getMatcher(); Perl5Util getP5util(); List<String> getAllMatches(String content, String spattern, int group); List<String> getUniqueMatches(String content, String spattern, int group); static String cleanValue(String value); static String restoreValue(String value); static Hashtable<String, String> keyValueToHashtable(String mapString); static PatternCache getPatterns(); static Map<String, String[]> getObject(XWikiRequest request, String prefix); static Map<String, T> getSubMap(Map<String, T> map, String prefix); static String getWeb(String fullname); Vector<String> split(String pattern, String text); static boolean contains(String name, String list, String sep); static String noaccents(String text); static boolean isAlphaNumeric(String text); static String getName(String name); static String getName(String name, XWikiContext context); static Cookie getCookie(String cookieName, XWikiContext context); static Cookie getCookie(String cookieName, HttpServletRequest request); static String getHTMLExceptionMessage(XWikiException xe, XWikiContext context); static MonitorPlugin getMonitorPlugin(XWikiContext context); org.w3c.dom.Document getDOMForString(String str); org.w3c.dom.Document getDOMDocument(); @Deprecated static String escapeText(String text); @Deprecated static String escapeURL(String url); static String encodeURI(String text, XWikiContext context); static String decodeURI(String text, XWikiContext context); static String convertToAlphaNumeric(String text); static Date getFileLastModificationDate(String path); static boolean isValidXMLElementName(String elementName); static InputStream getResourceAsStream(String resource); static URL getResource(String resource); static String normalizeLanguage(String languageCode); static long getHash(String uid);  }