List of usage examples for org.apache.commons.lang3 StringUtils strip
public static String strip(String str, final String stripChars)
Strips any of a set of characters from the start and end of a String.
From source file:com.teradata.tempto.internal.hadoop.hdfs.WebHDFSClient.java
@Override public Optional<String> getXAttr(String path, String username, String key) { Pair[] params = { Pair.of("xattr.name", key) }; HttpGet setXAttrRequest = new HttpGet(buildUri(path, username, "GETXATTRS", params)); try (CloseableHttpResponse response = httpClient.execute(setXAttrRequest)) { if (response.getStatusLine().getStatusCode() == SC_NOT_FOUND) { return Optional.empty(); }/*from w ww .j a v a 2 s .c om*/ if (response.getStatusLine().getStatusCode() != SC_OK) { throw invalidStatusException("GETXATTRS", path, username, setXAttrRequest, response); } String responseContent = IOUtils.toString(response.getEntity().getContent()); if (GET_XATTR_JSON_PATH.read(responseContent) == null) { return Optional.empty(); } String xArgValue = StringUtils.strip(GET_XATTR_VALUE_JSON_PATH.read(responseContent).toString(), "\""); return Optional.of(xArgValue); } catch (IOException e) { throw new RuntimeException("Could not get xAttr for path: " + path + " in hdfs, user: " + username, e); } }
From source file:com.github.mbenson.privileged.weaver.PrivilegedMethodWeaver.java
private String generateActionClassname(CtMethod m) throws NotFoundException { final StringBuilder b = new StringBuilder(m.getName()); if (m.getParameterTypes().length > 0) { b.append("$$").append(StringUtils.strip(Descriptor.getParamDescriptor(m.getSignature()), "(;)") .replace("[", "ARRAYOF_").replace('/', '_').replace(';', '$')); }/*from www.j a v a 2s.com*/ return b.append(ACTION_SUFFIX).toString(); }
From source file:io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder.java
protected String normalizeAnchor(Markup spaceEscape, String anchor) { String normalizedAnchor = defaultString(anchorPrefix) + anchor.trim(); normalizedAnchor = Normalizer.normalize(normalizedAnchor, Normalizer.Form.NFD) .replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); normalizedAnchor = ANCHOR_IGNORABLE_PATTERN.matcher(normalizedAnchor).replaceAll(spaceEscape.toString()); normalizedAnchor = normalizedAnchor/*from w w w .j a v a 2s . c o m*/ .replaceAll(String.format("([%1$s])([%1$s]+)", ANCHOR_SEPARATION_CHARACTERS), "$1"); normalizedAnchor = StringUtils.strip(normalizedAnchor, ANCHOR_SEPARATION_CHARACTERS); normalizedAnchor = normalizedAnchor.trim().toLowerCase(); String validAnchor = ANCHOR_UNIGNORABLE_PATTERN.matcher(normalizedAnchor).replaceAll(""); if (validAnchor.length() != normalizedAnchor.length()) normalizedAnchor = DigestUtils.md5Hex(normalizedAnchor); else normalizedAnchor = validAnchor; return normalizedAnchor; }
From source file:eionet.gdem.conversion.excel.reader.ExcelReader.java
/** * Reads cell value and formats it according to element type defined in XML Schema. If the cell contains formula, * then calculated value is returned./*from w w w . ja v a 2s. c o m*/ * * @param cell Spreadsheet Cell object. * @param schemaType XML Schema data type for given cell. * @return string value of the cell. */ protected String cellValueToString(Cell cell, String schemaType) { String value = ""; if (cell != null) { switch (evaluator.evaluateInCell(cell).getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC: if (HSSFDateUtil.isCellDateFormatted(cell) && !isYearValue(cell.getNumericCellValue())) { Date dateValue = cell.getDateCellValue(); value = Utils.getFormat(dateValue, DEFAULT_DATE_FORMAT); } else if (HSSFDateUtil.isValidExcelDate(cell.getNumericCellValue()) && schemaType != null && schemaType.equals("xs:date") && !isYearValue(cell.getNumericCellValue())) { Date dateValue = cell.getDateCellValue(); value = Utils.getFormat(dateValue, DEFAULT_DATE_FORMAT); } else { value = formatter.formatCellValue(cell); } break; case HSSFCell.CELL_TYPE_STRING: RichTextString richText = cell.getRichStringCellValue(); value = richText.toString(); break; case HSSFCell.CELL_TYPE_BOOLEAN: value = Boolean.toString(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_ERROR: break; case HSSFCell.CELL_TYPE_FORMULA: break; default: break; } } return StringUtils.strip(value.trim(), String.valueOf(NON_BREAKING_SPACE)).trim(); }
From source file:com.ethlo.geodata.GeodataServiceImpl.java
@Override public Page<GeoLocation> filter(LocationFilter filter, Pageable pageable) { final Collection<Query<GeoLocation>> queries = new LinkedList<>(); if (filter.getName() != null) { if (filter.getName().endsWith("*")) { queries.add(QueryFactory.startsWith(CqGeonamesRepository.ATTRIBUTE_LC_NAME, StringUtils.strip(filter.getName(), "*"))); } else {/*from w ww .j a v a2 s. c om*/ queries.add(QueryFactory.equal(CqGeonamesRepository.ATTRIBUTE_LC_NAME, filter.getName())); } } if (!filter.getFeatureClasses().isEmpty()) { queries.add(QueryFactory.in(CqGeonamesRepository.ATTRIBUTE_FEATURE_CLASS, filter.getFeatureClasses())); } if (!filter.getFeatureCodes().isEmpty()) { queries.add(QueryFactory.in(CqGeonamesRepository.ATTRIBUTE_FEATURE_CODE, filter.getFeatureCodes())); } if (!filter.getCountryCodes().isEmpty()) { queries.add(QueryFactory.in(CqGeonamesRepository.ATTRIBUTE_COUNTRY_CODE, filter.getCountryCodes())); } Query<GeoLocation> query; if (queries.isEmpty()) { query = QueryFactory.none(GeoLocation.class); } else if (queries.size() == 1) { query = queries.iterator().next(); } else { query = new And<>(queries); } final ResultSet<GeoLocation> result = geoNamesRepository.retrieve(query, QueryFactory.queryOptions(QueryFactory.orderBy(QueryFactory .descending(QueryFactory.missingLast(CqGeonamesRepository.ATTRIBUTE_POPULATION))))); int index = 0; final List<GeoLocation> content = new LinkedList<>(); for (GeoLocation l : result) { if (index >= pageable.getOffset() && content.size() < pageable.getPageSize()) { content.add(l); } index++; } return new PageImpl<>(content, pageable, index); }
From source file:io.stallion.dataAccess.db.DB.java
/** * Update the object/* ww w .ja v a 2s .co m*/ * * @param obj * @return rows affected */ public int update(Model obj) { Schema schema = getSchemaForModelClass(obj.getClass()); String sql = "UPDATE `" + schema.getName() + "` SET "; List args = new ArrayList<>(); for (Col col : schema.getColumns()) { if (col.getUpdateable()) { sql += "`" + col.getName() + "`" + "=?, "; Object arg = PropertyUtils.getPropertyOrMappedValue(obj, col.getPropertyName()); arg = convertColumnArg(obj, col, arg); args.add(arg); } } sql = StringUtils.strip(sql.trim(), ","); sql += " WHERE id=?"; args.add(obj.getId()); QueryRunner run = new QueryRunner(dataSource); int affected = 0; try { affected = run.update(sql, args.toArray()); } catch (SQLException e) { throw new RuntimeException(e); } return affected; }
From source file:io.stallion.dataAccess.db.DB.java
/** * Update only the passed in key values/*from w w w .j a v a2 s .c om*/ * * @param obj * @return rows affected */ public int update(Model obj, Map<String, Object> values) { if (values.size() == 0) { return 0; } Schema schema = getSchemaForModelClass(obj.getClass()); String sql = "UPDATE `" + schema.getName() + "` SET "; List args = new ArrayList<>(); for (Col col : schema.getColumns()) { if (col.getUpdateable() && values.containsKey(col.getPropertyName())) { sql += "`" + col.getName() + "`" + "=?, "; Object arg = values.get(col.getPropertyName()); arg = convertColumnArg(obj, col, arg); args.add(arg); } } if (args.size() == 0) { return 0; } sql = StringUtils.strip(sql.trim(), ","); sql += " WHERE id=?"; args.add(obj.getId()); QueryRunner run = new QueryRunner(dataSource); int affected = 0; try { affected = run.update(sql, args.toArray()); } catch (SQLException e) { throw new RuntimeException(e); } return affected; }
From source file:io.stallion.dataAccess.db.DB.java
public SqlAndParams toInQueryParams(List things) { SqlAndParams o = new SqlAndParams(); StringBuffer buf = new StringBuffer(); buf.append("("); for (Object thing : things) { buf.append("?,"); }/*from w ww. j a va 2s. c o m*/ String sql = StringUtils.strip(buf.toString(), ","); sql = sql + ")"; o.setSql(sql); o.setParamsList(things); return o; }
From source file:org.apache.kylin.source.hive.BeelineHiveClient.java
private String stripQuotes(String input) { if (input.startsWith("'") && input.endsWith("'")) { return StringUtils.strip(input, "'"); } else if (input.startsWith("\"") && input.endsWith("\"")) { return StringUtils.strip(input, "\""); } else {//from w ww. ja v a 2 s . co m return input; } }
From source file:org.apache.syncope.core.logic.scim.SearchCondVisitor.java
private <E extends Enum<?>> SearchCond complex(final String operator, final String left, final String right, final List<SCIMComplexConf<E>> items) { if (left.endsWith(".type")) { Optional<SCIMComplexConf<E>> item = items.stream() .filter(object -> object.getType().name().equals(StringUtils.strip(right, "\""))).findFirst(); if (item.isPresent()) { AttributeCond attributeCond = new AttributeCond(); attributeCond.setSchema(item.get().getValue()); attributeCond.setType(AttributeCond.Type.ISNOTNULL); return SearchCond.getLeafCond(attributeCond); }/*w w w. ja v a 2 s . c o m*/ } else if (!conf.getUserConf().getEmails().isEmpty() && (MULTIVALUE.contains(left) || left.endsWith(".value"))) { List<SearchCond> orConds = new ArrayList<>(); items.forEach(item -> { AttributeCond cond = new AttributeCond(); cond.setSchema(item.getValue()); cond.setExpression(StringUtils.strip(right, "\"")); orConds.add(setOperator(cond, operator)); }); if (!orConds.isEmpty()) { return SearchCond.getOrCond(orConds); } } return null; }