List of usage examples for java.lang StringBuilder indexOf
@Override public int indexOf(String str)
From source file:Main.java
/** * Method reemplazaTextoDeLaEtiqueta. Dado una etiqueta con un contenido, lo reemplaza en todas las apariciones por uno nuevo en el documento dado * @param etiqueta Etiqueta a la que queremos reemplazarle el contenido. La etiqueta debe corresponderse con un item * @param contenidoViejo Contenido que queremos reemplazar * @param contenidoNuevo Nuevo contenido a poner en la etiqueta indicada * @param documento Documento con la etiqueta y contenido a reemplazar * @return String Documento con el contenido reemplazado *///from ww w .j a va 2 s . com public static String reemplazaTextoDeLaEtiqueta(String etiqueta, String contenidoViejo, String contenidoNuevo, String documento) { StringBuilder st = new StringBuilder(documento); String cadenaVieja = (new StringBuilder("<").append(etiqueta).append(">").append(contenidoViejo) .append("</").append(etiqueta).append(">")).toString(); int posIni = documento.indexOf(cadenaVieja); while (posIni != -1) { String cadenaNueva = (new StringBuilder("<").append(etiqueta).append(">").append(contenidoNuevo) .append("</").append(etiqueta).append(">")).toString(); st.replace(posIni, posIni + cadenaVieja.length(), cadenaNueva); posIni = st.indexOf(cadenaVieja); if (cadenaVieja.equals(cadenaNueva)) posIni = -1; } return st.toString(); }
From source file:org.dasein.cloud.digitalocean.models.rest.DigitalOceanModelFactory.java
public static DigitalOceanRestModel getModel(org.dasein.cloud.digitalocean.DigitalOcean provider, DigitalOcean model, int page) throws CloudException, InternalException { if (logger.isTraceEnabled()) { logger.trace("ENTER - " + DigitalOceanModelFactory.class.getName() + ".getModel(" + provider + "," + model + ")"); }// w w w. j a v a 2s . c o m String token = (String) provider.getContext().getConfigurationValue("token"); try { StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append(getApiUrl(provider)).append(getEndpoint(model)); if (page > 0) { if (urlBuilder.indexOf("?") > 0) { urlBuilder.append('&'); } else { urlBuilder.append('?'); } urlBuilder.append("page=").append(page); } String responseText = performHttpRequest(provider, RESTMethod.GET, token, urlBuilder.toString()); JSONObject jso = new JSONObject(responseText); return model.fromJson(jso); } catch (JSONException e) { throw new CloudException(e); } finally { if (logger.isTraceEnabled()) { logger.trace("EXIT - " + DigitalOceanModelFactory.class.getName() + ".getModel(" + provider + "," + model + ")"); } } }
From source file:com.easysoft.build.utils.PatchUtil.java
/** * ??//from www. ja va2 s. c o m * @param sb * @param sectionName ???? * @param content ?? */ public static void replaceSection(StringBuilder sb, String sectionName, String content) { String prefix = "\r\n-- -" + sectionName + "-\r\n"; String suffix = "\r\n-- =" + sectionName + "=\r\n"; int sIndex = sb.indexOf(prefix); int eIndex = sb.indexOf(suffix); if (sIndex != -1 && eIndex != -1 && sIndex < eIndex) { sb.replace(sIndex, eIndex + suffix.length(), ""); } if (content.length() > 0) { sb.append(prefix); content = content.replaceAll("", ",").replaceAll("", ";").replaceAll("", "'") .replaceAll("", "'").replaceAll("", "."); sb.append(content); sb.append(suffix); } }
From source file:com.lightbox.android.webservices.requests.ApiRequest.java
private static String insertParametersInPath(String url, Map<String, Object> parameters) { StringBuilder urlStringBuilder = new StringBuilder(url); if (parameters != null) { for (Iterator<Entry<String, Object>> iterator = parameters.entrySet().iterator(); iterator.hasNext();) { Entry<String, Object> paramEntry = iterator.next(); String pathParamName = String.format("{%s}", paramEntry.getKey()); int startIndex = urlStringBuilder.indexOf(pathParamName); if (startIndex != -1) { // We found the parameter name in the path: replace it, and remove it from the parameter map int endIndex = startIndex + pathParamName.length(); urlStringBuilder.replace(startIndex, endIndex, paramEntry.getValue().toString()); iterator.remove();/* ww w.ja v a2 s .c o m*/ } } } return urlStringBuilder.toString(); }
From source file:marytts.server.MaryProperties.java
/** * From a path entry in the properties, create an expanded form. * Replace the string MARY_BASE with the value of property "mary.base"; * replace all "/" and "\\" with the platform-specific file separator. *///from w w w .j a va 2 s .co m private static String expandPath(String path) { final String MARY_BASE = "MARY_BASE"; StringBuilder buf = null; if (path.startsWith(MARY_BASE)) { buf = new StringBuilder(maryBase()); buf.append(path.substring(MARY_BASE.length())); } else { buf = new StringBuilder(path); } if (File.separator.equals("/")) { int i = -1; while ((i = buf.indexOf("\\")) != -1) buf.replace(i, i + 1, "/"); } else if (File.separator.equals("\\")) { int i = -1; while ((i = buf.indexOf("/")) != -1) buf.replace(i, i + 1, "\\"); } else { throw new Error("Unexpected File.separator: `" + File.separator + "'"); } return buf.toString(); }
From source file:com.kotcrab.vis.editor.util.ApplicationUtils.java
public static String getRestartCommand() { List<String> vmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); StringBuilder vmArgsOneLine = new StringBuilder(); if (OsUtils.isMac()) { vmArgsOneLine.append("-XstartOnFirstThread "); }//from w w w. jav a 2s. c o m for (String arg : vmArguments) { if (arg.contains("-agentlib") == false) { vmArgsOneLine.append(arg).append(" "); } } final StringBuilder cmd = new StringBuilder(PlatformUtils.getJavaBinPath() + " " + vmArgsOneLine); String[] mainCommand = System.getProperty("sun.java.command").split(" "); if (mainCommand[0].endsWith(".jar")) cmd.append("-jar " + new File(mainCommand[0]).getPath()); else cmd.append("-cp \"" + System.getProperty("java.class.path") + "\" " + mainCommand[0]); for (int i = 1; i < mainCommand.length; i++) { cmd.append(" "); cmd.append(mainCommand[i]); } //if launching from idea, not in debug mode String ideaLauncher = "-Didea.launcher.bin.path="; int ideaLauncherStart = cmd.indexOf(ideaLauncher); if (ideaLauncherStart != -1) { cmd.insert(ideaLauncherStart + ideaLauncher.length(), "\""); cmd.insert(cmd.indexOf("-cp ", ideaLauncherStart) - 1, "\""); } return cmd.toString(); }
From source file:com.aurel.track.lucene.util.StringUtil.java
public static boolean contains(String s, String text, String delimiter) { if ((s == null) || (text == null) || (delimiter == null)) { return false; }//from w w w. ja va2 s . c om StringBuilder sb = new StringBuilder(s); if (!s.endsWith(delimiter)) { sb.append(delimiter); } int pos = sb.indexOf(delimiter + text + delimiter); if (pos == -1) { if (sb.toString().startsWith(text + delimiter)) { return true; } return false; } return true; }
From source file:org.loklak.android.data.MessageEntry.java
private static List<String> extract(StringBuilder s, Pattern p, int g) { Matcher m = p.matcher(s.toString()); List<String> l = new ArrayList<String>(); while (m.find()) l.add(m.group(g));//from w w w . jav a2 s . c om for (String r : l) { int i = s.indexOf(r); s.replace(i, i + r.length(), ""); } return l; }
From source file:de.mpg.escidoc.pubman.multipleimport.ImportProcess.java
public static void replace(String target, String replacement, StringBuilder builder) { int indexOfTarget = -1; while ((indexOfTarget = builder.indexOf(target)) >= 0) { builder.replace(indexOfTarget, indexOfTarget + target.length(), replacement); }// ww w . j av a 2 s . c o m }
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 {/*from ww w .j a v a2 s. c om*/ 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())); } }