public class DefaultPreviewDateWebRequestResolver extends Object implements PreviewDateWebRequestResolver
PreviewDateWebRequestResolver
that resolves a preview date
Instant
from a NativeWebRequest
when there is a PreviewToken
present.
This resolver will look for a header named getHeaderName()
or a request parameter named
getParameterName()
to detect a preview date String
. If a date-string is found,
it will use Instant.parse(CharSequence)
to construct an Instant
from the value.
If successful, and the PreviewToken
is found, it will return the Instant
.
If this resolver either fails to detect a preview date, or fails to parse a found date-string,
then it will return null
.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_HEADER_NAME |
static String |
DEFAULT_PARAMETER_NAME |
Constructor and Description |
---|
DefaultPreviewDateWebRequestResolver() |
Modifier and Type | Method and Description |
---|---|
protected String |
getHeaderName() |
protected String |
getParameterName() |
protected String |
parseRequestHeader(org.springframework.web.context.request.NativeWebRequest webRequest) |
protected String |
parseRequestParameter(org.springframework.web.context.request.NativeWebRequest webRequest) |
Instant |
resolve(org.springframework.web.context.request.NativeWebRequest webRequest)
Attempts to resolve a preview date for the provided request and preview token.
|
void |
setHeaderName(String headerName) |
void |
setParameterName(String parameterName) |
public static final String DEFAULT_HEADER_NAME
public static final String DEFAULT_PARAMETER_NAME
public DefaultPreviewDateWebRequestResolver()
public Instant resolve(org.springframework.web.context.request.NativeWebRequest webRequest)
PreviewDateWebRequestResolver
If no preview date is found this method is expected to return null
.
resolve
in interface PreviewDateWebRequestResolver
webRequest
- the current web requestInstant
or null
protected String parseRequestHeader(org.springframework.web.context.request.NativeWebRequest webRequest)
protected String parseRequestParameter(org.springframework.web.context.request.NativeWebRequest webRequest)
protected String getHeaderName()
public void setHeaderName(String headerName)
protected String getParameterName()
public void setParameterName(String parameterName)
Copyright © 2021. All rights reserved.