Package org.simpleframework.http.parse
Class LanguageParser
- java.lang.Object
-
- org.simpleframework.common.parse.Parser
-
- org.simpleframework.http.parse.ListParser<java.util.Locale>
-
- org.simpleframework.http.parse.LanguageParser
-
public class LanguageParser extends ListParser<java.util.Locale>
LanguageParser is used to parse the HTTPAccept-Language
header. This takes in anAccept-Language
header and parses it according the RFC 2616 BNF for theAccept-Language
header. This also has the ability to sequence the language tokens in terms of the most preferred and the least preferred.This uses the qvalues outlined by RFC 2616 to order the language tokens by preference. Typically the language tokens will not have qvalues with the language. However when a language tag has the qvalue parameter then this tag will be ordered based on the value of that parameter. A language tag without the qvalue parameter is considered to have a qvalue of 1 and is ordered accordingly.
-
-
Constructor Summary
Constructors Constructor Description LanguageParser()
This is used to create aLanguageParser
for theAccept-Language
HTTP header value.LanguageParser(java.lang.String text)
This is used to create aLanguageParser
for theAccept-Language
HTTP header value.LanguageParser(java.util.List<java.lang.String> list)
This is used to create aLanguageParser
for theAccept-Language
HTTP header value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
country(char[] text, int start, int len)
This will extract the primary country tag from the header.protected java.util.Locale
create(char[] text, int start, int len)
This creates a locale object using an offset and a length.private java.lang.String
language(char[] text, int start, int len)
This will extract the primary language tag from the header.private boolean
terminal(char ch)
This is used to determine whether the character provided is a terminal character.-
Methods inherited from class org.simpleframework.http.parse.ListParser
init, list, parse, parse
-
-
-
-
Constructor Detail
-
LanguageParser
public LanguageParser()
This is used to create aLanguageParser
for theAccept-Language
HTTP header value. This will parse a set of language tokens and there parameters. The languages will be ordered on preference. This constructor will parse the value given usingparse(String)
.
-
LanguageParser
public LanguageParser(java.lang.String text)
This is used to create aLanguageParser
for theAccept-Language
HTTP header value. This will parse a set of language tokens and there parameters. The languages will be ordered on preference. This constructor will parse the value given usingparse(String)
.- Parameters:
text
- value of aAccept-Language
header
-
LanguageParser
public LanguageParser(java.util.List<java.lang.String> list)
This is used to create aLanguageParser
for theAccept-Language
HTTP header value. This will parse a set of language tokens and there parameters. The languages will be ordered on preference. This constructor will parse the value given usingparse(String)
.- Parameters:
list
- value of aAccept-Language
header
-
-
Method Detail
-
create
protected java.util.Locale create(char[] text, int start, int len)
This creates a locale object using an offset and a length. The locale is created from the extracted token and the offset and length ensure that no leading or trailing whitespace are within the created locale object.- Specified by:
create
in classListParser<java.util.Locale>
- Parameters:
text
- this is the text buffer to acquire the value fromstart
- the offset within the array to take characterslen
- this is the number of characters within the token
-
language
private java.lang.String language(char[] text, int start, int len)
This will extract the primary language tag from the header. This token is used to represent the language that will be available in theLocale
object created.- Parameters:
text
- this is the text buffer to acquire the value fromstart
- the offset within the array to take characterslen
- this is the number of characters within the token
-
country
private java.lang.String country(char[] text, int start, int len)
This will extract the primary country tag from the header. This token is used to represent the country that will be available in theLocale
object created.- Parameters:
text
- this is the text buffer to acquire the value fromstart
- the offset within the array to take characterslen
- this is the number of characters within the token
-
terminal
private boolean terminal(char ch)
This is used to determine whether the character provided is a terminal character. The terminal token is the value that is used to separate the country from the language and also any character the marks the end of the language token.- Parameters:
ch
- this is the character that is to be evaluated- Returns:
- true if the character represents a terminal token
-
-