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:gov.nih.nci.cacis.common.util.CommonsPropertyLoaderUtil.java

/**
 * fill properties from file system/*from w w w .  j  a  va2 s  .c om*/
 *
 * @param properties          - properties to merge
 * @param environmentVariable - environment variable (for ex : user.home, tomcat.home etc)
 * @param pathToScan          - the detailed path to scan
 */
private static void fillPropertiesFromFileSystem(Properties properties, final String environmentVariable,
        String pathToScan) {
    if (StringUtils.isBlank(System.getProperty(environmentVariable))) {
        LOG.info(String.format("%s is not set. So skipping property lookup from %s", environmentVariable,
                environmentVariable));
    } else {
        final String detailedEnvironmentPath = StringUtils.replace(pathToScan, environmentVariable,
                System.getProperty(environmentVariable));
        fillProperties(new FileSystemResource(detailedEnvironmentPath), properties);
    }
}

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

/**
 * <p>/*w w  w  .  j  a v a2  s.c  o m*/
 * Elimina simbolos como: <pre>><,;.:!*&%+-_<>[]\/</pre>
 * </p>
 * 
 * @param str
 *            String com os smbolos a serem removidos.
 * @return String sem smbolos.
 * @since 0.2
 */
public static String eliminateSymbols(final String str) {

    String modifiedStr = str;

    if (isNotNull(modifiedStr)) {

        modifiedStr = StringUtils.replace(str, "-", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "_", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "=", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "+", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "%", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "*", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "@", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "#", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "&", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, ":", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, ".", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, ";", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, ",", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "!", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "?", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "(", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, ")", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "{", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "}", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "[", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "]", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "/", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "\\", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, ">", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "<", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "\"", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "'", StringUtils.EMPTY);
        modifiedStr = StringUtils.replace(str, "`", StringUtils.EMPTY);
    }

    return modifiedStr;
}

From source file:com.sfs.whichdoctor.export.prepare.ExportHandlerBase.java

/**
 * Prepare custom export./* www.jav  a 2  s  .c  o m*/
 *
 * @param request the request
 *
 * @return the builder bean
 */
protected final BuilderBean prepareCustomExport(final HttpServletRequest request) {

    final BuilderBean display = new BuilderBean();

    for (String fieldName : this.getFieldNames()) {

        final String inputName = "custom_" + StringUtils.replace(fieldName, " ", "_");
        final String inputValue = request.getParameter(inputName);

        if (StringUtils.equalsIgnoreCase(inputValue, "true")) {
            display.setParameter(fieldName, true);
        }
    }

    for (String section : this.getSections().keySet()) {

        final String[] sectionEntries = this.getSections().get(section);

        final BuilderBean details = new BuilderBean();
        boolean detailsSet = false;

        for (String entry : sectionEntries) {
            final String inputName = StringUtils.replace(section + "_" + entry, " ", "_");
            final String inputValue = request.getParameter(inputName);

            if (StringUtils.equalsIgnoreCase(inputValue, "true")) {
                details.setParameter(entry, true);
                detailsSet = true;
            }
        }
        if (detailsSet) {
            display.addSection(section, details);
        }
    }
    return display;
}

From source file:de.minehattan.chatter.Chatter.java

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) {
    event.setQuitMessage(replaceColorCodes(StringUtils.replace(config.getString("messages.onQuit"), "%player",
            event.getPlayer().getDisplayName())));
}

From source file:com.ctrip.api.Flight.java

public String search() throws XmlMappingException, FileNotFoundException {
    // FlightRoute
    FlightRoute flightRoute = new FlightRoute();
    flightRoute.setDepartCity("SHA");
    flightRoute.setArriveCity("BJS");
    flightRoute.setDepartDate("2014-04-20");
    flightRoute.setAirlineDibitCode("CA");
    flightRoute.setDepartPort("");
    flightRoute.setArrivePort("");
    flightRoute.setEarliestDepartTime("2014-04-20T08:00:00");
    flightRoute.setLatestDepartTime("2014-04-20T12:00:00");
    // Routes//  ww  w. j a  va  2  s.co  m
    Routes routes = new Routes();
    routes.setFlightRoute(flightRoute);
    // FlightSearchRequest
    FlightSearchRequest flightSearchRequest = new FlightSearchRequest();
    flightSearchRequest.setSearchType(FlightSearchType.DAN_CHENG.getCode());
    flightSearchRequest.setRoutes(routes);
    flightSearchRequest.setSendTicketCity("SHA");
    flightSearchRequest.setIsSimpleResponse("false");
    flightSearchRequest.setIsLowestPrice("false");
    flightSearchRequest.setPriceTypeOptions("NormalPrice");
    flightSearchRequest.setProductTypeOptions("Normal");
    flightSearchRequest.setClassgrade("F");
    flightSearchRequest.setOrderBy("DepartTime");
    flightSearchRequest.setDirection("ASC");
    // FlightSearch
    FlightSearchRequestBody flightSearchRequestBody = new FlightSearchRequestBody();
    flightSearchRequestBody.setHeader(ctripApiTemplate.getHeader());
    flightSearchRequestBody.setFlightSearchRequest(flightSearchRequest);
    StringResult requestBodyResult = new StringResult();
    jaxb2Marshaller.marshal(flightSearchRequestBody, requestBodyResult);
    // SoapRequest
    SoapRequest soapRequest = new SoapRequest();
    soapRequest.setRequest(requestBodyResult.toString());
    SoapResponse soapResponse = ctripApiTemplate.send(OTA_FLIGHT_SEARCH, soapRequest);
    // FlightSearchResponseBody
    String responseContent = soapResponse.getResponse();
    responseContent = StringUtils.replace(responseContent, CtripApiTemplate.SOAP_RESPONSE_DECLARE,
            StringUtils.EMPTY);
    FlightSearchResponseBody flightSearchResponseBody = (FlightSearchResponseBody) jaxb2Marshaller
            .unmarshal(new StringSource(responseContent));
    return flightSearchResponseBody.getFlightSearchResponse();
}

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

@Override
public void setFormat(String format) {
    Map<String, String> vars = new HashMap<>();

    format = StringUtils.replace(format, "%1$s", "{DISPLAYNAME}");
    format = StringUtils.replace(format, "%2$s", "{MESSAGE}");

    vars.put("0", "{GROUP}");
    vars.put("1", "{WORLD}");
    vars.put("1", "{WORLDNAME}");
    vars.put("2", "{SHORTWORLDNAME}");
    vars.put("3", "{TEAMPREFIX}");
    vars.put("4", "{TEAMSUFFIX}");
    vars.put("5", "{TEAMNAME}");

    format = co.marcin.novaguilds.util.StringUtils.replaceMap(format, vars);

    this.format = format;
}

From source file:com.wolvencraft.yasp.db.ScriptRunner.java

/**
 * Executes a database script/*from   w  w w .j  a  va  2  s .c  om*/
 *
 * @param reader Reader
 * @throws RuntimeSQLException thrown if an error occurs while executing a line
 */
public void runScript(Reader reader) throws RuntimeSQLException {
    Message.log(Level.FINER, "Executing a database script");

    try {
        StringBuilder command = new StringBuilder();
        try {
            BufferedReader lineReader = new BufferedReader(reader);
            int i = 0;
            String line = "";
            String dbName = LocalConfiguration.DBName.toString();
            String dbPrefix = LocalConfiguration.DBPrefix.toString();
            boolean debug = LocalConfiguration.Debug.toBoolean();
            while ((line = lineReader.readLine()) != null) {
                line = StringUtils.replace(line, "$dbname", dbName);
                line = StringUtils.replace(line, "$prefix_", dbPrefix);
                command = this.handleLine(command, line);
                i++;
                if (i % 50 == 0 && debug)
                    Message.log(Level.FINEST, "Executing line " + i);
            }
            Message.log(Level.FINER, "Executed " + i + " lines total");
            this.commitConnection();
            this.checkForMissingLineTerminator(command);
        } catch (Exception e) {
            String message = "Error executing: " + command + ".  Cause: " + e;
            throw new RuntimeSQLException(message, e);
        }
    } finally {
        this.rollbackConnection();
    }
}

From source file:edu.ku.brc.specify.conversion.ConversionLogger.java

/**
 * @param tableName//from   w ww  . j  ava  2 s  .c o m
 * @return
 * @throws IOException
 */
public TableWriter getWriter(final String fileName, final String title, final String extraStyle,
        final boolean doCenterTitle) {
    TableWriter tblWriter = null;
    try {
        if (printWritersNameHash.get(fileName) == null) {
            String path = dir.getAbsolutePath() + File.separator + StringUtils.replace(fileName, " ", "_");
            tblWriter = new TableWriter(path, title, extraStyle, doCenterTitle);
            printWritersNameHash.put(fileName, path);
            printWritersHash.put(fileName, tblWriter);
            printWritersList.add(tblWriter);

        } else {
            System.err.println("Duplicate file name[" + fileName + "]");
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return tblWriter;
}

From source file:adalid.util.meta.CodeAnalyzerTreeVisitor.java

private void info(String string) {
    string = StringUtils.removeEnd(string, CM);
    //      string = StringUtils.remove(string, NL);
    string = StringUtils.replace(string, EOL, SP); // "<n>"
    //      string = StringUtils.remove(string, TB);
    string = StringUtils.replace(string, TAB, SP); // "<t>"
    string = StringUtils.remove(string, SP + SP);
    string = StringUtils.trimToEmpty(string);
    logger.info(tabs() + string);/*from   www. ja  v a2 s.  com*/
}

From source file:edu.utah.further.core.api.text.TextTemplate.java

/**
 * Evaluate a template./*from  w ww.j  av a2  s  . c o  m*/
 *
 * @param values
 *            parameter value list. Must match the parameter list size and order (i.e.
 *            the first <code>values</code> element corresponds to the first
 *            parameter, etc.)
 * @return evaluated template
 */
public String evaluate(final List<String> values) {
    final int size = parameters.size();
    Validate.isTrue(values.size() == size, "Value list size must equal the parameter list size. parameters "
            + parameters + " values " + values);

    // Replace arguments by values
    String evaluated = text;
    for (int i = 0; i < size; i++) {
        evaluated = StringUtils.replace(evaluated, parameters.get(i), values.get(i));
    }
    return evaluated;
}