public class ScriptHelper extends Object implements SlingScriptHelper
sling
variable.
Client code using this object should take care to call cleanup()
when the object is not used anymore!Modifier and Type | Field and Description |
---|---|
protected org.osgi.framework.BundleContext |
bundleContext
The bundle context.
|
protected 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 Map<String,Object> |
services
A map of found services.
|
Constructor and Description |
---|
ScriptHelper(org.osgi.framework.BundleContext ctx,
SlingScript script) |
ScriptHelper(org.osgi.framework.BundleContext ctx,
SlingScript script,
SlingHttpServletRequest request,
SlingHttpServletResponse response) |
Modifier and Type | Method and Description |
---|---|
void |
cleanup()
Clean up this instance.
|
void |
dispose()
Deprecated.
|
void |
forward(Resource resource)
Same as
SlingScriptHelper.forward(Resource,RequestDispatcherOptions) , but using
empty options. |
void |
forward(Resource resource,
RequestDispatcherOptions options)
Helper method to forward the request to a Servlet or script for the given
resource and options . |
void |
forward(Resource resource,
String options)
Helper method to forward the request to a Servlet or script for the given
resource and requestDispatcherOptions . |
void |
forward(String path)
Same as
SlingScriptHelper.forward(String,RequestDispatcherOptions) , but using
empty options. |
void |
forward(String path,
RequestDispatcherOptions options)
Helper method to forward the request to a Servlet or script for the given
path and options . |
void |
forward(String path,
String options)
Helper method to forward the request to a Servlet or script for the given
path and requestDispatcherOptions . |
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> |
getService(Class<ServiceType> type)
Lookup a single service
|
<ServiceType> |
getServices(Class<ServiceType> serviceType,
String filter)
Lookup one or several services
|
void |
include(Resource resource)
Same as
SlingScriptHelper.include(Resource,RequestDispatcherOptions) , but using
empty options. |
void |
include(Resource resource,
RequestDispatcherOptions options)
Helper method to include the result of processing the request for the
given
resource and options . |
void |
include(Resource resource,
String options)
Helper method to include the result of processing the request for the
given
resource and requestDispatcherOptions . |
void |
include(String path)
Same as
SlingScriptHelper.include(String,RequestDispatcherOptions) , but using
empty options. |
void |
include(String path,
RequestDispatcherOptions options)
Helper method to include the result of processing the request for the
given
path and options . |
void |
include(String path,
String options)
Helper method to include the result of processing the request for the
given
path and requestDispatcherOptions . |
protected final org.osgi.framework.BundleContext bundleContext
protected List<org.osgi.framework.ServiceReference> references
public ScriptHelper(org.osgi.framework.BundleContext ctx, SlingScript script)
public ScriptHelper(org.osgi.framework.BundleContext ctx, SlingScript script, SlingHttpServletRequest request, SlingHttpServletResponse response)
public SlingScript getScript()
SlingScriptHelper
SlingScript
being called to handle the request.getScript
in interface SlingScriptHelper
SlingScriptHelper.getScript()
public SlingHttpServletRequest getRequest()
SlingScriptHelper
SlingHttpServletRequest
representing the input of the
request.getRequest
in interface SlingScriptHelper
SlingScriptHelper.getRequest()
public SlingHttpServletResponse getResponse()
SlingScriptHelper
SlingHttpServletResponse
representing the output of
the request.getResponse
in interface SlingScriptHelper
SlingScriptHelper.getResponse()
public void include(String path)
SlingScriptHelper
SlingScriptHelper.include(String,RequestDispatcherOptions)
, but using
empty options.include
in interface SlingScriptHelper
SlingScriptHelper.include(java.lang.String)
public void include(String path, String options)
SlingScriptHelper
path
and requestDispatcherOptions
.
This method is intended to be implemented as follows:
RequestDispatcher dispatcher = getRequest().getRequestDispatcher(path, "option:xyz"); if (dispatcher != null) { dispatcher.include(getRequest(), getResponse()); }
This method creates a RequestDispatcherOptions
object by
calling the
RequestDispatcherOptions.RequestDispatcherOptions(String)
constructor.
include
in interface SlingScriptHelper
path
- The path to the resource to include.options
- influence the rendering of the included
ResourceSlingScriptHelper.include(java.lang.String, java.lang.String)
public void include(String path, RequestDispatcherOptions options)
SlingScriptHelper
path
and options
. This method is
intended to be implemented as follows:
RequestDispatcherOptions opts = new RequestDispatcherOptions(); opts.put("option", "xyz"); RequestDispatcher dispatcher = getRequest().getRequestDispatcher(path, opts); if (dispatcher != null) { dispatcher.include(getRequest(), getResponse()); }
include
in interface SlingScriptHelper
path
- The path to the resource to include.options
- influence the rendering of the included ResourceSlingScriptHelper.include(java.lang.String, org.apache.sling.api.request.RequestDispatcherOptions)
public void forward(String path)
SlingScriptHelper
SlingScriptHelper.forward(String,RequestDispatcherOptions)
, but using
empty options.forward
in interface SlingScriptHelper
SlingScriptHelper.forward(java.lang.String)
public void forward(String path, String options)
SlingScriptHelper
path
and requestDispatcherOptions
. This method
is intended to be implemented as follows:
RequestDispatcher dispatcher = getRequest().getRequestDispatcher(path, "option:xyz"); if (dispatcher != null) { dispatcher.forward(getRequest(), getResponse()); }
This method creates a RequestDispatcherOptions
object by
calling the
RequestDispatcherOptions.RequestDispatcherOptions(String)
constructor.
forward
in interface SlingScriptHelper
path
- The path to the resource to forward to.options
- influence the rendering of the forwarded
ResourceSlingScriptHelper.forward(java.lang.String, java.lang.String)
public void forward(String path, RequestDispatcherOptions options)
SlingScriptHelper
path
and options
. This method is intended
to be implemented as follows:
RequestDispatcherOptions opts = new RequestDispatcherOptions(); opts.put("option", "xyz"); RequestDispatcher dispatcher = getRequest().getRequestDispatcher(path, opts); if (dispatcher != null) { dispatcher.forward(getRequest(), getResponse()); }
forward
in interface SlingScriptHelper
path
- The path to the resource to forward the request to.options
- influence the rendering of the forwarded ResourceSlingScriptHelper.forward(java.lang.String, org.apache.sling.api.request.RequestDispatcherOptions)
@Deprecated public void dispose()
SlingScriptHelper
dispose
in interface SlingScriptHelper
SlingScriptHelper.dispose()
public <ServiceType> ServiceType getService(Class<ServiceType> type)
SlingScriptHelper
getService
in interface SlingScriptHelper
type
- The type (interface) of the service.SlingScriptHelper.getService(java.lang.Class)
public <ServiceType> ServiceType[] getServices(Class<ServiceType> serviceType, String filter) throws InvalidServiceFilterSyntaxException
SlingScriptHelper
getServices
in interface SlingScriptHelper
serviceType
- The type (interface) of the service.filter
- An optional filter (LDAP-like, see OSGi spec)InvalidServiceFilterSyntaxException
- If the filter
string is not a valid OSGi service filter string.SlingScriptHelper.getServices(java.lang.Class, java.lang.String)
public void cleanup()
public void forward(Resource resource)
SlingScriptHelper
SlingScriptHelper.forward(Resource,RequestDispatcherOptions)
, but using
empty options.forward
in interface SlingScriptHelper
SlingScriptHelper.forward(org.apache.sling.api.resource.Resource)
public void forward(Resource resource, String options)
SlingScriptHelper
resource
and requestDispatcherOptions
. This method
is intended to be implemented as follows:
RequestDispatcher dispatcher = getRequest().getRequestDispatcher(resource, "option:xyz"); if (dispatcher != null) { dispatcher.forward(getRequest(), getResponse()); }
This method creates a RequestDispatcherOptions
object by
calling the
RequestDispatcherOptions.RequestDispatcherOptions(String)
constructor.
forward
in interface SlingScriptHelper
resource
- The resource to forward to.options
- influence the rendering of the forwarded
ResourceSlingScriptHelper.forward(org.apache.sling.api.resource.Resource, java.lang.String)
public void forward(Resource resource, RequestDispatcherOptions options)
SlingScriptHelper
resource
and options
. This method is intended
to be implemented as follows:
RequestDispatcherOptions opts = new RequestDispatcherOptions(); opts.put("option", "xyz"); RequestDispatcher dispatcher = getRequest().getRequestDispatcher(resource, opts); if (dispatcher != null) { dispatcher.forward(getRequest(), getResponse()); }
forward
in interface SlingScriptHelper
resource
- The resource to forward the request to.options
- influence the rendering of the forwarded ResourceSlingScriptHelper.forward(org.apache.sling.api.resource.Resource, org.apache.sling.api.request.RequestDispatcherOptions)
public void include(Resource resource)
SlingScriptHelper
SlingScriptHelper.include(Resource,RequestDispatcherOptions)
, but using
empty options.include
in interface SlingScriptHelper
SlingScriptHelper.forward(org.apache.sling.api.resource.Resource)
public void include(Resource resource, String options)
SlingScriptHelper
resource
and requestDispatcherOptions
.
This method is intended to be implemented as follows:
RequestDispatcher dispatcher = getRequest().getRequestDispatcher(resource, "option:xyz"); if (dispatcher != null) { dispatcher.include(getRequest(), getResponse()); }
This method creates a RequestDispatcherOptions
object by
calling the
RequestDispatcherOptions.RequestDispatcherOptions(String)
constructor.
include
in interface SlingScriptHelper
resource
- The resource to include.options
- influence the rendering of the included
ResourceSlingScriptHelper.include(org.apache.sling.api.resource.Resource, java.lang.String)
public void include(Resource resource, RequestDispatcherOptions options)
SlingScriptHelper
resource
and options
. This method is
intended to be implemented as follows:
RequestDispatcherOptions opts = new RequestDispatcherOptions(); opts.put("option", "xyz"); RequestDispatcher dispatcher = getRequest().getRequestDispatcher(resource, opts); if (dispatcher != null) { dispatcher.include(getRequest(), getResponse()); }
include
in interface SlingScriptHelper
resource
- The resource to include.options
- influence the rendering of the included ResourceSlingScriptHelper.include(org.apache.sling.api.resource.Resource, org.apache.sling.api.request.RequestDispatcherOptions)
Copyright © 2015 The Apache Software Foundation. All rights reserved.