Package dk.netarkivet.heritrix3.monitor
Class AcceptLanguageParser
- java.lang.Object
-
- dk.netarkivet.heritrix3.monitor.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".
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AcceptLanguageParser.AcceptLanguage
Parsed language, country, locale and qvalue.static class
AcceptLanguageParser.AcceptLanguageComparator
-
Field Summary
Fields Modifier and Type Field Description static AcceptLanguageParser.AcceptLanguageComparator
acceptLanguageComparator
Reusable comparator used to sort languages by their qvalue.static int
S_COUNTRY
Country state.static int
S_COUNTRY_SPC
Country parsed state.static int
S_EQ
State equal.static int
S_LANG
Language state.static int
S_NAME
State name.static int
S_NAME_SPC
State parsed name.static int
S_SEMICOLON
Semicolon state.static int
S_START_SPC
Start state.static int
S_VALUE
State value.
-
Constructor Summary
Constructors Constructor Description AcceptLanguageParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<AcceptLanguageParser.AcceptLanguage>
parseHeader(String acceptLanguageStr)
Parses a HTTP accept-language header string and returns a sorted list of valid languages.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.
-
-
-
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
-
acceptLanguageComparator
public static AcceptLanguageParser.AcceptLanguageComparator acceptLanguageComparator
Reusable comparator used to sort languages by their qvalue.
-
-
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
-
-