Package lumis.util

Class LocaleUtil


  • @StableMinor(version="16.0",
                 sinceVersion="4.0")
    public abstract class LocaleUtil
    extends java.lang.Object
    Utility class for Locale related operations
    Since:
    4.0.0
    Version:
    $Revision: 25808 $ $Date: 2023-07-04 15:20:55 -0300 (Tue, 04 Jul 2023) $
    • Field Detail

      • LOCALE_ATTRIBUTE_NAME

        public static final java.lang.String LOCALE_ATTRIBUTE_NAME
        See Also:
        Constant Field Values
    • Constructor Detail

      • LocaleUtil

        public LocaleUtil()
    • Method Detail

      • fromString

        public static java.util.Locale fromString​(java.lang.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 java.util.Locale fromXMLLang​(java.lang.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:
        java.lang.IllegalArgumentException - if xmlLang is null or is an invalid locale identifier.
        Since:
        5.5.0
      • fromRequest

        public static java.util.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