Package com.composum.sling.core.util
Class RequestUtil
- java.lang.Object
-
- org.apache.sling.api.request.RequestUtil
-
- com.composum.sling.core.util.RequestUtil
-
public class RequestUtil extends org.apache.sling.api.request.RequestUtil
A basic class for all '/bin/{service}/path/to/resource' servlets.
-
-
Constructor Summary
Constructors Constructor Description RequestUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkSelector(org.apache.sling.api.SlingHttpServletRequest request, String key)
Retrieves a key in the selectors and returns 'true' is the key is present.static <T extends Enum>
TgetExtension(org.apache.sling.api.SlingHttpServletRequest request, T defaultValue)
Returns the enum value of the requests extension if appropriate otherwise the default value.static int
getIntSelector(org.apache.sling.api.SlingHttpServletRequest request, int defaultValue)
Retrieves a number in the selectors and returns it if present otherwise the default value.static int
getIntSelector(org.apache.sling.api.SlingHttpServletRequest request, Pattern groupPattern, int defaultValue)
Retrieves a number in the selectors and returns it if present otherwise the default value.static Integer
getParameter(org.apache.sling.api.request.RequestParameterMap parameters, String name, Integer defaultValue)
static String
getParameter(org.apache.sling.api.request.RequestParameterMap parameters, String name, String defaultValue)
static <T extends Enum>
TgetParameter(org.apache.sling.api.request.RequestParameterMap parameters, String name, T defaultValue)
static Boolean
getParameter(org.apache.sling.api.SlingHttpServletRequest request, String name, Boolean defaultValue)
static Integer
getParameter(org.apache.sling.api.SlingHttpServletRequest request, String name, Integer defaultValue)
static String
getParameter(org.apache.sling.api.SlingHttpServletRequest request, String name, String defaultValue)
static <T extends Enum>
TgetParameter(org.apache.sling.api.SlingHttpServletRequest request, String name, T defaultValue)
static <T extends Enum>
TgetSelector(org.apache.sling.api.SlingHttpServletRequest request, T defaultValue)
Returns an enum value from selectors if an appropriate selector can be found otherwise the default value given.static javax.jcr.Session
getSession(org.apache.sling.api.SlingHttpServletRequest request)
-
-
-
Method Detail
-
getSession
public static javax.jcr.Session getSession(org.apache.sling.api.SlingHttpServletRequest request)
-
getExtension
public static <T extends Enum> T getExtension(org.apache.sling.api.SlingHttpServletRequest request, T defaultValue)
Returns the enum value of the requests extension if appropriate otherwise the default value.- Type Parameters:
T
- the enum type derived from the default value- Parameters:
request
- the request object with the extension infodefaultValue
- the default enum value
-
getSelector
public static <T extends Enum> T getSelector(org.apache.sling.api.SlingHttpServletRequest request, T defaultValue)
Returns an enum value from selectors if an appropriate selector can be found otherwise the default value given.- Type Parameters:
T
- the enum type derived from the default value- Parameters:
request
- the request object with the selector infodefaultValue
- the default enum value
-
checkSelector
public static boolean checkSelector(org.apache.sling.api.SlingHttpServletRequest request, String key)
Retrieves a key in the selectors and returns 'true' is the key is present.- Parameters:
request
- the request object with the selector infokey
- the selector key which is checked
-
getIntSelector
public static int getIntSelector(org.apache.sling.api.SlingHttpServletRequest request, int defaultValue)
Retrieves a number in the selectors and returns it if present otherwise the default value.- Parameters:
request
- the request object with the selector infodefaultValue
- the default number value
-
getIntSelector
public static int getIntSelector(org.apache.sling.api.SlingHttpServletRequest request, Pattern groupPattern, int defaultValue)
Retrieves a number in the selectors and returns it if present otherwise the default value.- Parameters:
request
- the request object with the selector infogroupPattern
- the regex to extract the value - as group '1'; e.g. 'key([\d]+)'defaultValue
- the default number value
-
getParameter
public static String getParameter(org.apache.sling.api.request.RequestParameterMap parameters, String name, String defaultValue)
-
getParameter
public static String getParameter(org.apache.sling.api.SlingHttpServletRequest request, String name, String defaultValue)
-
getParameter
public static Integer getParameter(org.apache.sling.api.request.RequestParameterMap parameters, String name, Integer defaultValue)
-
getParameter
public static Integer getParameter(org.apache.sling.api.SlingHttpServletRequest request, String name, Integer defaultValue)
-
getParameter
public static Boolean getParameter(org.apache.sling.api.SlingHttpServletRequest request, String name, Boolean defaultValue)
-
getParameter
public static <T extends Enum> T getParameter(org.apache.sling.api.request.RequestParameterMap parameters, String name, T defaultValue)
-
-