public abstract class FreeMarkerTag extends Object implements freemarker.template.TemplateDirectiveModel
Constructor and Description |
---|
FreeMarkerTag() |
Modifier and Type | Method and Description |
---|---|
protected AppContext |
appContext()
Returns instance of
AppContext . |
protected String |
context()
Provides a context of the request - usually an app name (as seen on URL of request).
|
Cookie |
cookie(String name)
Returns a cookie by name, null if not found.
|
List<Cookie> |
cookies()
Returns collection of all cookies browser sent.
|
protected String |
cookieValue(String name)
Convenience method, returns cookie value.
|
void |
execute(freemarker.core.Environment env,
Map params,
freemarker.template.TemplateModel[] loopVars,
freemarker.template.TemplateDirectiveBody body) |
protected boolean |
exists(String name)
Tests if a request parameter exists.
|
protected String |
format()
Returns a format part of the URI, or null if URI does not have a format part.
|
protected freemarker.template.TemplateModel |
get(Object name)
Gets an object from context - by name.
|
protected Map |
getAllVariables()
Returns a map of all variables in scope.
|
protected String |
getContextPath()
Returns this applications' context path.
|
protected String |
getId()
Returns value of ID if one is present on a URL.
|
protected Locale |
getLocale()
Same as
locale() . |
protected String |
getRequestHost()
This method returns a host name of a web server if this container is fronted by one, such that
it sets a header
X-Forwarded-Host on the request and forwards it to the Java container. |
protected int |
getRequestPort()
This method returns a port of a web server if this Java container is fronted by one, such that
it sets a header
X-Forwarded-Port on the request and forwards it to the Java container. |
protected String |
getRequestProtocol()
This method returns a protocol of a request to web server if this container is fronted by one, such that
it sets a header
X-Forwarded-Proto on the request and forwards it to the Java container. |
protected Route |
getRoute()
Returns instance of
Route to be used for potential conditional logic inside controller filters. |
protected Object |
getUnwrapped(Object name)
Gets an object from context - by name.
|
protected <T> T |
getUnwrapped(Object name,
Class<T> clazz) |
protected String |
header(String name)
Returns a request header by name.
|
protected Map<String,String> |
headers()
Returns all headers from a request keyed by header name.
|
protected String |
host()
Returns local host name on which request was received.
|
protected String |
ipAddress()
Returns local IP address on which request was received.
|
protected String |
ipForwardedFor()
Returns IP address that the web server forwarded request for.
|
protected boolean |
isDelete()
True if this request uses HTTP DELETE method, false otherwise.
|
protected boolean |
isGet()
True if this request uses HTTP GET method, false otherwise.
|
protected boolean |
isHead()
True if this request uses HTTP HEAD method, false otherwise.
|
protected boolean |
isMethod(String method) |
protected boolean |
isPost()
True if this request uses HTTP POST method, false otherwise.
|
protected boolean |
isPut()
True if this request uses HTTP PUT method, false otherwise.
|
protected boolean |
isXhr()
Returns true if this request is Ajax.
|
protected Locale |
locale()
Returns locale of request.
|
protected org.slf4j.Logger |
logger()
Provides a logger to a subclass.
|
protected String |
method()
Returns an HTTP method from the request.
|
void |
overrideContext(String context)
Use to override context of the application.
|
protected String |
param(String name)
Returns value of one named parameter from request.
|
protected Map<String,String[]> |
params()
Returns an instance of
java.util.Map containing parameter names as keys and parameter values as map values. |
protected List<String> |
params(String name)
Returns multiple request values for a name.
|
protected Map<String,String> |
params1st()
Returns a map where keys are names of all parameters, while values are first value for each parameter, even
if such parameter has more than one value submitted.
|
protected String |
path()
Returns a path of the request.
|
protected int |
port()
Returns port on which the of the server received current request.
|
protected void |
process(String text,
Map params,
Writer writer)
Processes text as a FreeMarker template.
|
protected String |
protocol()
Returns protocol of request, for example: HTTP/1.1.
|
protected String |
queryString()
Returns query string of the request.
|
protected String |
remoteAddress()
IP address of the requesting client.
|
protected String |
remoteHost()
Host name of the requesting client.
|
protected abstract void |
render(Map params,
String body,
Writer writer)
Implement this method ina concrete subclass.
|
protected boolean |
requestHas(String name)
Synonym of
exists(String) . |
protected Map |
session()
Returns reference to a current session map.
|
protected Object |
session(String name)
Synonym of
sessionObject(String) . |
protected Object |
sessionObject(String name)
Convenience method, returns object from session, equivalent of:
|
protected String |
uri()
Returns URI, or a full path of request.
|
protected String |
url()
Returns a full URL of the request, all except a query string.
|
protected String |
userAgent()
Helper method, returns user-agent header of the request.
|
protected void |
validateParamsPresence(Map params,
String... names)
Will throw
IllegalArgumentException if a parameter on the list is missing |
protected boolean |
xhr()
Synonym for
isXhr() . |
protected org.slf4j.Logger logger()
public void execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException
execute
in interface freemarker.template.TemplateDirectiveModel
freemarker.template.TemplateException
IOException
protected freemarker.template.TemplateModel get(Object name)
name
- name of objectprotected Object getUnwrapped(Object name)
name
- name of objectprotected abstract void render(Map params, String body, Writer writer) throws Exception
params
- this is a list of parameters as provided to tag in HTML.body
- body of tagwriter
- writer to write output to.Exception
- if anyprotected void validateParamsPresence(Map params, String... names)
IllegalArgumentException
if a parameter on the list is missingparams
- as a map passed in by Freemarkernames
- list if valid parameter names for this tag.protected String getContextPath()
protected void process(String text, Map params, Writer writer)
text
- text of a template.params
- map with parameters for processing.writer
- writer to write output to.protected Map getAllVariables()
public void overrideContext(String context)
context
- this context will be used instead of one provided by Servlet APIprotected String param(String name)
IllegalArgumentException
.name
- name of parameter.protected String getId()
/controller/action/id
.
This depends on a type of a URI, and whether controller is RESTful or not.protected String format()
/books.xml
, here "xml" is a format.protected AppContext appContext()
AppContext
.AppContext
.protected boolean isXhr()
protected String userAgent()
protected boolean xhr()
isXhr()
.protected Route getRoute()
Route
to be used for potential conditional logic inside controller filters.Route
protected boolean exists(String name)
name
- name of request parameter to test.protected boolean requestHas(String name)
exists(String)
.name
- name of request parameter to test.protected String host()
protected String ipAddress()
protected String getRequestProtocol()
X-Forwarded-Proto
on the request and forwards it to the Java container.
If such header is not present, than the protocol()
method is used.X-Forwarded-Proto
header is found, otherwise current
protocol.protected int getRequestPort()
X-Forwarded-Port
on the request and forwards it to the Java container.
If such header is not present, than the port()
method is used.X-Forwarded-Port
header is found, otherwise port of the Java container.protected int port()
protected String protocol()
protected String getRequestHost()
X-Forwarded-Host
on the request and forwards it to the Java container.
If such header is not present, than the host()
method is used.X-Forwarded-Host
header is found, otherwise local host name.protected String ipForwardedFor()
protected List<String> params(String name)
name
- name of multiple values from request.protected Map<String,String> params1st()
protected Map<String,String[]> params()
java.util.Map
containing parameter names as keys and parameter values as map values.
The keys in the parameter map are of type String. The values in the parameter map are of type String array.java.util.Map
containing parameter names as keys and parameter values as map values.
The keys in the parameter map are of type String. The values in the parameter map are of type String array.protected Locale locale()
protected Map session()
protected Object sessionObject(String name)
session().get(name)
name
- name of object,protected Object session(String name)
sessionObject(String)
.name
- name of session attributepublic List<Cookie> cookies()
public Cookie cookie(String name)
name
- name of a cookie.protected String cookieValue(String name)
name
- name of cookie.protected String path()
/controller/action/id
protected String url()
protected String queryString()
protected String method()
protected boolean isGet()
protected boolean isPost()
protected boolean isPut()
protected boolean isDelete()
protected boolean isMethod(String method)
protected boolean isHead()
protected String context()
/mywebapp
protected String uri()
/mywebapp/controller/action/id
protected String remoteHost()
protected String remoteAddress()
protected String header(String name)
name
- name of headerCopyright © 2019. All rights reserved.