List of usage examples for org.apache.commons.lang StringUtils trim
public static String trim(String str)
Removes control characters (char <= 32) from both ends of this String, handling null
by returning null
.
From source file:com.fengduo.bee.commons.util.ObjectUtils.java
/** * string?trim?//from ww w. j a va2 s . com * * @param object * @throws Exception */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static void trimStringField(Object object, Class<?> clazz) throws Exception { if (object instanceof Map<?, ?>) { Map<Object, Object> target = new HashMap<Object, Object>(); for (Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (key instanceof String) { key = StringUtils.trim((String) key); } else { trim(key); } if (value instanceof String) { value = StringUtils.trim((String) value); value = StringUtils.replace((String) value, "\"", StringUtils.EMPTY); } else { trim(value); } target.put(key, value); } ((Map<?, ?>) object).clear(); ((Map) object).putAll((Map) target); return; } Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (field.getType() == String.class) { boolean isFoolback = false; if (field.isAccessible() == false) { isFoolback = true; field.setAccessible(true); } String value = (String) field.get(object); if (StringUtils.isNotEmpty(value)) { value = value.trim(); field.set(object, value); } if (isFoolback) { field.setAccessible(false); } } } }
From source file:com.taobao.tdhs.jdbc.util.StringUtil.java
public static String escapeValue(String value) { value = StringUtils.trim(value); if (StringUtils.startsWith(value, FIELD_ESCAPE_QUOTATION) || StringUtils.endsWith(value, FIELD_ESCAPE_QUOTATION)) { return null; }/* w ww .j a va 2 s . com*/ if (StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_1) && !StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_1)) { return null; } if (!StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_1) && StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_1)) { return null; } if (StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_2) && !StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_2)) { return null; } if (!StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_2) && StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_2)) { return null; } if (StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_1) && StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_1)) { if (value.length() > 1) return value.substring(1, value.length() - 1); else return null; } if (StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_2) && StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_2)) { if (value.length() > 1) return value.substring(1, value.length() - 1); else return null; } return value; }
From source file:com.mks.zookeeper.addrs.url.UrlAddressReader.java
private String read(String url) { try {/* w w w. ja v a 2 s . c o m*/ HttpResponse resp = HttpUtils.get(new HttpRequest(url)); String addrs = resp.getEntityString(); return StringUtils.isBlank(addrs) ? null : StringUtils.trim(addrs); } catch (HttpException e) { LOGGER.error("read:", e); return null; } }
From source file:easycare.cuke.pageObjects.patient.PatientPhysicianSearchResultPage.java
public void selectPhysicianToAdd(String physicianName) { List<WebElement> physicianOrgDataTableList = findElementsByCssSelector("table.physicianOrg"); for (WebElement physicianOrgDataTable : physicianOrgDataTableList) { WebElement orgNameInList = physicianOrgDataTable.findElement(By.cssSelector("th.orgName a")); String organisation = StringUtils.trim(orgNameInList.getText()); if (organisation.equalsIgnoreCase(physicianName)) { orgNameInList.click();//from w w w.ja va2 s. c o m return; } List<WebElement> physicianRowList = physicianOrgDataTable.findElements(By.cssSelector("tbody > tr")); for (WebElement physicianRow : physicianRowList) { WebElement physicianNameAsElement = physicianRow.findElement(By.cssSelector("td.physicianName a")); String physicianNameAsString = physicianNameAsElement.getText(); if (physicianNameAsString.toUpperCase().contains(physicianName.toUpperCase())) { physicianNameAsElement.click(); return; } } } throw new IllegalStateException("No physician on page matching " + physicianName); }
From source file:com.hpe.application.automation.tools.model.SvExportModel.java
@DataBoundConstructor public SvExportModel(String serverName, boolean force, String targetDirectory, boolean cleanTargetDirectory, SvServiceSelectionModel serviceSelection, boolean switchToStandByFirst, boolean archive) { super(serverName, force, serviceSelection); this.targetDirectory = StringUtils.trim(targetDirectory); this.cleanTargetDirectory = cleanTargetDirectory; this.switchToStandByFirst = switchToStandByFirst; this.archive = archive; }
From source file:hydrograph.ui.expression.editor.styletext.ExpressionEditorStyledText.java
private String getExpressionText(String expressionText) { StringBuffer buffer = new StringBuffer(expressionText); int startIndex = buffer.indexOf(RETURN_STATEMENT); if (startIndex > -1) { buffer.delete(0, startIndex);/*from ww w. j a v a 2 s . c om*/ buffer.delete(0, buffer.indexOf("\n")); } return StringUtils.trim(buffer.toString()); }
From source file:hydrograph.ui.expression.editor.datastructure.MethodDetails.java
private void createPlaceHolderFromSource(IMethod iMethod, String className) throws JavaModelException { StringBuffer buffer = new StringBuffer(iMethod.getSource()); int indexOfPlaceHolder = buffer.lastIndexOf("@see"); if (indexOfPlaceHolder != -1 && iMethod.getParameterNames() != null && iMethod.getParameterNames().length > 0) { buffer = buffer.delete(0, indexOfPlaceHolder + 4); buffer = buffer.delete(buffer.indexOf("\n") + 1, buffer.capacity()); if (StringUtils.contains(buffer.toString(), className + Constants.DOT + iMethod.getElementName())) { placeHolder = StringUtils.trim(buffer.toString()); } else//from www . j av a2 s. c o m placeHolder = createDefaultPlaceHolder(iMethod, className); } else { placeHolder = createDefaultPlaceHolder(iMethod, className); } }
From source file:com.incapture.slate.model.node.ApiNode.java
@Override public String getContent() { String template = TemplateRepo.INSTANCE.getTemplate("apiNode"); CompiledTemplate compiled = TemplateCompiler.compileTemplate(template); Map<String, Object> vars = new HashMap<>(); vars.put("title", getTitle()); vars.put("descriptionNode", getDescriptionNode()); vars.put("codeNode", getCodeWrapperNode()); vars.put("functionNodes", functions); return StringUtils.trim(TemplateRuntime.execute(compiled, vars).toString()); }
From source file:hydrograph.ui.engine.ui.converter.UiConverter.java
/** * Generate basic properties that are common in all components. *///from w w w . j av a2 s .c om public void prepareUIXML() { componentId = StringUtils.trim(typeBaseComponent.getId()); componentName = StringUtils.trim(typeBaseComponent.getName()); if (StringUtils.isBlank(componentName)) { componentName = componentId; } name_suffix = uiComponent.getComponentName() + "_"; LOGGER.debug("Preparing basic properties for component Name:{} and Id{}", componentName, componentId); propertyMap.put(NAME, componentName); propertyMap.put(BATCH, typeBaseComponent.getBatch().toString()); uiComponent.setComponentLabel(componentName); uiComponent.setParent(container); uiComponent.setComponentId(componentId); currentRepository.getComponentUiFactory().put(componentId, uiComponent); }
From source file:com.thoughtworks.go.config.ArtifactConfig.java
public void setDestination(String destination) { this.destination = StringUtils.trim(destination); }