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

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

Introduction

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

Prototype

public static String remove(String str, char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

Usage

From source file:com.cubusmail.mail.util.MessageUtils.java

/**
 * Filter the messages.//from  www. j  av  a  2s  . c om
 * 
 * @param msgs
 * @param searchFields
 * @param searchText
 * @return
 */
public static Message[] quickFilterMessages(Message[] msgs, String searchFields, String searchText) {

    if (!StringUtils.isEmpty(searchFields) && !StringUtils.isEmpty(searchText)) {
        searchFields = StringUtils.remove(searchFields, '[');
        searchFields = StringUtils.remove(searchFields, ']');
        searchFields = StringUtils.remove(searchFields, '\"');
        String[] fields = StringUtils.split(searchFields, ',');
        List<Message> filteredMsgs = new ArrayList<Message>();

        Date searchDate = null;
        try {
            searchDate = DateUtils.parseDate(searchText, new String[] { "dd.MM.yyyy" });
        } catch (Exception e) {
            // do nothing
        }

        try {
            for (Message message : msgs) {
                boolean contains = false;
                for (String searchField : fields) {
                    if (MessageListFields.SUBJECT.name().equals(searchField)) {
                        String subject = message.getSubject();
                        contains = StringUtils.containsIgnoreCase(subject, searchText);
                    } else if (MessageListFields.FROM.name().equals(searchField)) {
                        String from = MessageUtils.getMailAdressString(message.getFrom(),
                                AddressStringType.COMPLETE);
                        contains = StringUtils.containsIgnoreCase(from, searchText) || contains;
                    } else if (searchDate != null && MessageListFields.DATE.name().equals(searchField)) {
                        Date sendDate = message.getSentDate();
                        contains = (sendDate != null && DateUtils.isSameDay(searchDate, sendDate)) || contains;
                    }
                }
                if (contains) {
                    filteredMsgs.add(message);
                }
            }
        } catch (MessagingException ex) {
            log.warn(ex.getMessage(), ex);
        }

        return filteredMsgs.toArray(new Message[0]);
    }

    return msgs;
}

From source file:com.opengamma.bbg.BloombergHistoricalTimeSeriesSource.java

private String printYYYYMMDD(LocalDate localDate) {
    String formatted = DateTimeFormatters.isoLocalDate().print(localDate);
    return StringUtils.remove(formatted, '-');
}

From source file:com.qualogy.qafe.business.resource.rdb.query.QueryToStringCreator.java

/**
 * @param userOperator/*from  ww  w .  j  a va  2s.  c  o  m*/
 * @param userFilledValue
 * @param columnName
 * @param namedParameters
 * @return
 */
private static String generateConditionForUserFilledValue(boolean isReverseCondition, String userOperator,
        String userFilledValue, String columnName, MapSqlParameterSource namedParameters) {
    String sql = "";
    if (isLikeOperator(userOperator)) {
        sql = replaceUserOperatorInLikeSqlStatement(isReverseCondition, columnName, userFilledValue);
    } else if (userOperator.equals("NULL")) {
        sql = replaceUserOperatorInNULLSqlStatement(isReverseCondition, columnName);
    } else if (userOperator.equals("IN")) {
        sql = replaceUserOperatorInINSqlStatement(columnName, userFilledValue);
    } else if (userOperator.equals("NOT")) {
        sql = replaceUserOperatorInNOTSqlStatement(columnName, userFilledValue, namedParameters);
    } else if (userOperator.equals("BETWEEN")) {
        sql = replaceUserOperatorInBetweenSqlStatement(columnName, userFilledValue);
    } else {
        String userFilledValueWithoutOperator = StringUtils.remove(userFilledValue, userOperator);
        namedParameters.addValue(columnName, userFilledValueWithoutOperator);

        sql += (columnName + userOperator + ":" + columnName);
    }
    sql = removeFromEnd(sql, "AND");
    sql += " AND ";
    return sql;
}

From source file:easycare.load.util.db.loader.UserDataLoader.java

public void buildUser(ContextOfCurrentLoad context, String userName, Title title, String firstName,
        String lastName, Organisation organisation, List<Role> roles, Location... locations) {

    String organisationNumber = StringUtils.remove(organisation.getAccountNumber(), "APT");
    String email = userName + "@" + organisationNumber + ".com";
    buildUser(context, userName, title, firstName, lastName, email, UserGeneratorHelper.DEFAULT_PASSWORD,
            organisation, roles, locations);
}

From source file:com.taobao.android.builder.tools.solib.NativeSoUtils.java

/**
 * ?//from w ww.jav  a 2  s. c o m
 *
 * @param baseDir
 * @param file
 * @return
 */
public static String getRelativePath(File baseDir, File file) {
    return StringUtils.remove(file.getAbsolutePath(), baseDir.getAbsolutePath());
}

From source file:hydrograph.ui.engine.ui.util.ImportedSchemaPropagation.java

private ComponentsOutputSchema getComponentOutputSchemaFromInputPort(Component component, String inputPortId) {
    inputPortId = StringUtils.remove(inputPortId, Constants.COPY_FROM_INPUT_PORT_PROPERTY);
    ComponentsOutputSchema componentsOutputSchema = null;
    for (Link link : component.getTargetConnections()) {
        if (StringUtils.equalsIgnoreCase(link.getTargetTerminal(), inputPortId)) {
            componentsOutputSchema = SchemaPropagation.INSTANCE.getComponentsOutputSchema(link);
        }//from   w  w w . j a  v  a 2  s.co m
    }
    return componentsOutputSchema;
}

From source file:gov.nih.nci.sdk.modelconverter.xmi2ecore.XMI2EcoreModelConverter.java

static String getValueForToken(String line, String token) {
    if (line.endsWith("/>")) {
        line = line.substring(0, line.length() - 2);
    } else if (line.endsWith(">")) {
        line = line.substring(0, line.length() - 2);
    }//from w ww .j  a va 2s .  co m
    int nameIndex = line.indexOf(token + '=');
    if (nameIndex == -1)
        return null;

    int startIndex = nameIndex + token.length() + 1;
    int endIndex = line.indexOf(' ', startIndex + 1);
    String s = (endIndex != -1) ? line.substring(startIndex, endIndex) : line.substring(startIndex);
    s = StringUtils.remove(s, '"');
    return s;
}

From source file:edu.ku.brc.specify.dbsupport.SpecifyQueryAdjusterForDomain.java

/**
 * @param specialSQL/*  ww w . ja  va 2 s  .  c o  m*/
 * @param key
 * @return
 */
private String removeSpecialFilter(final String specialSQL, final String key) {
    String lowerSQL = specialSQL.toLowerCase();

    String frontStr = "";
    String whereStr = "";

    int whereInx = lowerSQL.indexOf("where");
    if (whereInx == -1) {
        whereInx = 0;
        whereStr = specialSQL;
    } else {
        whereInx += 6;
        frontStr = specialSQL.substring(0, whereInx);
        whereStr = itrim(specialSQL.substring(whereInx, specialSQL.length()));//.replaceAll("\n", ""));
        lowerSQL = itrim(lowerSQL.substring(whereInx, specialSQL.length()));//.replaceAll("\n", ""));
    }

    //System.out.println("["+lowerSQL+"]\n["+whereStr+"]");

    int inx = whereStr.indexOf(key);
    if (inx > -1) {
        int endInx = inx + key.length();
        if (endInx < whereStr.length() && lowerSQL.charAt(endInx) == ')') {
            int startInx = lowerSQL.lastIndexOf('(', inx);
            if (startInx > -1) // here we have source.replaceAll("\\b\\s{2,}\\b", " ");the bounds of the '(' to ')'
            {
                // Now check to see what is ahead of it
                int bInx = checkAhead(lowerSQL, startInx, "and");
                if (bInx > 0) {
                    startInx -= bInx;
                } else {
                    bInx = checkAhead(lowerSQL, startInx, "or");
                    if (bInx > 0) {
                        startInx -= bInx;
                    } else {
                        // check after
                        int eInx = checkAfter(lowerSQL, endInx, "and");
                        if (eInx > 0) {
                            endInx += eInx;
                        } else {
                            endInx += checkAfter(lowerSQL, endInx, "or");
                        }
                    }
                }
                String segment = whereStr.substring(startInx, endInx + 1);
                String newStr = frontStr + StringUtils.remove(whereStr, segment);

                //System.out.println("["+specialSQL+"]\n["+newStr+"]");
                return newStr;
            }
        }
        //System.out.println("Skipped1["+specialSQL+"]");
    } /* else
      {
      System.out.println("Skipped2["+specialSQL+"]");
      }*/
    return null;
}

From source file:hydrograph.ui.graph.schema.propagation.SchemaPropagation.java

private String getPortIndex(Link link) {
    if (StringUtils.startsWithIgnoreCase(link.getSourceTerminal(), Constants.INPUT_SOCKET_TYPE)) {
        return StringUtils.remove(link.getSourceTerminal(), Constants.INPUT_SOCKET_TYPE);
    } else {//from   w  w w.j a  v  a 2 s . c o  m
        return StringUtils.remove(link.getSourceTerminal(), Constants.OUTPUT_SOCKET_TYPE);
    }

}

From source file:com.dream.messaging.engine.fixformat.FixformatDataHandler.java

@Override
protected String formatStringData(String value, Node node) {
    String length = QueryNode.getAttribute(node, ElementAttr.Attr_Length);
    if (length != null) {
        int len = Integer.parseInt(length);
        if (value.length() > len) {
            value = value.substring(0, len);
        }//from   w  w  w.j  a v  a  2  s .c  o m
    }
    String format = QueryNode.getAttribute(node, ElementAttr.Attr_Format);
    if (format == null) {
        return value;
    }
    try {

        ElementFormat eformat = new ElementFormat(format);
        int max = eformat.getMaxLen();
        int min = eformat.getMinLen();
        if (max < min) {
            max = min;
        }
        if (value.length() < min) {
            // LogManager.logInfo("element value shorter than the min length:"
            // + QueryNode.getAttribute(node, ElementAttr.Attr_Name)
            // + " value:" + value);
            char ch = format.charAt(0);

            boolean isNumber = ((ch == 'n') || (ch == 'N')) ? true : false;
            String type = isNumber ? FixformatMessageEngine.NUMBER : FixformatMessageEngine.TEXT;
            boolean fromLeft = Boolean.parseBoolean(
                    (String) this.engine.getProperties().get(type + FixformatMessageEngine.START_FROM_LEFT));
            String fillUpWith = (String) this.engine.getProperties()
                    .get(type + FixformatMessageEngine.FILL_UP_WITH);
            StringBuffer sb = new StringBuffer();

            while (sb.length() < min - value.length()) {
                sb.append(fillUpWith);
            }

            if (fromLeft) {
                value = value + sb.toString();
            } else {
                value = sb.append(value).toString();
            }

            String clzName = QueryNode.getAttribute(node, ElementAttr.Attr_Class);
            if (clzName != null) {
                if (clzName.equalsIgnoreCase(ElementClassType.CLASS_DOUBLE)
                        || clzName.equalsIgnoreCase(ElementClassType.CLASS_DECIMAL)
                        || clzName.equalsIgnoreCase(ElementClassType.CLASS_FLOAT)) {
                    value = StringUtils.remove(value, ".");
                }
            }
        }
        if (value.length() > max) {
            // LogManager.logError("element value longer than the max length:"
            // + QueryNode.getAttribute(node, ElementAttr.Attr_Name)
            // + " value:" + value);
            value = value.substring(0, max);
        }
        if (this.validateStringElemnet(eformat, value)) {
            // dataHandler.appendMessage(message, value);
            // return message;
            return value;
        } else {
            // LogManager.logError("element value invalid:"
            // + QueryNode.getAttribute(node, ElementAttr.Attr_Name)
            // + " value:" + value);
        }

    } catch (ElementFormatParseException e) {
        // FixformatDataHandler.logger.error(this,
        // "ElementFormatParseException occurs in method formatStringData,format is "
        // + format);
    }
    return null;
}