Package lumis.util

Class LocaleUtil


  • @StableMinor(version="14.0",
                 sinceVersion="4.0")
    public abstract class LocaleUtil
    extends Object
    Utility class for Locale related operations
    Since:
    4.0.0
    Version:
    $Revision: 24477 $ $Date: 2021-04-28 11:30:36 -0300 (Wed, 28 Apr 2021) $
    • Constructor Detail

      • LocaleUtil

        public LocaleUtil()
    • Method Detail

      • fromString

        public static Locale fromString​(String locale)
                                 throws PortalException
        Returns the locale represented by the given string. Expects a string with the following format:
        <language>_<country>_<variant> Where:
        <language>
        is the language code
        <country>
        is the country code
        <variant>
        is the variant part

        For more information, refer to Locale.

        Parameters:
        locale - the locale string.
        Returns:
        the locale represented by the given string.
        Throws:
        PortalException
        Since:
        8.1.0
        See Also:
        Locale(String, String, String)
      • fromXMLLang

        public static Locale fromXMLLang​(String xmlLang)
        Returns the locale corresponding to a String following XML lang syntax (e.g.: en-US).
        Parameters:
        xmlLang - the XML lang value, according to the RFC3066.
        Returns:
        the locale.
        Throws:
        IllegalArgumentException - if xmlLang is null or is an invalid locale identifier.
        Since:
        5.5.0
      • fromRequest

        public static Locale fromRequest​(HttpServletRequest request,
                                         boolean fallbackToDefault)
                                  throws PortalException
        Returns the locale requested by the given HttpServletRequest.
        Parameters:
        request - the request.
        fallbackToDefault - if true the default locale is returned instead of null when no locale is specified in the request.
        Returns:
        the requested locale. If no locale is specified in the request, returns the default locale if fallbackToDefault is true or returns null if it is false.
        Throws:
        PortalException
        Since:
        12.5.0