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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces all occurrences of a String within another String.

A null reference passed to this method is a no-op.

 StringUtils.replace(null, *, *)        = null StringUtils.replace("", *, *)          = "" StringUtils.replace("any", null, *)    = "any" StringUtils.replace("any", *, null)    = "any" StringUtils.replace("any", "", *)      = "any" StringUtils.replace("aba", "a", null)  = "aba" StringUtils.replace("aba", "a", "")    = "b" StringUtils.replace("aba", "a", "z")   = "zbz" 

Usage

From source file:er.selenium.SeleniumTestSuite.java

@Override
public WOActionResults performActionNamed(String anActionName) {
    if (!ERSelenium.testsEnabled()) {
        return new ERXResponse(ERXHttpStatusCodes.FORBIDDEN);
    }//from   w w  w  .  j a v a2s.c om
    if (anActionName.equals("default")) {
        return defaultAction();
    }

    SeleniumTestSuitePage page = (SeleniumTestSuitePage) pageWithName(SeleniumTestSuitePage.class.getName());
    page.setTestPath(StringUtils.replace(anActionName, ERSelenium.SUITE_SEPERATOR, "/"));
    return page;
}

From source file:com.thruzero.common.core.strategy.MapSubstitutionStrategy.java

/**
 * Using the provided list of name/value pairs, search and replace all matching substitution variables, in the given
 * {@code source} string, with their associated values.
 *///from  w  w  w.j a v  a2  s  . c om
@Override
public String replaceAll(final String source) {
    String result = source;

    for (Entry<String, String> entry : substitutionSpecs.entrySet()) {
        result = StringUtils.replace(result, namePrefix + entry.getKey() + nameSuffix, entry.getValue());
    }

    return result;
}

From source file:net.ontopia.topicmaps.webed.impl.utils.ModelLinkGeneratorWithObjID.java

@Override
public String generate(ContextTag contextTag, TMObjectIF tmObj, String topicmapId, String template)
        throws NavigatorRuntimeException {

    String link = template;//from ww w  . j ava 2s  .com

    // replace object id placeholder with real value
    if (tmObj != null) {
        String objectId = tmObj.getObjectId();
        link = StringUtils.replace(link, LINK_ID_KEY, objectId);
    }

    // replace topicmap id placeholder with real value
    if (topicmapId != null)
        link = StringUtils.replace(link, LINK_TOPICMAP_KEY, topicmapId);

    // replace model placeholder with real value
    UserIF user = FrameworkUtils.getUser(contextTag.getPageContext());
    String model = user.getModel();
    link = StringUtils.replace(link, LINK_MODEL_KEY, model);

    return link;
}

From source file:me.mayo.telnetkek.player.PlayerCommandEntry.java

public String buildOutput(PlayerInfo player, boolean useReasonPrompt) {
    String output = StringUtils.replaceEach(getFormat(),
            new String[] { "$TARGET_NAME", "$TARGET_IP", "$TARGET_UUID", },
            new String[] { player.getName(), player.getIp(), player.getUuid() });

    if (useReasonPrompt && output.contains("$REASON")) {
        final String reason = StringUtils.trimToEmpty(JOptionPane.showInputDialog(null,
                "Input reason:\n" + output, "Input Reason", JOptionPane.PLAIN_MESSAGE));
        output = StringUtils.replace(output, "$REASON", reason);
    }/*  ww w .  j av a 2  s  .  c  o  m*/

    return StringUtils.trimToEmpty(output);
}

From source file:de.ks.idnadrev.expimp.xls.ToManyColumn.java

@Override
public Object getValue(Object object) {

    StringBuilder builder = new StringBuilder();
    if (Collection.class.isAssignableFrom(attribute.getJavaType())) {

        Collection collection = (Collection) ReflectionUtil.getFieldValue(object, attribute.getName());
        for (java.util.Iterator iterator = collection.iterator(); iterator.hasNext();) {
            Object next = iterator.next();

            if (IdentifyableEntity.class.isAssignableFrom(next.getClass())) {
                Object idValue = ((IdentifyableEntity) next).getIdValue();
                if (idValue instanceof String) {
                    String replaced = StringUtils.replace(String.valueOf(idValue), SEPARATOR,
                            SEPARATOR_REPLACEMENT);
                    builder.append(replaced).append(SEPARATOR);
                } else {
                    builder.append(idValue).append(SEPARATOR);
                }//  www. j  a v  a2  s  .  c  om
            }
        }
        if (builder.length() == 0) {
            return null;
        } else {
            return builder.substring(0, builder.length() - 1);
        }
    }
    throw new IllegalArgumentException("Cannot resolve to many relation "
            + attribute.getDeclaringType().getJavaType().getName() + "." + attribute.getName());
}

From source file:com.thoughtworks.go.domain.builder.CommandBuilder.java

private String translateToWindowsPath(String command) {
    return StringUtils.replace(command, "/", "\\");
}

From source file:net.ontopia.topicmaps.nav2.impl.framework.ModelLinkGenerator.java

@Override
public String generate(ContextTag contextTag, TMObjectIF tmObj, String topicmapId, String template)
        throws NavigatorRuntimeException {

    String link = template;//from   w  w w  .  j  av  a2s .  com

    // replace object id placeholder with real value
    if (tmObj != null) {
        String objectId = NavigatorUtils.getStableId(tmObj);
        link = StringUtils.replace(link, LINK_ID_KEY, objectId);
    }

    // replace topicmap id placeholder with real value
    if (topicmapId != null)
        link = StringUtils.replace(link, LINK_TOPICMAP_KEY, topicmapId);

    // replace model placeholder with real value
    UserIF user = FrameworkUtils.getUser(contextTag.getPageContext());
    String model = user.getModel();
    link = StringUtils.replace(link, LINK_MODEL_KEY, model);

    return link;
}

From source file:in.mycp.remote.SecurityGroupService.java

@RemoteMethod
public GroupDescriptionP saveOrUpdate(GroupDescriptionP instance) {
    try {//w  w w.ja v a 2s.  c  o m
        try {
            String s = instance.getName();
            instance.setName(StringUtils.replace(s, " ", "_"));

        } catch (Exception e) {
        }
        //String companyName = Commons.getCurrentSession().getCompany();
        /*String pId="";String dId="";String cId="";
        try{pId = Commons.getCurrentUser().getProject().getId()+"";}catch(Exception e){}
        try{dId = Commons.getCurrentUser().getProject().getDepartment().getId()+"";}catch(Exception e){}
        try{cId = Commons.getCurrentUser().getProject().getDepartment().getCompany().getId()+"";}catch(Exception e){}
                
        if(instance!=null && instance.getName()!=null && instance.getName().indexOf("_"+companyName) <0){
           instance.setName(instance.getName()+"_"+pId+"_"+dId+"_"+cId);
        }*/
        //check unique name per infra
        try {
            if (GroupDescriptionP
                    .findGroupDescriptionPsByNameEqualsAndCompanyEquals(instance.getName(),
                            Commons.getCurrentUser().getProject().getDepartment().getCompany())
                    .getSingleResult().getId() > 0) {
                throw new Exception(
                        "Security group with this name already exists for this account, Choose another name.");
            }
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getMessage().contains("returns more than one elements")
                    || e.getMessage().contains("Security group with this name already exists")) {
                throw new Exception(
                        "Security group with this name already exists for this account, Choose another name.");
            }
        }

        AssetType assetTypeSecurityGroup = AssetType
                .findAssetTypesByNameEquals(Commons.ASSET_TYPE.SecurityGroup + "").getSingleResult();
        if (instance.getId() != null && instance.getId() > 0) {
            instance = GroupDescriptionP.findGroupDescriptionP(instance.getId());
        } else {
            User currentUser = Commons.getCurrentUser();
            Asset asset = Commons.getNewAsset(assetTypeSecurityGroup, currentUser, instance.getProduct());
            instance.setAsset(asset);

            if (true == assetTypeSecurityGroup.getWorkflowEnabled()) {
                instance.setStatus(Commons.WORKFLOW_STATUS.PENDING_APPROVAL + "");
                instance = instance.merge();
                Commons.createNewWorkflow(
                        workflowService.createProcessInstance(Commons.PROCESS_DEFN.SecGroup_Request + ""),
                        instance.getId(), assetTypeSecurityGroup.getName());

            } else {
                instance.setStatus(Commons.secgroup_STATUS.starting + "");
                instance = instance.merge();
                workflowApproved(instance);
            }
        }
        return instance;
    } catch (Exception e) {
        e.printStackTrace();
        if (e.getMessage().contains("Security group with this name already exists for this account")) {
            Commons.setSessionMsg(
                    "Security group with this name already exists for this account, Choose another name.");
        }
        log.error(e);
    }
    return null;
}

From source file:net.ontopia.persistence.rdbms.CSVExport.java

public void exportCSV(Writer writer, String table, String[] columns) throws SQLException, IOException {
    Statement stm = conn.createStatement();
    ResultSet rs = stm.executeQuery("select " + StringUtils.join(columns, ", ") + " from " + table);
    try {//from   www.  j a  va 2 s. com
        while (rs.next()) {
            for (int i = 1; i <= columns.length; i++) {
                if (i > 1)
                    writer.write(separator);
                writer.write('"');
                String value = rs.getString(i);
                if (value != null) {
                    writer.write(StringUtils.replace(value, "\"", "\\\""));
                }
                writer.write('"');
            }
            writer.write('\n');
        }
    } finally {
        rs.close();
        stm.close();
    }
    writer.flush();
}

From source file:de.micromata.genome.db.jdbc.trace.SqlLiteralArgRenderer.java

@Override
public String renderSqlArg(Object arg) {
    if (arg instanceof String) {
        // TODO replace with proper SQL escaping
        return "'" + StringUtils.replace((String) arg, "'", "''") + "'";
    }/* ww w.  j  a  v a2  s .c  o  m*/
    if (arg instanceof Integer || arg instanceof Long || arg instanceof Short || arg instanceof Byte) {
        return Objects.toString(arg, StringUtils.EMPTY);
    }
    if (arg instanceof BigDecimal) {
        return Objects.toString(arg, StringUtils.EMPTY); // TODO
    }
    if (arg instanceof Date) {
        return '#' + sqlDateFormatter.get().format((Date) arg) + '#';
    }
    if (arg instanceof Time) {
        return '#' + sqlTimeFormatter.get().format((Time) arg) + '#';
    }
    if (arg instanceof Timestamp) {
        return '#' + sqlTimestampFormatter.get().format((Timestamp) arg) + '#';
    }
    if (arg instanceof java.util.Date) {
        return '#' + sqlTimestampFormatter.get().format((java.util.Date) arg) + '#';
    }
    // TODO andere typen unterstuetzen
    return Objects.toString(arg, StringUtils.EMPTY);
}