org.springframework.extensions.webscripts
Class ScriptHelper

java.lang.Object
  extended by org.springframework.extensions.webscripts.ScriptHelper
All Implemented Interfaces:
Serializable

public final class ScriptHelper
extends Object
implements Serializable

A helper class with static functions for working with Scriptable maps, arrays and ScriptModelObjects.

Author:
muzquiano
See Also:
Serialized Form

Constructor Summary
ScriptHelper()
           
 
Method Summary
static ScriptModelObject getObject(RequestContext context, String objectTypeId, String objectId)
          Retrieves a model object from the underlying store and hands it back wrapped as a ScriptModelObject.
static org.mozilla.javascript.Scriptable toScriptableArray(org.mozilla.javascript.Scriptable scope, String[] elements)
          Converts a given array to a Scriptable array that can be traversed by the script and Freemarker engines
static ScriptableMap toScriptableMap(Map<String,Serializable> map)
          Converts an existing map to a Scriptable map
static ScriptableMap toScriptableMap(RequestContext context, Map<String,ModelObject> objects)
          Creates a Scriptable Map for a given map of model objects
static ScriptableMap toScriptableMap(RequestContext context, ModelObject[] modelObjects)
          Creates a Scriptable Map for a given array of model objects
static ScriptModelObject toScriptModelObject(RequestContext context, ModelObject modelObject)
          Wraps a ModelObject with a script wrapper to produce a ScriptModelObject that can be used by the script and Freemarker engines.
static Object[] toScriptModelObjectArray(RequestContext context, Map<String,ModelObject> objects)
          Converts a map of model objects to an array of ScriptModelObjects which can be used by the script and Freemarker engines.
static Object[] toScriptModelObjectArray(RequestContext context, ModelObject[] modelObjects)
          Converts an array of ModelObjects to an array of ScriptModelObjects which can be used by the script and Freemarker engines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptHelper

public ScriptHelper()
Method Detail

toScriptableMap

public static ScriptableMap toScriptableMap(RequestContext context,
                                            ModelObject[] modelObjects)
Creates a Scriptable Map for a given array of model objects

Parameters:
context - the context
modelObjects - the model objects
Returns:
the scriptable map

toScriptableMap

public static ScriptableMap toScriptableMap(RequestContext context,
                                            Map<String,ModelObject> objects)
Creates a Scriptable Map for a given map of model objects

Parameters:
context - the context
objects - a map of model objects (keyed by object id)
Returns:
the scriptable map

toScriptableMap

public static ScriptableMap toScriptableMap(Map<String,Serializable> map)
Converts an existing map to a Scriptable map

Parameters:
map - the map
Returns:
the scriptable map

toScriptableArray

public static org.mozilla.javascript.Scriptable toScriptableArray(org.mozilla.javascript.Scriptable scope,
                                                                  String[] elements)
Converts a given array to a Scriptable array that can be traversed by the script and Freemarker engines

Parameters:
scope - the scope
elements - the elements
Returns:
the scriptable

toScriptModelObject

public static ScriptModelObject toScriptModelObject(RequestContext context,
                                                    ModelObject modelObject)
Wraps a ModelObject with a script wrapper to produce a ScriptModelObject that can be used by the script and Freemarker engines.

Parameters:
context - the context
modelObject - the model object
Returns:
the script model object

toScriptModelObjectArray

public static Object[] toScriptModelObjectArray(RequestContext context,
                                                ModelObject[] modelObjects)
Converts an array of ModelObjects to an array of ScriptModelObjects which can be used by the script and Freemarker engines.

Parameters:
context - the context
modelObjects - the model objects
Returns:
the object[]

toScriptModelObjectArray

public static Object[] toScriptModelObjectArray(RequestContext context,
                                                Map<String,ModelObject> objects)
Converts a map of model objects to an array of ScriptModelObjects which can be used by the script and Freemarker engines.

Parameters:
context - the context
objects - the model objects
Returns:
the object[]

getObject

public static ScriptModelObject getObject(RequestContext context,
                                          String objectTypeId,
                                          String objectId)
Retrieves a model object from the underlying store and hands it back wrapped as a ScriptModelObject. If the model object cannot be found, null will be returned.

Parameters:
id - the id
Returns:
the script model object


Copyright © 2009 SpringSource, Inc. All Rights Reserved.