Class RequestDispatcherOptions

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,String>
org.apache.sling.api.request.RequestDispatcherOptions
All Implemented Interfaces:
Serializable, Cloneable, Map<String,String>

public class RequestDispatcherOptions extends HashMap<String,String>
RequestDispatcherOptions are used in the SlingHttpServletRequest.getRequestDispatcher(org.apache.sling.api.resource.Resource, RequestDispatcherOptions) method, to give more control on some aspects of the include/forward mechanism. Typical use cases include:
  • Forcing a resource type, to render a Resource in a specific way, like for example render myself in a suitable way for a navigation box.
  • Adding selectors when including a Resource, like for example add a "teaser" selector to the request that I'm including here.
See Also:
  • Field Details

    • OPT_FORCE_RESOURCE_TYPE

      public static final String OPT_FORCE_RESOURCE_TYPE
      When dispatching, use the value provided by this option as the resource type, instead of the one defined by the Resource.
      See Also:
    • OPT_REPLACE_SELECTORS

      public static final String OPT_REPLACE_SELECTORS
      When dispatching, replace RequestPathInfo selectors by the value provided by this option. If this value contains an empty string, all original selectors are removed.
      See Also:
    • OPT_ADD_SELECTORS

      public static final String OPT_ADD_SELECTORS
      When dispatching, add the value provided by this option to the RequestPathInfo selectors.
      See Also:
    • OPT_REPLACE_SUFFIX

      public static final String OPT_REPLACE_SUFFIX
      When dispatching, replace the RequestPathInfo suffix by the value provided by this option
      See Also:
    • OPT_REPLACE_EXTENSION

      public static final String OPT_REPLACE_EXTENSION
      When dispatching, replace the RequestPathInfo extension by the value provided by this option
      Since:
      2.5.0
      See Also:
    • OPT_PROTECT_HEADERS_ON_INCLUDE

      public static final String OPT_PROTECT_HEADERS_ON_INCLUDE
      When dispatching with the include method, any headers set by the included resource are ignored. This defaults to "false".
      Since:
      2.7.0
      See Also:
  • Constructor Details

    • RequestDispatcherOptions

      public RequestDispatcherOptions()
      Creates an instance with no options set.
    • RequestDispatcherOptions

      public RequestDispatcherOptions(String options)
      Creates a new instances setting options by parsing the given options string as follows:
      • If the string is empty or null no options are set.
      • If the string neither contains a comma nor an equals sign, the string is assumed to be a resource type. Hence a RequestDispatcherOptions object is created with the OPT_FORCE_RESOURCE_TYPE field set to the string.
      • Otherwise the string is assumed to be a comma separated list of name value pairs where the equals sign is used to separate the name from its value. Hence a RequestDispatcherOptions object is created from the name value pair list.
      Parameters:
      options - The options to set.
  • Method Details

    • setForceResourceType

      public void setForceResourceType(String resourceType)
      Sets the OPT_FORCE_RESOURCE_TYPE option to the given resourceType if not null.
      Parameters:
      resourceType - the resource type
    • getForceResourceType

      public String getForceResourceType()
      Returns the OPT_FORCE_RESOURCE_TYPE option or null if not set.
      Returns:
      The resource type.
    • setAddSelectors

      public void setAddSelectors(String additionalSelectors)
      Sets the OPT_ADD_SELECTORS option to the given additionalSelectors if not null.
      Parameters:
      additionalSelectors - The add selectors
    • getAddSelectors

      public String getAddSelectors()
      Returns the OPT_ADD_SELECTORS option or null if not set.
      Returns:
      The add selectors.
    • setReplaceSelectors

      public void setReplaceSelectors(String replaceSelectors)
      Sets the OPT_REPLACE_SELECTORS option to the given replaceSelectors if not null. If this value contains an empty string, all original selectors are removed.
      Parameters:
      replaceSelectors - The replace selectors.
    • getReplaceSelectors

      public String getReplaceSelectors()
      Returns the OPT_REPLACE_SELECTORS option or null if not set.
      Returns:
      The replace selectors.
    • setReplaceSuffix

      public void setReplaceSuffix(String replaceSuffix)
      Sets the OPT_REPLACE_SUFFIX option to the given replaceSuffix if not null.
      Parameters:
      replaceSuffix - The replace suffix
    • getReplaceSuffix

      public String getReplaceSuffix()
      Returns the OPT_REPLACE_SUFFIX option or null if not set.
      Returns:
      The replace suffix
    • setReplaceExtension

      public void setReplaceExtension(String replaceExtension)
      Sets the OPT_REPLACE_EXTENSION option to the given replaceExtension if not null. If this value contains an empty string, the original extension will be removed.
      Parameters:
      replaceExtension - The replace extension
      Since:
      2.5.0
    • getReplaceExtension

      public String getReplaceExtension()
      Returns the OPT_REPLACE_EXTENSION option or null if not set.
      Returns:
      The replace extension
      Since:
      2.5.0
    • setProtectHeadersOnInclude

      public void setProtectHeadersOnInclude(boolean flag)
      Sets the OPT_PROTECT_HEADERS_ON_INCLUDE option to the given value.
      Parameters:
      flag - The value to set
      Since:
      2.7.0
    • isProtectHeadersOnInclude

      public boolean isProtectHeadersOnInclude()
      Returns the OPT_PROTECT_HEADERS_ON_INCLUDE option or false if not set.
      Returns:
      Are headers protected on include?
      Since:
      2.7.0