List of usage examples for java.lang StringBuilder indexOf
@Override public int indexOf(String str)
From source file:org.apache.lucene.search.SearchUtil.java
public static String removeSecureContents(String contents) { StringBuilder sb = new StringBuilder(contents); while (true) { if (sb.indexOf("$SECURE_START$") != -1 && sb.indexOf("$SECURE_END$") != -1) { int start = sb.indexOf("$SECURE_START$"); int end = sb.indexOf("$SECURE_END$"); sb.replace(start, end + "$SECURE_END$".length(), ""); } else {//from ww w .j a v a2s . co m break; } } return sb.toString(); }
From source file:org.openlegacy.designtime.generators.GenerateUtil.java
public static void replicateTemplate(File file, Object model, String placeHolderStart, String placeHolderEnd, String existingCodeplaceHolderStart, String existingCodePlaceHolderEnd) { try {//from w w w.ja v a2 s .c om StringBuilder fileContent = new StringBuilder(FileUtils.readFileToString(file)); int placeHolderReplaceMarkerStart = fileContent.indexOf(existingCodeplaceHolderStart) - 1; int placeHolderReplaceMarkerEnd = fileContent.indexOf(existingCodePlaceHolderEnd) + existingCodePlaceHolderEnd.length(); if (placeHolderReplaceMarkerStart > 0 && placeHolderReplaceMarkerStart > 0) { fileContent.delete(placeHolderReplaceMarkerStart, placeHolderReplaceMarkerEnd); } int templateMarkerStart = fileContent.indexOf(placeHolderStart); int templateMarkerEnd = fileContent.indexOf(placeHolderEnd) - 2; if (templateMarkerStart < 0 || templateMarkerEnd < 0) { return; } // replace tokens within the place holder tag String definitionTemplate = fileContent.substring(templateMarkerStart + placeHolderStart.length(), templateMarkerEnd); String definitionTemplateNew = generate(model, new StringReader(definitionTemplate)); fileContent = fileContent.insert(templateMarkerStart, MessageFormat.format("{0}{1}{2}{3}", existingCodeplaceHolderStart, definitionTemplateNew, existingCodePlaceHolderEnd, SystemUtils.LINE_SEPARATOR)); FileUtils.write(file, fileContent); } catch (IOException e) { throw (new GenerationException(e)); } }
From source file:Main.java
/** * Sanitizes the XML represented by {@code xml} by replacing dirty header XML * snippets in the {@code dirtyXmlMap} map with clean header XML snippets from * the {@code cleanXmlMap} map.//from ww w . ja v a 2s . c o m * * @param xml the XML to sanitize * @param dirtyXmlMap a map of tag name to dirty XML header * @param cleanXmlMap a map of tag name to clean XML header * @return a sanitized copy of the XML with all sensitive tags masked */ private static String sanitizeXml(StringBuilder xml, Map<String, String> dirtyXmlMap, Map<String, String> cleanXmlMap) { for (Entry<String, String> cleanXml : cleanXmlMap.entrySet()) { String dirtyXml = dirtyXmlMap.get(cleanXml.getKey()); String endTag = cleanXml.getKey() + ">"; int startIndex = xml.indexOf(dirtyXml.split(" ")[0]); int endIndex = xml.lastIndexOf(endTag) + endTag.length(); xml = xml.replace(startIndex, endIndex, cleanXml.getValue()); } return xml.toString(); }
From source file:Main.java
/** * Appends the given set of parameters to the given query string * @param queryBuilder The query url string to append the parameters * @param parameters The parameters to append * @return The modified query url string */ public static void appendUrlWithQueryParameters(StringBuilder queryBuilder, Map<String, Object> parameters) { //perform parameter validation if (null == queryBuilder) throw new IllegalArgumentException("Given value for parameter \"queryBuilder\" is invalid."); if (null == parameters) return;//from w w w. j av a2 s. c om //does the query string already has parameters boolean hasParams = (queryBuilder.indexOf("?") > 0); //iterate and append parameters for (Map.Entry<String, Object> pair : parameters.entrySet()) { //ignore null values if (null == pair.getValue()) continue; //if already has parameters, use the & to append new parameters char separator = (hasParams) ? '&' : '?'; queryBuilder.append(separator + pair.getKey() + "=" + pair.getValue()); //indicate that now the query has some params hasParams = true; } }
From source file:com.qmetry.qaf.automation.ws.rest.RequestLogger.java
public static void deleteAll(StringBuilder builder, String str) { if (null == builder) { return;/*from w w w . ja v a 2s.co m*/ } int index = builder.indexOf(str); while (index != -1) { builder.delete(index, index + str.length()); index = builder.indexOf(str, index); } }
From source file:org.wso2.carbon.apimgt.impl.utils.CommonUtil.java
public static void validateWsdl(String url) throws APIManagementException, IOException { BufferedReader in = null;//from w w w. j a v a2 s .com try { URL wsdl = new URL(url); in = new BufferedReader(new InputStreamReader(wsdl.openStream())); String inputLine; boolean isWsdl2 = false; boolean isWsdl10 = false; StringBuilder urlContent = new StringBuilder(); while ((inputLine = in.readLine()) != null) { String wsdl2NameSpace = "http://www.w3.org/ns/wsdl"; String wsdl10NameSpace = "http://schemas.xmlsoap.org/wsdl/"; urlContent.append(inputLine); isWsdl2 = urlContent.indexOf(wsdl2NameSpace) > 0; isWsdl10 = urlContent.indexOf(wsdl10NameSpace) > 0; } if (isWsdl10) { javax.wsdl.xml.WSDLReader wsdlReader11 = null; try { wsdlReader11 = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader(); wsdlReader11.readWSDL(url); } catch (WSDLException e) { handleException("Unable to process wsdl 1.0", e); } } else if (isWsdl2) { WSDLReader wsdlReader20 = null; try { wsdlReader20 = WSDLFactory.newInstance().newWSDLReader(); wsdlReader20.readWSDL(url); } catch (org.apache.woden.WSDLException e) { handleException("Unable to process wsdl 2.0", e); } } else { handleException("URL is not in format of wsdl1/wsdl2"); } } finally { in.close(); } }
From source file:org.fao.fenix.wds.core.utils.olap.OLAPWrapper.java
public static StringBuilder cleanJSON(StringBuilder sb) { String s = "{},"; while ((sb.indexOf(s)) > -1) sb.replace(sb.indexOf(s), s.length() + sb.indexOf(s), ""); s = "\"v\":[{}]"; while ((sb.indexOf(s)) > -1) sb.replace(sb.indexOf(s), s.length() + sb.indexOf(s), ""); s = ",}";//from w w w .ja va 2 s . c o m while ((sb.indexOf(s)) > -1) sb.replace(sb.indexOf(s), s.length() + sb.indexOf(s), "}"); int idx_1 = -1; int idx_2 = -1; for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == '{') idx_1 = i; if (sb.charAt(i) == '}') idx_2 = i; if (idx_1 > -1 && idx_2 > -1) { int count = 0; for (int j = idx_1; j < idx_2; j++) if (sb.charAt(j) == '"') count++; if (count == 4) { for (int z = idx_2; z >= idx_1; z--) { sb.setCharAt(z, ' '); } } i = 1 + idx_2; idx_1 = -1; idx_2 = -1; } } s = " , "; while ((sb.indexOf(s)) > -1) sb.replace(sb.indexOf(s), s.length() + sb.indexOf(s), ""); s = " ,{"; while ((sb.indexOf(s)) > -1) sb.replace(sb.indexOf(s), s.length() + sb.indexOf(s), "{"); s = "}]}, "; while ((sb.indexOf(s)) > -1) sb.replace(sb.indexOf(s), s.length() + sb.indexOf(s), "}]}"); idx_1 = -1; idx_2 = -1; for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == '}') idx_1 = i; if (sb.charAt(i) == '{' && i > idx_1) idx_2 = i; if (idx_1 > -1 && idx_2 > -1 && idx_2 > idx_1) { String tmp = sb.substring(idx_1, 1 + idx_2); int blanks = 0; int commas = 0; for (int z = 0; z < tmp.length(); z++) { switch (tmp.charAt(z)) { case ' ': blanks++; break; case ',': commas++; break; } } if (blanks > 0 && commas == 0) { String s1 = sb.substring(0, idx_1); String s2 = sb.substring(1 + idx_2); sb = new StringBuilder(s1 + "},{" + s2); } i = 1 + idx_2; idx_1 = -1; idx_2 = -1; } } s = "{}"; while ((sb.indexOf(s)) > -1) sb.replace(sb.indexOf(s), s.length() + sb.indexOf(s), ""); s = "},]"; while ((sb.indexOf(s)) > -1) sb.replace(sb.indexOf(s), s.length() + sb.indexOf(s), "}]"); return sb; }
From source file:net.bulletin.pdi.xero.step.support.Helpers.java
/** * <p>If the value is provided then this method will augment the supplied URL by adding on the * query to the URL.</p>/*from w w w .ja v a 2 s.c o m*/ */ public static StringBuilder appendUrlQuery(StringBuilder url, String key, String value) { if (null == url || 0 == url.length()) { throw new IllegalArgumentException("the supplied url may not be empty."); } if (StringUtils.isEmpty(key)) { throw new IllegalArgumentException("the supplied query key may not be empty."); } if (StringUtils.isNotBlank(value)) { url.append(-1 == url.indexOf("?") ? '?' : '&'); url.append(key); url.append("="); try { url.append(URLEncoder.encode(value, CharEncoding.UTF_8)); } catch (UnsupportedEncodingException uee) { throw new IllegalStateException("the encoding must be supported; " + CharEncoding.UTF_8); } } return url; }
From source file:com.melani.utils.ProjectHelpers.java
public static String parsearCaracteresEspecialesXML(String xmlNota) { String xml = "No paso Nada"; StringBuilder sb = null; try {/*from w ww . j av a 2 s. co m*/ sb = new StringBuilder(); sb.append(xmlNota); xml = StringEscapeUtils .escapeXml10(xmlNota.substring(xmlNota.indexOf("es>") + 3, xmlNota.indexOf("</ob"))); sb.replace(sb.indexOf("es>") + 3, sb.indexOf("</ob"), xml); } catch (Exception e) { xml = "Error"; logger.error("Error en metodo parsearCaracteresEspecialesXML " + e.getMessage()); } finally { return sb.toString(); } }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * //from w w w . j av a2s .c o m * @param targets * @param string * @return */ public static <T> String join(T[] targets, String delimiter) { if (ValidationUtils.isEmpty(targets)) return StringUtils.EMPTY; StringBuilder builder = new StringBuilder(); for (T target : targets) { builder.append(target).append(delimiter); } //? if (builder.indexOf(delimiter) > 0) builder.deleteCharAt(builder.lastIndexOf(delimiter)); return builder.toString(); }