@LevelUpApi(contract=INTERNAL) public final class LinkHeaderParser extends Object
A regular expression -based parser implementing RFC5988.
This does not check the parameters against the list defined in the RFC. Instead it treats all parameters as key/value pairs, allowing both quoted and unquoted values according to the grammar outlined in the RFC.
Modifier and Type | Class and Description |
---|---|
static class |
LinkHeaderParser.LinkHeader
An immutable representation of a "Link:" header.
|
static class |
LinkHeaderParser.MalformedLinkHeaderException
This is thrown if there is an error parsing the link.
|
Modifier and Type | Field and Description |
---|---|
static String |
PARAMETER_ANCHOR
Link anchor.
|
static String |
PARAMETER_HREFLANG
The language of the link.
|
static String |
PARAMETER_MEDIA
The media type, similar to \@media in CSS.
|
static String |
PARAMETER_REL
Relation.
|
static String |
PARAMETER_REV
A reverse relation.
|
static String |
PARAMETER_TITLE
The title of the resource.
|
static String |
PARAMETER_TITLE_STAR
The extended title of the resource.
|
static String |
PARAMETER_TYPE
The MIME type of the resource.
|
Modifier and Type | Method and Description |
---|---|
static LinkHeaderParser.LinkHeader |
parseLinkHeader(String headerValue)
Parses the header value and extracts the link and its parameters.
|
static LinkHeaderParser.LinkHeader |
parseLinkHeader(Uri context,
String headerValue)
Parses the header value and extracts the link and its parameters, resolving the link relative
to the supplied context.
|
public static final String PARAMETER_REL
public static final String PARAMETER_ANCHOR
public static final String PARAMETER_REV
PARAMETER_REL
.public static final String PARAMETER_HREFLANG
public static final String PARAMETER_MEDIA
public static final String PARAMETER_TITLE
public static final String PARAMETER_TITLE_STAR
public static final String PARAMETER_TYPE
public static LinkHeaderParser.LinkHeader parseLinkHeader(String headerValue) throws LinkHeaderParser.MalformedLinkHeaderException
context=null
to parseLinkHeader(Uri, String)
.headerValue
- the input header value. This is the portion after "Link:".LinkHeaderParser.LinkHeader
representing the results of the parse.LinkHeaderParser.MalformedLinkHeaderException
- if the
header could not be parsed.public static LinkHeaderParser.LinkHeader parseLinkHeader(Uri context, String headerValue) throws LinkHeaderParser.MalformedLinkHeaderException
context
- the URI that any relative URIs will be resolved against. This can be null to
disable relative URI resolution.headerValue
- the input header value. This is the portion after "Link:".LinkHeaderParser.LinkHeader
representing the results of the parse.LinkHeaderParser.MalformedLinkHeaderException
- if the header could not be parsed.