Java 类org.apache.commons.lang3.text.StrLookup 实例源码
项目:careconnect-reference-implementation
文件:ServerInterceptor.java
@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;
}
项目:careconnect-reference-implementation
文件:ServerInterceptor.java
@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()+"]");
}
项目:dcos-commons
文件:YAMLConfigurationLoader.java
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);
}
项目:Aletheia
文件:AletheiaConfig.java
private String resolve(final String configurationWithPlaceholders, final Properties placeholderValues)
throws IOException {
return new StrSubstitutor(
new StrLookup<String>() {
@Override
public String lookup(final String key) {
Preconditions.checkNotNull(placeholderValues.getProperty(key),
"placeholder: \"${%s}\" was not assigned",
key);
return placeholderValues.getProperty(key);
}
},
"${",
"}",
'#')
.replace(configurationWithPlaceholders);
}
项目:SciGraph
文件:CypherUtil.java
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);
}
项目:jmxeval
文件:Element.java
/**
* Construct with the execution context.
*
* @param context Execution context
*/
protected Element(final Context context) {
this.context = context;
// Initialise string substituter for token replacement in variables
this.substitutor = new StrSubstitutor(new StrLookup<String>() {
@Override
public String lookup(final String key) {
final Object value = context.getVar(key);
if (value == null) {
return null;
} else {
return String.valueOf(value);
}
}
});
this.substitutor.setEnableSubstitutionInVariables(true);
}
项目:arquillian-cube
文件:IOUtil.java
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);
}
项目:timbuctoo
文件:Utils.java
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);
}
项目:undercarriage
文件:DefaultConfigSubstitutor.java
@Inject
public DefaultConfigSubstitutor(Iterable<ConfigVariableValueProvider> configVariableValueProviders) {
this.configVariableValueProviders = configVariableValueProviders;
this.strSubstitutor = new StrSubstitutor(
new StrLookup<Object>() {
@Override
public String lookup(String key) {
return value(key);
}
},
VARIABLE_PREFIX,
VARIABLE_SUFFIX,
ESCAPE);
}
项目:AugumentedSzczecin_java
文件:AugmentedApplication.java
@Override
public void initialize(final Bootstrap<AugmentedConfiguration> bootstrap) {
// Enable configuration variable substitution with system property values
final StrSubstitutor systemPropertyStrSubstitutor = new StrSubstitutor(StrLookup.systemPropertiesLookup());
bootstrap.setConfigurationSourceProvider(
new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(), systemPropertyStrSubstitutor));
// setup guice builder
final Builder<AugmentedConfiguration> guiceConfiguration = GuiceBundle.<AugmentedConfiguration>newBuilder() //
.addModule(new AugmentedModule()) //
.addModule(new OpenDataClientModule()) //
.enableAutoConfig(getClass().getPackage().getName()) //
.setConfigClass(AugmentedConfiguration.class);
// setup db backend based - choice i based on system property value
if (isDbTypeSetToMongodb(systemPropertyStrSubstitutor.getVariableResolver().lookup(DBTYPE_PROPERTY_NAME))) {
guiceConfiguration.addModule(new MongodbModule());
} else {
bootstrap.addBundle(createMigrationBundle());
guiceConfiguration.addModule(new RdbmsModule<AugmentedConfiguration>(bootstrap) {
@Override
public DataSourceFactory getRealDataSourceFactory(final AugmentedConfiguration configuration) {
return configuration.getRdbmsConfig();
}
@Override
public String getPackagesToScanForEntities() {
return RDBMS_ENTITIES_PACKAGE;
}
});
}
// eagerly inject all dependencies: note Stage.DEVELOPMENT it's a hack
final GuiceBundle<AugmentedConfiguration> guiceBundle = guiceConfiguration.build(Stage.DEVELOPMENT);
bootstrap.addBundle(guiceBundle);
injector = guiceBundle.getInjector();
}
项目:FHIR-Server
文件:LoggingInterceptor.java
@Override
public boolean incomingRequestPostProcessed(final RequestDetails theRequestDetails, final HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
// Perform any string substitutions from the message format
StrLookup<?> lookup = new MyLookup(theRequest, theRequestDetails);
StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');
// Actuall log the line
String line = subs.replace(myMessageFormat);
myLogger.info(line);
return true;
}
项目:oap
文件:Strings.java
public static String substitute( String s, Function<String, Object> mapper ) {
return new StrSubstitutor( new StrLookup<Object>() {
@Override
public String lookup( String key ) {
Object value = mapper.apply( key );
return value == null ? "" : String.valueOf( value );
}
} ).replace( s );
}
项目:hapi-fhir
文件:BaseValidatingInterceptor.java
private void addResponseIssueHeader(RequestDetails theRequestDetails, SingleValidationMessage theNext) {
// Perform any string substitutions from the message format
StrLookup<?> lookup = new MyLookup(theNext);
StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');
// Log the header
String headerValue = subs.replace(myResponseIssueHeaderValue);
ourLog.trace("Adding header to response: {}", headerValue);
theRequestDetails.getResponse().addHeader(myResponseIssueHeaderName, headerValue);
}
项目:hapi-fhir
文件:LoggingInterceptor.java
@Override
public boolean handleException(RequestDetails theRequestDetails, BaseServerResponseException theException, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws ServletException, IOException {
if (myLogExceptions) {
// Perform any string substitutions from the message format
StrLookup<?> lookup = new MyLookup(theServletRequest, theException, theRequestDetails);
StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');
// Actuall log the line
String line = subs.replace(myErrorMessageFormat);
myLogger.info(line);
}
return true;
}
项目:hapi-fhir
文件:LoggingInterceptor.java
@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, "${", "}", '\\');
// Actually log the line
String line = subs.replace(myMessageFormat);
myLogger.info(line);
}
项目:spring-cloud-connectors
文件:PropertiesFileResolver.java
/**
* Adapter from the {@link EnvironmentAccessor}'s system-property resolution to the {@code StrLookup} interface.
*
* @param env the {@code EnvironmentAccessor} to use for the lookups
* @return a {@code StrLookup} view of the accessor's system properties
*/
private StrLookup<String> systemPropertiesLookup(final EnvironmentAccessor env) {
return new StrLookup<String>() {
@Override
public String lookup(String key) {
return env.getSystemProperty(key);
}
};
}
项目:interfax-java
文件:ConfigLoader.java
public ConfigLoader(Class<T> configClass, String configFileName, StrLookup<Object> stringLookup) {
this.configClass = configClass;
this.configFileName = configFileName;
this.reader = new ObjectMapper(new YAMLFactory()).reader(configClass);
this.substitutor = new StrSubstitutor(stringLookup);
}
项目:onetwo
文件:ExpressionFacotry.java
public static <V> StrSubstitutor newStrSubstitutor(String start, String end, char escape, final Map<String, V> valueMap){
StrSubstitutor substitutor = new StrSubstitutor(StrLookup.mapLookup(valueMap), StrMatcher.stringMatcher(start), StrMatcher.stringMatcher(end), escape);
return substitutor;
}
项目:atam4j
文件:ConfigLoader.java
public ConfigLoader(Class<T> configClass, String configFileName, StrLookup<Object> stringLookup) {
this.configClass = configClass;
this.configFileName = configFileName;
this.reader = new ObjectMapper(new YAMLFactory()).reader(configClass);
this.substitutor = new StrSubstitutor(stringLookup);
}
项目:sunstone
文件:ObjectProperties.java
/**
* Replaces all the occurrences of variables in the given source object with their matching values from the system
* properties.
*
* @param source the source text containing the variables to substitute, null returns null
* @return the result of the replace operation
*/
public static String replaceSystemProperties(final Object source) {
final StrSubstitutor strSubstitutor = new StrSubstitutor(StrLookup.systemPropertiesLookup());
strSubstitutor.setValueDelimiter(
System.getProperty(SYSTEM_PROPERTY_VALUE_DELIMITER, SYSTEM_PROPERTY_VALUE_DELIMITER_DEFAULT));
return strSubstitutor.replace(source);
}