List of usage examples for java.lang StringBuilder replace
@Override public StringBuilder replace(int start, int end, String str)
From source file:fr.landel.utils.commons.StringUtils.java
private static void replaceBrace(final StringBuilder output, final String text, final String replacement) { int index = 0; while ((index = output.indexOf(text, index)) > -1) { output.replace(index, index + text.length(), replacement); index += replacement.length();/*from w w w . j a va2s. c om*/ } }
From source file:org.kuali.rice.krad.data.metadata.impl.MetadataCommonBase.java
/** * Parses the label from the property name. * * @param propertyName the full property name including separators *//*from w w w . ja v a 2s. c o m*/ protected String getLabelFromPropertyName(String propertyName) { // We only want to include the component after the last property separator if (propertyName.contains(".")) { propertyName = StringUtils.substringAfterLast(propertyName, "."); } StringBuilder label = new StringBuilder(propertyName); // upper case the 1st letter label.replace(0, 1, label.substring(0, 1).toUpperCase()); // loop through, inserting spaces when cap for (int i = 0; i < label.length(); i++) { if (Character.isUpperCase(label.charAt(i)) || Character.isDigit(label.charAt(i))) { label.insert(i, ' '); i++; } } return label.toString().trim(); }
From source file:net.duckling.ddl.service.resource.dao.StarmarkDAOImpl.java
@Override public List<Starmark> getStarmarkOfRids(String uid, int tid, List<Long> rids) { List<Starmark> results = new ArrayList<Starmark>(); if (null != rids && !rids.isEmpty()) { String sql = "select * from a1_starmark where uid=? and tid=? and rid in ("; StringBuilder sb = new StringBuilder(); for (long rid : rids) { sb.append(rid + ","); }//from w ww.j a v a 2 s . c o m sb.replace(sb.lastIndexOf(","), sb.length(), ")"); sql += sb.toString(); results = this.getJdbcTemplate().query(sql, new Object[] { uid, tid }, starmarkRowMapper); } return results; }
From source file:pl.nask.hsn2.normalizers.URLNormalizerUtils.java
static String encodePath(StringBuilder pathIn, int start, int end) throws URLParseException { StringBuilder sb = new StringBuilder(pathIn.substring(start, end)); if (!processIISenc()) { removeObfuscatedEncoding(sb, new EncodingType[] { EncodingType.PATH_ALLOWED, EncodingType.IIS_ENC }); } else {//from w ww . jav a 2s. c o m removeObfuscatedEncoding(sb, new EncodingType[] { EncodingType.PATH_ALLOWED }); } int find = 0; while ((find = findFirstMatch(sb, new String[] { "//" }, 0)) >= 0) { sb.replace(find, find + 2, "/"); } String ignore = "%+"; // URIUtils doen't conform to RFC 3986 spec regarding '+' encoding find = findFirstMatch(sb, ignore, 0); if (find >= 0) { ArrayList<Integer> toIgnore = new ArrayList<Integer>(); while (find >= 0) { if (percentEnc.matcher(sb.substring(find)).matches() || sb.codePointAt(find) == '+') { toIgnore.add(find); } find = findFirstMatch(sb, ignore, find + 1); } StringBuilder enc = new StringBuilder(); try { if (toIgnore.size() > 0) { int tmpBeg = 0; for (int i = 0; i < toIgnore.size(); i++) { enc.append(URIUtil.encodePath(sb.substring(tmpBeg, toIgnore.get(i)), DEFAULT_CHARSET)); tmpBeg = toIgnore.get(i) + 1; enc.append(sb.charAt(toIgnore.get(i))); } enc.append(URIUtil.encodePath(sb.substring(tmpBeg), DEFAULT_CHARSET)); } else { enc.append(URIUtil.encodePath(sb.toString())); } } catch (URIException e) { LOG.error(e.getMessage(), e); throw new URLParseException("Cannot parse path:" + sb.substring(start, end), e); } pathIn.replace(start, end, enc.toString()); return enc.toString(); } else { try { String enc = URIUtil.encodePath(sb.toString(), DEFAULT_CHARSET); pathIn.replace(start, end, enc); return enc; } catch (URIException e) { LOG.error(e.getMessage(), e); throw new URLParseException("Cannot parse path:" + sb.substring(start, end), e); } } }
From source file:com.plugin.excel.types.ExcelCell.java
public String getDocumentation() { if (StringUtils.isNotBlank(documentation)) { StringBuilder sb = new StringBuilder(documentation); int i = 0; int length = 70; while (i + length < sb.length() && (i = sb.lastIndexOf(" ", i + length)) != -1) { sb.replace(i, i + 1, "\n"); }// w w w. j a v a 2 s.c o m return sb.toString(); } return documentation; }
From source file:io.github.seleniumquery.by.common.preparser.NotEqualsAttributeSelectorFix.java
/** * Boldly attempts to change all "element[attribute!=value]" into a "element:not([attribute=value])". * * It uses regex, not a parser. In an idel world, the CSS parser would accept such syntax, but it'd * be too much work to fork and extend it (and keep it updated). * * The method tries to ignore declarations inside strings, such as: "element:contains('[attribute!=value]')", * and ":contains()" contents, even when not escaped, such as: "element:contains([attribute!=value])", * which is a valid selector, btw.//from ww w .j av a2 s.c o m * * @param input An ordinary selector. * @return The same selector with the "[attribute!=value]"s turned to ":not([attribute=value])". */ public String turnAttributeNotEqualsIntoNotAttributeEquals(String input) { if (!input.matches(".*" + ATTR_NEQ_REGEX + ".*")) { return input; } String inputWithoutStrings = removeStrings(input); String inputWithoutStringsAndContains = removeContains(inputWithoutStrings); StringBuilder sb = new StringBuilder(input); Matcher m = ATTR_NEQ_PATTERN.matcher(inputWithoutStringsAndContains); while (m.find()) { String leftPart = input.substring(m.start(1), m.end(1)); String rightPart = input.substring(m.start(2), m.end(2)); sb.replace(m.start(1), m.end(2), ":not(" + leftPart + rightPart + ")"); } return sb.toString(); }
From source file:com.surveypanel.utils.PlaceHolderParser.java
protected static String parseStringValue(Form form, String strVal, Set<String> visitedPlaceholders) { StringBuilder buf = new StringBuilder(strVal); int startIndex = strVal.indexOf(DEFAULT_PLACEHOLDER_PREFIX); while (startIndex != -1) { int endIndex = findPlaceholderEndIndex(buf, startIndex); if (endIndex != -1) { String placeholder = buf.substring(startIndex + DEFAULT_PLACEHOLDER_PREFIX.length(), endIndex); if (!visitedPlaceholders.add(placeholder)) { logger.error("Circular placeholder reference '" + placeholder + "' in property definitions"); return placeholder; }//from www . j av a 2 s .co m // Recursive invocation, parsing placeholders contained in the // placeholder key. placeholder = parseStringValue(form, placeholder, visitedPlaceholders); // Now obtain the value for the fully resolved key... String propVal = resolvePlaceholder(form, placeholder); if (propVal != null) { // Recursive invocation, parsing placeholders contained in // the // previously resolved placeholder value. propVal = parseStringValue(form, propVal, visitedPlaceholders); buf.replace(startIndex, endIndex + DEFAULT_PLACEHOLDER_SUFFIX.length(), propVal); if (logger.isTraceEnabled()) { logger.trace("Resolved placeholder '" + placeholder + "'"); } startIndex = buf.indexOf(DEFAULT_PLACEHOLDER_PREFIX, startIndex + propVal.length()); } else { // Proceed with unprocessed value. startIndex = buf.indexOf(DEFAULT_PLACEHOLDER_PREFIX, endIndex + DEFAULT_PLACEHOLDER_SUFFIX.length()); } visitedPlaceholders.remove(placeholder); } else { startIndex = -1; } } return buf.toString(); }
From source file:com.aurel.track.exchange.docx.exporter.AssembleWordprocessingMLPackage.java
private static void replaceIssueLinksWithDescription(String psrc, List<Integer> itemIDs, List<Section> sections, boolean isInline) { StringBuilder src = new StringBuilder(psrc); int startIndex = src.indexOf(ISSUE_TAG); String paragraph = "<p>"; if (startIndex == -1) { //add the original description (no inline content) sections.add(new Section(isInline, src.toString())); } else {//w w w. j a v a 2 s .c o m while ((startIndex = src.toString().indexOf(ISSUE_TAG/*, startIndex*/)) != -1) { int endIndex = src.toString().indexOf(CLOSE, startIndex); if (endIndex == -1 || (endIndex <= startIndex)) { //no closing tag found: remove the opening tag and go on src = src.replace(startIndex, startIndex + ISSUE_TAG.length(), EMPTY); continue; } String key = src.substring(startIndex + ISSUE_TAG.length(), endIndex).trim(); try { Integer itemID = Integer.decode(key); LOGGER.debug("ItemID " + itemID + " found"); itemIDs.add(itemID); TWorkItemBean itemBean = null; try { itemBean = ItemBL.loadWorkItem(itemID); } catch (ItemLoaderException e) { LOGGER.warn("Loading the workItemID " + itemID + " failed with " + e.getMessage()); } if (itemBean == null) { //item not found, neglect the link to this item src = src.replace(startIndex, endIndex + CLOSE.length(), EMPTY); } else { //item found sections.add(new Section(isInline, src.substring(0, startIndex))); String description = itemBean.getDescription(); boolean noDescription = false; if (description == null || description.length() == 0) { noDescription = true; description = itemBean.getSynopsis(); } else { description = removeHtmlHeadings(description); } //add itemNo before the inline description String itemNo = AssembleWordprocessingMLPackage.getItemNo(itemBean); if (description.startsWith(paragraph)) { description = paragraph + itemNo + description.substring(paragraph.length()); } else { description = itemNo + description; } if (noDescription) { sections.add(new Section(true, description)); } else { exportDescription(description, itemIDs, sections, true); } src = new StringBuilder(src.substring(endIndex + CLOSE.length())); } } catch (NumberFormatException e) { LOGGER.info("The key " + key + " is not a number. Remove the start and end tag but do not remove the content between the two"); src = src.replace(startIndex, startIndex + ISSUE_TAG.length(), EMPTY); //recalculate end index endIndex = src.toString().indexOf(CLOSE, startIndex); src = src.replace(endIndex, endIndex + CLOSE.length(), EMPTY); } } sections.add(new Section(isInline, src.toString())); } }
From source file:com.aionengine.gameserver.cache.HTMLCache.java
private void replaceAll(StringBuilder sb, String pattern, String value) { for (int index = 0; (index = sb.indexOf(pattern, index)) != -1;) sb.replace(index, index + pattern.length(), value); }
From source file:com.aionemu.gameserver.cache.HTMLCache.java
private void replaceAll(StringBuilder sb, String pattern, String value) { for (int index = 0; (index = sb.indexOf(pattern, index)) != -1;) { sb.replace(index, index + pattern.length(), value); }//www . ja v a 2 s .c o m }