Example usage for java.lang StringBuffer insert

List of usage examples for java.lang StringBuffer insert

Introduction

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

Prototype

@Override
public StringBuffer insert(int offset, double d) 

Source Link

Usage

From source file:org.squale.squalix.tools.compiling.java.parser.rsa.JRSAParser.java

/**
 * Parse le manifest/*from  w w  w. j av  a 2s  .  c  o m*/
 * 
 * @param pProject le projet
 * @param pManifest le manifest  parser
 * @param earProject le nom du projet EAR
 * @throws Exception si erreur
 */
public void parseManifest(JWSADProject pProject, File pManifest, StringBuffer earProject) throws Exception {
    LOGGER.info("On parse le manifest de " + pProject.getName() + " pour trouver les librairies EAR");
    // Chaque ligne peut-tre CR LF | LF | CR(not followed by LF) code ASCII 13 et 10";
    // On rcupre toutes les valeurs (commence par un espace et se termine par un espace)
    BufferedReader reader = new BufferedReader(new FileReader(pManifest));

    StringBuffer value = new StringBuffer();
    String line = reader.readLine();
    while (null != line && !line.startsWith(CLASS_PATH)) {
        // on parse jusqu' trouver la partie qui nous intresse
        line = reader.readLine();
    }
    if (null != line) {
        // On rcupre chaque lib
        line = line.replaceFirst(CLASS_PATH, "");
        String[] libs = line.split(" +"); // On spare les libs qui sont spares par un ou plsr espaces
        for (int i = 0; i < libs.length; i++) {
            if (i == libs.length - 1 && !line.endsWith(" ")) {
                value = earProject;
                value.append(line.trim());
            } else if (libs[i].trim().length() > 0) {
                // On ajoute la valeur au classpath
                processLib(pProject, earProject + libs[i].trim(), false);
                value.setLength(0);
            }
        }
        // On parcours jusqu' ce qu'in ligne ne commence pas par un espace
        line = reader.readLine();
        while (null != line && line.matches(" +.*")) {
            // Si il y a plus d'un espace en dbut de ligne
            // ou un espace sans rien derrire
            if (line.matches("  +| ") && value.length() > 0) {
                // nouvelle ligne
                value.insert(0, earProject);
                processLib(pProject, value.toString(), false);
                value.setLength(0);
            }
            libs = line.split(" +"); // On spare les libs qui sont spares par un ou plsr espaces
            for (int i = 0; i < libs.length; i++) {
                if (i == libs.length - 1 && !line.endsWith(" ")) {
                    value.append(libs[i].trim());
                } else if (libs[i].trim().length() > 0) {
                    if (value.length() > 0) {
                        value.append(libs[i].trim());
                    }
                    // On ajoute la valeur au classpath
                    processLib(pProject, earProject + libs[i].trim(), false);
                    value.setLength(0);
                }
            }
            line = reader.readLine();
        }
    }
}

From source file:cx.fbn.nevernote.sql.REnSearch.java

private void resolveSearch(String search) {
    List<String> words = new ArrayList<String>();
    StringBuffer b = new StringBuffer(search);

    int len = search.length();
    char nextChar = ' ';
    boolean quote = false;
    for (int i = 0, j = 0; i < len; i++, j++) {
        if (search.charAt(i) == nextChar && !quote) {
            b.setCharAt(j, '\0');
            nextChar = ' ';
        } else {//from  w  w  w .  jav  a 2 s. co  m
            if (search.charAt(i) == '\"') {
                if (!quote) {
                    quote = true;
                } else {
                    quote = false;
                    j++;
                    b.insert(j, "\0");
                }
            }
        }
        if (((i + 2) < len) && search.charAt(i) == '\\') {
            i = i + 2;
        }
    }

    search = b.toString();
    int pos = 0;
    for (int i = 0; i < search.length(); i++) {
        if (search.charAt(i) == '\0') {
            search = search.substring(1);
            i = 0;
        } else {
            pos = search.indexOf('\0');
            if (pos > 0) {
                words.add(search.substring(0, pos).toLowerCase());
                search = search.substring(pos);
                i = 0;
            }
        }
    }
    if (search.charAt(0) == '\0')
        words.add(search.substring(1).toLowerCase());
    else
        words.add(search.toLowerCase());
    parseTerms(words);
}

From source file:com.grossbart.jslim.JSlim.java

private String getConcatenatedStringIndex(Node getElem) {
    if (getElem.getFirstChild().getNext().getType() == Token.STRING) {
        /*/*  w  ww  .  j  a  v  a2s.  c  om*/
         Then this is a simple string reference like obj['hello']
         and we can just return the string
         */
        return getElem.getFirstChild().getNext().getString();
    } else if (getElem.getFirstChild().getNext().getType() == Token.ADD) {
        /*
         Then this is a concatenated string like obj['h' + 'el' + 'lo']
         */

        StringBuffer sb = new StringBuffer();
        Node current = getElem.getFirstChild().getNext();
        while (current != null) {
            if (current.getFirstChild().getType() == Token.ADD) {
                String s = getString(current.getFirstChild().getNext());
                if (s != null) {
                    sb.insert(0, s);
                } else {
                    return null;
                }
                current = current.getFirstChild();
            } else if (current.getFirstChild().getType() == Token.STRING) {
                String s = getString(current.getFirstChild().getNext());
                if (s != null) {
                    sb.insert(0, s);
                } else {
                    return null;
                }

                s = getString(current.getFirstChild());
                if (s != null) {
                    sb.insert(0, s);
                } else {
                    return null;
                }
                current = null;
            } else {
                current = null;
            }
        }

        return sb.toString();
    } else {
        /*
         Then this was some more complex type of string like
         obj[('h' + 'el' + 'lo').substring(2)].  We can't evaluate
         that string with just static evaluation so the user
         will have to declare an external for that.
         */
        return null;
    }
}

From source file:com.sfs.whichdoctor.beans.BulkEmailBean.java

/**
 * Gets the append description.//w ww .  ja  v a2  s .  c  o m
 *
 * @return the append description
 */
public final String getAppendDescription() {
    final StringBuffer description = new StringBuffer();

    if (this.appendContact) {
        description.append("contact details");
    }
    if (this.appendLogo) {
        if (description.length() > 0) {
            if (this.appendPrivacy) {
                description.append(", ");
            } else {
                description.append(" and ");
            }
        }
        description.append("logo");
    }
    if (this.appendPrivacy) {
        if (description.length() > 0) {
            description.append(" and ");
        }
        description.append("privacy statement");
    }

    if (description.length() > 0) {
        description.insert(0, "Appended ");
        description.append(".");
    }
    if (this.getDeliverOutOfHours()) {
        if (description.length() > 0) {
            description.append(" ");
        }
        description.append("Delivered outside of office hours.");
    }

    return description.toString();
}

From source file:org.dspace.browse.BrowseDAOOracle.java

/**
 * Prepare the select clause using the pre-prepared arguments.  This will produce something
 * of the form://from  w  ww  .  j a  v a2 s.c o m
 *
 * <code>
 * SELECT [arguments] FROM [table]
 * </code>
 */
private void buildSelectStatement(StringBuffer queryBuf, List<Serializable> params) throws BrowseException {
    if (queryBuf.length() == 0) {
        throw new BrowseException("No arguments for SELECT statement");
    }

    if (table == null || "".equals(table)) {
        throw new BrowseException("No table for SELECT statement");
    }

    // queryBuf already contains what we are selecting,
    // so insert the statement at the beginning
    queryBuf.insert(0, "SELECT ");

    // Then append the table
    queryBuf.append(" FROM ");
    queryBuf.append(table);
    if (containerTable != null
            || (value != null && valueField != null && tableDis != null && tableMap != null)) {
        queryBuf.append(", (SELECT ");
        if (containerTable != null) {
            queryBuf.append(containerTable).append(".item_id");
        } else {
            queryBuf.append("DISTINCT ").append(tableMap).append(".item_id");
        }
        queryBuf.append(" FROM ");
        buildFocusedSelectTables(queryBuf);
        queryBuf.append(" WHERE ");
        buildFocusedSelectClauses(queryBuf, params);
        queryBuf.append(") mappings");
    }
    queryBuf.append(" ");
}

From source file:org.dspace.browse.BrowseDAOOracle.java

/**
 * Prepare the select clause using the pre-prepared arguments.  This will produce something
 * of the form://from   w ww.j  a  va2s .c o  m
 *
 * <code>
 * SELECT [arguments] FROM [table]
 * </code>
 *
 * @param queryBuf  the string value obtained from distinctClause, countClause or selectValues
 * @return  the SELECT part of the query
 */
private void buildSelectStatementDistinct(StringBuffer queryBuf, List<Serializable> params)
        throws BrowseException {
    if (queryBuf.length() == 0) {
        throw new BrowseException("No arguments for SELECT statement");
    }

    if (table == null || "".equals(table)) {
        throw new BrowseException("No table for SELECT statement");
    }

    // queryBuf already contains what we are selecting,
    // so insert the statement at the beginning
    queryBuf.insert(0, "SELECT ");

    // Then append the table
    queryBuf.append(" FROM ");
    queryBuf.append(table);
    if (containerTable != null && tableMap != null) {
        queryBuf.append(", (SELECT DISTINCT ").append(tableMap).append(".distinct_id ");
        queryBuf.append(" FROM ");
        buildFocusedSelectTables(queryBuf);
        queryBuf.append(" WHERE ");
        buildFocusedSelectClauses(queryBuf, params);
        queryBuf.append(") mappings");
    }
    queryBuf.append(" ");
}

From source file:fitnesserefactor.FitnesseRefactor.java

public void ModifiedTable(File file, int ColumnNum) throws IOException {
    int TotalColData = EditArea.getLineCount();
    if (TotalColData != 0) {
        String[] ColumnData = EditArea.getText().split("\\n");
        String ModifiedLine;/*from w  w w .  j  ava  2s  .c om*/
        ModifiedLines = new ArrayList();
        ArrayList noOfPipes = new ArrayList();
        int l = p + 1;
        String line;
        int TotalLinesInTable = 0;
        do {
            line = (String) FileUtils.readLines(file).get(l);
            TotalLinesInTable = TotalLinesInTable + 1;
            l++;
        } while (!line.isEmpty());
        int k = 1;
        int t = 0;
        do {
            ModifiedLine = (String) FileUtils.readLines(file).get(p + k);
            if (ModifiedLine.isEmpty()) {
                break;
            }
            StringBuffer buff = new StringBuffer(ModifiedLine);
            for (int pipes = 0; pipes < ModifiedLine.length(); pipes++) {
                char ch = ModifiedLine.charAt(pipes);
                if (ch == '|') {
                    noOfPipes.add(pipes);
                }
            }
            int TotalPipes = noOfPipes.size();
            int length = ColumnData.length;
            if (length > t && !ColumnData[t].isEmpty()) {
                buff.insert((int) noOfPipes.get(ColumnNum - 1), "|" + ColumnData[t]);
                ModifiedLines.add(buff.toString());
            } else {
                buff.insert((int) noOfPipes.get(ColumnNum - 1), "| ");
                ModifiedLines.add(buff.toString());
            }
            k++;
            t++;
        } while (!ModifiedLine.isEmpty());
    } else {
        JOptionPane.showMessageDialog(null, "Please enter the column header to added the column", "Error",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.liferay.portal.util.HttpImpl.java

public String getCompleteURL(HttpServletRequest request) {
    StringBuffer sb = request.getRequestURL();

    if (sb == null) {
        sb = new StringBuffer();
    }/*from  w ww  .  java 2s.  c o m*/

    if (request.getQueryString() != null) {
        sb.append(StringPool.QUESTION);
        sb.append(request.getQueryString());
    }

    String proxyPath = PortalUtil.getPathProxy();

    if (Validator.isNotNull(proxyPath)) {
        int x = sb.indexOf(Http.PROTOCOL_DELIMITER) + Http.PROTOCOL_DELIMITER.length();
        int y = sb.indexOf(StringPool.SLASH, x);

        sb.insert(y, proxyPath);
    }

    String completeURL = sb.toString();

    if (request.isRequestedSessionIdFromURL()) {
        HttpSession session = request.getSession();

        String sessionId = session.getId();

        completeURL = PortalUtil.getURLWithSessionId(completeURL, sessionId);
    }

    if (_log.isWarnEnabled()) {
        if (completeURL.contains("?&")) {
            _log.warn("Invalid url " + completeURL);
        }
    }

    return completeURL;
}

From source file:org.apache.hive.jdbc.HivePreparedStatement.java

/**
 * update the SQL string with parameters set by setXXX methods of {@link PreparedStatement}
 *
 * @param sql//  w  ww .  j a va2s.c o  m
 * @param parameters
 * @return updated SQL string
 */
private String updateSql(final String sql, HashMap<Integer, String> parameters) {

    StringBuffer newSql = new StringBuffer(sql);

    int paramLoc = 1;
    while (getCharIndexFromSqlByParamLocation(sql, '?', paramLoc) > 0) {
        // check the user has set the needs parameters
        if (parameters.containsKey(paramLoc)) {
            int tt = getCharIndexFromSqlByParamLocation(newSql.toString(), '?', 1);
            newSql.deleteCharAt(tt);
            newSql.insert(tt, parameters.get(paramLoc));
        }
        paramLoc++;
    }

    return newSql.toString();

}

From source file:com.linuxbox.enkive.docsearch.indri.IndriQueryComposer.java

/**
 * Creates an Indri query by using the filter-require (#filreq) and
 * filter-reject (#filrej) operators to filter the results. Then it uses the
 * #compose operator to rank/weight the result of the the required elements.
 * If there are no required elements, it uses a simple #not to complete the
 * query./*from www  .j av a  2  s  .  c o  m*/
 * 
 * @param query
 * @return
 * @throws DocSearchException
 */
public static CharSequence composeQuery(TextQueryParser.Query query) throws DocSearchException {
    if (LOGGER.isTraceEnabled()) {
        StringBuilder output = new StringBuilder();
        boolean first = true;
        for (Phrase p : query) {
            if (first) {
                first = false;
            } else {
                output.append(", ");
            }
            output.append(p.getTermsAsCharSeq());
        }
        LOGGER.trace("composeQuery receives phrases: " + output.toString());
    }

    StringBuffer result = new StringBuffer();

    /*
     * Separate the requirements and the rejections and sanitize in place.
     */
    List<Phrase> requirements = new LinkedList<Phrase>();
    List<Phrase> rejections = new LinkedList<Phrase>();
    for (Phrase p : query) {
        sanitizePhraseInPlace(p);

        if (p.isNegated()) {
            rejections.add(p);
        } else {
            requirements.add(p);
        }
    }

    if (!requirements.isEmpty()) {
        // prefer to combine requirements with #combine, which does some
        // perhaps useful weighting of search terms based on frequency
        if (requirements.size() > 1) {
            result.append("#combine(");
        }

        for (Phrase p : requirements) {
            result.append(composePhrase(p));
            result.append(' ');
        }
        result.deleteCharAt(result.length() - 1);

        if (requirements.size() > 1) {
            result.append(")");
        }
    } else if (!rejections.isEmpty()) {
        // if everything is negation, so we have something in the query,
        // just prohibit the first element, given that we've already
        // #filrej'ed everything
        result.append("#not(");
        result.append(composePhrase(rejections.get(0)));
        result.append(')');
    } else {
        throw new DocSearchException("illegal query: empty");
    }

    // now we have the core; lets add the filters to the outside; since
    // requirements (#filereq) are likely to reduce the number of results
    // more quickly, make that the outer filter with the rejections within.

    // first wrap rejection filter if necessary
    if (!rejections.isEmpty()) {
        StringBuffer prefix = new StringBuffer("#filrej(");

        if (rejections.size() > 1) {
            prefix.append("#syn(");
        }

        for (Phrase p : rejections) {
            prefix.append(composePhrase(p));
            prefix.append(' ');
        }

        // delete last space
        prefix.deleteCharAt(prefix.length() - 1);

        if (rejections.size() > 1) {
            prefix.append(')');
        }

        prefix.append(' ');

        result.insert(0, prefix);
        result.append(")");
    }

    // now wrap requirements filter if necessary; this will be executed
    // before any rejection filter
    if (!requirements.isEmpty()) {
        StringBuffer prefix = new StringBuffer("#filreq(");

        if (requirements.size() > 1) {
            prefix.append("#band(");
        }

        for (Phrase p : requirements) {
            prefix.append(composePhrase(p));
            prefix.append(' ');
        }

        // delete last space
        prefix.deleteCharAt(prefix.length() - 1);

        if (requirements.size() > 1) {
            prefix.append(')');
        }

        prefix.append(' ');

        result.insert(0, prefix);
        result.append(")");
    }

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("composeQuery produces: " + result);
    }
    return result;
}