List of usage examples for org.apache.commons.lang3 StringUtils isBlank
public static boolean isBlank(final CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false
From source file:controllers.api.v1.Flow.java
public static Result getPagedRootProjects() { ObjectNode result = Json.newObject(); int page = 1; String pageStr = request().getQueryString("page"); if (StringUtils.isBlank(pageStr)) { page = 1;//from w ww. ja va2 s . co m } else { try { page = Integer.parseInt(pageStr); } catch (NumberFormatException e) { Logger.error("Flow Controller getPagedRootProjects wrong page parameter. Error message: " + e.getMessage()); page = 1; } } int size = 10; String sizeStr = request().getQueryString("size"); if (StringUtils.isBlank(sizeStr)) { size = 10; } else { try { size = Integer.parseInt(sizeStr); } catch (NumberFormatException e) { Logger.error("Flow Controller getPagedRootProjects wrong size parameter. Error message: " + e.getMessage()); size = 10; } } result.put("status", "ok"); result.set("data", FlowsDAO.getPagedProjects(page, size)); return ok(result); }
From source file:io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.java
public static String literalText(MarkupDocBuilder markupDocBuilder, String text) { if (StringUtils.isBlank(text)) { return StringUtils.EMPTY; }/*w w w. j a v a 2 s. c o m*/ return copyMarkupDocBuilder(markupDocBuilder).literalText(text).toString(); }
From source file:com.mirth.connect.server.util.ConnectorUtil.java
public static ConnectionTestResponse testConnection(String host, int port, int timeout, String localAddr, int localPort) throws Exception { Socket socket = null;/* w ww. ja v a2 s. co m*/ InetSocketAddress address = null; InetSocketAddress localAddress = null; try { address = new InetSocketAddress(host, port); if (StringUtils.isBlank(address.getAddress().getHostAddress()) || (address.getPort() < 0) || (address.getPort() > 65534)) { throw new Exception(); } } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Invalid host or port."); } if (localAddr != null) { try { localAddress = new InetSocketAddress(localAddr, localPort); if (StringUtils.isBlank(localAddress.getAddress().getHostAddress()) || (localAddress.getPort() < 0) || (localAddress.getPort() > 65534)) { throw new Exception(); } } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Invalid local host or port."); } } try { socket = new Socket(); if (localAddress != null) { try { socket.bind(localAddress); } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Could not bind to local address: " + localAddress.getAddress().getHostAddress() + ":" + localAddress.getPort()); } } socket.connect(address, timeout); String connectionInfo = socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + " -> " + address.getAddress().getHostAddress() + ":" + address.getPort(); return new ConnectionTestResponse(ConnectionTestResponse.Type.SUCCESS, "Successfully connected to host: " + connectionInfo, connectionInfo); } catch (SocketTimeoutException ste) { return new ConnectionTestResponse(ConnectionTestResponse.Type.TIME_OUT, "Timed out connecting to host: " + address.getAddress().getHostAddress() + ":" + address.getPort()); } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Could not connect to host: " + address.getAddress().getHostAddress() + ":" + address.getPort()); } finally { if (socket != null) { socket.close(); } } }
From source file:com.mycompany.listBoxer.dto.RangeType.java
public static RangeType fromKey(String rangeTypeKey) { RangeType[] enums = RangeType.values(); for (RangeType item : enums) { if (StringUtils.isBlank(rangeTypeKey) && item.getKey().equals(rangeTypeKey)) { return item; }/* w w w . j a va 2 s . c om*/ } throw new IllegalArgumentException(String.format("Unknown cssClassName %s", RangeType.class)); }
From source file:aiai.ai.utils.EnvProperty.java
public static int minMax(String prop, int min, int max, Integer defForBlank) { if (StringUtils.isBlank(prop)) { if (defForBlank == null) { throw new IllegalStateException("prop and defForBlank both are null"); }/*from w ww . java 2 s.c o m*/ if (defForBlank > max || defForBlank < min) { throw new IllegalStateException( "misconfiguration: min: " + min + ", max: " + max + ", def: " + defForBlank); } return defForBlank; } int i = Integer.parseInt(prop); if (i >= min && i <= max) { return i; } else if (i < min) { return min; } return max; }
From source file:ch.citux.td.util.Log.java
public static void d(Object caller, String message) { String tag = caller.getClass().getSimpleName(); if (!StringUtils.isBlank(message)) { android.util.Log.d(tag, message); }/*from w w w . ja va 2s .c om*/ }
From source file:com.netflix.imfutility.itunes.locale.LocaleValidator.java
public static void validateLocale(String str) throws LocaleValidationException { if (StringUtils.isBlank(str)) { throw new LocaleValidationException("Locale must be set."); }/* w w w.jav a 2s . c o m*/ try { Locale locale = LocaleHelper.fromITunesLocale(str); if (!LocaleUtils.availableLocaleList().contains(locale)) { throw new LocaleValidationException(String.format("Locale %s is unavailable.", str)); } } catch (IllegalArgumentException e) { throw new LocaleValidationException("Locale validation failed.", e); } }
From source file:com.dtstack.jlogstash.utils.Package.java
public static String getRealClassName(String name, String key) { if (StringUtils.isBlank(name)) return null; if (name.indexOf(point) >= 0) return name; return SystemProperty.getSystemProperty(key) + point + name; }
From source file:de.micromata.genome.gwiki.utils.ScriptUtils.java
public static Object executeScriptCode(String code, Map<String, Object> vars) { if (StringUtils.isBlank(code) == true) { return null; }/*from w ww .j a va 2 s. c o m*/ GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader()); Binding binding = new Binding(vars); GroovyShell shell = new GroovyShell(loader, binding); return shell.evaluate(code); }
From source file:controllers.api.v1.Metric.java
public static Result getPagedMetrics() { ObjectNode result = Json.newObject(); String username = session("user"); int page = 1; String pageStr = request().getQueryString("page"); if (StringUtils.isBlank(pageStr)) { page = 1;/*from w w w . ja va 2 s .c o m*/ } else { try { page = Integer.parseInt(pageStr); } catch (NumberFormatException e) { Logger.warn( "Metric Controller getPagedMetrics wrong page parameter. Error message: " + e.getMessage()); page = 1; } } int size = 10; String sizeStr = request().getQueryString("size"); if (StringUtils.isBlank(sizeStr)) { size = 10; } else { try { size = Integer.parseInt(sizeStr); } catch (NumberFormatException e) { Logger.warn( "Metric Controller getPagedMetrics wrong size parameter. Error message: " + e.getMessage()); size = 10; } } result.put("status", "ok"); result.set("data", MetricsDAO.getPagedMetrics("", "", page, size, username)); return ok(result); }