org.apache.sling.scripting.core
Class ScriptHelper

java.lang.Object
  extended by org.apache.sling.scripting.core.ScriptHelper
All Implemented Interfaces:
SlingScriptHelper

public class ScriptHelper
extends java.lang.Object
implements SlingScriptHelper

Simple script helper providing access to the (wrapped) response, the on-demand writer and a simple API for request inclusion. Instances of this class are made available to the scripts as the global sling variable.


Field Summary
protected  org.osgi.framework.BundleContext bundleContext
           
protected  java.util.List<org.osgi.framework.ServiceReference> references
          The list of references - we don't need to synchronize this as we are running in one single request.
protected  java.util.Map<java.lang.String,java.lang.Object> services
          A map of found services.
 
Constructor Summary
ScriptHelper(org.osgi.framework.BundleContext ctx, SlingScript script)
           
ScriptHelper(org.osgi.framework.BundleContext ctx, SlingScript script, SlingHttpServletRequest request, SlingHttpServletResponse response)
           
 
Method Summary
 void dispose()
          Dispose the helper.
 void forward(java.lang.String path)
          Forward the request to another resource, using no options
 void forward(java.lang.String path, RequestDispatcherOptions options)
          Forward the request to another resource, using specified options
 void forward(java.lang.String path, java.lang.String options)
          Forward the request to another resource, using specified options
 SlingHttpServletRequest getRequest()
          Returns the SlingHttpServletRequest representing the input of the request.
 SlingHttpServletResponse getResponse()
          Returns the SlingHttpServletResponse representing the output of the request.
 SlingScript getScript()
          Returns the SlingScript being called to handle the request.
<ServiceType>
ServiceType
getService(java.lang.Class<ServiceType> type)
          Lookup a single service
<ServiceType>
ServiceType[]
getServices(java.lang.Class<ServiceType> serviceType, java.lang.String filter)
          Lookup one or several services
 void include(java.lang.String path)
          Same as SlingScriptHelper.include(String,RequestDispatcherOptions), but using empty options.
 void include(java.lang.String path, RequestDispatcherOptions options)
          Include the output of another request, using specified options
 void include(java.lang.String path, java.lang.String options)
          Include the output of another request, using specified options
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bundleContext

protected final org.osgi.framework.BundleContext bundleContext

references

protected final java.util.List<org.osgi.framework.ServiceReference> references
The list of references - we don't need to synchronize this as we are running in one single request.


services

protected final java.util.Map<java.lang.String,java.lang.Object> services
A map of found services.

Constructor Detail

ScriptHelper

public ScriptHelper(org.osgi.framework.BundleContext ctx,
                    SlingScript script)

ScriptHelper

public ScriptHelper(org.osgi.framework.BundleContext ctx,
                    SlingScript script,
                    SlingHttpServletRequest request,
                    SlingHttpServletResponse response)
Method Detail

getScript

public SlingScript getScript()
Description copied from interface: SlingScriptHelper
Returns the SlingScript being called to handle the request.

Specified by:
getScript in interface SlingScriptHelper

getRequest

public SlingHttpServletRequest getRequest()
Description copied from interface: SlingScriptHelper
Returns the SlingHttpServletRequest representing the input of the request.

Specified by:
getRequest in interface SlingScriptHelper

getResponse

public SlingHttpServletResponse getResponse()
Description copied from interface: SlingScriptHelper
Returns the SlingHttpServletResponse representing the output of the request.

Specified by:
getResponse in interface SlingScriptHelper

include

public void include(java.lang.String path)
Description copied from interface: SlingScriptHelper
Same as SlingScriptHelper.include(String,RequestDispatcherOptions), but using empty options.

Specified by:
include in interface SlingScriptHelper
Throws:
SlingServletException - Wrapping a ServletException thrown while handling the include.

include

public void include(java.lang.String path,
                    java.lang.String options)
Include the output of another request, using specified options

Specified by:
include in interface SlingScriptHelper
Parameters:
path - The path to the resource to include.
options - influence the rendering of the included Resource
See Also:
RequestDispatcherOptions.RequestDispatcherOptions(String), SlingScriptHelper.include(String, RequestDispatcherOptions)

include

public void include(java.lang.String path,
                    RequestDispatcherOptions options)
Include the output of another request, using specified options

Specified by:
include in interface SlingScriptHelper
Parameters:
path - The path to the resource to include.
options - influence the rendering of the included Resource
See Also:
RequestDispatcherOptions, SlingScriptHelper.include(String, String)

forward

public void forward(java.lang.String path)
Forward the request to another resource, using no options

Specified by:
forward in interface SlingScriptHelper

forward

public void forward(java.lang.String path,
                    java.lang.String options)
Forward the request to another resource, using specified options

Specified by:
forward in interface SlingScriptHelper
Parameters:
path - The path to the resource to forward to.
options - influence the rendering of the forwarded Resource
See Also:
RequestDispatcherOptions.RequestDispatcherOptions(String), SlingScriptHelper.forward(String, RequestDispatcherOptions)

forward

public void forward(java.lang.String path,
                    RequestDispatcherOptions options)
Forward the request to another resource, using specified options

Specified by:
forward in interface SlingScriptHelper
Parameters:
path - The path to the resource to forward the request to.
options - influence the rendering of the forwarded Resource
See Also:
RequestDispatcherOptions

getService

public <ServiceType> ServiceType getService(java.lang.Class<ServiceType> type)
Description copied from interface: SlingScriptHelper
Lookup a single service

Specified by:
getService in interface SlingScriptHelper
Parameters:
type - The type (interface) of the service.
Returns:
The service instance, or null if the service is not available.
See Also:
SlingScriptHelper.getService(java.lang.Class)

getServices

public <ServiceType> ServiceType[] getServices(java.lang.Class<ServiceType> serviceType,
                                               java.lang.String filter)
                          throws InvalidServiceFilterSyntaxException
Description copied from interface: SlingScriptHelper
Lookup one or several services

Specified by:
getServices in interface SlingScriptHelper
Parameters:
serviceType - The type (interface) of the service.
filter - An optional filter (LDAP-like, see OSGi spec)
Returns:
The services object or null.
Throws:
InvalidServiceFilterSyntaxException - If the filter string is not a valid OSGi service filter string.
See Also:
SlingScriptHelper.getServices(java.lang.Class, java.lang.String)

dispose

public void dispose()
Description copied from interface: SlingScriptHelper
Dispose the helper. This method can be used to clean up the script helper after the script is run.

Specified by:
dispose in interface SlingScriptHelper
See Also:
SlingScriptHelper.dispose()


Copyright © 2007-2009. All Rights Reserved.