org.springframework.extensions.webscripts
Class AbstractWebScript

java.lang.Object
  extended by org.springframework.extensions.webscripts.AbstractWebScript
All Implemented Interfaces:
WebScript
Direct Known Subclasses:
DeclarativeWebScript

public abstract class AbstractWebScript
extends Object
implements WebScript

Abstract implementation of a Web Script

Author:
davidc

Nested Class Summary
protected static class AbstractWebScript.ScriptDetails
          The combination of a ScriptContent and a request MIME type.
 
Constructor Summary
AbstractWebScript()
           
 
Method Summary
protected  Map<String,String> createArgs(WebScriptRequest req)
          Create a map of arguments from Web Script Request (for scripting)
protected  Map<String,String[]> createArgsM(WebScriptRequest req)
          Create a map of (array) arguments from Web Script Request (for scripting)
protected  Map<String,String> createHeaders(WebScriptRequest req)
          Create a map of headers from Web Script Request (for scripting)
protected  Map<String,String[]> createHeadersM(WebScriptRequest req)
          Create a map of (array) headers from Web Script Request (for scripting)
protected  Map<String,Object> createScriptParameters(WebScriptRequest req, WebScriptResponse res, AbstractWebScript.ScriptDetails script, Map<String,Object> customParams)
          Create a model for script usage
protected  WebScriptException createStatusException(Throwable e, WebScriptRequest req, WebScriptResponse res)
          Create an exception whose associated message is driven from a status template and model
protected  Map<String,Object> createTemplateParameters(WebScriptRequest req, WebScriptResponse res, Map<String,Object> customParams)
          Create a model for template usage
protected  void executeScript(ScriptContent location, Map<String,Object> model)
          Execute a script
protected  Container getContainer()
           
 Description getDescription()
          Gets the Service Description
protected  AbstractWebScript.ScriptDetails getExecuteScript(String mimetype)
          Find execute script for given request format Note: This method caches the script to request format mapping
 ResourceBundle getResources()
          Gets the Service Resources
protected  StatusTemplate getStatusTemplate(String scriptId, int statusCode, String format)
          Find status template Note: This method caches template search results
 void init(Container container, Description description)
          Initialise Web Script
protected  void renderString(String template, Map<String,Object> model, Writer writer)
          Render a template (contents as string)
protected  void renderString(String template, Map<String,Object> model, Writer writer, String extension)
          Render a template (contents as string)
protected  void renderTemplate(String templatePath, Map<String,Object> model, Writer writer)
          Render a template (identified by path)
protected  void sendStatus(WebScriptRequest req, WebScriptResponse res, Status status, Cache cache, String format, Map<String,Object> model)
          Render an explicit response status template
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.extensions.webscripts.WebScript
execute
 

Constructor Detail

AbstractWebScript

public AbstractWebScript()
Method Detail

init

public void init(Container container,
                 Description description)
Initialise Web Script

Parameters:
scriptRegistry -

getContainer

protected final Container getContainer()
Returns:
web script container

getDescription

public final Description getDescription()
Description copied from interface: WebScript
Gets the Service Description

Specified by:
getDescription in interface WebScript
Returns:
the service description

getResources

public final ResourceBundle getResources()
Description copied from interface: WebScript
Gets the Service Resources

Specified by:
getResources in interface WebScript
Returns:
the services resources or null if none present

getExecuteScript

protected AbstractWebScript.ScriptDetails getExecuteScript(String mimetype)
Find execute script for given request format Note: This method caches the script to request format mapping

Parameters:
mimetype -
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 request
res - web script response
script - script details
customModel - custom model entries
Returns:
script model

createTemplateParameters

protected Map<String,Object> createTemplateParameters(WebScriptRequest req,
                                                      WebScriptResponse res,
                                                      Map<String,Object> customParams)
Create a model for template usage

Parameters:
req - web script request
res - web script response
customModel - custom model entries
Returns:
template model

createArgs

protected final Map<String,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 Map<String,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 Map<String,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 Map<String,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(String templatePath,
                                    Map<String,Object> model,
                                    Writer writer)
Render a template (identified by path)

Parameters:
templatePath - template path
model - model
writer - output writer

renderString

protected final void renderString(String template,
                                  Map<String,Object> model,
                                  Writer writer)
Render a template (contents as string)

Parameters:
template - the template
model - model
writer - 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 template
model - model
writer - output writer
extension - 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 IOException
Render an explicit response status template

Parameters:
req - web script request
res - web script response
status - web script status
format - format
model - 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 - exception
req - web script request
res - web script response
Returns:
web script exception with associated template message and model

getStatusTemplate

protected StatusTemplate getStatusTemplate(String scriptId,
                                           int statusCode,
                                           String format)
Find status template Note: This method caches template search results

Parameters:
scriptId -
statusCode -
format -
Returns:
status template (or null if not found)

executeScript

protected void executeScript(ScriptContent location,
                             Map<String,Object> model)
Execute a script

Parameters:
location - script location
model - model

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009-2010 SpringSource, Inc. All Rights Reserved.