Class AcceptLanguageParser


  • public class AcceptLanguageParser
    extends Object
    HTTP accept-language header state machine based parser. Example: "da, en-gb;q=0.8, en;q=0.7".
    • Field Detail

      • S_START_SPC

        public static final int S_START_SPC
        Start state. Look for a language.
        See Also:
        Constant Field Values
      • S_LANG

        public static final int S_LANG
        Language state. Look for country, qvalue or start of next locale.
        See Also:
        Constant Field Values
      • S_COUNTRY

        public static final int S_COUNTRY
        Country state. Look for a country.
        See Also:
        Constant Field Values
      • S_COUNTRY_SPC

        public static final int S_COUNTRY_SPC
        Country parsed state. Look for qvalue or next locale.
        See Also:
        Constant Field Values
      • S_SEMICOLON

        public static final int S_SEMICOLON
        Semicolon state. Look for an optional qvalue.
        See Also:
        Constant Field Values
      • S_NAME

        public static final int S_NAME
        State name. Look for attribute name.
        See Also:
        Constant Field Values
      • S_NAME_SPC

        public static final int S_NAME_SPC
        State parsed name. Look for value or next attribute or next locale.
        See Also:
        Constant Field Values
      • S_EQ

        public static final int S_EQ
        State equal. Look for first value character or next attribute or next locale.
        See Also:
        Constant Field Values
      • S_VALUE

        public static final int S_VALUE
        State value. Look for the rest of the value and next attribute or next locale.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AcceptLanguageParser

        public AcceptLanguageParser()
    • Method Detail

      • parseHeader

        public static List<AcceptLanguageParser.AcceptLanguage> parseHeader​(javax.servlet.http.HttpServletRequest req)
        Parses a HTTP accept-language header, if present, from the supplied HTTP request and returns a sorted list of valid languages. Languages are sorted by their qvalue.
        Parameters:
        acceptLanguageStr - accept language header string from a HTTP request
        Returns:
        List of valid languages sorted by their qvalue
      • parseHeader

        public static List<AcceptLanguageParser.AcceptLanguage> parseHeader​(String acceptLanguageStr)
        Parses a HTTP accept-language header string and returns a sorted list of valid languages. Languages are sorted by their qvalue.
        Parameters:
        acceptLanguageStr - accept language header string from a HTTP request
        Returns:
        List of valid languages sorted by their qvalue