Class FreeMarkerConlet<S>
java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jgrapes.webconsole.base.AbstractConlet<S>
org.jgrapes.webconsole.base.freemarker.FreeMarkerConlet<S>
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
- Direct Known Subclasses:
FormTestConlet
,HelloWorldConlet
,JmxBrowserConlet
,LoginConlet
,LoginConlet
,LogViewerConlet
,MarkdownDisplayConlet
,MessageBoxConlet
,StyleTestConlet
,SysInfoConlet
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jgrapes.webconsole.base.AbstractConlet
AbstractConlet.ConletTrackingInfo
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
Fields inherited from class org.jgrapes.webconsole.base.AbstractConlet
TYPE_INSTANCE_SEPARATOR
-
Constructor Summary
ConstructorDescriptionFreeMarkerConlet
(Channel componentChannel) Creates a new component that listens for new events on the given channel.FreeMarkerConlet
(Channel componentChannel, HandlerDefinition.ChannelReplacements channelReplacements) LikeFreeMarkerConlet(Channel)
, but supports the specification of channel replacements. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doGetResource
(ConletResourceRequest event, IOSubchannel channel) Checks if the path of the requested resource ends with*.ftl.*
.fmConletModel
(Event<?> event, IOSubchannel channel, String conletId, Object conletState) Build a freemarker model for the current request.fmModel
(NotifyConletModel event, ConsoleConnection channel, String conletId, Object conletState) fmModel
(RenderConletRequestBase<?> event, ConsoleConnection channel, String conletId, Object conletState) fmSessionModel
(Session session) Build a freemarker model holding the information associated with the session.fmTypeModel
(RenderSupport renderSupport) Creates the request independent part of the freemarker model.protected Configuration
Create the base freemarker configuration.processTemplate
(Event<?> request, Template template, Object dataModel) Returns a future string providing the result from processing the given template with the given data.processTemplate
(RenderConletRequestBase<?> request, Template template, Object dataModel) Returns a future string providing the result from processing the given template with the given data.Methods inherited from class org.jgrapes.webconsole.base.AbstractConlet
afterOnClosed, conletIds, conletIdsByConsoleConnection, conletViews, createNewState, createStateRepresentation, doConletDeleted, doRemoveConletType, doRenderConlet, doSetLocale, doUpdateConletState, generateInstanceId, l10nBundles, localizations, onAddConletRequest, onClosed, onConletDeleted, onConletResourceRequest, onDetached, onNotifyConletModel, onRenderConletRequest, onSetLocale, putInSession, readContent, readContent, recreateState, removeState, resourceBundle, setPeriodicRefresh, stateFromSession, statesFromSession, supportedLocales, trackConlet, trackedConnections, type, typeFromId
Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
FreeMarkerConlet
Creates a new component that listens for new events on the given channel.- Parameters:
componentChannel
-
-
FreeMarkerConlet
public FreeMarkerConlet(Channel componentChannel, HandlerDefinition.ChannelReplacements channelReplacements) LikeFreeMarkerConlet(Channel)
, but supports the specification of channel replacements.- Parameters:
componentChannel
-channelReplacements
- the channel replacements (seeComponent
)
-
-
Method Details
-
freemarkerConfig
Create the base freemarker configuration.- Returns:
- the configuration
-
fmTypeModel
Creates the request independent part of the freemarker model.The result is cached as unmodifiable map as it can safely be assumed that the render support does not change for a given web console.
This model provides:
- The function
conletResource
that makesRenderSupport.conletResource(String, java.net.URI)
available in the template. The first argument is set to the name of the web console component, only the second must be supplied when the function is invoked in a template.
- Parameters:
renderSupport
- the render support from the web console- Returns:
- the result
- The function
-
fmSessionModel
Build a freemarker model holding the information associated with the session.This model provides:
- The
locale
(of typeLocale
). - The
resourceBundle
(of typeResourceBundle
). - A function
_
that looks up the given key in the web console component’s resource bundle. - A function
supportedLanguages
that returns aMap
with language identifiers as keys andLanguageInfo
instances as values (derived fromAbstractConlet.supportedLocales()
).
- Parameters:
session
- the session- Returns:
- the model
- The
-
fmConletModel
protected Map<String,Object> fmConletModel(Event<?> event, IOSubchannel channel, String conletId, Object conletState) Build a freemarker model for the current request.This model provides:
- The
event
property (of typeRenderConletRequest
). - The
conletType
property (of typeString
). - The
conletId
property (of typeString
). - The
conlet
property with the conlet’s state (if notnull
). - The function
_Id(String base)
that creates a unique id for an HTML element by appending the web console component id to the provided base. - The
conletProperties
which are the properties from anAddConletRequest
, or an empty map.
- Parameters:
event
- the eventchannel
- the channelconletId
- the conlet idconletState
- the conlet’s state information- Returns:
- the model
- The
-
fmModel
protected Map<String,Object> fmModel(RenderConletRequestBase<?> event, ConsoleConnection channel, String conletId, Object conletState) Build a freemarker model that combinesfmTypeModel(org.jgrapes.webconsole.base.RenderSupport)
,fmSessionModel(org.jgrapes.http.Session)
andfmConletModel(org.jgrapes.core.Event<?>, org.jgrapes.io.IOSubchannel, java.lang.String, java.lang.Object)
.- Parameters:
event
- the eventchannel
- the channelconletId
- the conlet idconletState
- the conlet’s state information- Returns:
- the model
-
fmModel
protected Map<String,Object> fmModel(NotifyConletModel event, ConsoleConnection channel, String conletId, Object conletState) Build a freemarker model that combinesfmTypeModel(org.jgrapes.webconsole.base.RenderSupport)
,fmSessionModel(org.jgrapes.http.Session)
andfmConletModel(org.jgrapes.core.Event<?>, org.jgrapes.io.IOSubchannel, java.lang.String, java.lang.Object)
.- Parameters:
event
- the eventchannel
- the channelconletId
- the conlet idconletState
- the conlet’s state information- Returns:
- the model
-
doGetResource
Checks if the path of the requested resource ends with*.ftl.*
.If so, processes the template with the
fmTypeModel(RenderSupport)
andfmSessionModel(Session)
and sends the result. Else, invoke the super class’ method.- Overrides:
doGetResource
in classAbstractConlet<S>
- Parameters:
event
- the event. The result will be set totrue
on successchannel
- the channel
-
processTemplate
public Future<String> processTemplate(RenderConletRequestBase<?> request, Template template, Object dataModel) Returns a future string providing the result from processing the given template with the given data.The method delegates to
processTemplate(Event, Template, Object)
. The version with this signature is kept for backward compatibility.- Parameters:
request
- the request, used to obtain theExecutorService
service related with the request being processedtemplate
- the templatedataModel
- the data model- Returns:
- the future
-
processTemplate
Returns a future string providing the result from processing the given template with the given data.- Parameters:
request
- the request, used to obtain theExecutorService
service related with the request being processedtemplate
- the templatedataModel
- the data model- Returns:
- the future
-