Example usage for org.apache.commons.lang.text StrSubstitutor StrSubstitutor

List of usage examples for org.apache.commons.lang.text StrSubstitutor StrSubstitutor

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrSubstitutor StrSubstitutor.

Prototype

public StrSubstitutor(StrLookup variableResolver) 

Source Link

Document

Creates a new instance and initializes it.

Usage

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnReplicationCodeFileWriter.java

public String generateEdaLines() {
    String template = "aol<-c(1,1,0)\n" + "try(dir.create('./Zlg_${PID}'))\n"
            + "htmlsink<-HTMLInitFile(outdir = './Zlg_${PID}', filename='Rout_${PID}', \n"
            + "extension='html', CSSFile='R2HTML.css', Title ='Dataverse Analysis: Request #${PID}')\n"
            + "hdrContents <- '<h1>Dataverse Analysis</h1><h2>Results</h2><p>Study\n"
            + " Title:testDataForDSB</p><hr />'\n" + "HTML(file=htmlsink,hdrContents)\n"
            + "try(dir.create('./Zlg_${PID}/visuals'))\n"
            + "try(${dvn_dataframe}<-univarStat(dtfrm=${dvn_dataframe}))\n"
            + "try({${dvn_dataframe}<-univarChart(dtfrm=${dvn_dataframe}, analysisoptn=aol,\n"
            + "imgflprfx='./Zlg_${PID}/visuals/Rvls.${PID}',standalone=F)})\n"
            + "try(univarStatHtmlBody(dtfrm=${dvn_dataframe},whtml=htmlsink, analysisoptn=aol))\n"
            + "HTMLEndFile()\n" + "file.rename('R2HTML.css', './Zlg_${PID}/R2HTML.css')\n"
            + "wrkdir<-'./Zlg_${PID}'\n"
            + "htmlfile <- paste(wrkdir,'/', list.files(wrkdir, pattern='.html'), sep='')\n"
            + "browseURL(htmlfile)\n";
    StrSubstitutor sub = new StrSubstitutor(valueMap);

    return sub.replace(template);
}

From source file:com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver.java

public String replaceAll(String str, String replacement) {
    if (str != null) {
        StrLookup lookup = new StrLookup() {
            @Override//from www .  j a  v a2 s.  co  m
            public String lookup(String key) {
                return replacement;
            }
        };
        StrSubstitutor ss = new StrSubstitutor(lookup);
        return ss.replace(str);
    }
    return null;
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnReplicationREADMEFileWriter.java

public String generatePtCitationBlock() {
    StrSubstitutor sub = new StrSubstitutor(valueMap);
    return sub.replace(citationTemplate);
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnReplicationCodeFileWriter.java

public String generateXtabLines() {
    String template = "aol<-c(0,0,1)\n" + "try(dir.create('./Zlg_${PID}'))\n"
            + "htmlsink<-HTMLInitFile(outdir = './Zlg_${PID}', filename='Rout_${PID}', \n"
            + "extension='html', CSSFile='R2HTML.css', Title ='Dataverse Analysis: Request #${PID}')\n"
            + "hdrContents <- '<h1>Dataverse Analysis</h1><h2>Results</h2><p>Study\n"
            + " Title:testDataForDSB</p><hr />'\n" + "HTML(file=htmlsink,hdrContents)\n" +

            "try(${dvn_dataframe}<-univarStat(dtfrm=${dvn_dataframe}))\n" + "library(VDCutil)\n"
            + "classVar<-c(${class_var_set})\n" + "freqVar<-c(${freq_var})\n" +

            "try(VDCcrossTabulation(HTMLfile=htmlsink, data=${dvn_dataframe},\n" +

            "classificationVars=classVar, freqVars=freqVar, wantPercentages=${wantPercentages}, \n" +

            "wantTotals=${wantTotals}, wantStats=${wantStats}, wantExtraTables=${wantExtraTables}))\n" +

            "HTMLEndFile()\n" + "file.rename('R2HTML.css', './Zlg_${PID}/R2HTML.css')\n"
            + "wrkdir<-'./Zlg_${PID}'\n"
            + "htmlfile <- paste(wrkdir,'/', list.files(wrkdir, pattern='.html'), sep='')\n"
            + "browseURL(htmlfile)\n";

    StrSubstitutor sub = new StrSubstitutor(valueMap);

    return sub.replace(template);
}

From source file:com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver.java

/**
 * Resolve the str with values from the supplied {@code properties} This will recursively fill out the str looking back at the properties to get the correct value. NOTE the property values will be
 * overwritten if replacement is found!//w w  w . ja v  a2 s  . c om
 */
public ResolvedVariables resolveVariables(String str, List<NifiProperty> properties) {
    ResolvedVariables variables = new ResolvedVariables(str);

    StrLookup resolver = new StrLookup() {
        @Override
        public String lookup(String key) {
            Optional<NifiProperty> optional = properties.stream().filter(prop -> key.equals(prop.getKey()))
                    .findFirst();
            if (optional.isPresent()) {
                NifiProperty property = optional.get();
                String value = StringUtils.isNotBlank(property.getValue()) ? property.getValue().trim() : "";
                variables.getResolvedVariables().put(property.getKey(), value);
                return value;
            } else {
                return null;
            }
        }
    };

    StrSubstitutor ss = new StrSubstitutor(resolver);
    variables.setResolvedString(ss.replace(str));

    Map<String, String> map = variables.getResolvedVariables();
    Map<String, String> vars = map.entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, entry -> ss.replace(entry.getValue())));
    variables.getResolvedVariables().putAll(vars);

    return variables;
}

From source file:com.thoughtworks.go.buildsession.BuildSession.java

String buildVariableSubstitute(String str) {
    return new StrSubstitutor(buildVariables).replace(str);
}

From source file:com.clank.launcher.launch.Runner.java

/**
 * Add arguments for the application.//from w ww . j a  va2  s  .  c  o  m
 *
 * @throws JsonProcessingException on error
 */
private void addJarArgs() throws JsonProcessingException {
    List<String> args = builder.getArgs();

    String[] rawArgs = versionManifest.getMinecraftArguments().split(" +");
    StrSubstitutor substitutor = new StrSubstitutor(getCommandSubstitutions());
    for (String arg : rawArgs) {
        args.add(substitutor.replace(arg));
    }
}

From source file:com.facebook.presto.accumulo.tools.PaginationTask.java

public int runQuery() throws SQLException {
    int numErrors = 0;
    numErrors += checkParam(config, "config");
    numErrors += checkParam(host, "host");
    numErrors += checkParam(port, "port");
    numErrors += checkParam(query, "query");
    numErrors += checkParam(columns, "columns");

    if (numErrors > 0) {
        return 1;
    }//  w  w w. j a va  2  s .  c o  m

    // Clean up any previously run queries in the event the user did not call it explicitly
    cleanup();

    // Open JDBC connection
    String dbUrl = String.format("%s%s:%d/%s", SCHEME, host, port, CATALOG);
    Properties jdbcProps = new Properties();
    jdbcProps.setProperty("user", "root");
    conn = (PrestoConnection) DriverManager.getConnection(dbUrl, jdbcProps);
    conn.setCatalog(CATALOG);
    setSessionProperties(conn);

    // Randomly generate a table name as a local variable
    String tmpTable = "accumulo.pagination.tmp_" + UUID.randomUUID().toString().replaceAll("\\W", "");

    // Build the column mapping based on
    StringBuilder columnMapping = new StringBuilder();
    for (String col : columns) {
        columnMapping.append(col).append(":f:").append(UUID.randomUUID().toString().substring(0, 8))
                .append(',');
    }
    columnMapping.deleteCharAt(columnMapping.length() - 1);

    StringBuilder queryWithGroupBy = new StringBuilder("SELECT 0 AS groupby, ");
    queryWithGroupBy.append(query.substring(query.indexOf("SELECT ") + 7));

    // Substitute the parameters to generate the create table query
    Map<String, String> queryProps = new HashMap<>();
    queryProps.put(TMP_TABLE, tmpTable);
    queryProps.put(TMP_COLUMN_MAPPING, columnMapping.toString());
    queryProps.put(SUBQUERY_COLUMNS, StringUtils.join(columns, ','));
    queryProps.put(USER_QUERY, queryWithGroupBy.toString());

    // Execute the create table query
    StrSubstitutor sub = new StrSubstitutor(queryProps);
    String createTableQuery = sub.replace(createTableTemplate);
    LOG.info(format("Executing query to create temporary table:\n%s", createTableQuery));
    Statement stmt = conn.createStatement();
    stmt.execute(createTableQuery);

    // Execute the query to get the max offset i.e. number of rows from the user query
    stmt = conn.createStatement();
    ResultSet results = stmt.executeQuery("SELECT MAX(offset) FROM " + tmpTable);
    results.next();
    maxOffset = results.getLong(1);
    LOG.info(format("Query has %d results", maxOffset));

    // Set the temp table name now that we have made it through the gauntlet
    this.tmpTableName = tmpTable;
    return 0;
}

From source file:com.redhat.lightblue.rest.crud.AbstractCrudResource.java

private String buildQueryFieldTemplate(String s1) {
    String sq;//from w w w. j av  a 2  s  .  c o m
    String template = null;

    String[] split = s1.split(":");

    Map<String, String> map = new HashMap<>();
    map.put("field", split[0]);
    String value = null;

    String[] comma = split[1].split(",");
    if (comma.length > 1) {
        template = FIELD_Q_IN_TMPL;
        value = "\"" + StringUtils.join(comma, "\",\"") + "\"";
    } else {
        template = FIELD_Q_EQ_TMPL;
        value = split[1];
    }
    map.put("value", value);

    StrSubstitutor sub = new StrSubstitutor(map);

    sq = sub.replace(template);
    return sq;
}

From source file:com.redhat.lightblue.rest.crud.AbstractCrudResource.java

private String buildProjectionTemplate(String s1) {
    String sp;//from   w w w  .  ja  v  a  2  s.  c  o m
    String[] split = s1.split(":");

    Map<String, String> map = new HashMap<>();
    map.put("field", split[0]);
    map.put("include", split[1].charAt(0) == '1' ? "true" : "false");
    map.put("recursive", split[1].length() < 2 ? "false" : (split[1].charAt(1) == 'r' ? "true" : "false"));

    StrSubstitutor sub = new StrSubstitutor(map);

    sp = sub.replace(PROJECTION_TMPL);
    return sp;
}