public class MessagesWebScript
extends org.springframework.extensions.webscripts.AbstractWebScript
The JavaScript object is created as 'SpringSurf.messages' - example usage:
var msg = SpringSurf.messages["messageid"];
| Modifier and Type | Field and Description |
|---|---|
protected org.springframework.extensions.webscripts.Cache |
cache
As WebScript beans as singletons, we can create a new Date() once when runtime
instantiates bean and use this as the "last modified" for the global messages
WebScript response Cache value.
|
protected Map<String,String> |
localeToChecksum
When configured to use checksum dependencies this will contain a mapping of the
locale to the last checksum generated for the cached message contents.
|
protected Map<String,String> |
messages
The response is built once per locale and cached - they do not change for the life
of the server instance.
|
| Constructor and Description |
|---|
MessagesWebScript()
Construction
|
| Modifier and Type | Method and Description |
|---|---|
void |
execute(org.springframework.extensions.webscripts.WebScriptRequest req,
org.springframework.extensions.webscripts.WebScriptResponse res)
Execute the webscript and return the cached JavaScript response
|
String |
generateCachedLocaleChecksum(String locale)
Attempts to retrieve the checksum for messages generated for the supplied locale.
|
String |
generateCacheKey(String locale)
It is necessary to include the protocol as well as the locale as the cache key.
|
protected String |
generateMessages(String locale)
Generates a String containing a JSON representation of all the i18n messages.
|
protected String |
generateMessages(org.springframework.extensions.webscripts.WebScriptRequest req,
org.springframework.extensions.webscripts.WebScriptResponse res,
String locale)
Generate the message for a given locale.
|
protected String |
getMessagesPrefix(org.springframework.extensions.webscripts.WebScriptRequest req,
org.springframework.extensions.webscripts.WebScriptResponse res,
String locale)
Generates a String prefix of JavaScript that by default sets up a namespace for the messages object
to which the messages JSON output should be assigned.
|
protected String |
getMessagesSuffix(org.springframework.extensions.webscripts.WebScriptRequest req,
org.springframework.extensions.webscripts.WebScriptResponse res,
String locale)
Generates a String suffix of JavaScript that defaults to a closing semi-colon.
|
protected void |
setCachedLocaleChecksum(String locale,
String checksum)
Maps a locale to a checksum in the cache
|
void |
setDependencyHandler(DependencyHandler dependencyHandler)
Setter provided to allow the Spring framework to set the link
DependencyHandler. |
void |
setWebFrameworkConfigElement(WebFrameworkConfigElement webFrameworkConfigElement)
Setter provided to allow the Spring framework to set the
WebFrameworkConfigElement. |
addModuleBundleToCache, checkModuleBundleCache, createArgs, createArgsM, createHeaders, createHeadersM, createScriptParameters, createStatusException, createTemplateParameters, executeScript, getContainer, getDescription, getExecuteScript, getResources, getStatusTemplate, init, renderString, renderString, renderTemplate, sendStatus, setURLModelFactory, toStringprotected final org.springframework.extensions.webscripts.Cache cache
protected final Map<String,String> messages
public void setWebFrameworkConfigElement(WebFrameworkConfigElement webFrameworkConfigElement)
Setter provided to allow the Spring framework to set the WebFrameworkConfigElement.
webFrameworkConfigElement - WebFrameworkConfigElementpublic void setDependencyHandler(DependencyHandler dependencyHandler)
Setter provided to allow the Spring framework to set the link DependencyHandler.
dependencyHandler - DependencyHandlerpublic void execute(org.springframework.extensions.webscripts.WebScriptRequest req,
org.springframework.extensions.webscripts.WebScriptResponse res)
throws IOException
IOExceptionpublic String generateCacheKey(String locale)
locale - Stringpublic String generateCachedLocaleChecksum(String locale)
Attempts to retrieve the checksum for messages generated for the supplied locale. This checksum
will only exist if the messages have already been generated (i.e. the generateMessages()
method has been called.
locale - Stringprotected void setCachedLocaleChecksum(String locale, String checksum)
Maps a locale to a checksum in the cache
locale - The locale to map againstchecksum - The checksum to mapprotected String getMessagesPrefix(org.springframework.extensions.webscripts.WebScriptRequest req, org.springframework.extensions.webscripts.WebScriptResponse res, String locale) throws IOException
Generates a String prefix of JavaScript that by default sets up a namespace for the messages object to which the messages JSON output should be assigned.
req - The current WebScriptRequestres - The current WebScriptResponselocale - The locale for the messages being generated.IOExceptionprotected String getMessagesSuffix(org.springframework.extensions.webscripts.WebScriptRequest req, org.springframework.extensions.webscripts.WebScriptResponse res, String locale) throws IOException
Generates a String suffix of JavaScript that defaults to a closing semi-colon.
req - The current WebScriptRequestres - The current WebScriptResponselocale - The locale for the messages being generated.IOExceptionprotected final String generateMessages(String locale)
Generates a String containing a JSON representation of all the i18n messages. This method
also uses the associated DependencyHandler to generate a checksum from that String and
maps against the supplied locale. This method has been declared as final to ensure that it
the checksum is always generated and set.
locale - The locale to generate messages forprotected String generateMessages(org.springframework.extensions.webscripts.WebScriptRequest req, org.springframework.extensions.webscripts.WebScriptResponse res, String locale) throws IOException
locale - Java locale formatIOExceptionCopyright © 2005–2016 Alfresco Software. All rights reserved.