Class HttpServerUtil
java.lang.Object
org.eclipse.rdf4j.common.webapp.util.HttpServerUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic List
<HeaderElement> getHeaderElements
(javax.servlet.http.HttpServletRequest request, String headerName) Gets the elements of the request header with the specified name.static String
getMIMEType
(String contentType) Extracts the MIME type from the specified content type string.static String
getPostDataParameter
(Map<String, Object> formData, String name) Gets the trimmed value of a request parameter as a String.static boolean
static boolean
static boolean
static HeaderElement
matchAcceptHeader
(String mimeTypeSpec, List<HeaderElement> acceptElements) Tries to match the specified MIME type spec against the list of Accept header elements, returning the applicable header element if available.static String
selectPreferredMIMEType
(Iterator<String> mimeTypes, javax.servlet.http.HttpServletRequest request) Selects from a set of MIME types, the MIME type that has the highest quality score when matched with the Accept headers in the supplied request.splitHeaderString
(String s, char splitChar) Splits the supplied string into sub parts using the specified splitChar as a separator, ignoring occurrences of this character inside quoted strings.
-
Constructor Details
-
HttpServerUtil
public HttpServerUtil()
-
-
Method Details
-
getMIMEType
Extracts the MIME type from the specified content type string. This method parses the content type string and returns just the MIME type, ignoring any parameters that are included.- Parameters:
contentType
- A content type string, e.g. application/xml; charset=utf-8 .- Returns:
- The MIME type part of the specified content type string, or null if the specified content type string was null.
-
selectPreferredMIMEType
public static String selectPreferredMIMEType(Iterator<String> mimeTypes, javax.servlet.http.HttpServletRequest request) Selects from a set of MIME types, the MIME type that has the highest quality score when matched with the Accept headers in the supplied request.- Parameters:
mimeTypes
- The set of available MIME types.request
- The request to match the MIME types against.- Returns:
- The MIME type that best matches the types that the client finds acceptable, or null in case no acceptable MIME type could be found.
-
getHeaderElements
public static List<HeaderElement> getHeaderElements(javax.servlet.http.HttpServletRequest request, String headerName) Gets the elements of the request header with the specified name.- Parameters:
request
- The request to get the header from.headerName
- The name of the header to get the elements of.- Returns:
- A List of
HeaderElement
objects.
-
splitHeaderString
Splits the supplied string into sub parts using the specified splitChar as a separator, ignoring occurrences of this character inside quoted strings.- Parameters:
s
- The header string to split into sub parts.splitChar
- The character to use as separator.- Returns:
- A List of Strings.
-
matchAcceptHeader
public static HeaderElement matchAcceptHeader(String mimeTypeSpec, List<HeaderElement> acceptElements) Tries to match the specified MIME type spec against the list of Accept header elements, returning the applicable header element if available.- Parameters:
mimeTypeSpec
- The MIME type to determine the quality for, e.g. "text/plain" or "application/xml; charset=utf-8".acceptElements
- A List ofHeaderElement
objects.- Returns:
- The Accept header element that matches the MIME type spec most closely, or null if no such header element could be found.
-
getPostDataParameter
Gets the trimmed value of a request parameter as a String.- Returns:
- The trimmed value, or null if the parameter does not exist.
-
isEmpty
- Returns:
- true if the string is either null or equal to ""
-
isTrue
- Returns:
- true if the string is !isEmpty and equal to "true"
-
isFalse
- Returns:
- true if the string is !isEmpty and equal to "false"
-