Example usage for org.apache.commons.lang StringUtils splitPreserveAllTokens

List of usage examples for org.apache.commons.lang StringUtils splitPreserveAllTokens

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils splitPreserveAllTokens.

Prototype

public static String[] splitPreserveAllTokens(String str, String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

Usage

From source file:org.jboss.richfaces.integrationTest.extendedDataTable.SelectingTestCase.java

private int[] getRowSelection(String message) {
    String[] tokens = StringUtils.splitPreserveAllTokens(message, ',');
    int[] rows = new int[tokens.length];

    for (int i = 0; i < tokens.length; i++) {
        rows[i] = Integer.valueOf(tokens[i]);
    }//from   w  ww  .j a v  a2  s. c o m

    return rows;
}

From source file:org.jboss.richfaces.integrationTest.tableFiltering.TableFilteringTestCase.java

/**
 * Alternate between state input and timezone select filtering - enter to
 * each one predefined prefix (resp. value). Checks that only column
 * corresponding to set filter are displayed in whole table on all pages.
 *//* ww  w.  jav  a2 s .  co  m*/
@Test
public void externalFilteringTest() {

    openTab("External Filtering Usage");

    scrollIntoView(LOC_TABLE_COMMON, true);

    for (int i = 0; i < MSG_LIST_OF_PAIRS_STATE_TIMEZONE.length; i++) {
        String[] pair = StringUtils.splitPreserveAllTokens(MSG_LIST_OF_PAIRS_STATE_TIMEZONE[i], ':');

        // change state prefix
        String tableText = selenium.getText(LOC_TABLE_COMMON);

        selenium.type(LOC_INPUT_STATE, pair[0]);
        selenium.fireEvent(LOC_INPUT_STATE, Event.KEYUP);

        Wait.dontFail().timeout(5000).waitForChange(tableText, retrieveTableText);

        checkExternalFiltering();

        // change time zone
        tableText = selenium.getText(LOC_TABLE_COMMON);

        selenium.select(LOC_SELECT_TIMEZONE, pair[1]);
        selenium.fireEvent(LOC_SELECT_TIMEZONE, Event.CHANGE);

        Wait.dontFail().timeout(5000).waitForChange(tableText, retrieveTableText);

        checkExternalFiltering();
    }
}

From source file:org.jboss.richfaces.integrationTest.tableSorting.TableSortingTestCase.java

/**
 * Select three columns to sort table in predefined orders and checks that
 * after application of all settings are data sorted well.
 *///ww w .  j a  v  a2  s.  c o  m
@Test
public void testExternalSorting() {
    openTab("External Sorting");

    scrollIntoView(LOC_TABLE_COMMON, true);

    final int columns = MSG_LIST_OF_SORTED_COLUMNS.length;

    // define 3 columns sorting in table
    for (int column = 0; column < columns; column++) {
        final String[] association = StringUtils.splitPreserveAllTokens(MSG_LIST_OF_SORTED_COLUMNS[column],
                '|');
        final String msgLabel = association[0];
        final String msgColumnName = association[1];
        final String msgColumnOrder = association[2];

        final String locSelectColumn = format(LOC_SELECT_COLUMN_PREFORMATTED, msgLabel);
        final String locSelectOrder = format(LOC_SELECT_ORDER_PREFORMATTED, msgLabel);

        Wait.failWith(format("Given SELECTs never appeared - '{0}', '{1}'", locSelectColumn, locSelectOrder))
                .until(new Condition() {
                    public boolean isTrue() {
                        return selenium.isElementPresent(locSelectColumn)
                                && selenium.isElementPresent(locSelectOrder);
                    }
                });

        selenium.select(locSelectColumn, msgColumnName);
        selenium.select(locSelectOrder, msgColumnOrder);

        Wait.failWith("Sort table button never got enabled").until(new Condition() {
            public boolean isTrue() {
                return !selenium.isElementPresent(format("{0}[disabled]", LOC_BUTTON_SORT));
            }
        });
    }

    // check sorting
    String tableText = getTableText();

    selenium.click(LOC_BUTTON_SORT);
    waitForTextChanges(LOC_TABLE_COMMON, tableText);

    checkSortingForColumnOrder(LOC_LIST_OF_TD_PREFORMATTED);
}

From source file:org.jminix.console.resource.ValueParser.java

public Object parse(String value, String type) {
    Object result = null;/*w  ww . j  ava2s  . c o m*/

    if (type.equals("java.lang.String")) {
        return value;
    } else if (type.equals("java.lang.Byte") || type.equals("byte")) {
        if (isNullOrEmpty(value)) {
            return "byte".equals(type) ? (byte) 0 : null;
        }

        result = new Byte(value);
    } else if (type.equals("java.lang.Short") || type.equals("short")) {
        if (isNullOrEmpty(value)) {
            return "short".equals(type) ? (short) 0 : null;
        }

        result = new Short(value);
    } else if (type.equals("java.lang.Integer") || type.equals("int")) {
        if (isNullOrEmpty(value)) {
            return "int".equals(type) ? (int) 0 : null;
        }

        result = new Integer(value);
    } else if (type.equals("java.lang.Long") || type.equals("long")) {
        if (isNullOrEmpty(value)) {
            return "long".equals(type) ? (long) 0 : null;
        }

        result = new Long(value);
    } else if (type.equals("java.lang.Double") || type.equals("double")) {
        if (isNullOrEmpty(value)) {
            return "double".equals(type) ? (double) 0 : null;
        }

        result = new Double(value);
    } else if (type.equals("java.lang.Float") || type.equals("float")) {
        if (isNullOrEmpty(value)) {
            return "float".equals(type) ? (float) 0 : null;
        }

        result = new Float(value);
    } else if (type.equals("java.lang.Boolean") || type.equals("boolean")) {
        if (isNullOrEmpty(value)) {
            return "boolean".equals(type) ? false : null;
        }

        result = new Boolean(value);
    } else if (type.equals("[Ljava.lang.String;")) {
        result = StringUtils.splitPreserveAllTokens(value, stringArraySeparator);
    }

    if (result == null) {
        throw new RuntimeException("Type " + type + " is not supported");
    }

    return result;
}

From source file:org.jumpmind.symmetric.db.derby.DerbyFunctions.java

public static void insertData(int enabled, String schemaName, String prefixName, String tableName,
        String channelName, String dmlType, int triggerHistId, String transactionId, String externalData,
        String columnNames, String pkColumnNames) throws SQLException {
    if (enabled == 1) {
        TriggerExecutionContext context = Factory.getTriggerExecutionContext();
        String rowData = null;/*from   www  . jav a2 s  . c  o m*/
        String pkData = null;
        String oldData = null;
        String[] parsedColumnNames = StringUtils.splitPreserveAllTokens(columnNames, ',');
        String[] parsedPkColumnNames = StringUtils.splitPreserveAllTokens(pkColumnNames, ',');
        if (dmlType.equals("I") || dmlType.equals("U")) {
            StringBuilder dataBuilder = new StringBuilder();
            appendCsvString(tableName, parsedColumnNames, parsedPkColumnNames, context.getNewRow(),
                    dataBuilder);
            rowData = dataBuilder.substring(0, dataBuilder.length() - 1);
        }

        if (dmlType.equals("U") || dmlType.equals("D")) {
            StringBuilder dataBuilder = new StringBuilder();
            appendCsvString(tableName, parsedColumnNames, parsedPkColumnNames, context.getOldRow(),
                    dataBuilder);
            oldData = dataBuilder.substring(0, dataBuilder.length() - 1);

            dataBuilder = new StringBuilder();
            appendCsvString(tableName, parsedPkColumnNames, parsedPkColumnNames, context.getOldRow(),
                    dataBuilder);
            pkData = dataBuilder.substring(0, dataBuilder.length() - 1);

        }

        Connection conn = DriverManager.getConnection(CURRENT_CONNECTION_URL);
        StringBuilder sql = new StringBuilder("insert into ");
        sql.append(schemaName);
        sql.append(prefixName);
        sql.append(
                "_data (table_name, event_type, trigger_hist_id, pk_data, row_data, old_data, channel_id, transaction_id, source_node_id, external_data, create_time) ");
        sql.append(" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, current_timestamp)");
        PreparedStatement ps = conn.prepareStatement(sql.toString());
        ps.setString(1, tableName);
        ps.setString(2, dmlType);
        ps.setLong(3, triggerHistId);
        ps.setString(4, pkData);
        ps.setString(5, rowData);
        ps.setString(6, oldData);
        ps.setString(7, channelName);
        ps.setString(8, transactionId);
        ps.setString(9, getSyncNodeDisabled());
        ps.setString(10, externalData);
        ps.executeUpdate();
        ps.close();
        conn.close();
    }
}

From source file:org.jumpmind.util.FormatUtils.java

public static String[] wordWrap(String str, int lineSize) {
    if (str != null && str.length() > lineSize) {
        Pattern regex = Pattern.compile("(\\S\\S{" + lineSize + ",}|.{1," + lineSize + "})(\\s+|$)");
        List<String> list = new ArrayList<String>();
        Matcher m = regex.matcher(str);
        while (m.find()) {
            String group = m.group();
            // Preserve multiple newlines
            String[] lines = StringUtils.splitPreserveAllTokens(group, '\n');

            for (String line : lines) {
                // Trim whitespace from end since a space on the end can
                // push line wrap and cause an unintentional blank line.
                line = StringUtils.removeEnd(line, " ");
                list.add(line);//  ww  w. j ava  2s. c  o  m
            }
        }
        return (String[]) list.toArray(new String[list.size()]);
    } else {
        return new String[] { str };
    }
}

From source file:org.kiji.express.wikimedia.util.RevisionDelta.java

/**
 * Parses a delta string./*from ww w .j  av  a2s. c om*/
 *
 * @param delta The entire delta string.
 */
public RevisionDelta(String delta) {
    if (null == delta) {
        throw new IllegalArgumentException("delta may not be null.");
    }
    final String[] operationStrings = StringUtils.splitPreserveAllTokens(delta, INSTRUCTION_SEPERATOR);

    mOperations = new ArrayList<Operation>(operationStrings.length);
    for (String operationString : operationStrings) {
        mOperations.add(new Operation(operationString));
    }
}

From source file:org.kiji.mapreduce.bulkimport.DelimitedJsonBulkImporter.java

/**
 * Parse the line into separate data for each column family.
 *
 * @param line The line of input text from the file.
 * @return A list of column data.//from   w w  w  .ja v a2  s.co  m
 * @throws MalformedLineException if this line does not split to the same number
 *     of elements as <code>getColumnInfo().size()</code>.
 */
private String[] readColumnData(String line) throws MalformedLineException {
    String[] columnData = StringUtils.splitPreserveAllTokens(line, getColumnDelimiter());
    if (columnData.length != getColumnInfo().size()) {
        // Line is malformed.  Log error, and throw a handlable exception so
        // that the produce() method can skip this line.
        String message = "Row with incorrect number of columns: " + line + "  Expected "
                + getColumnInfo().size() + " but was " + columnData.length + ".";
        LOG.warn(message);
        throw new MalformedLineException(message);
    }
    return columnData;
}

From source file:org.kuali.kfs.module.endow.document.EndowmentAccountingLineParserBase.java

/**
 * Parses the csv line//from w  ww .j  a va 2s .  c om
 * 
 * @param accountingLineClass
 * @param lineToParse
 * @return Map containing accounting line attribute,value pairs
 */
protected Map<String, String> parseAccountingLine(Class<? extends EndowmentAccountingLine> accountingLineClass,
        String lineToParse) {
    if (StringUtils.isNotBlank(fileName) && !StringUtils.lowerCase(fileName).endsWith(".csv")) {
        throw new AccountingLineParserException("unsupported file format: " + fileName,
                ERROR_INVALID_FILE_FORMAT, fileName);
    }
    String[] attributes = chooseFormat(accountingLineClass);
    String[] attributeValues = StringUtils.splitPreserveAllTokens(lineToParse, ",");

    Map<String, String> attributeValueMap = new HashMap<String, String>();

    for (int i = 0; i < Math.min(attributeValues.length, attributes.length); i++) {
        attributeValueMap.put(attributes[i], attributeValues[i]);
    }

    return attributeValueMap;
}

From source file:org.kuali.kfs.module.endow.util.LineParserBase.java

/**
 * Parses a line of transactions data from a csv file and retrieves the attributes as key-value string pairs into a map.
 * /* w w  w  .j a v a 2 s .c o m*/
 * @param line a string read from a line in the line import file
 * @return a map containing line attribute name-value string pairs
 */
protected Map<String, String> retrieveLineAttributes(String line,
        Class<? extends EndowmentTransactionLine> lineClass) {
    String[] attributeNames = getLineFormat();
    String[] attributeValues = StringUtils.splitPreserveAllTokens(line, ',');

    if (attributeNames.length != attributeValues.length) {
        String[] errorParams = { "" + attributeNames.length, "" + attributeValues.length, "" + lineNo };
        GlobalVariables.getMessageMap().putError(TRANSACTION_LINE_ERRORS,
                EndowmentTransactionDocumentConstants.ERROR_LINEPARSER_WRONG_PROPERTY_NUMBER, errorParams);
        throw new LineParserException(
                "Wrong number of Line properties: " + attributeValues.length + " exist, "
                        + attributeNames.length + " expected (line " + lineNo + ")",
                EndowmentTransactionDocumentConstants.ERROR_LINEPARSER_WRONG_PROPERTY_NUMBER, errorParams);
    }

    Map<String, String> lineMap = new HashMap<String, String>();
    for (int i = 0; i < attributeNames.length; i++) {
        String attributeName = attributeNames[i];
        String attributeValue = attributeValues[i];
        // if the attribute has an forceUpper = true in the data dictionary, convert the value to upper case...
        if (SpringContext.getBean(DataDictionaryService.class).getAttributeForceUppercase(lineClass,
                attributeName)) {
            attributeValue = attributeValue.toUpperCase();
        }

        lineMap.put(attributeName, attributeValue);
    }
    return lineMap;
}