Class AcceptLanguage

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

public class AcceptLanguage extends Object
Represents a single language entry from an Accept-Language header.
  • Constructor Details

    • AcceptLanguage

      protected AcceptLanguage(Locale locale, double quality)
      Constructs a new AcceptLanguage.
      Parameters:
      locale - The locale of this language entry
      quality - The quality value for this language entry
  • Method Details

    • getLocale

      public Locale getLocale()
      Returns the locale.
      Returns:
      The locale of this language entry
    • getQuality

      public double getQuality()
      Returns the quality value.
      Returns:
      The quality value of this language entry
    • parse

      public static List<AcceptLanguage> parse(StringReader input) throws IOException
      Parses an Accept-Language header value.
      Parameters:
      input - The StringReader containing the header value
      Returns:
      A list of AcceptLanguage entries in the order they appear in the header
      Throws:
      IOException - If an I/O error occurs while reading the input
    • 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. Parsing stops as soon as the maximum number of entries has been read. This limits the number of Locale objects created when the caller has no use for entries beyond the limit (e.g. when a container level limit means the request is going to be rejected).
      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 sorted by quality. 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