org.swisspush.reststorage.util.HttpRequestParam Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-storage Show documentation
Show all versions of rest-storage Show documentation
Persistence for REST resources in the filesystem or a redis database
package org.swisspush.reststorage.util;
import io.vertx.core.MultiMap;
/**
* Enum for HTTP request params used in vertx-rest-storage
*
* @author https://github.com/mcweba [Marc-Andre Weber]
*/
public enum HttpRequestParam {
RECURSIVE_PARAMETER("recursive"),
STORAGE_EXPAND_PARAMETER("storageExpand"),
LIMIT_PARAMETER("limit"),
OFFSET_PARAMETER("offset");
private final String name;
HttpRequestParam(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static boolean containsParam(MultiMap params, HttpRequestParam httpRequestParam){
if(params == null){
return false;
}
return params.contains(httpRequestParam.getName());
}
/**
* Get the value of the provided {@link HttpRequestParam} as String.
* Returns null
in the following cases:
*
*
* - params are
null
* - params does not contain httpRequestParam
*
*
* @param params the http request params
* @param httpRequestParam the http request param to get the value from
* @return a String representing the value of the httpRequestParam or null
*/
public static String getString(MultiMap params, HttpRequestParam httpRequestParam) {
if(params == null) {
return null;
}
return params.get(httpRequestParam.getName());
}
/**
* Get the value of the provided {@link HttpRequestParam} as boolean.
* Returns false
in the following cases:
*
*
* - params are
null
* - params does not contain httpRequestParam
* - value of httpRequestParam does not equal "true" ignoring the case
*
*
* @param params the http request params
* @param httpRequestParam the http request param to get the value from
* @return a boolean representing the value of the httpRequestParam
*/
public static boolean getBoolean(MultiMap params, HttpRequestParam httpRequestParam) {
if(params == null) {
return false;
}
String paramValue = params.get(httpRequestParam.getName());
return "true".equalsIgnoreCase(paramValue);
}
}