本文整理汇总了Java中org.apache.commons.lang3.text.StrLookup类的典型用法代码示例。如果您正苦于以下问题:Java StrLookup类的具体用法?Java StrLookup怎么用?Java StrLookup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StrLookup类属于org.apache.commons.lang3.text包,在下文中一共展示了StrLookup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: incomingRequestPostProcessed
import org.apache.commons.lang3.text.StrLookup; //导入依赖的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.StrLookup; //导入依赖的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.StrLookup; //导入依赖的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: resolve
import org.apache.commons.lang3.text.StrLookup; //导入依赖的package包/类
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);
}
示例5: substituteRelationships
import org.apache.commons.lang3.text.StrLookup; //导入依赖的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);
}
示例6: Element
import org.apache.commons.lang3.text.StrLookup; //导入依赖的package包/类
/**
* 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);
}
示例7: replacePlaceholdersWithWhiteSpace
import org.apache.commons.lang3.text.StrLookup; //导入依赖的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: replaceVariableReferences
import org.apache.commons.lang3.text.StrLookup; //导入依赖的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);
}
示例9: DefaultConfigSubstitutor
import org.apache.commons.lang3.text.StrLookup; //导入依赖的package包/类
@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);
}
示例10: initialize
import org.apache.commons.lang3.text.StrLookup; //导入依赖的package包/类
@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();
}
示例11: incomingRequestPostProcessed
import org.apache.commons.lang3.text.StrLookup; //导入依赖的package包/类
@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;
}
示例12: substitute
import org.apache.commons.lang3.text.StrLookup; //导入依赖的package包/类
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 );
}
示例13: addResponseIssueHeader
import org.apache.commons.lang3.text.StrLookup; //导入依赖的package包/类
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);
}
示例14: handleException
import org.apache.commons.lang3.text.StrLookup; //导入依赖的package包/类
@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;
}
示例15: processingCompletedNormally
import org.apache.commons.lang3.text.StrLookup; //导入依赖的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, "${", "}", '\\');
// Actually log the line
String line = subs.replace(myMessageFormat);
myLogger.info(line);
}