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

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

Introduction

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

Prototype

public static String replace(String text, String searchString, String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

Usage

From source file:com.opengamma.component.ComponentConfigLoader.java

private String applyReplacements(String line, ConcurrentMap<String, String> properties) {
    for (Entry<String, String> entry : properties.entrySet()) {
        line = StringUtils.replace(line, entry.getKey(), entry.getValue());
    }/* w ww. ja  v  a2 s  . c o  m*/
    return line;
}

From source file:eu.annocultor.analyzers.SolrPropertyHitsAnalyzer.java

static String extractQuery(String line) {
    line = StringUtils.substringAfter(line, ", query=");
    String query = StringUtils.substringBefore(line, ", ");
    if (StringUtils.length(query) < 3) {
        // try referal
        query = StringUtils.substringAfter(line, ", referer=");
        query = StringUtils.substringAfter(query, "&q=");
        if (!StringUtils.isBlank(query)) {
            query = StringUtils.substringBefore(query, "&");
            query = StringUtils.replace(query, "+", " ");
            if (isLongEnoughToCount(query)) {
                return query;
            } else {
                return "";
            }/*  w w  w .ja  v  a  2  s . co m*/
        }
    }
    return query;
}

From source file:net.sf.zekr.common.config.KeyboardShortcut.java

private int extractKeyCode(String key) {
    key = key.toLowerCase();/*from w  w  w  .  j  a v  a  2 s. c  o m*/
    key = StringUtils.replace(key, "\\+", "plus");
    String[] keyParts = StringUtils.split(key, '+');
    int accel = 0;

    for (int j = 0; j < keyParts.length; j++) {
        String part = keyParts[j].trim();
        if ("ctrl".equals(part)) {
            if (GlobalConfig.isMac && commandAndControlAreSame) {
                accel |= SWT.COMMAND;
            } else {
                accel |= SWT.CTRL;
            }
        } else if ("cmd".equals(part)) {
            accel |= SWT.COMMAND;
        } else if ("alt".equals(part)) {
            accel |= SWT.ALT;
        } else if ("shift".equals(part)) {
            accel |= SWT.SHIFT;
        } else if ("win".equals(part)) {
            accel |= WINKEY;
        } else if ("plus".equals(part)) {
            accel |= '+';
        } else if (controlMap.containsKey(part)) {
            accel |= controlMap.get(part);
        } else if (part.length() >= 2 && part.charAt(0) == 'f' && NumberUtils.isDigits(part.substring(1))) {
            int f = Integer.parseInt(part.substring(1));
            accel |= SWT.F1 - 1 + f;
        } else if (part.length() == 1) {
            accel |= part.toUpperCase().charAt(0);
        }
    }
    return accel;
}

From source file:com.flexive.faces.components.content.FxValueHandler.java

@Override
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, ELException {
    final String var;
    try {// w ww  .java2  s  .co  m
        if (this.getAttribute("var") == null) {
            // no variable name specified, use enclosing content view
            if (!(parent instanceof FxContentView)) {
                throw new FacesException(
                        "Facelet parent is no FxContentView instance and \"var\" attribute not specified.");
            }
            var = ((FxContentView) parent).getVar();
        } else {
            // use a custom variable name
            var = this.getAttribute("var").getValue(ctx);
        }
    } catch (FxRuntimeException e) {
        throw new FacesException("The fx:value component must be embedded in a fx:content instance.");
    }
    final boolean isNewValue = this.getAttribute("new") != null
            && Boolean.valueOf(this.getAttribute("new").getValue(ctx));
    final VariableMapper origMapper = ctx.getVariableMapper();
    final VariableMapperWrapper mapper = new VariableMapperWrapper(origMapper);
    try {
        ctx.setVariableMapper(mapper);

        // get property attribute
        final String property;
        final TagAttribute propertyAttribute = this.getAttribute("property");
        if (propertyAttribute != null) {
            final ValueExpression propertyExpression = propertyAttribute.getValueExpression(ctx, String.class);
            property = (String) propertyExpression.getValue(ctx);
        } else {
            property = null;
        }
        FxJsfComponentUtils.requireAttribute("fx:value", "property", property);

        // assign id, label/labelKey and value based on the enclosing FxContentView instance
        final ExpressionFactory expressionFactory = ctx.getExpressionFactory();
        mapper.setVariable("id",
                expressionFactory.createValueExpression(StringUtils.replace(property, "/", "_"), String.class));
        if (this.getAttribute("labelKey") == null) {
            // use property label
            mapper.setVariable("label", expressionFactory.createValueExpression(ctx,
                    FxContentView.getExpression(var, property, "label"), FxString.class));
        } else {
            // use provided message key
            assignAttribute(ctx, mapper, "labelKey", String.class);
        }
        // retrieve content from content view
        mapper.setVariable("value", expressionFactory.createValueExpression(ctx,
                FxContentView.getExpression(var, property, isNewValue ? "new" : null), FxValue.class));

        // passthrough other template attributes
        assignAttribute(ctx, mapper, "inputMapper", InputMapper.class);
        assignAttribute(ctx, mapper, "onchange", String.class);
        assignAttribute(ctx, mapper, "readOnly", Boolean.class);
        assignAttribute(ctx, mapper, "decorate", Boolean.class);
        assignAttribute(ctx, mapper, "filter", Boolean.class);
        assignAttribute(ctx, mapper, "forceLineInput", Boolean.class);
        assignAttribute(ctx, mapper, "newLine", Boolean.class);
        assignAttribute(ctx, mapper, "valueFormatter", FxValueFormatter.class);
        assignAttribute(ctx, mapper, "containerDivClass", String.class);
        assignAttribute(ctx, mapper, "autocompleteHandler", String.class);
        assignAttribute(ctx, mapper, "disableMultiLanguage", Boolean.class);
        assignAttribute(ctx, mapper, "disableLytebox", Boolean.class);
        assignAttribute(ctx, mapper, "tooltip", String.class);
        assignAttribute(ctx, mapper, "tooltipKey", String.class);

        // TODO: cache templates/use a facelet ResourceResolver to encapsulate this
        ctx.includeFacelet(parent,
                Thread.currentThread().getContextClassLoader().getResource(TEMPLATE_ROOT + template));
    } finally {
        ctx.setVariableMapper(origMapper);
    }
}

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

/**
 * @param fmpInfo/*from  ww w  .  j  a  va 2 s  . c  om*/
 * @param srcFileName
 * @throws UnsupportedEncodingException
 * @throws FileNotFoundException
 * @throws IOException
 */
private void processFieldSizes(final FMPCreateTable fmpInfo, final String srcFileName)
        throws UnsupportedEncodingException, FileNotFoundException, IOException {
    Vector<FieldDef> fieldDefs = fmpInfo.getFields();
    BufferedReader in = new BufferedReader(
            new InputStreamReader(new FileInputStream(new File(srcFileName)), "UTF8"));
    String str = in.readLine(); // header row

    int recNumber = 41477000;
    str = in.readLine();
    int rowCnt = 0;
    while (str != null) {

        String line = str;

        char sep = '`';
        String sepStr = "";
        for (char c : seps) {
            if (line.indexOf(c) == -1) {
                sepStr += c;
                sep = c;
                break;
            }
        }

        /*if (rowCnt >= recNumber) 
        {
        System.out.println("Num Commas: "+StringUtils.countMatches(str, ","));
        System.out.println(line);
        }*/

        str = StringUtils.replace(str.substring(1, str.length() - 1), "\",\"", sepStr);
        /*if (rowCnt >= recNumber) 
        {
        System.out.println("Num pipe: "+StringUtils.countMatches(str, "|"));
        System.out.println(str);
        }*/

        if (rowCnt >= recNumber) {
            Vector<String> fields = split(str, '|');
            Vector<String> fields2 = new Vector<String>(split(str, sep));
            for (int x = 0; x < fields.size(); x++) {
                if ((StringUtils.isNotEmpty(fields.get(x)) && StringUtils.isNotEmpty(fields2.get(x)))
                        || (x > 39 && x < 51)) {
                    System.out.println(x + "  [" + fields.get(x) + "][" + fields2.get(x) + "]");
                }
            }
            System.out.println(line);
            System.out.println(str);
        }

        Vector<String> fields = split(str, sep);

        if (fields.size() != fieldDefs.size() - 1) {
            System.out.println(rowCnt + "  -  " + fields.size() + " != " + (fieldDefs.size() - 1));
            int i = 0;
            for (String value : fields) {
                System.out.println(i + " [" + value + "]");
                i++;
            }
            System.out.println(line);
        }
        int inx = 1;
        for (String value : fields) {
            FieldDef fd = fieldDefs.get(inx);
            int len = value.length() + 1;
            fd.setMaxSize(len);

            if (fd.getType() == DataType.eNumber) {
                if (value.contains(".")) {
                    fd.setDouble(true);
                }
            }
            inx++;
        }

        rowCnt++;
        if (rowCnt % 1000 == 0)
            System.out.println(rowCnt);
        str = in.readLine();
    }
    in.close();
}

From source file:com.opengamma.util.db.DbDialect.java

/**
 * Adjusts wildcards from the public values of * and ? to the database
 * values of % and _.//  ww  w  . j a va 2  s  . co m
 * 
 * @param value  the string value, may be null
 * @return the SQL fragment, not null
 */
public String sqlWildcardAdjustValue(String value) {
    if (value == null || isWildcard(value) == false) {
        return value;
    }
    value = StringUtils.replace(value, "%", "\\%");
    value = StringUtils.replace(value, "_", "\\_");
    value = StringUtils.replace(value, "*", "%");
    value = StringUtils.replace(value, "?", "_");
    return value;
}

From source file:net.itransformers.toplogyviewer.gui.neo4j.Neo4jLoader.java

public void getNeighbourVertexes(String networkNodeId) {
    String query = "start network=node(" + networkNodeId
            + ") match network-->device-->interface-->neighbor where device.objectType='Node' and neighbor.objectType='DiscoveredNeighbor' return device.name, interface.name, neighbor.name, neighbor.Reachable?, neighbor.SNMPCommunity?,neighbor.DiscoveryMethod?,neighbor.LocalIPAddress?,neighbor.NeighborIPAddress?,neighbor.NeighborHostname?,neighbor.NeighborDeviceType?";
    String params = "";
    String output = executeCypherQuery(query, params);
    JSONObject json = null;/*from   w  w  w  .  j  a v a  2s  .c om*/
    try {
        json = (JSONObject) new JSONParser().parse(output);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    JSONArray data = (JSONArray) json.get("data");
    JSONArray columns = (JSONArray) json.get("columns");

    HashMap<String, HashMap<String, String>> neighborMap = new HashMap<String, HashMap<String, String>>();

    Iterator dataIter = data.iterator();
    while (dataIter.hasNext()) {
        JSONArray temp = (JSONArray) dataIter.next();
        Iterator tempIter = temp.iterator();
        Iterator columnsIter = columns.iterator();
        String neighborName = null;
        String deviceName = null;
        String interfaceName = null;
        String edgeName = null;
        //        HashMap<String, GraphMLMetadata<String>> nodeMetaData = new HashMap<String, GraphMLMetadata<String>>();
        HashMap<String, GraphMLMetadata<String>> nodePropertiesMap = new HashMap<String, GraphMLMetadata<String>>();
        HashMap<String, GraphMLMetadata<String>> graphMLPropertiesMap = new HashMap<String, GraphMLMetadata<String>>();
        while (tempIter.hasNext() & columnsIter.hasNext()) {

            String column = columnsIter.next().toString();

            String keyNodeProperty = (String) tempIter.next();

            String columnsValue = null;
            if (column.contains("neighbor.")) {
                columnsValue = StringUtils.replace(StringUtils.substringAfter(column, "neighbor."), "%20", " ");
            } else {
                columnsValue = column;
            }
            if (columnsValue.equals("device.name")) {
                deviceName = keyNodeProperty;

            } else if (columnsValue.equals("interface.name")) {
                interfaceName = keyNodeProperty;
            } else if (columnsValue.equals("name")) {

                neighborName = keyNodeProperty;
                nodePropertiesMap.put(neighborName, null);

            } else {
                if (keyNodeProperty == null) {
                    keyNodeProperty = "";
                } else if (keyNodeProperty.equals("emptyValue")) {
                    keyNodeProperty = "";
                }
                HashMap<String, String> transformerValue = new HashMap<String, String>();
                transformerValue.put(neighborName, keyNodeProperty);
                MapSettableTransformer<String, String> transfrmer = new MapSettableTransformer<String, String>(
                        transformerValue);

                GraphMLMetadata<String> t = new GraphMLMetadata<String>(null, null, transfrmer);
                nodePropertiesMap.put(columnsValue, t);

            }

        }
        String[] tempArray = { deviceName, neighborName };
        Arrays.sort(tempArray);
        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < tempArray.length; i++) {
            builder.append(tempArray[i]);
        }
        edgeName = builder.toString();
        Pair<String> endpoints = new Pair<String>(deviceName, neighborName);
        //Bogon filter
        if ((neighborName != null) && !entireGraph.containsVertex(neighborName) && (neighborName != "0.0.0.0")
                && !(StringUtils.contains(neighborName, "128.") || StringUtils.contains(neighborName, "127.")
                        || StringUtils.contains(neighborName, "169.254.")
                        || StringUtils.contains(neighborName, "0."))) {
            entireGraph.addVertex(neighborName);
            vertexMetadatas.put(neighborName, nodePropertiesMap);
            graphMetadatas.put(neighborName, graphMLPropertiesMap);

        }
        if (!entireGraph.containsEdge(edgeName)) {

            entireGraph.addEdge(edgeName, endpoints);
        }

    }

}

From source file:nc.noumea.mairie.appock.core.utility.AppockUtilTest.java

private void assertEqualsAvecPointOuVirgule(String texte1, String texte2) {
    String texte1Modifie = StringUtils.replace(texte1, ",", ".");
    String texte2Modifie = StringUtils.replace(texte2, ",", ".");
    Assert.assertEquals(texte1Modifie, texte2Modifie);
}

From source file:com.google.gdt.eclipse.designer.core.model.web.WebModelTest.java

/**
 * Tests for {@link WelcomeFileElement}, parse and update existing.
 *///from  www.ja v a  2  s . c o  m
public void test_WelcomeFileElement_update() throws Exception {
    parse("<web-app>", "  <welcome-file-list>", "    <welcome-file>MyFile.html</welcome-file>",
            "  </welcome-file-list>", "</web-app>");
    assertThat(m_webElement.getChildren()).hasSize(1);
    // prepare WelcomeFileListElement
    WelcomeFileListElement welcomeFileListElement;
    {
        List<WelcomeFileListElement> welcomeListElements = m_webElement.getWelcomeFileListElements();
        assertThat(welcomeListElements).hasSize(1);
        welcomeFileListElement = welcomeListElements.get(0);
    }
    // prepare WelcomeFileElement
    WelcomeFileElement welcomeFile;
    {
        List<WelcomeFileElement> welcomeFiles = welcomeFileListElement.getWelcomeFiles();
        assertThat(welcomeFiles).hasSize(1);
        welcomeFile = welcomeFiles.get(0);
    }
    // initial state
    assertEquals("MyFile.html", welcomeFile.getName());
    // set new "name" value
    {
        welcomeFile.setName("newName.html");
        assertEquals("newName.html", welcomeFile.getName());
        m_webContent = StringUtils.replace(m_webContent, "MyFile", "newName");
        assertUpdatedModuleFile(m_webContent);
    }
    // toString()
    assertEquals(getSource("<web-app>", "  <welcome-file-list>",
            "    <welcome-file>newName.html</welcome-file>", "  </welcome-file-list>", "</web-app>"),
            m_webElement.toString());
}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

/**
 * Append columns.// ww  w  .  j a v a 2  s .c  o  m
 * 
 * @param builder
 *            the builder
 * @param columns
 *            the columns
 * @param selectQuery
 *            the select query
 * @param translator
 *            the translator
 */
public static StringBuilder appendColumns(StringBuilder builder, List<String> columns, String selectQuery,
        CQLTranslator translator) {
    if (columns != null) {
        for (String column : columns) {
            translator.appendColumnName(builder, column);
            builder.append(",");
        }
    }
    if (builder.lastIndexOf(",") != -1) {
        builder.deleteCharAt(builder.length() - 1);
        selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMNS, builder.toString());
    }

    builder = new StringBuilder(selectQuery);
    return builder;
}