Class FreeMarkerTag
java.lang.Object
org.javalite.activeweb.freemarker.FreeMarkerTag
- All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel
,freemarker.template.TemplateModel
,RequestAccess
- Direct Known Subclasses:
ConfirmationTag
,CSRFTokenTag
,DebugTag
,FormTag
,LinkToTag
,MessageTag
,SelectTag
,YieldTag
public abstract class FreeMarkerTag
extends Object
implements freemarker.template.TemplateDirectiveModel, RequestAccess
Convenience class for implementing application - specific tags.
- Author:
- Igor Polevoy
-
Field Summary
Fields inherited from interface org.javalite.activeweb.RequestAccess
LOGGER
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body)
protected freemarker.template.TemplateModel
Gets an object from context - by name.protected Map
Returns a map of all variables in scope.protected String
Returns this applications' context path.protected Object
getUnwrapped(Object name)
Gets an object from context - by name.protected <T> T
getUnwrapped(Object name, Class<T> clazz)
protected org.slf4j.Logger
logger()
Provides a logger to a subclass.void
overrideContext(String context)
Use to override context of the application.protected void
Processes text as a FreeMarker template.protected abstract void
Implement this method ina concrete subclass.protected Map
session()
Returns reference to a current session map.protected Object
sessionObject(String name)
Convenience method, returns object from session, equivalent of:protected void
validateParamsPresence(Map params, String... names)
Will throwIllegalArgumentException
if a parameter on the list is missingMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.javalite.activeweb.RequestAccess
appContext, context, cookie, cookies, cookieValue, exists, format, getId, getLocale, getRequestHost, getRequestPort, getRequestProperties, getRequestProtocol, getRoute, header, headers, host, ipAddress, ipForwardedFor, isDelete, isGet, isHead, isMethod, isMultipartContent, isPost, isPut, isXhr, locale, method, param, param, params, params, params, params1st, params1st, path, port, protocol, queryString, remoteAddress, remoteHost, requestHas, servletPath, session, session, uri, url, userAgent, xhr
-
Constructor Details
-
FreeMarkerTag
public FreeMarkerTag()
-
-
Method Details
-
logger
protected org.slf4j.Logger logger()Provides a logger to a subclass.- Returns:
- initialized instance of logger.
-
execute
public void execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException- Specified by:
execute
in interfacefreemarker.template.TemplateDirectiveModel
- Throws:
freemarker.template.TemplateException
IOException
-
get
Gets an object from context - by name.- Parameters:
name
- name of object- Returns:
- object or null if not found.
-
getUnwrapped
Gets an object from context - by name.- Parameters:
name
- name of object- Returns:
- object or null if not found.
-
getUnwrapped
-
render
Implement this method ina concrete subclass.- Parameters:
params
- this is a list of parameters as provided to tag in HTML.body
- body of tagwriter
- writer to write output to.- Throws:
Exception
- if any
-
validateParamsPresence
Will throwIllegalArgumentException
if a parameter on the list is missing- Parameters:
params
- as a map passed in by Freemarkernames
- list if valid parameter names for this tag.
-
getContextPath
Returns this applications' context path.- Returns:
- context path.
-
process
Processes text as a FreeMarker template. Usually used to process an inner body of a tag.- Parameters:
text
- text of a template.params
- map with parameters for processing.writer
- writer to write output to.
-
getAllVariables
Returns a map of all variables in scope.- Returns:
- map of all variables in scope.
-
overrideContext
Use to override context of the application. Usually this is done because you need to generate special context related paths due to web server configuration- Parameters:
context
- this context will be used instead of one provided by Servlet API
-
session
Returns reference to a current session map.- Returns:
- reference to a current session map.
-
sessionObject
Convenience method, returns object from session, equivalent of:session().get(name)
- Parameters:
name
- name of object,- Returns:
- session object.
-