Class AbstractWebScript
- java.lang.Object
-
- org.springframework.extensions.webscripts.AbstractWebScript
-
- All Implemented Interfaces:
WebScript
- Direct Known Subclasses:
DeclarativeWebScript
public abstract class AbstractWebScript extends java.lang.Object implements WebScript
Abstract implementation of a Web Script- Author:
- davidc, kevinr
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractWebScript.ScriptDetailsThe combination of a ScriptContent and a request MIME type.
-
Constructor Summary
Constructors Constructor Description AbstractWebScript()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddModuleBundleToCache(java.lang.String path, java.util.ResourceBundle bundle)Adds a newResourceBundleinto the cache mapped against the path that the bundle was found.protected java.util.ResourceBundlecheckModuleBundleCache(java.lang.String path)Attempts to retrieve a previously cachedResourceBundlefor the supplied path.protected java.util.Map<java.lang.String,java.lang.String>createArgs(WebScriptRequest req)Create a map of arguments from Web Script Request (for scripting)protected java.util.Map<java.lang.String,java.lang.String[]>createArgsM(WebScriptRequest req)Create a map of (array) arguments from Web Script Request (for scripting)protected java.util.Map<java.lang.String,java.lang.String>createHeaders(WebScriptRequest req)Create a map of headers from Web Script Request (for scripting)protected java.util.Map<java.lang.String,java.lang.String[]>createHeadersM(WebScriptRequest req)Create a map of (array) headers from Web Script Request (for scripting)protected java.util.Map<java.lang.String,java.lang.Object>createScriptParameters(WebScriptRequest req, WebScriptResponse res, AbstractWebScript.ScriptDetails script, java.util.Map<java.lang.String,java.lang.Object> customParams)Create a model for script usageprotected WebScriptExceptioncreateStatusException(java.lang.Throwable e, WebScriptRequest req, WebScriptResponse res)Create an exception whose associated message is driven from a status template and modelprotected java.util.Map<java.lang.String,java.lang.Object>createTemplateParameters(WebScriptRequest req, WebScriptResponse res, java.util.Map<java.lang.String,java.lang.Object> customParams)Create a model for template usageprotected voidexecuteScript(ScriptContent location, java.util.Map<java.lang.String,java.lang.Object> model)Execute a scriptprotected ContainergetContainer()DescriptiongetDescription()Gets the Service Descriptionprotected AbstractWebScript.ScriptDetailsgetExecuteScript(java.lang.String mimetype)Find execute script for given request format Note: This method caches the script to request format mappingjava.util.ResourceBundlegetResources()Gets the Service Resourcesprotected StatusTemplategetStatusTemplate(java.lang.String scriptId, int statusCode, java.lang.String format)Find status template Note: This method caches template search resultsvoidinit(Container container, Description description)Initialise a WebScriptprotected voidrenderString(java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> model, java.io.Writer writer)Render a template (contents as string)protected voidrenderString(java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> model, java.io.Writer writer, java.lang.String extension)Render a template (contents as string)protected voidrenderTemplate(java.lang.String templatePath, java.util.Map<java.lang.String,java.lang.Object> model, java.io.Writer writer)Render a template (identified by path)protected voidsendStatus(WebScriptRequest req, WebScriptResponse res, Status status, Cache cache, java.lang.String format, java.util.Map<java.lang.String,java.lang.Object> model)Render an explicit response status templatevoidsetURLModelFactory(URLModelFactory urlModelFactory)java.lang.StringtoString()
-
-
-
Method Detail
-
init
public void init(Container container, Description description)
Initialise a WebScript
-
getContainer
protected final Container getContainer()
- Returns:
- web script container
-
getDescription
public final Description getDescription()
Description copied from interface:WebScriptGets the Service Description- Specified by:
getDescriptionin interfaceWebScript- Returns:
- the service description
-
checkModuleBundleCache
protected java.util.ResourceBundle checkModuleBundleCache(java.lang.String path)
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
protected void addModuleBundleToCache(java.lang.String path, java.util.ResourceBundle bundle)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
public final java.util.ResourceBundle getResources()
Description copied from interface:WebScriptGets the Service Resources- Specified by:
getResourcesin interfaceWebScript- Returns:
- the services resources or null if none present
-
getExecuteScript
protected AbstractWebScript.ScriptDetails getExecuteScript(java.lang.String mimetype)
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 java.util.Map<java.lang.String,java.lang.Object> createScriptParameters(WebScriptRequest req, WebScriptResponse res, AbstractWebScript.ScriptDetails script, java.util.Map<java.lang.String,java.lang.Object> customParams)
Create a model for script usage- Parameters:
req- web script requestres- web script responsescript- script detailscustomParams- Map- Returns:
- script model
-
setURLModelFactory
public void setURLModelFactory(URLModelFactory urlModelFactory)
- Specified by:
setURLModelFactoryin interfaceWebScript
-
createTemplateParameters
protected java.util.Map<java.lang.String,java.lang.Object> createTemplateParameters(WebScriptRequest req, WebScriptResponse res, java.util.Map<java.lang.String,java.lang.Object> customParams)
Create a model for template usage- Parameters:
req- web script requestres- web script responsecustomParams- Map- Returns:
- template model
-
createArgs
protected final java.util.Map<java.lang.String,java.lang.String> createArgs(WebScriptRequest req)
Create a map of arguments from Web Script Request (for scripting)- Parameters:
req- Web Script Request- Returns:
- argument map
-
createArgsM
protected final java.util.Map<java.lang.String,java.lang.String[]> createArgsM(WebScriptRequest req)
Create a map of (array) arguments from Web Script Request (for scripting)- Parameters:
req- Web Script Request- Returns:
- argument map
-
createHeaders
protected final java.util.Map<java.lang.String,java.lang.String> createHeaders(WebScriptRequest req)
Create a map of headers from Web Script Request (for scripting)- Parameters:
req- Web Script Request- Returns:
- header map
-
createHeadersM
protected final java.util.Map<java.lang.String,java.lang.String[]> createHeadersM(WebScriptRequest req)
Create a map of (array) headers from Web Script Request (for scripting)- Parameters:
req- Web Script Request- Returns:
- argument map
-
renderTemplate
protected final void renderTemplate(java.lang.String templatePath, java.util.Map<java.lang.String,java.lang.Object> model, java.io.Writer writer)Render a template (identified by path)- Parameters:
templatePath- template pathmodel- modelwriter- output writer
-
renderString
protected final void renderString(java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> model, java.io.Writer writer)Render a template (contents as string)- Parameters:
template- the templatemodel- modelwriter- output writer
-
renderString
protected final void renderString(java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> model, java.io.Writer writer, java.lang.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, java.lang.String format, java.util.Map<java.lang.String,java.lang.Object> model) throws java.io.IOException
Render an explicit response status template- Parameters:
req- web script requestres- web script responsestatus- web script statusformat- formatmodel- model- Throws:
java.io.IOException
-
createStatusException
protected final WebScriptException createStatusException(java.lang.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
protected StatusTemplate getStatusTemplate(java.lang.String scriptId, int statusCode, java.lang.String format)
Find status template Note: This method caches template search results- Parameters:
scriptId- StringstatusCode- intformat- String- Returns:
- status template (or null if not found)
-
executeScript
protected void executeScript(ScriptContent location, java.util.Map<java.lang.String,java.lang.Object> model)
Execute a script- Parameters:
location- script locationmodel- model
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-