Example usage for java.lang StringBuilder delete

List of usage examples for java.lang StringBuilder delete

Introduction

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

Prototype

@Override
public StringBuilder delete(int start, int end) 

Source Link

Usage

From source file:net.sourceforge.vulcan.web.ProjectFileServlet.java

private String getFallbackParentPath(HttpServletRequest request, String workDir) {
    final StringBuilder pathInfo = new StringBuilder(request.getPathInfo());

    while (!getFile(workDir, pathInfo.toString(), true).exists()) {
        pathInfo.delete(pathInfo.lastIndexOf("/"), pathInfo.length());
    }//from  w w w  .j a  v a2 s.c  om

    final StringBuilder buf = new StringBuilder(request.getContextPath());
    buf.append(request.getServletPath());
    buf.append(pathInfo);
    buf.append("/");

    return buf.toString();
}

From source file:Main.java

/**
 * takes an escape'd XML string and converts it back to orginal text contents
 * /*from  www. j av a2  s  . c  o 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:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.DroppedBarcodeFinder.java

@Override
protected Archive doWork(final Archive archive, final QcContext context) throws ProcessorException {
    final List<BCRID> currentBarcodeList = bcrIdQueries.getArchiveBarcodes(archive.getId());
    final Archive previousArchive = context.getExperiment().getPreviousArchiveFor(archive);
    if (previousArchive != null) {
        final List<BCRID> previousBarcodeList = bcrIdQueries.getArchiveBarcodes(previousArchive.getId());
        final Collection<BCRID> droppedBarcodeList = filterBarcodes(currentBarcodeList, previousBarcodeList);
        if (droppedBarcodeList.size() > 0) {
            final StringBuilder warning = new StringBuilder(
                    "The following barcodes have been dropped in the archive '");
            warning.append(archive.getArchiveName());
            warning.append("': ");

            for (final BCRID bcrId : droppedBarcodeList) {
                warning.append(bcrId.getFullID()).append(", ");
            }/*from  w  w w . j  a  v a 2s.  c  om*/
            final int length = warning.length();
            warning.delete(length - 2, length - 1); // remove the extra , at the end
            context.addWarning(warning.toString());
        }
    }
    return archive;
}

From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java

protected Locale extractLocale(Resource resource, String suffix) {
    String filename = resource.getFilename();

    StringBuilder locale = new StringBuilder(filename);
    // Find the last part that fits the bundle's name
    int basenameIndex = filename.lastIndexOf(MESSAGES_BUNDLENAME);
    int length = MESSAGES_BUNDLENAME.length();

    // Remove everything before the basename, the basename and one more char to eat the '_'
    locale.delete(0, basenameIndex + length + 1);
    int suffixIndex = locale.lastIndexOf(suffix);
    locale.delete(suffixIndex, locale.length());

    return new Locale(locale.toString());
}

From source file:cz.strmik.cmmitool.web.controller.RatingController.java

private void addAggregatedMessage(Set<RatingScale> aggregated, ModelMap modelMap) {
    String result;//from   w  ww  .j  a  v  a 2  s. com
    if (aggregated.isEmpty()) {
        result = LangProvider.getString("team-judgement");
    } else {
        StringBuilder sb = new StringBuilder();
        for (RatingScale rs : aggregated) {
            sb.append(rs.getName());
            sb.append(", ");
        }
        if (sb.length() > 2) {
            sb.delete(sb.length() - 2, sb.length() - 1);
        }
        result = sb.toString();
    }
    modelMap.addAttribute("aggregatedMessage", result);
}

From source file:com.gargoylesoftware.htmlunit.libraries.DojoTestBase.java

private String normalize(final String text) {
    StringBuilder normalized = new StringBuilder();

    for (int i = 0; i < text.length(); i++) {
        char ch = text.charAt(i);
        if (ch == 'f' && (text.indexOf("function ", i) == i || text.indexOf("function(", i) == i)) {
            if (normalized.toString().endsWith("(")) {
                normalized.delete(normalized.length() - 1, normalized.length());
            }/*from  ww  w.  j a va2 s  .co  m*/
            normalized = new StringBuilder(normalized.toString().trim());

            normalized.append("  function...");
            int count = 1;
            i = text.indexOf("{", i);
            while (i < text.length()) {
                i++;
                ch = text.charAt(i);
                if ('{' == ch) {
                    count++;
                } else if ('}' == ch) {
                    count--;
                }
                if (count == 0) {
                    break;
                }
            }
            if (normalized.toString().endsWith(")")) {
                normalized.delete(normalized.length() - 1, normalized.length());
            }
        } else if (ch == 'T' && text.indexOf("TypeError: ", i) == i) {
            normalized.append("TypeError:...");
            while (i < text.length()) {
                i++;
                ch = text.charAt(i);
                if ('\r' == ch || '\n' == ch) {
                    break;
                }
            }
        } else {
            normalized.append(ch);
        }
    }
    return normalized.toString();
}

From source file:cn.guoyukun.spring.jpa.repository.callback.DefaultSearchCallback.java

public void prepareOrder(StringBuilder ql, Searchable search) {
    if (search.hashSort()) {
        ql.append(" order by ");
        for (Sort.Order order : search.getSort()) {
            ql.append(String.format("%s%s %s, ", getAliasWithDot(), order.getProperty(),
                    order.getDirection().name().toLowerCase()));
        }// w w  w.  j a  v  a2  s . co m

        ql.delete(ql.length() - 2, ql.length());
    }
}

From source file:it.unibas.spicy.model.algebra.query.operators.sql.GenerateSQL.java

/*************************** SQL GENERATION FOR PRIMARY KEY TRIGGER FUNCTIONS DURING SCHEMA LOADING
 * @param table/*from  ww  w  .java2  s.  c  o m*/
 * @param tableName
 * @param schemaName
 * @param PKcolumnNames
 * @return  ******************************************************/

public static String createTriggerFunction(String table, String schemaName, String tableName,
        List<String> PKcolumnNames) {
    String tempTable = SpicyEngineConstants.WORK_SCHEMA_NAME + ".\"" + tableName + "\"";
    StringBuilder result = new StringBuilder();
    result.append("CREATE OR REPLACE FUNCTION ").append(schemaName).append(".").append(tableName)
            .append("_check_not_equal()\n");
    result.append("RETURNS trigger AS ' begin\n");
    result.append("if exists (select * from ").append(table).append(" where ");
    for (String PKcolumnName : PKcolumnNames) {
        result.append(table).append(".").append(PKcolumnName).append(" = new.").append(PKcolumnName)
                .append(" and ");
    }
    //delete the last " and "
    result.delete(result.length() - 5, result.length());
    result.append(") then\n");
    result.append("EXECUTE ''create table if not exists ").append(tempTable).append(" (like ").append(table)
            .append(")''; \n");
    result.append("insert into ").append(tempTable).append(" SELECT (NEW).*; \n");
    result.append("raise NOTICE ''").append(SpicyEngineConstants.PRIMARY_KEY_CONSTR_NOTICE).append(tableName)
            .append("'';");
    result.append("return null; \n");
    result.append("end if; \n");
    result.append("return new; \n");
    result.append("end; ' LANGUAGE plpgsql;");
    return result.toString();
}

From source file:com.uvt.whitelab.util.ResultHandler.java

private String loadStylesheet(String name) throws IOException {
    // clear string builder
    StringBuilder builder = new StringBuilder();
    builder.delete(0, builder.length());

    BufferedReader br = new BufferedReader(
            new FileReader(this.servlet.getRealPath() + "WEB-INF/stylesheets/" + name));

    String line;//  w w  w  .  j  av a 2  s  .co m

    this.servlet.log("Loading stylesheet: " + name);

    // read the response from the webservice
    while ((line = br.readLine()) != null)
        builder.append(line);

    br.close();

    return builder.toString();
}

From source file:monasca.thresh.utils.StatsdMetricConsumer.java

private List<Metric> dataPointsToMetrics(TaskInfo taskInfo, Collection<DataPoint> dataPoints) {
    List<Metric> res = new LinkedList<>();

    StringBuilder sb = new StringBuilder().append(clean(taskInfo.srcComponentId)).append(".");

    int hdrLength = sb.length();

    for (DataPoint p : dataPoints) {

        sb.delete(hdrLength, sb.length());
        sb.append(clean(p.name));/*from   ww  w.  jav a 2s.  c o  m*/

        logger.debug("Storm StatsD metric p.name ({}) p.value ({})", new Object[] { p.name, p.value });

        if (p.value instanceof Number) {
            res.add(new Metric(sb.toString(), ((Number) p.value).doubleValue()));
        }
        // There is a map of data points and it's not empty
        else if (p.value instanceof Map && !(((Map<?, ?>) (p.value)).isEmpty())) {
            int hdrAndNameLength = sb.length();
            @SuppressWarnings("rawtypes")
            Map map = (Map) p.value;
            for (Object subName : map.keySet()) {
                Object subValue = map.get(subName);
                if (subValue instanceof Number) {
                    sb.delete(hdrAndNameLength, sb.length());
                    sb.append(".").append(clean(subName.toString()));

                    res.add(new Metric(sb.toString(), ((Number) subValue).doubleValue()));
                }
            }
        }
    }
    return res;
}