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.flexive.faces.components.content.Jsf2FxValueHandler.java

@Override
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException {
    final String var;
    try {/*from www.j a v a2 s .c o  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, "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:com.flexive.tests.embedded.jsf.bean.MessageBeanTest.java

@Test
public void getMessageArgsElStringWithComma() {
    String message = (String) messageBean.get(KEY_1 + ",#{'some string value, with comma'}");
    String expected = StringUtils.replace(MSG_1, "{0}", "some string value, with comma");
    Assert.assertTrue(expected.equals(message), "Expected: " + expected + ", got: " + message);
}

From source file:com.mothsoft.alexis.engine.numeric.StockQuoteDataSetImporter.java

private void importStockQuotes(final HttpClientResponse response) {
    try {//from ww w.  j a  v  a 2  s .  co  m
        this.transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                final DataSetType type = StockQuoteDataSetImporter.this.dataSetTypeDao
                        .findSystemDataSetType(STOCK_QUOTES);

                BufferedReader reader = null;
                try {
                    reader = new BufferedReader(
                            new InputStreamReader(response.getInputStream(), response.getCharset()));
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        final String[] tokens = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
                        final String symbolName = StringUtils.replace(tokens[0], "\"", "");
                        final Double price;

                        try {
                            price = Double.valueOf(tokens[2]);
                        } catch (final Exception e) {
                            logger.error("Unable to parse stock price, exception: " + e, e);
                            return;
                        }

                        DataSet dataSet = StockQuoteDataSetImporter.this.dataSetDao.findSystemDataSet(type,
                                symbolName);

                        if (dataSet == null) {
                            dataSet = new DataSet(symbolName, type);
                            StockQuoteDataSetImporter.this.dataSetDao.add(dataSet);
                        }

                        final DataSetPoint point = new DataSetPoint(dataSet, new Date(), price);
                        StockQuoteDataSetImporter.this.dataSetPointDao.add(point);
                    }
                } catch (IOException e) {
                    logger.warn(e, e);
                    throw new RuntimeException(e);
                } finally {
                    IOUtils.closeQuietly(reader);
                }

            }
        });
    } catch (final Exception e) {
        response.abort();
        logger.warn(e, e);
        throw new RuntimeException(e);
    } finally {
        response.close();
    }
}

From source file:at.general.solutions.android.ical.parser.ICalParserThread.java

private Date parseIcalDate(String dateLine) {
    try {//from  w  ww. ja  va2 s.co  m
        dateLine = StringUtils.replace(dateLine, ";", "");
        Date date = null;
        if (dateLine.contains(ICalTag.DATE_TIMEZONE)) {
            String[] parts = StringUtils.split(dateLine, ":");
            ICAL_DATETIME_FORMAT.setTimeZone(TimeZone
                    .getTimeZone(parts[0].substring(ICalTag.DATE_TIMEZONE.length(), parts[0].length())));
            date = ICAL_DATETIME_FORMAT.parse(parts[1]);
            ICAL_DATETIME_FORMAT.setTimeZone(icalDefaultTimeZone);
        } else if (dateLine.contains(ICalTag.DATE_VALUE)) {
            String[] parts = StringUtils.split(dateLine, ":");
            date = ICAL_DATE_FORMAT.parse(parts[1]);
            date.setHours(0);
            date.setMinutes(0);
            date.setSeconds(0);
        } else {
            dateLine = StringUtils.replace(dateLine, ":", "");
            date = ICAL_DATETIME_FORMAT.parse(dateLine);
        }
        return date;
    } catch (ParseException e) {
        Log.e(LOG_TAG, "Cant't parse date!", e);
        return null;
    }
}

From source file:edu.ku.brc.specify.toycode.FixSQLString.java

/**
 * //from ww w  .  j av a2  s .  co m
 */
private void fix() {
    StringBuilder sb = new StringBuilder("sql = \"");
    String srcStr = srcTA.getText();
    boolean wasInner = false;
    for (String line : StringUtils.split(srcStr, "\n")) {
        String str = StringUtils.deleteWhitespace(line);

        if (str.toUpperCase().startsWith("INNER") || str.toUpperCase().startsWith("ORDER")
                || str.toUpperCase().startsWith("GROUP")) {
            if (!wasInner) {
                sb.append(" \" +");
                wasInner = false;
            }
            sb.append("\n    \"" + line.trim() + " \" +");
            wasInner = true;
        } else {
            if (wasInner) {
                sb.append("    \"");
                wasInner = false;
            }
            sb.append(' ');
            sb.append(StringUtils.replace(line.trim(), "\n", " "));
        }
    }

    if (wasInner) {
        sb.setLength(sb.length() - 3);
        sb.append("\";");
    } else {
        sb.append("\";");
    }
    dstTA.setText(sb.toString());

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dstTA.requestFocus();
            dstTA.selectAll();
            UIHelper.setTextToClipboard(dstTA.getText());
        }
    });

}

From source file:mashup.fm.github.BaseService.java

/**
 * Define the url that will be inquired on the remote API service
 * //from   w ww . ja v  a2s. c o m
 * @param url
 *            the url
 * @param args
 *            the args
 * @return the string
 */
private static String url(String url, String... args) {
    try {
        String u = String.format(url, args);
        String empty = "";
        u = StringUtils.replace(u, String.valueOf('"'), empty);
        Logger.info("Github Url: %s", u);
        return u;
    } catch (Throwable t) {
        Logger.error(ExceptionUtil.getStackTrace(t));
        throw new RuntimeException(t.fillInStackTrace());
    }
}

From source file:com.iticket.util.JsonLogger.java

/**
 * Given an underlying logger, construct an XLogger
 * //from www. j a v  a 2s  .  co  m
 * @param logger
 *           underlying logger
 */
public JsonLogger(Logger logger, String serverIp2, String systemId2) {
    // If class B extends A, assuming B does not override method x(), the caller
    // of new B().x() is A and not B, see also
    // http://bugzilla.slf4j.org/show_bug.cgi?id=114
    super(logger, LoggerWrapper.class.getName());
    if (StringUtils.isNotBlank(systemId2) && StringUtils.equals(systemId, "NOTSET")) {
        systemId = systemId2;
    }
    if (StringUtils.isNotBlank(serverIp2) && StringUtils.equals(server, "127001")) {
        server = StringUtils.replace(serverIp2, ".", "");
        ;
    }

}

From source file:com.yenlo.synapse.transport.vfs.VFSOutTransportInfo.java

private String cleanURI(String vfsURI, String queryParams, String originalFileURI) {
    // Using Apache Commons StringUtils and Java StringBuilder for improved performance.
    vfsURI = StringUtils.replace(vfsURI, "?" + queryParams, "");

    for (String deleteParam : uriParamsToDelete) {
        queryParams = StringUtils.replace(queryParams, deleteParam, "");
    }//from w w w  .j a  v a  2s  .  c o  m
    queryParams = StringUtils.replace(queryParams, "&&", "&");

    // We can sometimes be left with && in the URI
    if (!"".equals(queryParams) && queryParams.toCharArray()[0] == "&".charAt(0)) {
        queryParams = queryParams.substring(1);
    } else if ("".equals(queryParams)) {
        return vfsURI;
    }

    String[] queryParamsArray = queryParams.split("&");
    StringBuilder newQueryParams = new StringBuilder("");
    if (queryParamsArray.length > 0) {
        for (String param : queryParamsArray) {
            newQueryParams.append(param);
            newQueryParams.append("&");
        }
        newQueryParams = newQueryParams.deleteCharAt(newQueryParams.length() - 1);
        if (!"".equals(newQueryParams)) {
            return vfsURI + "?" + newQueryParams;
        } else {
            return vfsURI;
        }
    } else {
        return originalFileURI.substring(VFSConstants.VFS_PREFIX.length());
    }
}

From source file:com.easytrack.component.system.LicenseCheck.java

public boolean check() {
    boolean ret = false;

    int usedLicenseCount = 0;
    usedLicenseCount = getActiveUserCount();

    if (this.log.isInfoEnabled()) {
        this.log.info("Assigned license count is:" + this.license.getLicenseCount());
        this.log.info("Alert threshold is:" + this.alertThreshold);
        this.log.info("Currently used license count is:" + usedLicenseCount);
    }/*from  ww  w. j  a  va  2 s  . com*/

    if (usedLicenseCount >= this.license.getLicenseCount()) {
        sendAlert(this.exceedMessage);
        ret = true;
    } else if (usedLicenseCount >= this.license.getLicenseCount() * this.alertThreshold) {
        String s = StringUtils.replace(this.preAlertMessage, this.VAR_ALERT_THRESHOLD,
                Config.getConfig("LICENSE", "ALERT-THRESHOLD"));
        sendAlert(s);
        ret = true;
    }

    return ret;
}

From source file:co.marcin.novaguilds.impl.util.ChatMessageImpl.java

/**
 * Parse the message, fill variables//from w  w w.  ja v a2s . c om
 *
 * @return parsed string
 */
private String parse() {
    String format = getFormat();

    Map<VarKey, String> vars = new HashMap<>();
    vars.put(VarKey.DISPLAYNAME, getPlayer().getDisplayName());
    vars.put(VarKey.PLAYER, getPlayer().getName());
    vars.put(VarKey.WORLD, getPlayer().getWorld().getName());
    vars.put(VarKey.WORLDNAME, getPlayer().getWorld().getName());
    vars.put(VarKey.TAG, tag.get());

    format = co.marcin.novaguilds.util.StringUtils.replaceVarKeyMap(format, vars);
    format = co.marcin.novaguilds.util.StringUtils.fixColors(format);
    format = StringUtils.replace(format, "{MESSAGE}", getMessage());

    return format;
}