本文整理匯總了Java中org.apache.commons.lang3.text.StrSubstitutor.replace方法的典型用法代碼示例。如果您正苦於以下問題:Java StrSubstitutor.replace方法的具體用法?Java StrSubstitutor.replace怎麽用?Java StrSubstitutor.replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang3.text.StrSubstitutor
的用法示例。
在下文中一共展示了StrSubstitutor.replace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: incomingRequestPostProcessed
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
@Override
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
Enumeration<String> headers = theRequest.getHeaderNames();
while (headers.hasMoreElements()) {
String header = headers.nextElement();
log.debug("Header = "+ header + "="+ theRequest.getHeader(header));
}
// Perform any string substitutions from the message format
StrLookup<?> lookup = new MyLookup(theRequest, theRequestDetails);
StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');
// Actually log the line
String myMessageFormat = "httpVerb[${requestVerb}] Source[${remoteAddr}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] RequestId[${requestHeader.x-request-id}] ForwardedFor[${requestHeader.x-forwarded-for}] ForwardedHost[${requestHeader.x-forwarded-host}] CorrelationId[] ProcessingTime[] ResponseCode[]";
String line = subs.replace(myMessageFormat);
log.info(line);
return true;
}
示例2: processingCompletedNormally
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
@Override
public void processingCompletedNormally(ServletRequestDetails theRequestDetails) {
// Perform any string substitutions from the message format
StrLookup<?> lookup = new MyLookup(theRequestDetails.getServletRequest(), theRequestDetails);
StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');
for (String header : theRequestDetails.getServletResponse().getHeaderNames()) {
log.debug("Header = " + header + "=" + theRequestDetails.getServletResponse().getHeader(header));
}
String myMessageFormat = "httpVerb[${requestVerb}] Source[${remoteAddr}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] RequestId[${requestHeader.x-request-id}] ForwardedFor[${requestHeader.x-forwarded-for}] ForwardedHost[${requestHeader.x-forwarded-host}] CorrelationId[${requestHeader.x-request-id}] ProcessingTime[${processingTimeMillis}]";
String line = subs.replace(myMessageFormat);
log.info(line+" ResponseCode["+theRequestDetails.getServletResponse().getStatus()+"]");
}
示例3: loadConfigFromEnv
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
public static <T> T loadConfigFromEnv(Class<T> configurationClass, final String path)
throws IOException {
LOGGER.info("Parsing configuration file from {} ", path);
logProcessEnv();
final Path configPath = Paths.get(path);
final File file = configPath.toAbsolutePath().toFile();
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
final StrSubstitutor sub = new StrSubstitutor(new StrLookup<Object>() {
@Override
public String lookup(String key) {
return System.getenv(key);
}
});
sub.setEnableSubstitutionInVariables(true);
final String conf = sub.replace(FileUtils.readFileToString(file));
return mapper.readValue(conf, configurationClass);
}
示例4: awardPlayer
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
@Override
public boolean awardPlayer(Player player) {
Optional<String> commandTemplateOpt = Util.safeGetString(this.data, "command");
if (!commandTemplateOpt.isPresent()) {
this.plugin.getLogger().error("No command specified. Aborting.");
return false;
}
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("playerName", player.getName());
valuesMap.put("playerId", player.getUniqueId().toString());
StrSubstitutor sub = new StrSubstitutor(valuesMap);
String command = sub.replace(commandTemplateOpt.get());
this.plugin.getLogger().info("Executing command award as console: " + command);
CommandResult result = Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command);
return result.getSuccessCount().orElse(0) > 0;
}
示例5: applyLayout
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
public static String applyLayout(Map<String, String> valuesMap, String templateName) throws IOException {
String templateString = "";
if (templates.containsKey(templateName)) {
templateString = templates.get(templateName);
} else {
// get the file
InputStream inputStream = Resources.class.getResourceAsStream("/templates/" + templateName);
// convert to string
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, Charset.defaultCharset());
templateString = writer.toString();
templates.put(templateName, templateString);
}
// substitution & return
StrSubstitutor sub = new StrSubstitutor(valuesMap);
return sub.replace(templateString);
}
示例6: buildQueryFieldTemplate
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
private static String buildQueryFieldTemplate(String q) {
String sq;
String template = null;
String[] split = q.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;
}
示例7: replacePlaceholdersWithWhiteSpace
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
public static String replacePlaceholdersWithWhiteSpace(final String templateContent,
final Map<String, String> values) {
StrSubstitutor sub = new StrSubstitutor(values);
sub.setVariableResolver(new StrLookup<Object>() {
@Override
public String lookup(String key) {
if (values == null) {
return "";
}
Object obj = values.get(key);
if (obj == null) {
return "";
}
return obj.toString();
}
});
return sub.replace(templateContent);
}
示例8: buildURI
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
/**
* Given a url template, interpolate with keys and build the URI after adding query parameters
*
* <p>
* With url template: http://test.com/resource/(urn:${resourceId})/entities/(entity:${entityId}),
* keys: { "resourceId": 123, "entityId": 456 }, queryParams: { "locale": "en_US" }, the outpuT URI is:
* http://test.com/resource/(urn:123)/entities/(entity:456)?locale=en_US
* </p>
*
* @param urlTemplate url template
* @param keys data map to interpolate url template
* @param queryParams query parameters added to the url
* @return a uri
*/
public static URI buildURI(String urlTemplate, Map<String, String> keys, Map<String, String> queryParams) {
// Compute base url
String url = urlTemplate;
if (keys != null && keys.size() != 0) {
url = StrSubstitutor.replace(urlTemplate, keys);
}
try {
URIBuilder uriBuilder = new URIBuilder(url);
// Append query parameters
if (queryParams != null && queryParams.size() != 0) {
for (Map.Entry<String, String> entry : queryParams.entrySet()) {
uriBuilder.addParameter(entry.getKey(), entry.getValue());
}
}
return uriBuilder.build();
} catch (URISyntaxException e) {
throw new RuntimeException("Fail to build uri", e);
}
}
示例9: getCountForRange
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
/**
* Get the row count for a time range
*/
private int getCountForRange(TableCountProbingContext probingContext, StrSubstitutor sub,
Map<String, String> subValues, long startTime, long endTime) {
String startTimeStr = Utils.dateToString(new Date(startTime), SalesforceExtractor.SALESFORCE_TIMESTAMP_FORMAT);
String endTimeStr = Utils.dateToString(new Date(endTime), SalesforceExtractor.SALESFORCE_TIMESTAMP_FORMAT);
subValues.put("start", startTimeStr);
subValues.put("end", endTimeStr);
String query = sub.replace(PROBE_PARTITION_QUERY_TEMPLATE);
log.debug("Count query: " + query);
probingContext.probeCount++;
JsonArray records = getRecordsForQuery(probingContext.connector, query);
Iterator<JsonElement> elements = records.iterator();
JsonObject element = elements.next().getAsJsonObject();
return element.get("cnt").getAsInt();
}
示例10: substituteRelationships
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
String substituteRelationships(String query, final Multimap<String, Object> valueMap) {
StrSubstitutor substitutor = new StrSubstitutor(new StrLookup<String>() {
@Override
public String lookup(String key) {
Collection<String> resolvedRelationshipTypes =
transform(valueMap.get(key), new Function<Object, String>() {
@Override
public String apply(Object input) {
if (input.toString().matches(".*(\\s).*")) {
throw new IllegalArgumentException(
"Cypher relationship templates must not contain spaces");
}
return curieUtil.getIri(input.toString()).orElse(input.toString());
}
});
return on("|").join(resolvedRelationshipTypes);
}
});
return substitutor.replace(query);
}
示例11: getExternalDashboardUrlForMergedAnomaly
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
@GET
@Path("/external-dashboard-url/{mergedAnomalyId}")
public String getExternalDashboardUrlForMergedAnomaly(@NotNull @PathParam("mergedAnomalyId") Long mergedAnomalyId)
throws Exception {
MergedAnomalyResultDTO mergedAnomalyResultDTO = mergedAnomalyResultDAO.findById(mergedAnomalyId);
String metric = mergedAnomalyResultDTO.getMetric();
String dataset = mergedAnomalyResultDTO.getCollection();
Long startTime = mergedAnomalyResultDTO.getStartTime();
Long endTime = mergedAnomalyResultDTO.getEndTime();
MetricConfigDTO metricConfigDTO = metricConfigDAO.findByMetricAndDataset(metric, dataset);
Map<String, String> context = new HashMap<>();
context.put(MetricConfigBean.URL_TEMPLATE_START_TIME, String.valueOf(startTime));
context.put(MetricConfigBean.URL_TEMPLATE_END_TIME, String.valueOf(endTime));
StrSubstitutor strSubstitutor = new StrSubstitutor(context);
Map<String, String> urlTemplates = metricConfigDTO.getExtSourceLinkInfo();
for (Entry<String, String> entry : urlTemplates.entrySet()) {
String sourceName = entry.getKey();
String urlTemplate = entry.getValue();
String extSourceUrl = strSubstitutor.replace(urlTemplate);
urlTemplates.put(sourceName, extSourceUrl);
}
return new JSONObject(urlTemplates).toString();
}
示例12: replaceVariableReferences
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
public static String replaceVariableReferences(final Evaluator evaluator, final String body,
final ResultRecorder resultRecorder) {
if (body == null) {
return null;
}
StrSubstitutor sub = new StrSubstitutor(new StrLookup<Object>() {
@Override
public String lookup(String name) {
try {
Object value = evaluator.evaluate(name);
if (value == null) {
return "";
} else {
return value.toString();
}
} catch (Exception e) {
resultRecorder.record(Result.FAILURE);
return "<span class=\"failure\">" + e.toString() + "</span>";
}
}
}, "$(", ")", '\\');
return sub.replace(body);
}
示例13: warnBefore
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
public String warnBefore(ProceedingJoinPoint joinPoint, Loggable loggable, long nano) {
Map<String, Object> values = new HashMap<>();
values.put(METHDO_VALUE, methodName(joinPoint));
values.put(ARGS_VALUE, methodArgs(joinPoint, loggable));
values.put(DURATION_VALUE, durationString(nano));
values.put(WARN_DURATION_VALUE, warnDuration(loggable));
return StrSubstitutor.replace(formats.getWarnBefore(), values);
}
示例14: warnAfter
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
public String warnAfter(ProceedingJoinPoint joinPoint, Loggable loggable, Object result, long nano) {
Map<String, Object> values = new HashMap<>();
values.put(METHDO_VALUE, methodName(joinPoint));
values.put(ARGS_VALUE, methodArgs(joinPoint, loggable));
values.put(DURATION_VALUE, durationString(nano));
values.put(WARN_DURATION_VALUE, warnDuration(loggable));
values.put(RESULT_VALUE, methodResults(result, loggable));
return StrSubstitutor.replace(formats.getWarnAfter(), values);
}
示例15: after
import org.apache.commons.lang3.text.StrSubstitutor; //導入方法依賴的package包/類
public String after(ProceedingJoinPoint joinPoint, Loggable loggable, Object result, long nano) {
Map<String, Object> values = new HashMap<>();
values.put(METHDO_VALUE, methodName(joinPoint));
values.put(ARGS_VALUE, methodArgs(joinPoint, loggable));
values.put(DURATION_VALUE, durationString(nano));
values.put(RESULT_VALUE, methodResults(result, loggable));
return StrSubstitutor.replace(formats.getAfter(), values);
}