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.greenline.guahao.web.module.home.controllers.json.validcode.JsonValidCodeController.java
private BaseJsonObject sendMobileValidCode(String mobile, String signdata, String type, String strParam) { BaseJsonObject json = new BaseJsonObject(); boolean hasError = Boolean.FALSE; if (RegexUtil.isMobile(StringUtils.trim(mobile))) { // ??/* w w w.ja v a 2 s . co m*/ VerifyTypeEnum verEnum = VerifyTypeEnum.valueOf(type); // ??? if (StringUtils.isBlank(strParam) && VerifyTypeEnum.RES_CODE_MOBILE.equals(verEnum)) { log.error("?????(strParam,verEnum):" + strParam + "," + verEnum); return new BaseJsonObject(Boolean.TRUE, "?????,????."); } // // ??? // if (VerifyTypeEnum.PWD_RESET_MOBILE.equals(verEnum)) { // CheckResult result = userManager.isExistLoginId(mobile); // if (!result.isSystemError() && !result.isExist()) { // return new BaseJsonObject(Boolean.TRUE, "??."); // } // } // ? String mobilevalidcodepwd = (String) mursiFreeMarkerViewResolver.getAttributesMap() .get("mobilevalidcodepwd"); String clientsigndata = MD5Util.getMD5Format(type + mobile + mobilevalidcodepwd); if (StringUtils.isBlank(signdata) || !signdata.equals(clientsigndata)) { hasError = Boolean.TRUE; log.error("?????(signdata,clientsigndata):" + signdata + "," + clientsigndata); return new BaseJsonObject(Boolean.TRUE, "?????,????."); } if (!hasError) { String key = mobile; // ?: ???,??id+?id if (StringUtils.isNotBlank(strParam) && VerifyTypeEnum.RES_CODE_MOBILE.equals(verEnum)) { key += strParam; } // ??code String code = codeCacheManager.getCode(verEnum, VCodeCachePrefixEnum.CODE_PRE.getValue() + key); // ??,? if (StringUtils.isBlank(code)) { // ?? code = codeCacheManager.setCode(verEnum, VCodeCachePrefixEnum.CODE_PRE.getValue() + key, 6, orderValidLimitCacheManager.getOrderValidCodeTimeout() * 1000); json = this.sendMobileVerifyCode(mobile, verEnum, code, key); } else { // ???code String intervalCode = codeCacheManager.getCode(verEnum, VCodeCachePrefixEnum.INT_PRE.getValue() + key); // ???? if (StringUtils.isBlank(intervalCode)) { json = this.sendMobileVerifyCode(mobile, verEnum, code, key); } else { // ???? ???? ?????? json.setHasError(true); json.setMessage("?????,????."); } } } } else { json.setHasError(Boolean.TRUE); json.setMessage("??."); } return json; }
From source file:ml.shifu.shifu.udf.stats.CategoricalVarStats.java
/** * @param databag//from w ww . ja v a2s . c o m * @param columnConfig * @throws ExecException */ private void statsCategoricalColumnInfo(DataBag databag, ColumnConfig columnConfig) throws ExecException { // The last bin is for missingOrInvalid values Integer[] binCountPos = new Integer[columnConfig.getBinCategory().size() + 1]; Integer[] binCountNeg = new Integer[columnConfig.getBinCategory().size() + 1]; Double[] binWeightCountPos = new Double[columnConfig.getBinCategory().size() + 1]; Double[] binWeightCountNeg = new Double[columnConfig.getBinCategory().size() + 1]; int lastBinIndex = columnConfig.getBinCategory().size(); initializeZeroArr(binCountPos); initializeZeroArr(binCountNeg); initializeZeroArr(binWeightCountPos); initializeZeroArr(binWeightCountNeg); Iterator<Tuple> iterator = databag.iterator(); boolean isMissingValue = false; boolean isInvalidValue = false; while (iterator.hasNext()) { isInvalidValue = false; isMissingValue = false; Tuple element = iterator.next(); if (element.size() < 4) { continue; } Object value = element.get(1); String tag = CommonUtils.trimTag((String) element.get(2)); Double weight = (Double) element.get(3); int binNum = 0; if (value == null || modelConfig.getDataSet().getMissingOrInvalidValues() .contains(value.toString().toLowerCase().trim())) { // TODO check missing value list in ModelConfig?? missingValueCnt++; isMissingValue = true; } else { String str = StringUtils.trim(value.toString()); binNum = quickLocateCategorialBin(str); if (binNum < 0) { invalidValueCnt++; isInvalidValue = true; } } if (isInvalidValue || isMissingValue) { binNum = lastBinIndex; } if (modelConfig.getPosTags().contains(tag)) { increaseInstCnt(binCountPos, binNum); increaseInstCnt(binWeightCountPos, binNum, weight); } else if (modelConfig.getNegTags().contains(tag)) { increaseInstCnt(binCountNeg, binNum); increaseInstCnt(binWeightCountNeg, binNum, weight); } } columnConfig.setBinCountPos(Arrays.asList(binCountPos)); columnConfig.setBinCountNeg(Arrays.asList(binCountNeg)); columnConfig.setBinWeightedPos(Arrays.asList(binWeightCountPos)); columnConfig.setBinWeightedNeg(Arrays.asList(binWeightCountNeg)); calculateBinPosRateAndAvgScore(); for (int i = 0; i < columnConfig.getBinCountPos().size(); i++) { int posCount = columnConfig.getBinCountPos().get(i); int negCount = columnConfig.getBinCountNeg().get(i); binning.addData(columnConfig.getBinPosRate().get(i), posCount); binning.addData(columnConfig.getBinPosRate().get(i), negCount); streamStatsCalculator.addData(columnConfig.getBinPosRate().get(i), posCount); streamStatsCalculator.addData(columnConfig.getBinPosRate().get(i), negCount); } columnConfig.setMax(streamStatsCalculator.getMax()); columnConfig.setMean(streamStatsCalculator.getMean()); columnConfig.setMin(streamStatsCalculator.getMin()); if (binning.getMedian() == null) { columnConfig.setMedian(streamStatsCalculator.getMean()); } else { columnConfig.setMedian(binning.getMedian()); } columnConfig.setStdDev(streamStatsCalculator.getStdDev()); // Currently, invalid value will be regarded as missing columnConfig.setMissingCnt(missingValueCnt + invalidValueCnt); columnConfig.setTotalCount(databag.size()); columnConfig.setMissingPercentage(((double) columnConfig.getMissingCount()) / columnConfig.getTotalCount()); columnConfig.getColumnStats().setSkewness(streamStatsCalculator.getSkewness()); columnConfig.getColumnStats().setKurtosis(streamStatsCalculator.getKurtosis()); }
From source file:hydrograph.ui.graph.command.ComponentPasteCommand.java
private String getPrefix(Object node) { String currentName = ((Component) node).getComponentLabel().getLabelContents(); String prefix = currentName;//ww w . ja v a 2 s. co m StringBuffer buffer = new StringBuffer(currentName); try { if (buffer.lastIndexOf(UNDERSCORE) != -1 && (buffer.lastIndexOf(UNDERSCORE) != buffer.length())) { String substring = StringUtils .trim(buffer.substring(buffer.lastIndexOf(UNDERSCORE) + 1, buffer.length())); if (StringUtils.isNumeric(substring)) { prefix = buffer.substring(0, buffer.lastIndexOf(UNDERSCORE)); } } } catch (Exception exception) { LOGGER.warn("Cannot process component name for detecting prefix : ", exception.getMessage()); } return prefix; }
From source file:com.edgenius.wiki.PageTheme.java
public String getBodyMarkup() { return StringUtils.trim(bodyMarkup); }
From source file:com.github.dbourdette.otto.source.config.TransformConfig.java
public List<TransformOperation> parseOperations(String literal) { List<TransformOperation> operations = new ArrayList<TransformOperation>(); if (StringUtils.isEmpty(literal)) { return operations; }//from w w w . ja va 2s . c om String[] tokens = StringUtils.split(literal, ","); for (String token : tokens) { TransformOperation operation = REGISTRY.get(StringUtils.trim(token)); if (operation != null) { operations.add(operation); } } return operations; }
From source file:com.yahoo.flowetl.services.http.BaseHttpCaller.java
/** * Attempts to call the given method using the given client and will attempt * this repeatedly up to the max redirect amount. If no redirect location is * found a http exception will be propagated upwards. Otherwise for * non-redirect codes this method will stop. This function is recursively * called./* w w w . j a v a 2 s . com*/ * * @throws HttpException * @throws IOException */ private void handleRedirects(final HttpClient client, final HttpMethod method, final int curRedirAm, final int maxRedirAm) throws HttpException, IOException { if (logger.isEnabled(Level.DEBUG)) { logger.log(Level.DEBUG, "Executing " + method + " redir count = " + curRedirAm + " of " + maxRedirAm + " possible redirects "); } // exec and see what happened client.executeMethod(method); int code = method.getStatusCode(); if (logger.isEnabled(Level.DEBUG)) { logger.log(Level.DEBUG, "Executing " + method + " got status code " + code + ""); } // supposed redirect codes // everything else will just stop this function if (REDIR_CODES.contains(code) == false) { return; } // die or continue? if (curRedirAm < maxRedirAm) { // ok to try to find it Header locationHeader = method.getResponseHeader(REDIR_HEADER); String redirLoc = null; if (locationHeader != null) { redirLoc = locationHeader.getValue(); } // cleanup and see if we can use it... redirLoc = StringUtils.trim(redirLoc); if (StringUtils.isEmpty(redirLoc) == false) { // reset uri URI nUri = new URI(redirLoc, false); method.setURI(nUri); if (logger.isEnabled(Level.DEBUG)) { logger.log(Level.DEBUG, "Attempting redirect " + (curRedirAm + 1) + " due to status code " + code + " to location " + nUri); } handleRedirects(client, method, curRedirAm + 1, maxRedirAm); } else { // failure at finding header throw new HttpException("Unable to execute " + method + " - no " + REDIR_HEADER + " header found to redirect to during redirect " + curRedirAm); } } else { // max redirects done throw new HttpException("Unable to execute " + method + " after attempting " + curRedirAm + " redirects of " + maxRedirAm + " attempts"); } }
From source file:com.streamreduce.core.model.Connection.java
public void setUrl(String url) { //Validity of url will be determined by @URL validator on the url field. this.url = StringUtils.trim(url); }
From source file:io.kahu.hawaii.service.sql.ResourceSqlQueryService.java
private String makeQuery(List<String> lines) { StringBuilder query = new StringBuilder(); boolean isComment = false; boolean inBlockComment = false; for (String line : lines) { line = StringUtils.trim(line); if (line.startsWith("/*")) { inBlockComment = true;/*from ww w . j a v a 2 s.com*/ } if (line.startsWith("--")) { isComment = true; } if (line.endsWith(";")) { // Oracle does not like SQL statements via JDBC that end with // ';'. line = line.substring(0, line.length() - 1); } if (StringUtils.isNotBlank(line) && !(isComment || inBlockComment)) { if (query.length() != 0) { query.append(" "); } query.append(line); } isComment = false; if (line.startsWith("*/")) { inBlockComment = false; } } return query.toString(); }
From source file:com.izforge.izpack.integration.ExecutableFileTest.java
/** * Verifies that a file exists with the specified content. * * @param name the file name//from ww w. j a v a 2 s.c om * @param content the expected file content * @return the file * @throws IOException for any I/O error */ private File checkContains(String name, String content) throws IOException { checkExists(name); File file = new File(temporaryFolder.getRoot(), name); List<String> fileContent = FileUtil.getFileContent(file.getPath()); assertEquals(1, fileContent.size()); assertEquals(content, StringUtils.trim(fileContent.get(0))); return file; }
From source file:com.mindmutex.draugiem.DraugiemHttpFilter.java
/** * Configure the filter before the internal * filter chain is executed./* ww w. j a va 2 s .c o m*/ */ private void configureFilter() { // creates inner filter chain String filters = configuration.getProperty("application.filters"); if (filters == null || filters.equalsIgnoreCase("default")) { innerChain = InnerFilterChain.createDefault(configuration); } else { innerChain = new InnerFilterChain(configuration); String packageName = getClass().getPackage().getName(); String[] classNames = filters.split(","); for (String className : classNames) { className = StringUtils.trim(className); if (className.startsWith(".")) { className = packageName + className; } try { Class<?> clazz = Class.forName(className); Object filter = clazz.newInstance(); if (!(filter instanceof InnerFilter)) { throw new DraugiemException("application.filters must implement inner filter interface"); } logger.info("Adding Filter: {}", className); innerChain.addInnerFilter((InnerFilter) filter); } catch (ClassNotFoundException ex) { throw new DraugiemException(ex); } catch (InstantiationException ex) { throw new DraugiemException(ex); } catch (IllegalAccessException ex) { throw new DraugiemException(ex); } } } }