Package org.apache.sling.api.request
Class RequestUtil
- java.lang.Object
-
- org.apache.sling.api.request.RequestUtil
-
public class RequestUtil extends java.lang.ObjectRequest related utility methods.This class is not intended to be extended or instantiated because it just provides static utility methods not intended to be overwritten.
- Since:
- 2.1 (Sling API Bundle 2.1.0)
-
-
Constructor Summary
Constructors Constructor Description RequestUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull java.lang.StringgetServletName(@NotNull Servlet servlet)Utility method to return a name for the given servlet.static booleanhandleIfModifiedSince(@NotNull SlingHttpServletRequest req, @NotNull HttpServletResponse resp)Checks if the request contains a if-last-modified-since header and if the the request's underlying resource has a jcr:lastModified property.static @NotNull java.util.Map<java.lang.String,java.lang.Double>parserAcceptHeader(@NotNull java.lang.String value)Parses anAccept-*header of the form:static @NotNull java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>parserHeader(@NotNull java.lang.String value)Parses a header of the form:static @Nullable java.lang.ObjectsetRequestAttribute(@NotNull HttpServletRequest request, @NotNull java.lang.String name, java.lang.Object value)Sets the named request attribute to the new value and returns the previous value.
-
-
-
Method Detail
-
parserHeader
@NotNull public static @NotNull java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parserHeader(@NotNull @NotNull java.lang.String value)Parses a header of the form:Header = Token { "," Token } . Token = name { ";" Parameter } . Parameter = name [ "=" value ] ."," and ";" are not allowed within name and value- Parameters:
value- The header value- Returns:
- A Map indexed by the Token names where the values are Map instances indexed by parameter name
-
parserAcceptHeader
@NotNull public static @NotNull java.util.Map<java.lang.String,java.lang.Double> parserAcceptHeader(@NotNull @NotNull java.lang.String value)Parses anAccept-*header of the form:Header = Token { "," Token } . Token = name { ";" "q" [ "=" value ] } . Parameter = ."," and ";" are not allowed within name and value- Parameters:
value- The header value- Returns:
- A Map indexed by the Token names where the values are
Doubleinstances providing the value of theqparameter.
-
getServletName
@NotNull public static @NotNull java.lang.String getServletName(@NotNull @NotNull Servlet servlet)Utility method to return a name for the given servlet. This method applies the following algorithm to find a non-null, non-empty name:- If the servlet has a servlet config, the servlet name from the servlet config is taken.
- Otherwise check the servlet info
- Otherwise use the fully qualified name of the servlet class
- Parameters:
servlet- The servlet- Returns:
- The name of the servlet.
-
setRequestAttribute
@Nullable public static @Nullable java.lang.Object setRequestAttribute(@NotNull @NotNull HttpServletRequest request, @NotNull @NotNull java.lang.String name, java.lang.Object value)Sets the named request attribute to the new value and returns the previous value.- Parameters:
request- The request object whose attribute is to be set.name- The name of the attribute to be set.value- The new value of the attribute. If this isnullthe attribte is actually removed from the request.- Returns:
- The previous value of the named request attribute or
nullif it was not set.
-
handleIfModifiedSince
public static boolean handleIfModifiedSince(@NotNull @NotNull SlingHttpServletRequest req, @NotNull @NotNull HttpServletResponse resp)Checks if the request contains a if-last-modified-since header and if the the request's underlying resource has a jcr:lastModified property. if the properties were modified before the header a 304 is sent otherwise the response last modified header is set.- Parameters:
req- the requestresp- the response- Returns:
trueif the response was set
-
-