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.pentaho.di.trans.steps.http.HTTP.java

private String determineUrl(RowMetaInterface outputRowMeta, Object[] row)
        throws KettleValueException, KettleException {
    try {/* www .  j a  va  2s . co m*/
        if (meta.isUrlInField()) {
            // get dynamic url
            data.realUrl = outputRowMeta.getString(row, data.indexOfUrlField);
        }
        StringBuffer url = new StringBuffer(data.realUrl); // the base URL with variable substitution

        for (int i = 0; i < data.argnrs.length; i++) {
            if (i == 0 && url.indexOf("?") < 0) {
                url.append('?');
            } else {
                url.append('&');
            }

            url.append(URIUtil.encodeWithinQuery(meta.getArgumentParameter()[i]));
            url.append('=');
            String s = outputRowMeta.getString(row, data.argnrs[i]);
            if (s != null) {
                s = URIUtil.encodeWithinQuery(s);
            }
            url.append(s);
        }

        return url.toString();
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "HTTP.Log.UnableCreateUrl"), e);
    }
}

From source file:org.springframework.security.captcha.CaptchaEntryPoint.java

/**
 * @param redirectUrl StringBuffer./*from   w w w  .j  av a 2  s .c  o  m*/
 * @param req http servlet request
 */
private void includeOriginalRequest(StringBuffer redirectUrl, HttpServletRequest req) {
    // add original request to the url
    if (redirectUrl.indexOf("?") >= 0) {
        redirectUrl.append("&");
    } else {
        redirectUrl.append("?");
    }

    redirectUrl.append(originalRequestUrlParameterName);
    redirectUrl.append("=");

    try {
        redirectUrl.append(URLEncoder.encode(req.getRequestURL().toString(), urlEncodingCharset));
    } catch (UnsupportedEncodingException e) {
        logger.warn(e);
    }

    //append method
    redirectUrl.append("&");
    redirectUrl.append(originalRequestMethodParameterName);
    redirectUrl.append("=");
    redirectUrl.append(req.getMethod());

    if (includeOriginalParameters) {
        // append query params
        redirectUrl.append("&");
        redirectUrl.append(originalRequestParametersParameterName);
        redirectUrl.append("=");

        StringBuffer qp = new StringBuffer();
        Enumeration parameters = req.getParameterNames();

        if ((parameters != null) && parameters.hasMoreElements()) {
            //qp.append("?");
            while (parameters.hasMoreElements()) {
                String name = parameters.nextElement().toString();
                String value = req.getParameter(name);
                qp.append(name);
                qp.append(originalRequestParametersNameValueSeparator);
                qp.append(value);

                if (parameters.hasMoreElements()) {
                    qp.append(originalRequestParametersSeparator);
                }
            }
        }

        try {
            redirectUrl.append(URLEncoder.encode(qp.toString(), urlEncodingCharset));
        } catch (Exception e) {
            logger.warn(e);
        }
    }
}

From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java

private int parseStatusLine(PushbackInputStream in, StringBuffer line) throws IOException, HttpException {
    readLine(in, line, false);//from w w  w .jav a 2s.c o m

    int codeStart = line.indexOf(" ");
    int codeEnd = line.indexOf(" ", codeStart + 1);

    // handle lines with no plaintext result code, ie:
    // "HTTP/1.1 200" vs "HTTP/1.1 200 OK"
    if (codeEnd == -1)
        codeEnd = line.length();

    int code;
    try {
        code = Integer.parseInt(line.substring(codeStart + 1, codeEnd));
    } catch (NumberFormatException e) {
        throw new HttpException("bad status line '" + line + "': " + e.getMessage(), e);
    }

    return code;
}

From source file:com.meiah.core.util.StringUtil.java

/**
  * /* www .j  a  v a 2  s .co m*/
  * @description strKeyword?strSplit???
  * @param strSplit
  * @author zhangj
  * @date Jun 14, 2012
  */
 public static List<String> getEngKeyword(StringBuffer sbKeyword, String strSplit) {
     if (Validator.isNull(strSplit)) {
         strSplit = "\""; //""????
     }
     List<String> result = new ArrayList<String>();
     int index = 0, end = 0;
     int start = sbKeyword.indexOf(strSplit); //"?
     int count = 1;
     while (index != -1) {
         index = sbKeyword.indexOf(strSplit, index + 1);
         if (index != -1) {
             if (index == start) {
                 continue;
             }
             if (count % 2 == 0) {
                 start = index;
             } else {
                 end = index;
             }
             if (start < end) {
                 result.add(sbKeyword.substring(start + 1, end));
                 sbKeyword.replace(start + 1, end, "");
                 index = start + 1;
                 start = 0;
                 end = 0;
             }
             count++;
         }
     }
     return result;
 }

From source file:test.ShopThreadSrc.java

private String getParams() {
    StringBuffer parambuff = new StringBuffer(2000);
    Iterator<String> it = this.params.keys();
    while (it.hasNext()) {
        String key = it.next();/*from   w  w w .  j a v  a 2 s  .c  om*/
        parambuff.append(key + "=" + this.params.getString(key));
        parambuff.append("&");
    }
    if (parambuff.indexOf("&") != -1)
        parambuff.deleteCharAt(parambuff.lastIndexOf("&"));
    return parambuff.toString();
}

From source file:org.apache.nutch.protocol.htmlunit.HttpResponse.java

private void processHeaderLine(StringBuffer line) throws IOException, HttpException {

    int colonIndex = line.indexOf(":"); // key is up to colon
    if (colonIndex == -1) {
        int i;/*from w  w w.  ja  va2  s  . c o  m*/
        for (i = 0; i < line.length(); i++)
            if (!Character.isWhitespace(line.charAt(i)))
                break;
        if (i == line.length())
            return;
        throw new HttpException("No colon in header:" + line);
    }
    String key = line.substring(0, colonIndex);

    int valueStart = colonIndex + 1; // skip whitespace
    while (valueStart < line.length()) {
        int c = line.charAt(valueStart);
        if (c != ' ' && c != '\t')
            break;
        valueStart++;
    }
    String value = line.substring(valueStart);
    headers.set(key, value);
}

From source file:dk.defxws.fgssolrremote.OperationsImpl.java

protected boolean indexDocExists(String pid) throws GenericSearchException {
    boolean indexDocExists = true;
    StringBuffer resultXml = new StringBuffer();
    try {//from  w w  w .j  av  a 2 s  .c om
        resultXml = sendToSolr("/select?q=PID%3A%22" + pid + "%22&rows=0");
    } catch (Exception e) {
        throw new GenericSearchException("updateIndex sendToSolr:\n" + e, e);
    }
    int i = resultXml.indexOf("numFound=");
    int j = resultXml.indexOf("\"", i + 10);
    String numFound = resultXml.substring(i + 10, j);
    if (numFound.equals("0"))
        indexDocExists = false;
    if (logger.isDebugEnabled())
        logger.debug("indexDocExists pid=" + pid + " indexDocExists=" + indexDocExists);
    return indexDocExists;
}

From source file:cn.knet.showcase.demos.servletproxy.ProxyServlet.java

/** For a redirect response from the target server, this translates {@code theUrl} to redirect to
 * and translates it to one the original client can use. */
protected String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl) {
    //TODO document example paths
    final String targetUri = getTargetUri(servletRequest);
    if (theUrl.startsWith(targetUri)) {
        /*-// w  w w.  j  av  a 2  s .c  o m
         * The URL points back to the back-end server.
         * Instead of returning it verbatim we replace the target path with our
         * source path in a way that should instruct the original client to
         * request the URL pointed through this Proxy.
         * We do this by taking the current request and rewriting the path part
         * using this servlet's absolute path and the path from the returned URL
         * after the base target URL.
         */
        StringBuffer curUrl = servletRequest.getRequestURL();//no query
        int pos;
        // Skip the protocol part
        if ((pos = curUrl.indexOf("://")) >= 0) {
            // Skip the authority part
            // + 3 to skip the separator between protocol and authority
            if ((pos = curUrl.indexOf("/", pos + 3)) >= 0) {
                // Trim everything after the authority part.
                curUrl.setLength(pos);
            }
        }
        // Context path starts with a / if it is not blank
        curUrl.append(servletRequest.getContextPath());
        // Servlet path starts with a / if it is not blank
        curUrl.append(servletRequest.getServletPath());
        curUrl.append(theUrl, targetUri.length(), theUrl.length());
        theUrl = curUrl.toString();
    }
    return theUrl;
}

From source file:org.ajax4jsf.webapp.WebXml.java

/**
 * Convert {@link org.ajax4jsf.resource.InternetResource } key to real URL
 * for handle by chameleon filter, depend of mapping in WEB.XML . For prefix
 * or * mapping, prepend servlet prefix and default Resource prefix to key.
 * For suffix mapping, prepend with resource prefix and append default faces
 * suffix to URL ( before request param ). After conversion, call
 * {@link javax.faces.application.ViewHandler#getResourceURL(javax.faces.context.FacesContext, java.lang.String)}
 * and//from w w  w.  j a  va2 s .  c o m
 * {@link javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)}
 * .
 *
 * @param context
 * @param Url
 * @return
 */
public String getFacesResourceURL(FacesContext context, String Url, boolean isGlobal) {
    StringBuffer buf = new StringBuffer();
    buf.append(isGlobal ? getGlobalResourcePrefix() : getSessionResourcePrefix()).append(Url);
    // Insert suffix mapping
    if (isPrefixMapping()) {
        buf.insert(0, getFacesFilterPrefix());
    } else {
        int index;
        if ((index = buf.indexOf("?")) >= 0) {
            buf.insert(index, getFacesFilterSuffix());
        } else {
            buf.append(getFacesFilterSuffix());
        }
    }
    String resourceURL = context.getApplication().getViewHandler().getResourceURL(context, buf.toString());
    return resourceURL;

}

From source file:net.alchemiestick.katana.winehqappdb.WineApp.java

@Override
protected String doInBackground(HttpUriRequest... url) {
    if (url[0] == null)
        return this.body;
    HttpResponse res = null;//from  ww  w.  j a  va2s .co m
    while (res == null)
        try {
            SearchView.do_sleep(500);
            res = this.client.execute(url[0]);
        } finally {
            continue;
        }

    while (res.getStatusLine() == null) {
        SearchView.do_sleep(500);
    }

    StringBuffer sb = new StringBuffer("");
    try {
        BufferedReader br = new BufferedReader(new InputStreamReader(res.getEntity().getContent()), (2 * 1024));
        String line;
        boolean first = true;
        while ((line = br.readLine()) != null) {
            if (first) {
                first = false;
                continue;
            }
            sb.append(line + "\n");
        }

        this.body = sb.substring(sb.indexOf("<body"), (sb.lastIndexOf("</body>") + 7));
    } catch (IOException ioe) {
        this.str = "IO Failed!!!:; ; ;";
        this.str += ioe.toString();
    } catch (Exception ex) {
    } finally {
        this.client.close();
    }
    return this.body;
}