Class AcceptLanguage2

java.lang.Object
org.apache.tomcat.util.http.parser.AcceptLanguage2

public final class AcceptLanguage2 extends Object
Parser for AcceptLanguage that parses an Accept-Language header value using the deprecated Locale(String, String, String) constructor, combined with a custom BCP 47 subtag parser that maps the language tag components onto the language/country/variant triple that the deprecated constructor accepts. This is done for better efficiency.

Known, accepted degradations compared with Locale.forLanguageTag():

  • Unicode, other and private use extensions (e.g. -u-ca-buddhist, -x-priv) are discarded rather than recorded on the Locale.
  • Script subtags (e.g. -Hant-) cannot be represented by the deprecated constructor and are mapped to the Locale variant, in upper case, instead of to the Locale script.
  • Tags that are syntactically invalid after the language subtag retain the components parsed up to that point rather than being replaced with Locale.ROOT.
  • Method Details

    • parse

      public static List<AcceptLanguage> parse(StringReader input, int maxElements) throws IOException
      Parses an Accept-Language header value, reading at most the specified number of entries. See AcceptLanguage.parse(StringReader, int).
      Parameters:
      input - The StringReader containing the header value
      maxElements - The maximum number of entries to parse or -1 for no limit
      Returns:
      A list of AcceptLanguage entries. If the limit was reached, the returned list has exactly maxElements entries and any remaining entries were not parsed.
      Throws:
      IOException - If an I/O error occurs while reading the input