Example usage for java.lang StringBuilder indexOf

List of usage examples for java.lang StringBuilder indexOf

Introduction

In this page you can find the example usage for java.lang StringBuilder indexOf.

Prototype

@Override
    public int indexOf(String str) 

Source Link

Usage

From source file:org.openspaces.pu.container.support.BeanLevelPropertiesUtils.java

public static String resolvePlaceholders(String text, BeanLevelProperties beanLevelProperties) {
    StringBuilder buf = new StringBuilder(text);

    int startIndex = buf.indexOf(PLACEHOLDER_PREFIX);
    while (startIndex != -1) {
        int endIndex = buf.indexOf(PLACEHOLDER_SUFFIX, startIndex + PLACEHOLDER_PREFIX.length());
        if (endIndex != -1) {
            String placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
            int nextIndex = endIndex + PLACEHOLDER_SUFFIX.length();
            try {
                String propVal = beanLevelProperties.getContextProperties().getProperty(placeholder);
                if (propVal == null) {
                    propVal = System.getProperty(placeholder);
                    if (propVal == null) {
                        // Fall back to searching the system environment.
                        propVal = System.getenv(placeholder);
                    }/*from   w  ww  . ja va  2  s .c o  m*/
                }
                if (propVal != null) {
                    buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal);
                    nextIndex = startIndex + propVal.length();
                }
            } catch (Throwable ex) {
                if (logger.isWarnEnabled()) {
                    logger.warn("Could not resolve placeholder '" + placeholder + "' in [" + text
                            + "] as system property: " + ex);
                }
            }
            startIndex = buf.indexOf(PLACEHOLDER_PREFIX, nextIndex);
        } else {
            startIndex = -1;
        }
    }

    return buf.toString();
}

From source file:at.gv.egovernment.moa.id.protocols.oauth20.OAuth20Util.java

/**
 * Simple helper function to add parameter to a url
 * /*from   w w w.ja  va 2s .c  om*/
 * @param url
 * @param name
 * @param value
 * @throws UnsupportedEncodingException
 */
public static void addParameterToURL(final StringBuilder url, final String name, final String value)
        throws UnsupportedEncodingException {
    if (url.indexOf("?") < 0) {
        url.append("?");
    } else {
        url.append("&");
    }
    // URLEncoder.encode(value, "UTF-8")
    url.append(name).append("=").append(value);
}

From source file:fr.putnami.pwt.plugin.ajaxbot.filter.AjaxPageFilter.java

private static String rewriteQueryString(String queryString) throws UnsupportedEncodingException {
    StringBuilder queryStringSb = new StringBuilder(queryString);
    int i = queryStringSb.indexOf("&" + QUERY_PARAM_ESCAPED_FRAGMENT);
    if (i != -1) {
        StringBuilder tmpSb = new StringBuilder(queryStringSb.substring(0, i));
        tmpSb.append("#!");
        tmpSb.append(URLDecoder.decode(queryStringSb.substring(i + 20, queryStringSb.length()), "UTF-8"));
        queryStringSb = tmpSb;/* w  ww  .  j  a va  2 s.  co  m*/
    }

    i = queryStringSb.indexOf(QUERY_PARAM_ESCAPED_FRAGMENT);
    if (i != -1) {
        StringBuilder tmpSb = new StringBuilder(queryStringSb.substring(0, i));
        tmpSb.append("#!");
        tmpSb.append(URLDecoder.decode(queryStringSb.substring(i + 19, queryStringSb.length()), "UTF-8"));
        queryStringSb = tmpSb;
    }
    if (queryStringSb.indexOf("#!") != 0) {
        queryStringSb.insert(0, '?');
    }

    return queryStringSb.toString();
}

From source file:net.duckling.common.util.CommonUtils.java

/**??"," 
 * @param str ??/*from  ww  w . j  av  a  2s .co  m*/
 * @param flag ","","
 * @return ??
 * */
public static String format(String str, String flag) {
    if (CommonUtils.isNull(str)) {
        return "";
    }
    StringBuilder sb = new StringBuilder(str);
    if (sb.indexOf(flag) > 0) {
        return sb.substring(0, sb.lastIndexOf(flag));
    }
    return sb.toString();
}

From source file:Main.java

public static SpannableStringBuilder replaceTags(String str, int flag) {
    try {/*from  w w  w. j a  v a2s .c o m*/
        int start;
        int end;
        StringBuilder stringBuilder = new StringBuilder(str);
        if ((flag & FLAG_TAG_BR) != 0) {
            while ((start = stringBuilder.indexOf("<br>")) != -1) {
                stringBuilder.replace(start, start + 4, "\n");
            }
            while ((start = stringBuilder.indexOf("<br/>")) != -1) {
                stringBuilder.replace(start, start + 5, "\n");
            }
        }
        ArrayList<Integer> bolds = new ArrayList<>();
        if ((flag & FLAG_TAG_BOLD) != 0) {
            while ((start = stringBuilder.indexOf("<b>")) != -1) {
                stringBuilder.replace(start, start + 3, "");
                end = stringBuilder.indexOf("</b>");
                if (end == -1) {
                    end = stringBuilder.indexOf("<b>");
                }
                stringBuilder.replace(end, end + 4, "");
                bolds.add(start);
                bolds.add(end);
            }
        }
        ArrayList<Integer> colors = new ArrayList<>();
        if ((flag & FLAG_TAG_COLOR) != 0) {
            while ((start = stringBuilder.indexOf("<c#")) != -1) {
                stringBuilder.replace(start, start + 2, "");
                end = stringBuilder.indexOf(">", start);
                int color = Color.parseColor(stringBuilder.substring(start, end));
                stringBuilder.replace(start, end + 1, "");
                end = stringBuilder.indexOf("</c>");
                stringBuilder.replace(end, end + 4, "");
                colors.add(start);
                colors.add(end);
                colors.add(color);
            }
        }
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder);
        // for (int a = 0; a < bolds.size() / 2; a++) {
        // spannableStringBuilder.setSpan(
        // new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")),
        // bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        // }
        for (int a = 0; a < colors.size() / 3; a++) {
            spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3),
                    colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return spannableStringBuilder;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new SpannableStringBuilder(str);
}

From source file:org.dcache.xrootd.plugins.authn.gsi.CertUtil.java

/**
 * remove all occurences of a character from a string
 *
 * @param sb the stringbuilder/*from  ww  w.  j  a  va  2 s . c o  m*/
 * @param c the char to be removed
 * @return the resulting stringbuilder
 */
private static StringBuilder removeChar(StringBuilder sb, char c) {
    int index;
    while ((index = sb.indexOf("\n")) > -1) {
        sb.deleteCharAt(index);
    }
    return sb;
}

From source file:Main.java

/**
 * takes an escape'd XML string and converts it back to orginal text contents
 * /*from  ww  w .j  a v  a  2 s. co m*/
 * @param chars XML contents
 * @return String translation of XML contents
 **/
public static final String unescape(final String chars) {
    if (chars == null) {
        return "";
    }

    final StringBuilder res = new StringBuilder(chars);
    int i = res.indexOf("&");

    while (i != -1) {
        final int j = res.indexOf(";", i + 1);
        if (j == -1) {
            break;
        }
        final String entity = res.substring(i + 1, j);
        if (entity.startsWith("#")) {
            if ((entity.length() == 3) && (entity.charAt(1) == 'x')) {
                // http://www.w3.org/TR/1999/WD-xml-c14n-19991109.html
                // 5.2 Character Escaping
                switch (entity.charAt(2)) {
                case '9':
                    res.replace(i, j + 1, "\t");
                    break;
                case 'D':
                    res.replace(i, j + 1, "\r");
                    break;
                case 'A':
                    res.replace(i, j + 1, "\n");
                    break;
                }
            } else {
                try {
                    final int charCode = Integer.parseInt(entity.substring(1));
                    final char c = (char) charCode;
                    res.replace(i, j + 1, Character.toString(c));
                    i = i + 1;
                } catch (final NumberFormatException e) {
                    res.delete(i, j + 1);
                }
            }
        } else {
            final String textEntity = XML_ENTITY_MAP.get(entity);
            if (textEntity != null) {
                res.replace(i, j + 1, textEntity);
                i = i + textEntity.length();
            } else {
                res.delete(i, j + 1);
            }
        }
        i = res.indexOf("&", i);
    }

    return res.toString();
}

From source file:wsattacker.plugin.dos.dosExtension.util.UtilHashDoS.java

public static String determineUntamperedAttributeName(CollisionInterface collisionInterface,
        int numberOfAttributes, boolean useNamespace) {
    String attributeName = DEFAULT_ATTRIBUTENAME;

    StringBuilder builder = new StringBuilder("");

    // n viele Kollisionen erzeugen
    collisionInterface.genNCollisions(numberOfAttributes, builder, useNamespace);
    int indexOf = builder.indexOf("=");
    if (indexOf != -1) {
        int start = 0;
        if (builder.indexOf(":") != -1) {
            start = builder.indexOf(":") + 1;
        }//ww  w .j  a  va  2  s .  c o  m

        CharSequence subSequence = builder.subSequence(start, indexOf);
        // length for the attribute name -> e.g. aaaa = 4
        int count = subSequence.length();
        // substract the count -> e.g. 10 elements -> aaa0 - aaa9
        count -= String.valueOf(numberOfAttributes).length();

        if (count > 0) {
            attributeName = RandomStringUtils.randomAlphabetic(count);
        }
    }

    return attributeName;
}

From source file:org.dataconservancy.packaging.tool.impl.generator.RemediationUtil.java

/**
 * Searches the supplied {@code packageResourcePath} for reserved path prefixes that should <em>not</em> be subject
 * to remediation, and removes them from the {@code packageResourcePath}.  The location of {@link PackageResourceType
 * package resources} are specified by the BagIt specification and the Data Conservancy BagIt profile, and
 * therefore:/*from   w  ww . j a  v a2 s.  co  m*/
 * <ol>
 *     <li>May be assumed to <em>not</em> violate the specification or profile (e.g. paths defined by the
 *     specification will never have a path component greater than 255 characters, or contain illegal
 *     characters)</li>
 *     <li>Must not be subject to remediation (e.g. truncation remediation shall not truncate a portion of the
 *     reserved path)</li>
 * </ol>
 *
 * @param packageResourcePath the full path of the resource in the package, relative to the base directory of the
 *                            package
 * @return the portion of the {@code packageResourcePath} that <em>must</em> be preserved from remediation
 *         (may be empty)
 */
private static StringBuilder preservePrefix(StringBuilder packageResourcePath) {
    for (String reserved : RESERVED_PATHS) {
        final int index = packageResourcePath.indexOf(reserved);
        if (index < 0) {
            // nothing to preserve, as the reserved path doesn't exist in the string being remediated
            continue;
        }

        // Preserve everything from index 0 in the string being remediated to the ending of the path being preserved
        // this is a bit greedy, but it does handle the case where the reserved path doesn't start with a /, and
        // the string being remediated does.
        StringBuilder preserved = new StringBuilder(
                packageResourcePath.subSequence(0, index + reserved.length()));
        packageResourcePath.delete(0, index + reserved.length());

        return preserved;
    }

    return new StringBuilder();
}

From source file:be.fedict.eid.pkira.blm.model.mail.MailTemplateBean.java

public static final String unescapeHTML(String s) {
    StringBuilder builder = new StringBuilder(s);

    while (true) {
        int i = builder.indexOf("&");

        if (i > -1) {
            int j = builder.indexOf(";", i);
            if (j > i) {
                String temp = builder.substring(i, j + 1);
                String replacement = "?";
                for (String[] replacements : htmlEscape) {
                    if (replacements[0].equals(temp)) {
                        replacement = replacements[1];
                        break;
                    }/*from   w w  w  . jav  a  2  s. com*/
                }
                builder.replace(i, j + 1, replacement);
            } else {
                break;
            }
        } else {
            break;
        }
    }

    return builder.toString();
}