本文整理汇总了Java中org.apache.commons.text.StrSubstitutor类的典型用法代码示例。如果您正苦于以下问题:Java StrSubstitutor类的具体用法?Java StrSubstitutor怎么用?Java StrSubstitutor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StrSubstitutor类属于org.apache.commons.text包,在下文中一共展示了StrSubstitutor类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: launch
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
public static void launch(LauncherModel launcher, ServerModel server, KeyModel key, ActionModel action, Map<String, String> params) {
params.put("host", server.getHost());
params.put("user", server.getUser());
params.put("keyPath", key.getPaths().get(launcher.getKeyFormat()));
StrSubstitutor sub = new StrSubstitutor(params);
String actionCommand = sub.replace(action.getCommand());
params.put("actionCommand", '"' + actionCommand + '"');
String shellCommand = sub.replace(launcher.getShellCommand());
params.put("shellCommand", shellCommand);
final List<String> terminalCommandList = launcher.getTerminalCommandList();
String[] terminalCommandArray = terminalCommandList.stream()
.map(sub::replace)
.collect(Collectors.toList())
.toArray(new String[terminalCommandList.size()]);
try {
final Process process = getRuntime().exec(terminalCommandArray);
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
示例2: resolveReferenceableProperties
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
/**
* Resolve as many property references as possible. For unresolved references, throw exception in the end.
* @throws IOException
*/
private void resolveReferenceableProperties() throws IOException {
List<String> undefinedProperties = new ArrayList<String>();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
Map<String, String> referenceableProperties = new HashMap<String, String>();
referenceableProperties.putAll(implicitProperties);
referenceableProperties.putAll(IronTestUtils.udpListToMap(testcaseUDPs));
// resolve references in teststep.otherProperties
String otherPropertiesJSON = objectMapper.writeValueAsString(teststep.getOtherProperties());
MapValueLookup propertyReferenceResolver = new MapValueLookup(referenceableProperties, true);
String resolvedOtherPropertiesJSON = new StrSubstitutor(propertyReferenceResolver).replace(otherPropertiesJSON);
undefinedProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
String tempStepJSON = "{\"type\":\"" + teststep.getType() + "\",\"otherProperties\":" +
resolvedOtherPropertiesJSON + "}";
Teststep tempStep = objectMapper.readValue(tempStepJSON, Teststep.class);
teststep.setOtherProperties(tempStep.getOtherProperties());
// resolve UDP references in teststep.request (text type)
if (teststep.getRequestType() == TeststepRequestType.TEXT) {
propertyReferenceResolver = new MapValueLookup(referenceableProperties, false);
teststep.setRequest(new StrSubstitutor(propertyReferenceResolver).replace(
(String) teststep.getRequest()));
undefinedProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
}
if (!undefinedProperties.isEmpty()) {
throw new RuntimeException("Properties " + undefinedProperties + " are undefined.");
}
}
示例3: parseInputField
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
private String parseInputField(String input, Map<String, String> replacements) {
if (input != null && input.length() > 0) {
StrSubstitutor substitutor = new StrSubstitutor(replacements);
String output = substitutor.replace(input);
checkForRemainingPlaceholders(output);
return output;
}
return input;
}
示例4: log
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
@Override
public void log(@NonNull final LogContext logContext)
{
String replacedMessage = StrSubstitutor.replace( CoreConfig.Logging.logFormat, logContext.toMap() );
if ( getPrintStream() != null )
{
getPrintStream().println( replacedMessage );
}
Bukkit.getConsoleSender()
.sendMessage( ChatColor.translateAlternateColorCodes( '&', replacedMessage ) );
}
示例5: verify
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
/**
* @param assertion the assertion to be verified (against the input)
* @param input the object that the assertion is verified against
* @return
*/
public AssertionVerificationResult verify(Assertion assertion, Object input) throws Exception {
Map<String, String> referenceableProperties = new HashMap<String, String>();
referenceableProperties.putAll(implicitProperties);
referenceableProperties.putAll(IronTestUtils.udpListToMap(testcaseUDPs));
MapValueLookup propertyReferenceResolver = new MapValueLookup(referenceableProperties, true);
// resolve property references in assertion.name
String resolvedAssertionName = new StrSubstitutor(propertyReferenceResolver)
.replace(assertion.getName());
assertion.setName(resolvedAssertionName);
Set<String> undefinedProperties = propertyReferenceResolver.getUnfoundKeys();
// resolve property references in assertion.otherProperties
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
String assertionOtherPropertiesJSON = objectMapper.writeValueAsString(assertion.getOtherProperties());
String resolvedAssertionOtherPropertiesJSON = new StrSubstitutor(propertyReferenceResolver)
.replace(assertionOtherPropertiesJSON);
undefinedProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
String tempAssertionJSON = "{\"type\":\"" + assertion.getType() + "\",\"otherProperties\":" +
resolvedAssertionOtherPropertiesJSON + "}";
Assertion tempAssertion = objectMapper.readValue(tempAssertionJSON, Assertion.class);
assertion.setOtherProperties(tempAssertion.getOtherProperties());
if (!undefinedProperties.isEmpty()) {
throw new RuntimeException("Properties " + undefinedProperties + " are undefined.");
}
return _verify(assertion, input);
}
示例6: createQuery
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
private static String createQuery( ExportParams params )
{
IdSchemes idSchemes = params.getOutputIdSchemes() != null ? params.getOutputIdSchemes() : new IdSchemes();
ImmutableMap.Builder<String, String> namedParamsBuilder = ImmutableMap.<String, String>builder()
.put( DATA_SET_SCHEME, idSchemes.getDataSetIdScheme().getIdentifiableString().toLowerCase() )
.put( ORG_UNIT_SCHEME, idSchemes.getOrgUnitIdScheme().getIdentifiableString().toLowerCase() )
.put( ATTR_OPT_COMBO_SCHEME, idSchemes.getAttributeOptionComboIdScheme().getIdentifiableString().toLowerCase() );
String sql =
"SELECT ds.${dsScheme} AS dsid, pe.startdate AS pe_start, pt.name AS ptname, ou.${ouScheme} AS ouid, " +
"aoc.${aocScheme} AS aocid, cdsr.storedby AS storedby, cdsr.date AS created " +
"FROM completedatasetregistration cdsr " +
"INNER JOIN dataset ds ON (cdsr.datasetid=ds.datasetid) " +
"INNER JOIN period pe ON (cdsr.periodid=pe.periodid) " +
"INNER JOIN periodtype pt ON (pe.periodtypeid=pt.periodtypeid) " +
"INNER JOIN organisationunit ou ON (cdsr.sourceid=ou.organisationunitid) " +
"INNER JOIN categoryoptioncombo aoc ON (cdsr.attributeoptioncomboid = aoc.categoryoptioncomboid) ";
sql += createOrgUnitGroupJoin( params );
sql += createDataSetClause( params, namedParamsBuilder );
sql += createOrgUnitClause( params, namedParamsBuilder );
sql += createPeriodClause( params, namedParamsBuilder );
sql += createCreatedClause( params, namedParamsBuilder );
sql += createLimitClause( params, namedParamsBuilder );
sql = new StrSubstitutor( namedParamsBuilder.build(), "${", "}" ).replace( sql );
log.debug( "CompleteDataSetRegistrations query: " + sql );
return sql;
}
示例7: getMapUrl
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
public static String getMapUrl(String lat, String lng, Map<ConfigurationKeys, Optional<String>> geoConf) {
Map<String, String> params = new HashMap<>();
params.put("latitude", lat);
params.put("longitude", lng);
ConfigurationKeys.GeoInfoProvider provider = getProvider(geoConf);
String mapUrl = mapUrl(provider);
fillParams(provider, geoConf, params);
return new StrSubstitutor(params).replace(mapUrl);
}
示例8: buildCheckSessionIframe
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
private String buildCheckSessionIframe() {
return StrSubstitutor.replace(CHECK_SESSION_IFRAME_TEMPLATE,
Collections.singletonMap("cookieName", this.cookieName));
}
示例9: resolve
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
public String resolve(final String text) {
return StrSubstitutor.replace(text, environmentVariables.toJavaMap());
}
示例10: substituteEnvironmentVariables
import org.apache.commons.text.StrSubstitutor; //导入依赖的package包/类
private void substituteEnvironmentVariables( Properties properties )
{
final StrSubstitutor substitutor = new StrSubstitutor( System.getenv() ); // Matches on ${...}
properties.entrySet().forEach( entry -> entry.setValue( substitutor.replace( entry.getValue() ).trim() ) );
}