2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mielecloud.internal.config.servlet;
15 import javax.servlet.http.HttpServletRequest;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * Utility class for common servlet tasks.
22 * @author Björn Lange - Initial Contribution
25 public final class ServletUtil {
26 private ServletUtil() {
27 throw new UnsupportedOperationException();
31 * Gets the value of a request parameter or returns a default if the parameter is not present.
33 public static String getParameterValueOrDefault(HttpServletRequest request, String parameterName,
34 String defaultValue) {
35 String parameterValue = request.getParameter(parameterName);
36 if (parameterValue == null) {
39 return parameterValue;
44 * Checks whether a request parameter is enabled.
46 public static boolean isParameterEnabled(HttpServletRequest request, String parameterName) {
47 return "true".equalsIgnoreCase(getParameterValueOrDefault(request, parameterName, "false"));
51 * Checks whether a parameter is present in a request.
53 public static boolean isParameterPresent(HttpServletRequest request, String parameterName) {
54 String parameterValue = request.getParameter(parameterName);
55 return parameterValue != null && !parameterValue.trim().isEmpty();