Class AbstractWebScript
java.lang.Object
org.springframework.extensions.webscripts.AbstractWebScript
- All Implemented Interfaces:
WebScript
- Direct Known Subclasses:
DeclarativeWebScript
Abstract implementation of a Web Script
- Author:
- davidc, kevinr
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThe combination of a ScriptContent and a request MIME type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddModuleBundleToCache(String path, ResourceBundle bundle) Adds a newResourceBundleinto the cache mapped against the path that the bundle was found.protected ResourceBundlecheckModuleBundleCache(String path) Attempts to retrieve a previously cachedResourceBundlefor the supplied path.Create a map of arguments from Web Script Request (for scripting)Create a map of (array) arguments from Web Script Request (for scripting)Create a map of headers from Web Script Request (for scripting)Create a map of (array) headers from Web Script Request (for scripting)createScriptParameters(WebScriptRequest req, WebScriptResponse res, AbstractWebScript.ScriptDetails script, Map<String, Object> customParams) Create a model for script usageprotected final WebScriptExceptioncreateStatusException(Throwable e, WebScriptRequest req, WebScriptResponse res) Create an exception whose associated message is driven from a status template and modelcreateTemplateParameters(WebScriptRequest req, WebScriptResponse res, Map<String, Object> customParams) Create a model for template usageprotected voidexecuteScript(ScriptContent location, Map<String, Object> model) Execute a scriptprotected final Containerfinal DescriptionGets the Service Descriptionprotected AbstractWebScript.ScriptDetailsgetExecuteScript(String mimetype) Find execute script for given request format Note: This method caches the script to request format mappingfinal ResourceBundleGets the Service Resourcesprotected StatusTemplategetStatusTemplate(String scriptId, int statusCode, String format) Find status template Note: This method caches template search resultsvoidinit(Container container, Description description) Initialise a WebScriptprotected final voidRender a template (contents as string)protected final voidRender a template (contents as string)protected final voidRender a template (identified by path)protected final voidsendStatus(WebScriptRequest req, WebScriptResponse res, Status status, Cache cache, String format, Map<String, Object> model) Render an explicit response status templatevoidsetURLModelFactory(URLModelFactory urlModelFactory) toString()
-
Constructor Details
-
AbstractWebScript
public AbstractWebScript()
-
-
Method Details
-
init
Initialise a WebScript -
getContainer
- Returns:
- web script container
-
getDescription
Description copied from interface:WebScriptGets the Service Description- Specified by:
getDescriptionin interfaceWebScript- Returns:
- the service description
-
checkModuleBundleCache
Attempts to retrieve a previously cached
ResourceBundlefor the supplied path.- Parameters:
path- The path to retrieve a cached bundle for.- Returns:
- A previously cached bundle or
nullif it cannot be found.
-
addModuleBundleToCache
Adds a new
ResourceBundleinto the cache mapped against the path that the bundle was found.- Parameters:
path- The path to map theResourceBundleagainst.bundle- TheResourceBundleto cache.
-
getResources
Description copied from interface:WebScriptGets the Service Resources- Specified by:
getResourcesin interfaceWebScript- Returns:
- the services resources or null if none present
-
getExecuteScript
Find execute script for given request format Note: This method caches the script to request format mapping- Parameters:
mimetype- String- Returns:
- execute script
-
createScriptParameters
protected Map<String,Object> createScriptParameters(WebScriptRequest req, WebScriptResponse res, AbstractWebScript.ScriptDetails script, Map<String, Object> customParams) Create a model for script usage- Parameters:
req- web script requestres- web script responsescript- script detailscustomParams- Map<String, Object>- Returns:
- script model
-
setURLModelFactory
- Specified by:
setURLModelFactoryin interfaceWebScript
-
createTemplateParameters
protected Map<String,Object> createTemplateParameters(WebScriptRequest req, WebScriptResponse res, Map<String, Object> customParams) Create a model for template usage- Parameters:
req- web script requestres- web script responsecustomParams- Map<String, Object>- Returns:
- template model
-
createArgs
Create a map of arguments from Web Script Request (for scripting)- Parameters:
req- Web Script Request- Returns:
- argument map
-
createArgsM
Create a map of (array) arguments from Web Script Request (for scripting)- Parameters:
req- Web Script Request- Returns:
- argument map
-
createHeaders
Create a map of headers from Web Script Request (for scripting)- Parameters:
req- Web Script Request- Returns:
- header map
-
createHeadersM
Create a map of (array) headers from Web Script Request (for scripting)- Parameters:
req- Web Script Request- Returns:
- argument map
-
renderTemplate
Render a template (identified by path)- Parameters:
templatePath- template pathmodel- modelwriter- output writer
-
renderString
Render a template (contents as string)- Parameters:
template- the templatemodel- modelwriter- output writer
-
renderString
protected final void renderString(String template, Map<String, Object> model, Writer writer, String extension) Render a template (contents as string)- Parameters:
template- the templatemodel- modelwriter- output writerextension- optional template extension type (i.e. ftl, php)
-
sendStatus
protected final void sendStatus(WebScriptRequest req, WebScriptResponse res, Status status, Cache cache, String format, Map<String, Object> model) throws IOExceptionRender an explicit response status template- Parameters:
req- web script requestres- web script responsestatus- web script statusformat- formatmodel- model- Throws:
IOException
-
createStatusException
protected final WebScriptException createStatusException(Throwable e, WebScriptRequest req, WebScriptResponse res) Create an exception whose associated message is driven from a status template and model- Parameters:
e- exceptionreq- web script requestres- web script response- Returns:
- web script exception with associated template message and model
-
getStatusTemplate
Find status template Note: This method caches template search results- Parameters:
scriptId- StringstatusCode- intformat- String- Returns:
- status template (or null if not found)
-
executeScript
Execute a script- Parameters:
location- script locationmodel- model
-
toString
-