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
FieldsModifier and TypeFieldDescriptionprotected final org.osgi.framework.BundleContextThe 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
ConstructorsConstructorDescriptionScriptHelper(org.osgi.framework.BundleContext ctx, SlingScript script) ScriptHelper(org.osgi.framework.BundleContext ctx, SlingScript script, SlingHttpServletRequest request, SlingHttpServletResponse response) -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()Clean up this instance.voiddispose()Deprecated.This method is deprecated and should never be called by clients!voidSame asSlingScriptHelper.forward(String,RequestDispatcherOptions), but using empty options.voidHelper method to forward the request to a Servlet or script for the givenpathandrequestDispatcherOptions.voidforward(String path, RequestDispatcherOptions options) Helper method to forward the request to a Servlet or script for the givenpathandoptions.voidSame asSlingScriptHelper.forward(Resource,RequestDispatcherOptions), but using empty options.voidHelper method to forward the request to a Servlet or script for the givenresourceandrequestDispatcherOptions.voidforward(Resource resource, RequestDispatcherOptions options) Helper method to forward the request to a Servlet or script for the givenresourceandoptions.Returns theSlingHttpServletRequestrepresenting the input of the request.Returns theSlingHttpServletResponserepresenting the output of the request.Returns theSlingScriptbeing called to handle the request.<T> TgetService(Class<T> type) Lookup a single service.<T> T[]getServices(Class<T> serviceType, String filter) Lookup one or several services.voidSame asSlingScriptHelper.include(String,RequestDispatcherOptions), but using empty options.voidHelper method to include the result of processing the request for the givenpathandrequestDispatcherOptions.voidinclude(String path, RequestDispatcherOptions options) Helper method to include the result of processing the request for the givenpathandoptions.voidSame asSlingScriptHelper.include(Resource,RequestDispatcherOptions), but using empty options.voidHelper method to include the result of processing the request for the givenresourceandrequestDispatcherOptions.voidinclude(Resource resource, RequestDispatcherOptions options) Helper method to include the result of processing the request for the givenresourceandoptions.
-
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:SlingScriptHelperReturns theSlingScriptbeing called to handle the request.- Specified by:
getScriptin interfaceSlingScriptHelper- Returns:
- The script
- See Also:
-
getRequest
Description copied from interface:SlingScriptHelperReturns theSlingHttpServletRequestrepresenting the input of the request.- Specified by:
getRequestin interfaceSlingScriptHelper- Returns:
- The request
- See Also:
-
getResponse
Description copied from interface:SlingScriptHelperReturns theSlingHttpServletResponserepresenting the output of the request.- Specified by:
getResponsein interfaceSlingScriptHelper- Returns:
- The response
- See Also:
-
include
Description copied from interface:SlingScriptHelperSame asSlingScriptHelper.include(String,RequestDispatcherOptions), but using empty options.- Specified by:
includein interfaceSlingScriptHelper- Parameters:
path- The path to include- See Also:
-
include
Description copied from interface:SlingScriptHelperHelper method to include the result of processing the request for the givenpathandrequestDispatcherOptions. 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
RequestDispatcherOptionsobject by calling theRequestDispatcherOptions(String)constructor.- Specified by:
includein 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:SlingScriptHelperHelper method to include the result of processing the request for the givenpathandoptions. 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:
includein 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:SlingScriptHelperSame asSlingScriptHelper.forward(String,RequestDispatcherOptions), but using empty options.- Specified by:
forwardin interfaceSlingScriptHelper- Parameters:
path- The path to forward to- See Also:
-
forward
Description copied from interface:SlingScriptHelperHelper method to forward the request to a Servlet or script for the givenpathandrequestDispatcherOptions. 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
RequestDispatcherOptionsobject by calling theRequestDispatcherOptions(String)constructor.- Specified by:
forwardin 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:SlingScriptHelperHelper method to forward the request to a Servlet or script for the givenpathandoptions. 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:
forwardin 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:SlingScriptHelperDispose the helper. This method can be used to clean up the script helper after the script is run.- Specified by:
disposein interfaceSlingScriptHelper- See Also:
-
getService
Description copied from interface:SlingScriptHelperLookup 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:
getServicein interfaceSlingScriptHelper- Type Parameters:
T- The type (interface) of the service.- Parameters:
type- The type (interface) of the service.- Returns:
- The service instance, or
nullif 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:SlingScriptHelperLookup 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:
getServicesin 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 thefilterstring is not a valid OSGi service filter string.- See Also:
-
cleanup
public void cleanup()Clean up this instance. -
forward
Description copied from interface:SlingScriptHelperSame asSlingScriptHelper.forward(Resource,RequestDispatcherOptions), but using empty options.- Specified by:
forwardin interfaceSlingScriptHelper- Parameters:
resource- The resource to forward to.- See Also:
-
forward
Description copied from interface:SlingScriptHelperHelper method to forward the request to a Servlet or script for the givenresourceandrequestDispatcherOptions. 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
RequestDispatcherOptionsobject by calling theRequestDispatcherOptions(String)constructor.- Specified by:
forwardin interfaceSlingScriptHelper- Parameters:
resource- The resource to forward to.options- influence the rendering of the forwarded Resource- See Also:
-
forward
Description copied from interface:SlingScriptHelperHelper method to forward the request to a Servlet or script for the givenresourceandoptions. 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:
forwardin 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:SlingScriptHelperSame asSlingScriptHelper.include(Resource,RequestDispatcherOptions), but using empty options.- Specified by:
includein interfaceSlingScriptHelper- Parameters:
resource- The resource to include- See Also:
-
include
Description copied from interface:SlingScriptHelperHelper method to include the result of processing the request for the givenresourceandrequestDispatcherOptions. 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
RequestDispatcherOptionsobject by calling theRequestDispatcherOptions(String)constructor.- Specified by:
includein interfaceSlingScriptHelper- Parameters:
resource- The resource to include.options- influence the rendering of the included Resource- See Also:
-
include
Description copied from interface:SlingScriptHelperHelper method to include the result of processing the request for the givenresourceandoptions. 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:
includein interfaceSlingScriptHelper- Parameters:
resource- The resource to include.options- influence the rendering of the included Resource- See Also:
-