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

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

Introduction

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

Prototype

public static String replaceChars(String str, String searchChars, String replaceChars) 

Source Link

Document

Replaces multiple characters in a String in one go.

Usage

From source file:gov.nih.nci.caarray.magetab.idf.IdfRowType.java

static IdfRowType get(String name) {
    String enumName = StringUtils.replaceChars(name, ' ', '_').toUpperCase();
    try {//ww w .ja v a 2s  .c  om
        return valueOf(enumName);
    } catch (IllegalArgumentException e) {
        return INVALID_TYPE;
    }
}

From source file:gov.nih.nci.firebird.web.action.search.AbstractPersonSearchAction.java

/**
 * @return Search Term with non-search characters removed.
 */// w  w  w. jav a  2  s  . c om
protected String filterSearchTerm() {
    return StringUtils.replaceChars(getTerm(), NON_VALID_SEARCH_CHARACTERS, null);
}

From source file:com.npower.dm.model.TestGenerateModelXMLByCSV.java

/**
 * @param maps//from w w w .j  av a  2  s.  c om
 * @param outputBaseDir
 * @throws DMException
 * @throws Exception
 */
private void outputManufacturersXML(Map<String, TreeSet<String>> maps, String outputBaseDir)
        throws DMException, Exception {
    // Generate XML
    ManagementBeanFactory factory = AllTests.getManagementBeanFactory();
    ModelBean bean = factory.createModelBean();
    int total = 0;
    int total4New = 0;
    int total4Exists = 0;
    try {
        for (String manufacturerExtID : maps.keySet()) {
            Manufacturer manufacturer = bean.getManufacturerByExternalID(manufacturerExtID);
            String folderName = manufacturerExtID.trim().toLowerCase();
            folderName = StringUtils.replaceChars(folderName, '-', '_');
            folderName = StringUtils.replaceChars(folderName, ' ', '_');
            File outputDir = new File(outputBaseDir, "manufacturers");
            if (!outputDir.exists()) {
                outputDir.mkdirs();
            }
            File outputFile = null;
            if (manufacturer != null) {
                outputFile = new File(outputDir, folderName + ".additional.xml");
            } else {
                outputFile = new File(outputDir, folderName + ".xml");
            }
            BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));
            out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
            out.write("<Setup>\n");
            out.write("<Manufacturers>\n");
            out.write("\n");
            out.write("<Manufacturer>\n");
            out.write("<Name>" + manufacturerExtID.trim() + "</Name>\n");
            out.write("<ExternalID>" + manufacturerExtID.trim() + "</ExternalID>\n");
            out.write("<Description>" + manufacturerExtID.trim() + "</Description>\n");
            out.write("<Models filename=\"./models/" + folderName.trim() + "/models.additional.xml\"/>\n");
            out.write("</Manufacturer>\n");
            out.write("\n");
            out.write("</Manufacturers>\n");
            out.write("</Setup>\n");

            out.close();
        }

    } catch (Exception e) {
        throw e;
    } finally {
        factory.release();
    }

    System.out.println("*********************************************************************");
    System.out.println(" Total         : " + total);
    System.out.println(" Total (Exists): " + total4Exists);
    System.out.println(" Total (New)   : " + total4New);
    System.out.println("*********************************************************************");
}

From source file:com.bibisco.manager.TextEditorManager.java

private static String replaceCharIntervalWithWhiteSpace(String pStr, int pIntFrom, int pIntTo) {

    for (int i = pIntFrom; i < pIntTo + 1; i++) {
        char lChar = ((char) i);
        pStr = StringUtils.replaceChars(pStr, lChar, ' ');
    }// www  .j a  v a  2 s  . c  o m

    return pStr;
}

From source file:edu.ku.brc.specify.toycode.mexconabio.AgentNames.java

/**
 * /*from w  w w .  j  a v a  2  s  . c o m*/
 */
protected void findBadAgents() {
    Connection dbConn = null;
    try {
        Vector<String> names = getDatabases();
        System.out.println("-------------- Bad Agent Databases ------------------");
        for (String dbName : names) {
            dbConn = DriverManager.getConnection(String.format(connStr, dbName), "root", "root");

            //System.out.println("-> "+dbName);
            String sql = "SELECT COUNT(*) FROM agent WHERE LastName IS NOT NULL AND (LastName LIKE '%;%' OR LastName LIKE '%,%')";
            int cnt = BasicSQLUtils.getCountAsInt(dbConn, sql);
            if (cnt > 1) {
                System.out.println(dbName + " " + cnt);
                if (cnt > 1) {
                    sql = "SELECT LastName, FirstName, MiddleInitial FROM agent WHERE LastName IS NOT NULL AND (LastName LIKE '%;%' OR LastName LIKE '%,%') LIMIT 0,10";
                    for (Object[] row : BasicSQLUtils.query(dbConn, sql)) {
                        String lastName = (String) row[0];
                        String firstName = (String) row[1];
                        String middleInit = (String) row[1];

                        lastName = StringUtils.replaceChars(lastName, '\n', ' ');
                        System.out.println("  [" + lastName + "][" + (firstName == null ? "" : firstName) + "]["
                                + (middleInit == null ? "" : middleInit) + "]");
                        parseForNames(lastName);
                    }
                }
            }
            dbConn.close();
        }

    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:info.magnolia.cms.taglibs.util.SimpleSearchTag.java

/**
 * Split search terms and build an xpath query in the form:
 * <code>//*[@jcr:primaryType='mgnl:content']/\*\/\*[jcr:contains(., 'first') or jcr:contains(., 'second')]</code>
 *
 * @return valid xpath expression or null if the given query doesn't contain at least one valid search term
 */// w  w  w. j ava  2 s  .c  om
protected String generateXPathQuery() {

    String startPath = null;

    // search only in a specific subtree
    if (this.startLevel != 0) {
        try {
            Content activePage = Resource.getActivePage((HttpServletRequest) this.pageContext.getRequest());
            if (activePage != null) {
                startPath = StringUtils.strip(activePage.getAncestor(this.startLevel).getHandle(), "/"); //$NON-NLS-1$
            }
        } catch (RepositoryException e) {
            log.error(e.getMessage(), e);
        }
    }

    // strip reserved chars and split
    String[] tokens = StringUtils
            .split(StringUtils.lowerCase(StringUtils.replaceChars(this.query, RESERVED_CHARS, null)));

    // null input string?
    if (tokens == null) {
        return null;
    }

    StringBuffer xpath = new StringBuffer(tokens.length * 20);
    if (StringUtils.isNotEmpty(startPath)) {
        xpath.append(startPath);
    }
    xpath.append("//*[@jcr:primaryType=\'mgnl:content\']/*/*["); //$NON-NLS-1$

    String joinOperator = "and"; //$NON-NLS-1$
    boolean emptyQuery = true;

    for (int j = 0; j < tokens.length; j++) {
        String tkn = tokens[j];
        if (ArrayUtils.contains(KEYWORDS, tkn)) {
            joinOperator = tkn;
        } else {
            if (!emptyQuery) {
                xpath.append(" "); //$NON-NLS-1$
                xpath.append(joinOperator);
                xpath.append(" "); //$NON-NLS-1$
            }
            xpath.append("jcr:contains(., '"); //$NON-NLS-1$
            xpath.append(tkn);
            xpath.append("')"); //$NON-NLS-1$
            emptyQuery = false;
        }

    }

    xpath.append("]"); //$NON-NLS-1$

    // if no valid search terms are added don't return a catch-all query
    if (emptyQuery) {
        return null;
    }

    return xpath.toString();
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopTimeField.java

private void updateTimeFormat() {
    mask = StringUtils.replaceChars(timeFormat, "Hhmsa", "####U");
    try {/*w  ww.j a v a 2  s .com*/
        formatter.setMask(mask);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
    impl.setValue(impl.getValue());
}

From source file:br.com.nordestefomento.jrimum.utilix.StringUtil.java

/**
 * <p>/*www. j a v a2 s  .com*/
 * Remove a acentuao do texto, que inclui os acentos:
 * <ul>
 * <li>Agudo. ex.: </li>
 * <li>Grave. ex.: </li>
 * <li>Til. ex.: </li>
 * <li>Trema. ex.: </li>
 * <li>Circunflexo. ex.: </li>
 * </ul>
 * e o Cedilha ().
 * </p>
 * <p>
 * Os acentos so removidos tanto para letras minsculas como para letras
 * maisculas.
 * </p>
 * 
 * @param value
 *            String com os caracteres a serem removidos.
 * @return String sem acentuao.
 * @since 0.2
 */
public static String eliminateAccent(final String value) {

    String modifiedValue = value;

    // Para  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E7', 'c');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C7', 'C');

    // Para , , ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E0', 'a');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E1', 'a');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E2', 'a');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E3', 'a');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E4', 'a');

    // Para , ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E8', 'e');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E9', 'e');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EA', 'e');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EB', 'e');

    // Para , ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EC', 'i');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00ED', 'i');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EE', 'i');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EF', 'i');

    // Para , , ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F2', 'o');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F3', 'o');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F4', 'o');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F5', 'o');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F6', 'o');

    // Para , ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F9', 'u');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00FA', 'u');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00FB', 'u');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00FC', 'u');

    // Para , ?, ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C0', 'A');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C1', 'A');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C2', 'A');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C3', 'A');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C4', 'A');

    // Para , ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C8', 'E');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C9', 'E');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CA', 'E');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CB', 'E');

    // Para , ?,  e ?
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CC', 'I');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CD', 'I');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CE', 'I');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CF', 'I');

    // Para , , ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D2', 'O');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D3', 'O');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D4', 'O');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D5', 'O');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D6', 'O');

    // Para , ,  e 
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D9', 'U');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00DA', 'U');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00DB', 'U');
    modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00DC', 'U');

    return modifiedValue;
}

From source file:com.prowidesoftware.swift.utils.SwiftFormatUtils.java

/**
 * Parses a Number into a SWIFT string number ####,## with truncated zero decimals and mandatory decimal separator.
 * <ul>/* w  w  w.j  a va  2 s.c  om*/
 *    <li>Example: 1234.00 -> 1234,</li>
 *    <li>Example: 1234 -> 1234,</li>
 *    <li>Example: 1234.56 -> 1234,56</li>
 * </ul>
 * @param number to parse
 * @return Number of the parsed amount or <code>null</code> if the number is null
 */
public static String getNumber(final Number number) {
    if (number != null) {
        final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        symbols.setDecimalSeparator(',');
        final DecimalFormat df = new DecimalFormat("0.##########", symbols);
        df.setParseBigDecimal(true);
        df.setDecimalSeparatorAlwaysShown(true);
        final String formatted = df.format(number);
        final String result = StringUtils.replaceChars(formatted, '.', ',');
        return result;
    }
    return null;
}

From source file:com.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java

public void initRuleTemplate(RuleTemplate ruleTemplate, InitializerContext initializerContext)
        throws Exception {
    TypeInfo typeInfo = TypeInfo.parse(ruleTemplate.getType());
    if (typeInfo == null) {
        return;//from  w  w  w  .  j  a  v a 2s  . co m
    }

    Class<?> type = typeInfo.getType();
    RuleTemplateManager ruleTemplateManager = initializerContext.getRuleTemplateManager();
    ruleTemplate.setAbstract(Modifier.isAbstract(type.getModifiers()));

    // ??SuperType?ParentTemplate
    Class<?> superType = type.getSuperclass();
    List<Class<?>> superTypes = new ArrayList<Class<?>>();
    while (superType != null && !superType.equals(Object.class)
            && !superType.equals(ClientEventSupportedObject.class)) {
        RuleTemplate parentRuleTemplate = ruleTemplateManager.getRuleTemplate(superType);
        if (parentRuleTemplate != null) {
            if (superTypes.isEmpty()) {
                ruleTemplate.setParents(new RuleTemplate[] { parentRuleTemplate });
            }
            break;
        }
        superTypes.add(superType);
        superType = superType.getSuperclass();
    }

    // ?AbstractParentTemplate
    RuleTemplate parentRuleTemplate = null;
    if (!superTypes.isEmpty()) {
        for (int i = superTypes.size() - 1; i >= 0; i--) {
            superType = superTypes.get(i);
            RuleTemplate newRuleTemplate = createRuleTemplate(ruleTemplateManager, superType,
                    parentRuleTemplate);
            parentRuleTemplate = newRuleTemplate;
        }
        if (parentRuleTemplate != null && ruleTemplate.getParents() == null) {
            ruleTemplate.setParents(new RuleTemplate[] { parentRuleTemplate });
        }
    }

    XmlNodeInfo xmlNodeInfo = getXmlNodeInfo(type);

    String scope = xmlNodeInfo.getScope();
    if (StringUtils.isEmpty(scope) && Component.class.isAssignableFrom(type)) {
        Widget widget = type.getAnnotation(Widget.class);
        boolean isDeclaredAnnotation = (widget != null
                && ArrayUtils.indexOf(type.getDeclaredAnnotations(), widget) >= 0);
        if (widget != null && !ruleTemplate.isAbstract()) {
            if (StringUtils.isNotEmpty(widget.name()) && !widget.name().equals(ruleTemplate.getName())
                    && (isDeclaredAnnotation || !AssembledComponent.class.isAssignableFrom(type))) {
                ruleTemplate.setLabel(widget.name());
            }
        }
        if (!(widget != null && isDeclaredAnnotation && !Modifier.isAbstract(type.getModifiers()))) {
            scope = "protected";
        }
    }
    if (StringUtils.isNotEmpty(scope) && StringUtils.isEmpty(ruleTemplate.getScope())) {
        ruleTemplate.setScope(scope);
    }

    String nodeName = xmlNodeInfo.getNodeName();
    if (StringUtils.isNotEmpty(nodeName)) {
        ruleTemplate.setNodeName(nodeName);
    }

    if (StringUtils.isEmpty(ruleTemplate.getLabel())) {
        String label = xmlNodeInfo.getLabel();
        if (StringUtils.isNotEmpty(label)) {
            ruleTemplate.setLabel(label);
        } else if (!ruleTemplate.isAbstract()) {
            ruleTemplate.setLabel(type.getSimpleName());
        }
    }

    if (StringUtils.isNotEmpty(xmlNodeInfo.getIcon())) {
        ruleTemplate.setIcon(xmlNodeInfo.getIcon());
    }

    int clientTypes = ClientType.parseClientTypes(xmlNodeInfo.getClientTypes());
    if (clientTypes > 0) {
        ruleTemplate.setClientTypes(clientTypes);
    } else if (Control.class.isAssignableFrom(type) && "public".equals(ruleTemplate.getScope())) {
        ruleTemplate.setClientTypes(ClientType.DESKTOP);
    }

    if (!ruleTemplate.isDeprecated() && xmlNodeInfo.isDeprecated()) {
        ruleTemplate.setDeprecated(true);
    }

    IdeObject ideObject = type.getAnnotation(IdeObject.class);
    if (ideObject != null && ArrayUtils.indexOf(type.getDeclaredAnnotations(), ideObject) >= 0) {
        if (StringUtils.isNotEmpty(ideObject.labelProperty())) {
            ruleTemplate.setLabelProperty(ideObject.labelProperty());
        }
        ruleTemplate.setVisible(ideObject.visible());
    }

    // search icon
    if (ruleTemplate.getIcon() == null) {
        String basePath = '/' + StringUtils.replaceChars(type.getName(), '.', '/'), iconPath;

        iconPath = basePath + ".png";
        if (getClass().getResource(iconPath) != null) {
            ruleTemplate.setIcon(iconPath);
        } else {
            iconPath = basePath + ".gif";
            if (getClass().getResource(iconPath) != null) {
                ruleTemplate.setIcon(iconPath);
            }
        }
    }

    if (Component.class.isAssignableFrom(type)) {
        Widget widget = type.getAnnotation(Widget.class);
        if (widget != null) {
            if (ArrayUtils.indexOf(type.getDeclaredAnnotations(), widget) >= 0) {
                if (StringUtils.isEmpty(ruleTemplate.getCategory())) {
                    ruleTemplate.setCategory(widget.category());
                }
                ruleTemplate.setAutoGenerateId(widget.autoGenerateId());
            }
        }
    }

    List<String> robots = null;
    Map<String, RobotInfo> robotMap = robotRegistry.getRobotMap();
    for (Map.Entry<String, RobotInfo> entry : robotMap.entrySet()) {
        RobotInfo robotInfo = entry.getValue();
        if (robotInfo != null) {
            String pattern = robotInfo.getViewObject();
            if (PathUtils.match(pattern, ruleTemplate.getName())) {
                if (robots == null) {
                    robots = new ArrayList<String>();
                }
                robots.add(robotInfo.getName() + '|' + robotInfo.getLabel());
            }
        }
    }

    if (robots != null) {
        ruleTemplate.setRobots(robots.toArray(new String[0]));
    }

    initProperties(ruleTemplate, typeInfo, xmlNodeInfo, initializerContext);
    initChildTemplates(ruleTemplate, typeInfo, xmlNodeInfo, initializerContext);
    initClientEvent(ruleTemplate, typeInfo, initializerContext);

    if (xmlNodeInfo != null && !xmlNodeInfo.getImplTypes().isEmpty()) {
        Set<Class<?>> implTypes = ClassUtils.findClassTypes(xmlNodeInfo.getImplTypes().toArray(new String[0]),
                type);
        for (Class<?> implType : implTypes) {
            if (implType.equals(type)) {
                continue;
            }

            if (ruleTemplateManager.getRuleTemplate(implType) == null) {
                // ?parentRuleTemplate??RuleTemplateinit?
                createRuleTemplate(ruleTemplateManager, implType, null);
            }
        }
    }
}