Example usage for java.lang StringBuffer indexOf

List of usage examples for java.lang StringBuffer indexOf

Introduction

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

Prototype

@Override
public int indexOf(String str) 

Source Link

Usage

From source file:org.glite.slcs.shibclient.TestShibbolethClient.java

public static String getDN(StringBuffer response) {
    String dn = null;/*w ww  . ja va2 s  . com*/
    int start = response.indexOf("<DN>");
    if (start != -1) {
        start += "<DN>".length();
        int stop = response.indexOf("</DN>", start);
        if (stop != -1) {
            dn = response.substring(start, stop);
        } else {
            System.err.println("</DN> not found!");
        }
    } else {
        System.err.println("<DN> not found!");
    }
    return dn;
}

From source file:org.kuali.rice.krad.util.UrlFactory.java

public static String parameterizeUrl(String baseUrl, Properties params) {
    baseUrl = StringUtils.trim(baseUrl);
    if (StringUtils.isEmpty(baseUrl)) {
        throw new IllegalArgumentException("invalid (blank) base URL");
    }/*from ww  w  .  ja  v a  2  s  .c  om*/
    if (params == null) {
        throw new IllegalArgumentException("invalid (null) Properties");
    }

    StringBuffer ret = new StringBuffer(baseUrl);
    // Only start with ? if it has not been added to the url
    String delimiter = (ret.indexOf("?") == -1) ? "?" : "&";
    for (Object key : params.keySet()) {
        String paramName = StringUtils.trim((String) key);
        String paramValue = params.getProperty(paramName);
        ret.append(delimiter);
        if (StringUtils.isEmpty(paramName)) {
            throw new IllegalArgumentException("invalid (blank) paramName");
        }
        if (paramValue == null) {
            ret.append(paramName);
            ret.append("=");
        } else {
            try {
                ret.append(paramName);
                ret.append("=");
                ret.append(urlCodec.encode(paramValue));
            } catch (EncoderException ex) {
                LOG.error("Unable to encode parameter name or value: " + paramName + "=" + paramValue, ex);
                throw new RuntimeException(
                        "Unable to encode parameter name or value: " + paramName + "=" + paramValue, ex);
            }
        }
        delimiter = "&";
    }

    return ret.toString();
}

From source file:org.glite.slcs.shibclient.TestShibbolethClient.java

public static String getCertificate(StringBuffer response) {
    String pemCert = null;/*from  w w w.j  av  a  2s.c o m*/
    int start = response.indexOf("<Certificate>");
    if (start != -1) {
        start += "<Certificate>".length();
        int stop = response.indexOf("</Certificate>", start);
        if (stop != -1) {
            pemCert = response.substring(start, stop);
        } else {
            System.err.println("</Certificate> not found!");
        }
    } else {
        System.err.println("<Certificate> not found!");
    }
    return pemCert;

}

From source file:org.glite.slcs.shibclient.TestShibbolethClient.java

public static String getAuthorizationToken(StringBuffer response) {
    String authToken = null;//w  w w .  ja  v a2 s .c  o m
    int start = response.indexOf("<AuthorizationToken>");
    if (start != -1) {
        start += "<AuthorizationToken>".length();
        int stop = response.indexOf("</AuthorizationToken>", start);
        if (stop != -1) {
            authToken = response.substring(start, stop);
        } else {
            System.err.println("</AuthorizationToken> not found!");
        }
    } else {
        System.err.println("<AuthorizationToken> not found!");
    }
    return authToken;
}

From source file:org.vosao.utils.StrUtil.java

public static String removeJavascript(String s) {
    StringBuffer buf = new StringBuffer(s);
    int scriptStart = buf.indexOf("<script");
    while (scriptStart > 0) {
        int scriptEnd = buf.indexOf("</script>", scriptStart) + 9;
        if (scriptEnd > 0) {
            buf.replace(scriptStart, scriptEnd, "");
        }/*from www . j a  va  2 s.c o  m*/
        scriptStart = buf.indexOf("<script", scriptStart);
    }
    return buf.toString();
}

From source file:com.doculibre.constellio.wicket.utils.SimpleParamsUtils.java

public static String appendParams(String url, SimpleParams simpleParams) {
    StringBuffer sb = new StringBuffer(url);
    for (String paramName : simpleParams.keySet()) {
        for (String paramValue : simpleParams.getList(paramName)) {
            if (sb.indexOf("?") == -1 && StringUtils.isNotBlank(url)) {
                sb.append("?");
            } else if (sb.length() > 0) {
                sb.append("&");
            }//from w w  w  .  j  a v a2s .c  o  m
            sb.append(paramName + "=" + paramValue);
        }
    }
    return sb.toString();
}

From source file:org.exoplatform.portal.webui.application.GadgetUtil.java

static private String getLocalHostName() {
    PortalRequestContext pContext = Util.getPortalRequestContext();
    StringBuffer requestUrl = pContext.getRequest().getRequestURL();
    int index = requestUrl.indexOf(pContext.getRequestContextPath());
    return requestUrl.substring(0, index);
}

From source file:cn.ctyun.amazonaws.util.StringUtils.java

public static String replace(String originalString, String partToMatch, String replacement) {
    StringBuffer buffer = new StringBuffer(originalString.length());
    buffer.append(originalString);/*from  ww w  .  j ava2 s.c  om*/

    int indexOf = buffer.indexOf(partToMatch);
    while (indexOf != -1) {
        buffer = buffer.replace(indexOf, indexOf + partToMatch.length(), replacement);
        indexOf = buffer.indexOf(partToMatch);
    }

    return buffer.toString();
}

From source file:com.robin.testcase.ApkResigner.java

private static String getAutVersion(final File autFile) {
    AndroidTools androidTools = AndroidTools.get();
    String versionCode = "";
    Process2 process = null;//w  w w  .jav  a 2 s  .c o m
    try {
        StringBuffer strBuffer = new StringBuffer();
        process = androidTools.aapt("dumb", "badging", autFile.getAbsolutePath());
        process.connectStdout(strBuffer).waitForSuccess();

        int versionCodePosition = strBuffer.indexOf("versionCode");
        int versionControlEndPosition = strBuffer.indexOf(" ", versionCodePosition);
        versionCode = splitVersionCode(strBuffer.substring(versionCodePosition, versionControlEndPosition));
    } catch (InterruptedException e) {
        versionCode = "NotSet";
    } catch (IOException e) {
        versionCode = "NotSet";
    }
    return versionCode;
}

From source file:org.rapidcontext.app.plugin.cmdline.CmdLineExecProcedure.java

/**
 * Analyzes the error output buffer from a process and adds the
 * relevant log messages/*from ww w.j  a  v  a2  s. com*/
 *
 * @param cx             the procedure call context
 * @param buffer         the process error output buffer
 */
private static void log(CallContext cx, StringBuffer buffer) {
    int pos;
    while ((pos = buffer.indexOf("\n")) >= 0) {
        String text = buffer.substring(0, pos).trim();
        if (text.length() > 0 && text.charAt(0) == '#') {
            if (cx.getCallStack().height() <= 1) {
                Matcher m = PROGRESS_PATTERN.matcher(text);
                if (m.find()) {
                    double progress = Double.parseDouble(m.group(1));
                    cx.setAttribute(CallContext.ATTRIBUTE_PROGRESS, Double.valueOf(progress));
                }
            }
        } else {
            cx.log(buffer.substring(0, pos));
        }
        buffer.delete(0, pos + 1);
    }
}