Example usage for java.lang StringBuilder replace

List of usage examples for java.lang StringBuilder replace

Introduction

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

Prototype

@Override
public StringBuilder replace(int start, int end, String str) 

Source Link

Usage

From source file:com.cisco.oss.foundation.tools.simulator.rest.resources.SimulatorResource.java

private String getQueryParamsStringForLogging(MultivaluedMap<String, String> multivaluedMap) {

    StringBuilder sb = new StringBuilder();

    for (String key : multivaluedMap.keySet()) {
        List<String> values = multivaluedMap.get(key);
        sb.append(key).append("=[");

        for (String value : values) {
            sb.append(value).append(",");
        }//w  ww  .ja v a  2  s.co m
        sb.replace(sb.length() - 1, sb.length(), "");
        sb.append("] ");
    }

    return sb.toString();
}

From source file:de.fhg.fokus.odp.portal.uploaddata.service.Worker.java

/**
 * substitutes last ',' by "}]" if there's any input.
 * /*from   w  w w  .j a va 2  s .  co  m*/
 * @param resourceStringBuilder
 */
private void finishParseResource(StringBuilder resourceStringBuilder) {
    int length = resourceStringBuilder.length();
    if (length > 2) {
        (resourceStringBuilder.replace(length - 1, length, "}")).append("]");
    } else {
        resourceStringBuilder.append("}]");
    }
}

From source file:com.certus.actions.uploadSliderImageAction.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String path = getServletContext().getRealPath("img/slider").replace("build/", "");
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);

    if (isMultipart) {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        try {/*w  w w  .  j  a v  a 2 s  .c om*/
            List<FileItem> multiparts = upload.parseRequest(request);
            StringBuilder sb = null;
            for (FileItem item : multiparts) {
                if (!item.isFormField()) {
                    double randomA = Math.random() * 1000000000;
                    int randA = (int) randomA;
                    String name = new File(item.getName()).getName();
                    sb = new StringBuilder(name);
                    sb.replace(0, name.length() - 4, "slider-" + randA);
                    item.write(new File(path + File.separator + sb));
                }
            }
            String pathTo = path + File.separator + sb;
            response.getWriter().write(pathTo.substring(pathTo.lastIndexOf("img")));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

From source file:com.nofuturecorp.www.connector.TransactOperation.java

@Override
public JSONObject toJSON() throws JSONException {
    StringBuilder builder = new StringBuilder();
    try {// w  w w  .j a va  2 s .  c o  m
        int cont = 0;
        builder.append("{\n");
        for (Operation mySQLOperation : operations) {
            builder.append("\"" + cont + "\":" + mySQLOperation.toJSON().toString());
            builder.append(",");
            cont++;
        }
        builder.replace(builder.length() - 1, builder.length(), "");
        builder.append("}\n");
    } catch (JSONException e) {
        return null;
    }
    return new JSONObject(builder.toString());
}

From source file:com.nofuturecorp.www.connector.TransactOperation.java

@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    try {/*from  w  w w .j a va 2s .  c  o  m*/
        int cont = 0;
        builder.append("{\n");
        for (Operation mySQLOperation : operations) {
            builder.append("\"" + cont + "\":" + mySQLOperation.toJSON().toString());
            builder.append(",");
            cont++;
        }
        builder.replace(builder.length() - 1, builder.length(), "");
        builder.append("}\n");
    } catch (JSONException e) {
        return null;
    }
    return builder.toString();
}

From source file:net.duckling.ddl.service.resource.dao.TagItemDAOImpl.java

@Override
public int deleteByTagIds(int[] tgids) {
    if (null == tgids || tgids.length <= 0) {
        return -1;
    }/*from w ww .j av  a2s  . co m*/
    StringBuilder sb = new StringBuilder();
    sb.append(" where tgid in(");
    for (int i = 0; i < tgids.length; i++) {
        sb.append(tgids[i] + ",");
    }
    sb.replace(sb.lastIndexOf(","), sb.length(), ")");
    return this.getJdbcTemplate().update(SQL_DELETE + sb.toString());
}

From source file:simplealbum.mvc.autocomplete.JTextPaneX.java

protected void colorStyledDocument(final DefaultStyledDocument document) {
    EventQueue.invokeLater(new Runnable() {

        @Override//from www  . j a  v a 2  s. co  m
        public void run() {
            String input = "";
            try {
                input = document.getText(0, document.getLength());
            } catch (BadLocationException ex) {
                Logger.getLogger(JTextPaneX.class.getName()).log(Level.SEVERE, null, ex);
            }

            StringBuilder inputMut = new StringBuilder(input);
            String[] split = StringUtils.split(inputMut.toString());
            int i = 0;
            for (String string : split) {
                int start = inputMut.indexOf(string);
                int end = start + string.length();
                inputMut.replace(start, end, StringUtils.repeat(" ", string.length()));
                document.setCharacterAttributes(start, string.length(), styles[i++ % styles.length], true);
            }
        }
    });
}

From source file:net.duckling.ddl.service.resource.dao.TagItemDAOImpl.java

@Override
public int removeItems(int tid, int tgid, List<Integer> rids) {
    if (null == rids || rids.isEmpty()) {
        return 0;
    }/*from   www.  j  a  v a2s .  c  o m*/
    StringBuilder sb = new StringBuilder();
    sb.append(" where tid=" + tid + " and tgid=" + tgid + " and rid in(");
    for (int rid : rids) {
        sb.append(rid + ",");
    }
    sb.replace(sb.lastIndexOf(","), sb.length(), ")");
    return this.getJdbcTemplate().update(SQL_DELETE + sb.toString());
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerFormLoadTest.java

@Test
public void testMultipleRequests() throws Exception {
    List<String> edRequests = new ArrayList<String>();

    edRequests.add(ControllerUtil.createEdsRequest("remoteProvider", "method1", 1,
            new Object[] { 3, 2.5, "string.param" }));
    edRequests.add(ControllerUtil.createEdsRequest("remoteProviderSimple", "method4", 2,
            new Object[] { 3, 2.5, "string.param" }));
    edRequests.add(ControllerUtil.createEdsRequest("remoteProviderSimple", "method1", 3, null));

    Map<String, Object> data = new HashMap<String, Object>();
    data.put("d", 1.1);
    edRequests.add(ControllerUtil.createEdsRequest("remoteProviderFormLoad", "method1", 4, data));

    data = new HashMap<String, Object>();
    data.put("d", 2.2);
    edRequests.add(ControllerUtil.createEdsRequest("remoteProviderFormLoad", "method1", 5, data));

    edRequests.add(/*from   w  w  w  . j  av  a2 s  .  com*/
            ControllerUtil.createEdsRequest("remoteProviderSimple", "method6", 6, new Object[] { 20, 20 }));

    StringBuilder sb = new StringBuilder();
    sb.append("[");
    for (String requests : edRequests) {
        sb.append(requests);
        sb.append(",");
    }
    sb.replace(sb.length() - 1, sb.length(), "]");

    MvcResult result = ControllerUtil.performRouterRequest(mockMvc, sb.toString());
    List<ExtDirectResponse> responses = ControllerUtil
            .readDirectResponses(result.getResponse().getContentAsByteArray());

    assertThat(responses).hasSize(6);
    ExtDirectResponse resp = responses.get(0);
    assertThat(resp.getAction()).isEqualTo("remoteProvider");
    assertThat(resp.getMethod()).isEqualTo("method1");
    assertThat(resp.getType()).isEqualTo("exception");
    assertThat(resp.getTid()).isEqualTo(1);
    assertThat(resp.getResult()).isNull();
    assertThat(resp.getMessage()).isEqualTo("Server Error");
    assertThat(resp.getWhere()).isNull();
    checkMethodNotFoundResponse(responses.get(1));
    checkNoParametersResponse(responses.get(2), 3);

    checkFormLoadResult(responses.get(3), 1.1, 4);
    checkFormLoadResult(responses.get(4), 2.2, 5);

    checkIntParameterResult(responses.get(5), 6, 40);
}

From source file:de.hybris.platform.acceleratorcms.services.impl.RankingCMSRestrictionService.java

protected String createMoreThanOneDefaultPageWarning(final Collection<AbstractPageModel> defaultPages) {
    final StringBuilder warningMessage = new StringBuilder(78);
    if (defaultPages.isEmpty()) {
        return warningMessage.toString();
    }//from   w w w  . j ava2  s .c o  m
    warningMessage.append("More than one default page defined! (");
    for (final AbstractPageModel defaultPage : defaultPages) {
        warningMessage.append(' ').append(defaultPage.getName()).append(',');
    }
    warningMessage.replace(warningMessage.length() - 1, warningMessage.length(), "");
    warningMessage.append(" ).");
    warningMessage.append(" First one will be taken as default.");
    return warningMessage.toString();
}