Interface SlingScriptHelper
-
- All Known Implementing Classes:
ScriptHelper
@ProviderType public interface SlingScriptHelper
TheSlingScriptHelper
interface defines the API of a helper class which is provided to the scripts called from sling through the global
variable.sling
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
dispose()
Deprecated.This method is deprecated since version 2.1 and will be removed.void
forward(@NotNull java.lang.String path)
Same asforward(String,RequestDispatcherOptions)
, but using empty options.void
forward(@NotNull java.lang.String path, java.lang.String requestDispatcherOptions)
Helper method to forward the request to a Servlet or script for the givenpath
andrequestDispatcherOptions
.void
forward(@NotNull java.lang.String path, RequestDispatcherOptions options)
Helper method to forward the request to a Servlet or script for the givenpath
andoptions
.void
forward(@NotNull Resource resource)
Same asforward(Resource,RequestDispatcherOptions)
, but using empty options.void
forward(@NotNull Resource resource, java.lang.String requestDispatcherOptions)
Helper method to forward the request to a Servlet or script for the givenresource
andrequestDispatcherOptions
.void
forward(@NotNull Resource resource, RequestDispatcherOptions options)
Helper method to forward the request to a Servlet or script for the givenresource
andoptions
.@NotNull SlingHttpServletRequest
getRequest()
Returns theSlingHttpServletRequest
representing the input of the request.@NotNull SlingHttpServletResponse
getResponse()
Returns theSlingHttpServletResponse
representing the output of the request.@NotNull SlingScript
getScript()
Returns theSlingScript
being called to handle the request.<ServiceType>
ServiceTypegetService(@NotNull java.lang.Class<ServiceType> serviceType)
Lookup a single service.<ServiceType>
@Nullable ServiceType[]getServices(@NotNull java.lang.Class<ServiceType> serviceType, java.lang.String filter)
Lookup one or several services.void
include(@NotNull java.lang.String path)
Same asinclude(String,RequestDispatcherOptions)
, but using empty options.void
include(@NotNull java.lang.String path, java.lang.String requestDispatcherOptions)
Helper method to include the result of processing the request for the givenpath
andrequestDispatcherOptions
.void
include(@NotNull java.lang.String path, RequestDispatcherOptions options)
Helper method to include the result of processing the request for the givenpath
andoptions
.void
include(@NotNull Resource resource)
Same asinclude(Resource,RequestDispatcherOptions)
, but using empty options.void
include(@NotNull Resource resource, java.lang.String requestDispatcherOptions)
Helper method to include the result of processing the request for the givenresource
andrequestDispatcherOptions
.void
include(@NotNull Resource resource, RequestDispatcherOptions options)
Helper method to include the result of processing the request for the givenresource
andoptions
.
-
-
-
Method Detail
-
getRequest
@NotNull @NotNull SlingHttpServletRequest getRequest()
Returns theSlingHttpServletRequest
representing the input of the request.- Returns:
- The request
-
getResponse
@NotNull @NotNull SlingHttpServletResponse getResponse()
Returns theSlingHttpServletResponse
representing the output of the request.- Returns:
- The response
-
getScript
@NotNull @NotNull SlingScript getScript()
Returns theSlingScript
being called to handle the request.- Returns:
- The script
-
include
void include(@NotNull @NotNull java.lang.String path)
Same asinclude(String,RequestDispatcherOptions)
, but using empty options.- Parameters:
path
- The path to include- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the include.SlingServletException
- Wrapping aServletException
thrown while handling the include.
-
include
void include(@NotNull @NotNull java.lang.String path, java.lang.String requestDispatcherOptions)
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.- Parameters:
path
- The path to the resource to include.requestDispatcherOptions
- influence the rendering of the included Resource- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the include.SlingServletException
- Wrapping aServletException
thrown while handling the include.- See Also:
RequestDispatcherOptions(String)
,include(String, RequestDispatcherOptions)
-
include
void include(@NotNull @NotNull java.lang.String path, RequestDispatcherOptions options)
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()); }
- Parameters:
path
- The path to the resource to include.options
- influence the rendering of the included Resource- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the include.SlingServletException
- Wrapping aServletException
thrown while handling the include.- See Also:
RequestDispatcherOptions
,include(String, String)
-
include
void include(@NotNull @NotNull Resource resource)
Same asinclude(Resource,RequestDispatcherOptions)
, but using empty options.- Parameters:
resource
- The resource to include- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the include.SlingServletException
- Wrapping aServletException
thrown while handling the include.
-
include
void include(@NotNull @NotNull Resource resource, java.lang.String requestDispatcherOptions)
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.- Parameters:
resource
- The resource to include.requestDispatcherOptions
- influence the rendering of the included Resource- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the include.SlingServletException
- Wrapping aServletException
thrown while handling the include.- See Also:
RequestDispatcherOptions(String)
,include(String, RequestDispatcherOptions)
-
include
void include(@NotNull @NotNull Resource resource, RequestDispatcherOptions options)
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()); }
- Parameters:
resource
- The resource to include.options
- influence the rendering of the included Resource- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the include.SlingServletException
- Wrapping aServletException
thrown while handling the include.- See Also:
RequestDispatcherOptions
,include(String, String)
-
forward
void forward(@NotNull @NotNull java.lang.String path)
Same asforward(String,RequestDispatcherOptions)
, but using empty options.- Parameters:
path
- The path to forward to- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the forward.SlingServletException
- Wrapping aServletException
thrown while handling the forward.
-
forward
void forward(@NotNull @NotNull java.lang.String path, java.lang.String requestDispatcherOptions)
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.- Parameters:
path
- The path to the resource to forward to.requestDispatcherOptions
- influence the rendering of the forwarded Resource- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the forward.SlingServletException
- Wrapping aServletException
thrown while handling the forward.- See Also:
RequestDispatcherOptions(String)
,forward(String, RequestDispatcherOptions)
-
forward
void forward(@NotNull @NotNull java.lang.String path, RequestDispatcherOptions options)
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()); }
- Parameters:
path
- The path to the resource to forward the request to.options
- influence the rendering of the forwarded Resource- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the forward.SlingServletException
- Wrapping aServletException
thrown while handling the forward.java.lang.IllegalStateException
- If the respoonse has already been committed- See Also:
RequestDispatcherOptions
-
forward
void forward(@NotNull @NotNull Resource resource)
Same asforward(Resource,RequestDispatcherOptions)
, but using empty options.- Parameters:
resource
- The resource to forward to.- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the forward.SlingServletException
- Wrapping aServletException
thrown while handling the forward.
-
forward
void forward(@NotNull @NotNull Resource resource, java.lang.String requestDispatcherOptions)
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.- Parameters:
resource
- The resource to forward to.requestDispatcherOptions
- influence the rendering of the forwarded Resource- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the forward.SlingServletException
- Wrapping aServletException
thrown while handling the forward.- See Also:
RequestDispatcherOptions(String)
,forward(String, RequestDispatcherOptions)
-
forward
void forward(@NotNull @NotNull Resource resource, RequestDispatcherOptions options)
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()); }
- Parameters:
resource
- The resource to forward the request to.options
- influence the rendering of the forwarded Resource- Throws:
SlingIOException
- Wrapping aIOException
thrown while handling the forward.SlingServletException
- Wrapping aServletException
thrown while handling the forward.java.lang.IllegalStateException
- If the respoonse has already been committed- See Also:
RequestDispatcherOptions
-
getService
@Nullable <ServiceType> ServiceType getService(@NotNull @NotNull java.lang.Class<ServiceType> serviceType)
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).
- Type Parameters:
ServiceType
- The type (interface) of the service.- Parameters:
serviceType
- The type (interface) of the service.- Returns:
- The service instance, or
null
if no services are registered which implement the specified class.
-
getServices
@Nullable <ServiceType> @Nullable ServiceType[] getServices(@NotNull @NotNull java.lang.Class<ServiceType> serviceType, java.lang.String filter)
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.
- Type Parameters:
ServiceType
- 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:
- Filter class in OSGi
-
dispose
@Deprecated void dispose()
Deprecated.This method is deprecated since version 2.1 and will be removed. It should never be called by clients.Dispose the helper. This method can be used to clean up the script helper after the script is run.
-
-