當前位置: 首頁>>代碼示例>>Java>>正文


Java StrSubstitutor.replace方法代碼示例

本文整理匯總了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;
}
 
開發者ID:nhsconnect,項目名稱:careconnect-reference-implementation,代碼行數:21,代碼來源:ServerInterceptor.java

示例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()+"]");
}
 
開發者ID:nhsconnect,項目名稱:careconnect-reference-implementation,代碼行數:17,代碼來源:ServerInterceptor.java

示例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);
}
 
開發者ID:mesosphere,項目名稱:dcos-commons,代碼行數:20,代碼來源:YAMLConfigurationLoader.java

示例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;
}
 
開發者ID:BadgeUp,項目名稱:badgeup-sponge-client,代碼行數:21,代碼來源:CommandAward.java

示例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);
}
 
開發者ID:appstatus,項目名稱:appstatus,代碼行數:21,代碼來源:HtmlUtils.java

示例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;
}
 
開發者ID:lightblue-platform,項目名稱:lightblue-rest,代碼行數:26,代碼來源:QueryTemplateUtils.java

示例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);
}
 
開發者ID:arquillian,項目名稱:arquillian-cube,代碼行數:19,代碼來源:IOUtil.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:35,代碼來源:HttpUtils.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:23,代碼來源:SalesforceSource.java

示例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);
}
 
開發者ID:SciGraph,項目名稱:SciGraph,代碼行數:22,代碼來源:CypherUtil.java

示例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();
}
 
開發者ID:linkedin,項目名稱:pinot,代碼行數:26,代碼來源:AnomalyResource.java

示例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);
}
 
開發者ID:HuygensING,項目名稱:timbuctoo,代碼行數:25,代碼來源:Utils.java

示例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);
}
 
開發者ID:rozidan,項目名稱:logger-spring-boot,代碼行數:9,代碼來源:LoggerMsgFormatter.java

示例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);
}
 
開發者ID:rozidan,項目名稱:logger-spring-boot,代碼行數:10,代碼來源:LoggerMsgFormatter.java

示例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);
}
 
開發者ID:rozidan,項目名稱:logger-spring-boot,代碼行數:9,代碼來源:LoggerMsgFormatter.java


注:本文中的org.apache.commons.lang3.text.StrSubstitutor.replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。