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.objectweb.proactive.extensions.vfsprovider.client.ProActiveFileNameParser.java

private static String extractServicePath(StringBuffer path) throws FileSystemException {
    if (path.length() > 0 && path.charAt(0) != FileName.SEPARATOR_CHAR) {
        throw new FileSystemException(
                "Invalid path in URI: service path after host name does not begin with slash");
    }/*from ww  w.  j ava  2s.  com*/

    int idx = path.indexOf(ProActiveFileName.SERVICE_AND_FILE_PATH_SEPARATOR);
    if (idx == -1) {
        // simply assume that whole path is a service path
        final String servicePath = path.toString();
        path.delete(0, path.length());
        return servicePath;
    }
    final String servicePath = path.substring(0, idx);
    path.delete(0, idx + ProActiveFileName.SERVICE_AND_FILE_PATH_SEPARATOR.length());
    return servicePath;
}

From source file:jp.co.opentone.bsol.framework.web.view.util.PageNavigationUtil.java

/**
 * ?viewId?url????.//from  w  w  w. ja v a 2s.c o m
 * @param contextPath ?ContextPath
 * @param viewId redirect?viewId
 * @param paramMap map
 * @param enc Character Encoding
 * @return redirect?url
 */
public static String createRedirectUrlFromViewId(String contextPath, String viewId,
        Map<String, String> paramMap, String enc) {
    StringBuffer url = new StringBuffer(contextPath);
    url.append(viewId.replace(".xhtml", ".jsf"));
    try {
        if (null != paramMap && 0 < paramMap.size()) {
            for (String key : paramMap.keySet()) {
                if (-1 == url.indexOf("?")) {
                    url.append('?');
                } else {
                    url.append('&');
                }
                String value = URLEncoder.encode(paramMap.get(key), enc);
                url.append(String.format("%s=%s", key, value));
            }
        }
    } catch (UnsupportedEncodingException e) {
        // ????????
        throw new AbortProcessingException(e);
    }
    return url.toString();
}

From source file:org.apache.axiom.attachments.impl.PartFactory.java

/**
 * Parse the header into a name and value pair.
 * Add the name value pair to the map.//  w  w  w .jav a 2s  .  c o m
 * @param header StringBuffer
 * @param headers Map
 */
private static void readHeader(StringBuffer header, Map headers) {
    int delimiter = header.indexOf(":");
    String name = header.substring(0, delimiter).trim();
    String value = header.substring(delimiter + 1, header.length()).trim();

    if (log.isDebugEnabled()) {
        log.debug("addHeader: (" + name + ") value=(" + value + ")");
    }
    Header headerObj = new Header(name, value);

    // Use the lower case name as the key
    String key = name.toLowerCase();
    headers.put(key, headerObj);
}

From source file:org.jmaki.model.impl.WidgetFactory.java

public static void replace(StringBuffer buff, String target, String replacement) {
    if (buff == null || target == null || replacement == null) {
        return;//from   w w w  .  jav a  2 s .  c  o  m
    }
    int index = 0;
    while (index < buff.length()) {
        index = buff.indexOf(target);
        if (index == -1) {
            break;
        }
        buff.replace(index, index + target.length(), replacement);
        index += replacement.length() + 1;
    }
}

From source file:com.wadpam.guja.oauth2.social.NetworkTemplate.java

public static String expandUrl(final String url, final String separator, Map<String, Object> paramMap) {
    StringBuffer sb = new StringBuffer(url);

    for (Entry<String, Object> entry : paramMap.entrySet()) {
        sb.append(-1 < sb.indexOf(separator) ? "&" : separator);
        sb.append(entry.getKey());//  ww w  .j  a v a2s. c o  m
        sb.append('=');
        try {
            sb.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
        } catch (UnsupportedEncodingException shouldNeverHappen) {
            LOG.error("Encoding parameter", shouldNeverHappen);
        }
    }

    return sb.toString();
}

From source file:org.sparqlbuilder.www.SPServlet.java

private static String rewriteSparql(String query) {
    StringBuffer tmp = new StringBuffer(query);
    int index = tmp.indexOf("WHERE");
    int begin = 0, cnt = 0;
    while (begin < index) {
        begin = tmp.indexOf("?c", begin);
        cnt++;/* ww w  .  jav  a2s  . c om*/

    }
    return null;
}

From source file:com.liusoft.dlog4j.action.ActionBase.java

protected static ActionForward makeForward(ActionForward forward, String p_name, String p_value) {
    StringBuffer uri = new StringBuffer(forward.getPath());
    if (uri.indexOf("?") >= 0)
        uri.append('&');
    else/*from w ww.ja  v  a  2  s .co  m*/
        uri.append('?');
    uri.append(p_name);
    uri.append('=');
    uri.append(p_value);
    return new ActionForward(uri.toString(), true);
}

From source file:com.liusoft.dlog4j.action.ActionBase.java

protected static ActionForward makeForward(ActionForward forward, int site_id, String extend) {
    StringBuffer uri = new StringBuffer(forward.getPath());
    if (uri.indexOf("?") >= 0)
        uri.append("&sid=");
    else/* ww w .jav  a  2  s . c  o m*/
        uri.append("?sid=");
    uri.append(site_id);
    if (StringUtils.isNotEmpty(extend)) {
        uri.append("&");
        uri.append(extend);
    }
    try {
        return new ActionForward(uri.toString(), true);
    } finally {
        uri = null;
    }
}

From source file:de.j4velin.mapsmeasure.Util.java

/**
 * Get the altitude data for a specific point
 * /*from  w  w  w  . j a v a 2 s .  c  o  m*/
 * @param p
 *            the point to get the altitude for
 * @param httpClient
 *            can be null if no network query should be performed
 * @param localContext
 *            can be null if no network query should be performed
 * @return the altitude at point p or -Float.MAX_VALUE if no valid data
 *         could be fetched
 * @throws IOException
 */
static float getAltitude(final LatLng p, final HttpClient httpClient, final HttpContext localContext)
        throws IOException {
    if (elevationCache == null) {
        elevationCache = new HashMap<LatLng, Float>(30);
    }
    if (elevationCache.containsKey(p)) {
        return elevationCache.get(p);
    } else if (httpClient != null && localContext != null) {
        float altitude = -Float.MAX_VALUE;
        String url = "http://maps.googleapis.com/maps/api/elevation/xml?locations=" + String.valueOf(p.latitude)
                + "," + String.valueOf(p.longitude) + "&sensor=true";
        HttpGet httpGet = new HttpGet(url);
        HttpResponse response = httpClient.execute(httpGet, localContext);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream instream = entity.getContent();
            int r = -1;
            StringBuffer respStr = new StringBuffer();
            while ((r = instream.read()) != -1)
                respStr.append((char) r);
            String tagOpen = "<elevation>";
            String tagClose = "</elevation>";
            if (respStr.indexOf(tagOpen) != -1) {
                int start = respStr.indexOf(tagOpen) + tagOpen.length();
                int end = respStr.indexOf(tagClose);
                altitude = Float.parseFloat(respStr.substring(start, end));
                elevationCache.put(p, altitude);
            }
            instream.close();
        }
        return altitude;
    } else {
        return elevationCache.get(p);
    }
}

From source file:pl.psnc.synat.wrdz.zmkd.invocation.RestServiceCallerUtils.java

/**
 * Constructs URI of the service based upon passed information.
 * /*from  w  ww  . j  a va 2  s  .com*/
 * @param address
 *            template address of the service
 * @param templateParams
 *            template parameters
 * @param queryParams
 *            query parameters
 * @return URI of the service
 * @throws URISyntaxException
 *             when correct URI cannot be constructed
 */
private static URI constructServiceURI(String address, List<ExecutionTemplateParam> templateParams,
        List<ExecutionQueryParam> queryParams) throws URISyntaxException {
    StringBuffer sb = new StringBuffer(address);
    for (ExecutionTemplateParam templateParam : templateParams) {
        String varParam = "{" + templateParam.getName() + "}";
        int idx = sb.indexOf(varParam);
        if (idx != -1) {
            sb.replace(idx, idx + varParam.length(), templateParam.getValue());
        }
    }
    boolean first = true;
    for (ExecutionQueryParam queryParam : queryParams) {
        if (first) {
            sb.append("?");
            first = false;
        } else {
            sb.append("&");
        }
        if (queryParam.getValues() != null) {
            for (String value : queryParam.getValues()) {
                sb.append(queryParam.getName()).append("=").append(value);
            }
        } else {
            sb.append(queryParam.getName());
        }
    }
    return new URI(sb.toString());
}