Class ScriptHelper
- All Implemented Interfaces:
SlingScriptHelper
sling
variable.
Client code using this object should take care to call cleanup()
when the object is not used anymore!-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.osgi.framework.BundleContext
The bundle context.protected List<org.osgi.framework.ServiceReference<?>>
The list of references - we don't need to synchronize this as we are running in one single request.A map of found services. -
Constructor Summary
ConstructorDescriptionScriptHelper
(org.osgi.framework.BundleContext ctx, SlingScript script) ScriptHelper
(org.osgi.framework.BundleContext ctx, SlingScript script, SlingHttpServletRequest request, SlingHttpServletResponse response) -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Clean up this instance.void
dispose()
Deprecated.This method is deprecated and should never be called by clients!void
Same asSlingScriptHelper.forward(String,RequestDispatcherOptions)
, but using empty options.void
Helper method to forward the request to a Servlet or script for the givenpath
andrequestDispatcherOptions
.void
forward
(String path, RequestDispatcherOptions options) Helper method to forward the request to a Servlet or script for the givenpath
andoptions
.void
Same asSlingScriptHelper.forward(Resource,RequestDispatcherOptions)
, but using empty options.void
Helper method to forward the request to a Servlet or script for the givenresource
andrequestDispatcherOptions
.void
forward
(Resource resource, RequestDispatcherOptions options) Helper method to forward the request to a Servlet or script for the givenresource
andoptions
.Returns theSlingHttpServletRequest
representing the input of the request.Returns theSlingHttpServletResponse
representing the output of the request.Returns theSlingScript
being called to handle the request.<T> T
getService
(Class<T> type) Lookup a single service.<T> T[]
getServices
(Class<T> serviceType, String filter) Lookup one or several services.void
Same asSlingScriptHelper.include(String,RequestDispatcherOptions)
, but using empty options.void
Helper method to include the result of processing the request for the givenpath
andrequestDispatcherOptions
.void
include
(String path, RequestDispatcherOptions options) Helper method to include the result of processing the request for the givenpath
andoptions
.void
Same asSlingScriptHelper.include(Resource,RequestDispatcherOptions)
, but using empty options.void
Helper method to include the result of processing the request for the givenresource
andrequestDispatcherOptions
.void
include
(Resource resource, RequestDispatcherOptions options) Helper method to include the result of processing the request for the givenresource
andoptions
.
-
Field Details
-
bundleContext
protected final org.osgi.framework.BundleContext bundleContextThe bundle context. -
references
The list of references - we don't need to synchronize this as we are running in one single request. -
services
A map of found services.
-
-
Constructor Details
-
ScriptHelper
-
ScriptHelper
public ScriptHelper(org.osgi.framework.BundleContext ctx, SlingScript script, SlingHttpServletRequest request, SlingHttpServletResponse response)
-
-
Method Details
-
getScript
Description copied from interface:SlingScriptHelper
Returns theSlingScript
being called to handle the request.- Specified by:
getScript
in interfaceSlingScriptHelper
- Returns:
- The script
- See Also:
-
getRequest
Description copied from interface:SlingScriptHelper
Returns theSlingHttpServletRequest
representing the input of the request.- Specified by:
getRequest
in interfaceSlingScriptHelper
- Returns:
- The request
- See Also:
-
getResponse
Description copied from interface:SlingScriptHelper
Returns theSlingHttpServletResponse
representing the output of the request.- Specified by:
getResponse
in interfaceSlingScriptHelper
- Returns:
- The response
- See Also:
-
include
Description copied from interface:SlingScriptHelper
Same asSlingScriptHelper.include(String,RequestDispatcherOptions)
, but using empty options.- Specified by:
include
in interfaceSlingScriptHelper
- Parameters:
path
- The path to include- See Also:
-
include
Description copied from interface:SlingScriptHelper
Helper method to include the result of processing the request for the givenpath
andrequestDispatcherOptions
. 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 theRequestDispatcherOptions(String)
constructor.- Specified by:
include
in interfaceSlingScriptHelper
- Parameters:
path
- The path to the resource to include.options
- influence the rendering of the included Resource- See Also:
-
include
Description copied from interface:SlingScriptHelper
Helper method to include the result of processing the request for the givenpath
andoptions
. 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()); }
- Specified by:
include
in interfaceSlingScriptHelper
- Parameters:
path
- The path to the resource to include.options
- influence the rendering of the included Resource- See Also:
-
forward
Description copied from interface:SlingScriptHelper
Same asSlingScriptHelper.forward(String,RequestDispatcherOptions)
, but using empty options.- Specified by:
forward
in interfaceSlingScriptHelper
- Parameters:
path
- The path to forward to- See Also:
-
forward
Description copied from interface:SlingScriptHelper
Helper method to forward the request to a Servlet or script for the givenpath
andrequestDispatcherOptions
. 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 theRequestDispatcherOptions(String)
constructor.- Specified by:
forward
in interfaceSlingScriptHelper
- Parameters:
path
- The path to the resource to forward to.options
- influence the rendering of the forwarded Resource- See Also:
-
forward
Description copied from interface:SlingScriptHelper
Helper method to forward the request to a Servlet or script for the givenpath
andoptions
. 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()); }
- Specified by:
forward
in interfaceSlingScriptHelper
- Parameters:
path
- The path to the resource to forward the request to.options
- influence the rendering of the forwarded Resource- See Also:
-
dispose
Deprecated.This method is deprecated and should never be called by clients!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 interfaceSlingScriptHelper
- See Also:
-
getService
Description copied from interface:SlingScriptHelper
Lookup a single service.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).
- Specified by:
getService
in interfaceSlingScriptHelper
- Type Parameters:
T
- The type (interface) of the service.- Parameters:
type
- The type (interface) of the service.- Returns:
- The service instance, or
null
if no services are registered which implement the specified class. - See Also:
-
getServices
public <T> T[] getServices(Class<T> serviceType, String filter) throws InvalidServiceFilterSyntaxException Description copied from interface:SlingScriptHelper
Lookup one or several services.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.
- Specified by:
getServices
in interfaceSlingScriptHelper
- Type Parameters:
T
- The type (interface) of the service.- Parameters:
serviceType
- The type (interface) of the service.filter
- An optional filter (LDAP-like, see OSGi spec)- Returns:
- An array of services objects or
null
. - Throws:
InvalidServiceFilterSyntaxException
- If thefilter
string is not a valid OSGi service filter string.- See Also:
-
cleanup
public void cleanup()Clean up this instance. -
forward
Description copied from interface:SlingScriptHelper
Same asSlingScriptHelper.forward(Resource,RequestDispatcherOptions)
, but using empty options.- Specified by:
forward
in interfaceSlingScriptHelper
- Parameters:
resource
- The resource to forward to.- See Also:
-
forward
Description copied from interface:SlingScriptHelper
Helper method to forward the request to a Servlet or script for the givenresource
andrequestDispatcherOptions
. 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 theRequestDispatcherOptions(String)
constructor.- Specified by:
forward
in interfaceSlingScriptHelper
- Parameters:
resource
- The resource to forward to.options
- influence the rendering of the forwarded Resource- See Also:
-
forward
Description copied from interface:SlingScriptHelper
Helper method to forward the request to a Servlet or script for the givenresource
andoptions
. 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()); }
- Specified by:
forward
in interfaceSlingScriptHelper
- Parameters:
resource
- The resource to forward the request to.options
- influence the rendering of the forwarded Resource- See Also:
-
include
Description copied from interface:SlingScriptHelper
Same asSlingScriptHelper.include(Resource,RequestDispatcherOptions)
, but using empty options.- Specified by:
include
in interfaceSlingScriptHelper
- Parameters:
resource
- The resource to include- See Also:
-
include
Description copied from interface:SlingScriptHelper
Helper method to include the result of processing the request for the givenresource
andrequestDispatcherOptions
. 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 theRequestDispatcherOptions(String)
constructor.- Specified by:
include
in interfaceSlingScriptHelper
- Parameters:
resource
- The resource to include.options
- influence the rendering of the included Resource- See Also:
-
include
Description copied from interface:SlingScriptHelper
Helper method to include the result of processing the request for the givenresource
andoptions
. 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()); }
- Specified by:
include
in interfaceSlingScriptHelper
- Parameters:
resource
- The resource to include.options
- influence the rendering of the included Resource- See Also:
-