Package lumis.util

Class LocaleUtil


  • @StableMinor(version="17.0",
                 sinceVersion="4.0")
    public abstract class LocaleUtil
    extends java.lang.Object
    Utility class for Locale related operations
    Since:
    4.0.0
    Version:
    $Revision$ $Date$
    • Constructor Summary

      Constructors 
      Constructor Description
      LocaleUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.util.Locale fromRequest​(javax.servlet.http.HttpServletRequest request)
      Returns the locale requested by the given HttpServletRequest, or the default locale if none was specified in the request.
      static java.util.Locale fromRequest​(javax.servlet.http.HttpServletRequest request, boolean fallbackToDefault)
      Returns the locale requested by the given HttpServletRequest.
      static java.util.Locale fromString​(java.lang.String locale)
      Returns the locale represented by the given string.
      static java.util.Locale FromString​(java.lang.String locale)
      Deprecated.
      since 8.1.0 replaced by fromString(String).
      static java.util.Locale fromXMLLang​(java.lang.String xmlLang)
      Returns the locale corresponding to a String following XML lang syntax (e.g.: en-US).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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​(javax.servlet.http.HttpServletRequest request)
                                            throws PortalException
        Returns the locale requested by the given HttpServletRequest, or the default locale if none was specified in the request.
        Parameters:
        request - the request.
        Returns:
        the locale.
        Throws:
        PortalException
        Since:
        4.0
      • fromRequest

        public static java.util.Locale fromRequest​(javax.servlet.http.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