List of usage examples for org.apache.commons.lang3 StringUtils trimToEmpty
public static String trimToEmpty(final String str)
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
private StatusLine executeRemoteRequest(HttpRequestBase request, HttpServletRequest req, HttpServletResponse rsp) throws IOException { copyRequestHeadersValues(req, request); final CloseableHttpResponse response; if (HttpPost.METHOD_NAME.equalsIgnoreCase(request.getMethod())) { response = transferPostedData((HttpEntityEnclosingRequestBase) request, req); } else {/* w ww . jav a2 s . c om*/ response = client.execute(request); } try { HttpEntity rspEntity = response.getEntity(); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if ((statusCode < HttpServletResponse.SC_OK) || (statusCode >= 300)) { String reason = StringUtils.trimToEmpty(statusLine.getReasonPhrase()); logger.warn("executeRemoteRequest(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " bad response (" + statusCode + ") from remote end: " + reason); EntityUtils.consume(rspEntity); rsp.sendError(statusCode, reason); } else { rsp.setStatus(statusCode); copyResponseHeadersValues(req, response, rsp); transferBackendResponse(req, rspEntity, rsp); } return statusLine; } finally { response.close(); } }
From source file:gov.ca.cwds.data.persistence.cms.BaseClient.java
/** * @return the emailAddress */ public String getEmailAddress() { return StringUtils.trimToEmpty(emailAddress); }
From source file:gov.ca.cwds.data.persistence.cms.BaseClient.java
/** * @return the estimatedDobCode */ public String getEstimatedDobCode() { return StringUtils.trimToEmpty(estimatedDobCode); }
From source file:com.intuit.karate.Script.java
public static void evalXmlEmbeddedExpressions(Node node, ScriptContext context) { if (node.getNodeType() == Node.DOCUMENT_NODE) { node = node.getFirstChild();//from www . ja v a 2s .co m } NamedNodeMap attribs = node.getAttributes(); int attribCount = attribs.getLength(); for (int i = 0; i < attribCount; i++) { Attr attrib = (Attr) attribs.item(i); String value = attrib.getValue(); value = StringUtils.trimToEmpty(value); if (isEmbeddedExpression(value)) { try { ScriptValue sv = evalInNashorn(value.substring(1), context); attrib.setValue(sv.getAsString()); } catch (Exception e) { logger.warn("embedded xml-attribute script eval failed: {}", e.getMessage()); } } } NodeList nodes = node.getChildNodes(); int childCount = nodes.getLength(); for (int i = 0; i < childCount; i++) { Node child = nodes.item(i); String value = child.getNodeValue(); if (value != null) { value = StringUtils.trimToEmpty(value); if (isEmbeddedExpression(value)) { try { ScriptValue sv = evalInNashorn(value.substring(1), context); child.setNodeValue(sv.getAsString()); } catch (Exception e) { logger.warn("embedded xml-text script eval failed: {}", e.getMessage()); } } } else if (child.hasChildNodes()) { evalXmlEmbeddedExpressions(child, context); } } }
From source file:gov.ca.cwds.data.persistence.cms.BaseClient.java
/** * @return the ethUnableToDetReasonCode */ public String getEthUnableToDetReasonCode() { return StringUtils.trimToEmpty(ethUnableToDetReasonCode); }
From source file:com.omertron.slackbot.listeners.GoogleSheetsListener.java
/** * Attempt to find the player in the list of names from the sheet. * * @param search Name to search for//w w w . j ava 2s . c o m * @return The closest match for the search name */ private static PlayerInfo findPlayer(final String player) { String search = StringUtils.trimToEmpty(player).toUpperCase(); LOG.info("Searching for player '{}'", search); if (PLAYERS.containsKey(search)) { LOG.info("Found direct inital match: {}", PLAYERS.get(search).toString()); return PLAYERS.get(search); } PlayerInfo matchedPlayer = null; int bestMatch = 0; LOG.info("Searching player list for match to '{}'", search); for (PlayerInfo pi : PLAYERS.values()) { if (search.equalsIgnoreCase(pi.getInitial())) { LOG.info("Found direct inital match: {}", pi.toString()); return pi; } int newScore = SCORE.fuzzyScore(search, pi.getName()); if (newScore > bestMatch) { LOG.info("\tBetter match found for '{}' with '{}', new score={}", search, pi.getName(), newScore); bestMatch = newScore; matchedPlayer = pi; } } if (bestMatch < 5) { LOG.info("No definitive match found for '{}' (best score was {}), using 'Other'", search, bestMatch); return PLAYERS.get("O"); } else if (matchedPlayer == null) { LOG.info("No match found for '{}', using 'Other'", search); return PLAYERS.get("O"); } else { LOG.info("Matched '{}' to '{}' with score of {}", matchedPlayer.getName(), search, bestMatch); return matchedPlayer; } }
From source file:gov.ca.cwds.data.persistence.cms.BaseClient.java
/** * @return the genderCode */ public String getGenderCode() { return StringUtils.trimToEmpty(genderCode); }
From source file:gov.nih.nci.caintegrator.application.study.StudyManagementServiceTest.java
@Test public void testCopyStudy() throws ValidationException, IOException, ConnectionException { StudyConfiguration copyTo = new StudyConfiguration(); copyTo.setId(1L);/*from w w w. j av a 2s .c o m*/ Study study = studyHelper.populateAndRetrieveStudyWithSourceConfigurations(); String name = "Copy of ".concat(StringUtils.trimToEmpty(study.getShortTitleText())); copyTo.getStudy().setShortTitleText(name); StudyConfiguration configTest = study.getStudyConfiguration(); configTest.setStudy(study); configTest.setUserWorkspace(new UserWorkspace()); configTest.getUserWorkspace().setUsername("user"); copyTo = studyManagementService.copy(configTest, copyTo); assertEquals("Copy of Test Study", copyTo.getStudy().getShortTitleText()); }
From source file:com.esri.geoportal.commons.agp.client.AgpClient.java
/** * Generates token.//w w w. j ava2s .com * * @param minutes expiration in minutes. * @return token response * @throws URISyntaxException if invalid URL * @throws IOException if accessing token fails */ public TokenResponse generateToken(int minutes) throws URISyntaxException, IOException { HttpPost req = new HttpPost(generateTokenUri()); HashMap<String, String> params = new HashMap<>(); params.put("f", "json"); if (credentials != null) { params.put("username", StringUtils.trimToEmpty(credentials.getUserName())); params.put("password", StringUtils.trimToEmpty(credentials.getPassword())); } params.put("client", "referer"); params.put("referer", InetAddress.getLocalHost().getHostAddress()); params.put("expiration", Integer.toString(minutes)); req.setEntity(createEntity(params)); return execute(req, TokenResponse.class); }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static String resolveStyleName(String extension) { String name;/*from www .j ava 2s . co m*/ switch (StringUtils.trimToEmpty(extension).toLowerCase()) { case "pdf": name = "attDocPDF"; break; case "xls": case "xlsx": name = "attDocSheet"; break; case "doc": case "docx": case "odt": name = "attDocWRD"; break; case "jpg": case "jpeg": case "gif": case "png": name = "attDocIMG"; break; default: name = "attDocDEF"; } return name; }