List of usage examples for java.lang StringBuilder replace
@Override public StringBuilder replace(int start, int end, String str)
From source file:org.cipango.callflow.JmxMessageLog.java
protected void replaceAll(StringBuilder sb, String toFind, Object toSet) { int index = 0; while ((index = sb.indexOf(toFind)) != -1) sb.replace(index, index + toFind.length(), toSet.toString()); }
From source file:org.mifos.framework.util.ConfigurationLocator.java
private void resolveEnvironmentProperties(String fileName, StringBuilder fileBuffer) { Matcher envVarMatcher = ENV_VAR_PATTERN.matcher(fileName); while (envVarMatcher.find()) { String envVar = envVarMatcher.group(); String environmentProperty = configurationLocatorHelper.getEnvironmentProperty(envVar.substring(1)); if (environmentProperty != null) { fileBuffer.replace(envVarMatcher.start(), envVarMatcher.end(), environmentProperty); }/*ww w . j a va2 s . c o m*/ } }
From source file:org.apache.wiki.diff.FlowchartDiffProvider.java
/** * removes the source of the flow from the article */// w w w .j a va2s. c om private void remove(Section<FlowchartType> flow, StringBuilder bob) { Section<DiaFluxType> diaFlux = Sections.ancestor(flow, DiaFluxType.class); int start = diaFlux.getOffsetInArticle(); int end = start + diaFlux.getText().length(); bob.replace(start, end, ""); }
From source file:org.mifos.framework.util.ConfigurationLocator.java
private void resolveHomeProperties(String fileName, StringBuilder fileBuffer) { Matcher matcher = PROPERTY_PATTERN.matcher(fileName); while (matcher.find()) { String property = matcher.group(); String homeProperty = configurationLocatorHelper .getHomeProperty(property.substring(2, property.length() - 1)); if (homeProperty != null) { fileBuffer.replace(matcher.start(), matcher.end(), homeProperty); }/*from w ww.j av a2s . co m*/ } }
From source file:pl.nask.hsn2.normalizers.URLNormalizerUtils.java
public static String numToIPv4(StringBuilder sb, int start, int endInd) { int end = findFirstMatch(sb, ":/?", start, endInd); if (end < 0) { end = endInd;//from w ww . j a v a 2 s . c o m } long ip; try { ip = Long.decode(sb.substring(start, end)); if (ip <= 0xffffff) { //disallow 0.x.x.x format return null; } } catch (NumberFormatException e) { return null; } StringBuilder tmp = new StringBuilder(); for (int i = 0; i < 3; i++) { tmp.insert(0, ip & 0xff); tmp.insert(0, '.'); ip = ip >> 8; } tmp.insert(0, ip & 0xff); sb.replace(start, end, tmp.toString()); return tmp.toString(); }
From source file:com.github.gekoh.yagen.util.FieldInfo.java
private static String formatAnnotation(Annotation annotation) { String a = annotation.toString(); StringBuilder result = new StringBuilder(); // wrap string value of attribute "name" into double quotes as needed for java code Matcher m = STRING_ATTR_PATTERN.matcher(a); int idx = 0;/*from w w w . j a v a 2 s . co m*/ while (m.find(idx)) { result.append(a.substring(idx, m.start(2))); result.append("\"").append(escapeAttributeValue(m.group(2))).append("\""); result.append(a.substring(m.end(2), m.end())); idx = m.end(); } result.append(a.substring(idx)); a = result.toString(); result = new StringBuilder(); // remove empty attributes like (columnDefinition=) m = Pattern.compile("\\(?(,?\\s*[A-Za-z]*=)[,|\\)]").matcher(a); idx = 0; while (m.find(idx)) { result.append(a.substring(idx, m.start(1))); idx = m.end(1); } result.append(a.substring(idx)); // set nullable=true m = NULLABLE_PATTERN.matcher(result); idx = 0; while (m.find(idx)) { if (m.group(1).equals("false")) { result.replace(m.start(1), m.end(1), "true"); } idx = m.start(1) + 1; m = NULLABLE_PATTERN.matcher(result); } // set unique=false m = UNIQUE_PATTERN.matcher(result); idx = 0; while (m.find(idx)) { if (m.group(1).equals("true")) { result.replace(m.start(1), m.end(1), "false"); } idx = m.start(1) + 1; m = UNIQUE_PATTERN.matcher(result); } return result.toString().replaceAll("=\\[([^\\]]*)\\]", "={$1}"); }
From source file:pl.nask.hsn2.normalizers.URLNormalizerUtils.java
public static String removeObfuscatedEncoding(StringBuilder sb, EncodingType[] type) { if (type == null) { return sb.toString(); }//from ww w .j a v a 2 s .c o m for (EncodingType t : type) { if (t == EncodingType.PLUS_AS_SPACE) { normalizeSpaceEncoding(sb); } else if (t == EncodingType.IIS_ENC) { removeIISenc(sb); } else { int i = sb.indexOf("%"); while (i >= 0) { if (i + 3 <= sb.length()) { try { int v = Integer.parseInt(sb.substring(i + 1, i + 3), 16); if (t.allowed(v)) { sb.replace(i, i + 3, Character.toString((char) v)); } } catch (NumberFormatException e) { LOG.debug(e.getMessage()); } } i = sb.indexOf("%", i + 1); } } } return sb.toString(); }
From source file:org.jamwiki.parser.jflex.ImageLinkTag.java
/** * Parse a Mediawiki link of the form "[[topic|text]]" and return the * resulting HTML output.//from w ww .j a v a 2 s . c o m */ public String parse(JFlexLexer lexer, String raw, Object... args) throws ParserException { if (lexer.getMode() <= JFlexParser.MODE_PREPROCESS) { // parse as a link if not doing a full parse return lexer.parse(JFlexLexer.TAG_TYPE_WIKI_LINK, raw); } WikiLink wikiLink = JFlexParserUtil.parseWikiLink(lexer.getParserInput(), lexer.getParserOutput(), raw); if (StringUtils.isBlank(wikiLink.getDestination())) { // no destination or section return raw; } if (wikiLink.getColon() || !wikiLink.getNamespace().getId().equals(Namespace.FILE_ID)) { // parse as a link return lexer.parse(JFlexLexer.TAG_TYPE_WIKI_LINK, raw); } try { String result = this.parseImageLink(lexer.getParserInput(), lexer.getParserOutput(), lexer.getMode(), wikiLink); // depending on image alignment/border the image may be contained within a div. If that's the // case, close any open paragraph tags prior to pushing the image onto the stack if (result.startsWith("<div") && ((JAMWikiLexer) lexer).peekTag().getTagType().equals("p")) { ((JAMWikiLexer) lexer).popTag("p"); StringBuilder tagContent = ((JAMWikiLexer) lexer).peekTag().getTagContent(); String trimmedTagContent = tagContent.toString().trim(); if (tagContent.length() != trimmedTagContent.length()) { // trim trailing whitespace tagContent.replace(0, tagContent.length() - 1, trimmedTagContent); } tagContent.append(result); ((JAMWikiLexer) lexer).pushTag("p", null); return ""; } else { // otherwise just return the image HTML return result; } } catch (DataAccessException e) { logger.error("Failure while parsing link " + raw, e); return ""; } catch (ParserException e) { logger.error("Failure while parsing link " + raw, e); return ""; } }
From source file:pt.webdetails.cfr.CfrApiTest.java
@Test public void testSetPermissionsAdmin() throws IOException, JSONException { CfrApiForTests cfrApi = new CfrApiForTests(); cfrApi.setIsAdmin(true);//from w w w . j a v a2s . com String top = "{" + " \"status\": \"Operation finished. Check statusArray for details.\"," + " \"statusArray\": ["; String bot = " ]}"; String singleBot = "]}"; String setOnDirRecur; StringBuilder sbAllDir = new StringBuilder(); for (String dir : dirStructure) { sbAllDir.append( " {\"status\": \"Added permission for path " + dir + " and user/role Authenticated\"},"); } setOnDirRecur = sbAllDir.toString(); setOnDirRecur = sbAllDir.replace(setOnDirRecur.lastIndexOf(","), setOnDirRecur.lastIndexOf(",") + 1, "") .toString(); String setOnDir = "{\"status\": \"Added permission for path " + dirStructure[0] + " and user/role Authenticated\"}"; String setOnFile = "{\"status\": \"Added permission for path " + fileStructure[0] + " and user/role Authenticated\"}"; String path = "/"; List<String> ids = new ArrayList<String>(); ids.add("Authenticated"); List<String> permissions = new ArrayList<String>(); permissions.add("read"); permissions.add("write"); boolean recursive = true; List<String> files = new ArrayList<String>(); files.addAll(Arrays.asList(fileStructure)); files.addAll(Arrays.asList(dirStructure)); cfrApi.setFileNames(files); createCfrServiceMock(); cfrApi.setCfrService(cfrServiceMock); // setPermissions on a dir, with recursive = true String result = cfrApi.setPermissions(path, ids, permissions, recursive); Assert.assertEquals(top + setOnDirRecur + bot, result.replaceAll("\n", "")); //set permissions on a file, with recursive = true path = fileStructure[0]; files = new ArrayList<String>(); files.addAll(Arrays.asList(fileStructure[0])); cfrApi.setFileNames(files); result = cfrApi.setPermissions(path, ids, permissions, recursive); Assert.assertEquals(top + setOnFile + singleBot, result.replaceAll("\n", "")); // setPermissions on a dir, with recursive = false path = dirStructure[0]; recursive = false; result = cfrApi.setPermissions(path, ids, permissions, recursive); Assert.assertEquals(top + setOnDir + singleBot, result.replaceAll("\n", "")); //set permissions on a file, with recursive = false path = fileStructure[0]; result = cfrApi.setPermissions(path, ids, permissions, recursive); Assert.assertEquals(top + setOnFile + singleBot, result.replaceAll("\n", "")); }
From source file:gov.nih.nci.nbia.customserieslist.FileGenerator.java
/** * generate comma separate string from the series instance uid list * @param seriesItems//from w w w .j a v a2s .c om */ public String generate(List<BasketSeriesItemBean> seriesItems) { StringBuilder sb = new StringBuilder(); int size = seriesItems.size(); for (int i = 0; i < size; i++) { BasketSeriesItemBean bsib = seriesItems.get(i); sb.append(bsib.getSeriesId()); sb.append(","); sb.append("\n"); } int lastComma = sb.lastIndexOf(","); //System.out.println("char at length - 1: " + sb.charAt(sb.length() - 1) + " length: " + sb.length() + " lastComma: " + lastComma); sb.replace(lastComma, lastComma, ""); sb.trimToSize(); //System.out.println("length: " + sb.length()); return sb.toString(); }