public class ScriptHelper extends java.lang.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 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 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,
java.lang.String options)
Helper method to forward the request to a Servlet or script for the given
resource and requestDispatcherOptions . |
void |
forward(java.lang.String path)
Same as
SlingScriptHelper.forward(String,RequestDispatcherOptions) , but using
empty options. |
void |
forward(java.lang.String path,
RequestDispatcherOptions options)
Helper method to forward the request to a Servlet or script for the given
path and options . |
void |
forward(java.lang.String path,
java.lang.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(java.lang.Class<ServiceType> type)
Lookup a single service.
|
<ServiceType> |
getServices(java.lang.Class<ServiceType> serviceType,
java.lang.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,
java.lang.String options)
Helper method to include the result of processing the request for the
given
resource and requestDispatcherOptions . |
void |
include(java.lang.String path)
Same as
SlingScriptHelper.include(String,RequestDispatcherOptions) , but using
empty options. |
void |
include(java.lang.String path,
RequestDispatcherOptions options)
Helper method to include the result of processing the request for the
given
path and options . |
void |
include(java.lang.String path,
java.lang.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 java.util.List<org.osgi.framework.ServiceReference> references
protected java.util.Map<java.lang.String,java.lang.Object> services
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(java.lang.String path)
SlingScriptHelper
SlingScriptHelper.include(String,RequestDispatcherOptions)
, but using
empty options.include
in interface SlingScriptHelper
path
- The path to includeSlingScriptHelper.include(java.lang.String)
public void include(java.lang.String path, java.lang.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(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(java.lang.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(java.lang.String path)
SlingScriptHelper
SlingScriptHelper.forward(String,RequestDispatcherOptions)
, but using
empty options.forward
in interface SlingScriptHelper
path
- The path to forward toSlingScriptHelper.forward(java.lang.String)
public void forward(java.lang.String path, java.lang.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(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(java.lang.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(java.lang.Class<ServiceType> type)
SlingScriptHelper
If multiple such services exist, the service with the highest ranking (as specified in its Constants.SERVICE_RANKING property) is returned. If there is a tie in ranking, the service with the lowest service ID (as specified in its Constants.SERVICE_ID property); that is, the service that was registered first is returned.
This is equal to the semantics from BundleContext.getServiceReference(Class).
getService
in interface SlingScriptHelper
ServiceType
- The type (interface) of the service.type
- The type (interface) of the service.null
if no services are registered which implement the specified class.SlingScriptHelper.getService(java.lang.Class)
public <ServiceType> ServiceType[] getServices(java.lang.Class<ServiceType> serviceType, java.lang.String filter) throws InvalidServiceFilterSyntaxException
SlingScriptHelper
The returned array is sorted descending by service ranking (i.e. the service with the highest ranking is returned first). If there is a tie in ranking, the service with the lowest service ID (as specified in its Constants.SERVICE_ID property); that is, the service that was registered first is returned first.
getServices
in interface SlingScriptHelper
ServiceType
- The type (interface) of the service.serviceType
- The type (interface) of the service.filter
- An optional filter (LDAP-like, see OSGi spec)null
.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
resource
- The resource to forward to.SlingScriptHelper.forward(org.apache.sling.api.resource.Resource)
public void forward(Resource resource, java.lang.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(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
resource
- The resource to includeSlingScriptHelper.forward(org.apache.sling.api.resource.Resource)
public void include(Resource resource, java.lang.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(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 © 2022 The Apache Software Foundation. All rights reserved.