org.apache.commons.lang3.text.StrLookup Java Examples
The following examples show how to use
org.apache.commons.lang3.text.StrLookup.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerInterceptor.java From careconnect-reference-implementation with Apache License 2.0 | 6 votes |
@Override public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException { log.trace("incomingRequestPostProcessed "+theRequest.getMethod()); 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; }
Example #2
Source File: ServerInterceptor.java From careconnect-reference-implementation with Apache License 2.0 | 6 votes |
@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()+"]"); }
Example #3
Source File: YAMLConfigurationLoader.java From dcos-commons with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: CypherUtil.java From SciGraph with Apache License 2.0 | 6 votes |
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); }
Example #5
Source File: Utils.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
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); }
Example #6
Source File: PropertiesFileResolver.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
/** * 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); } }; }
Example #7
Source File: ExpressionFacotry.java From onetwo with Apache License 2.0 | 4 votes |
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; }
Example #8
Source File: StrSubstitutorVisitor.java From studio with GNU General Public License v3.0 | 4 votes |
public StrSubstitutorVisitor(Map<String, String> variables) { Map<String, String> escapedVars = new HashMap<>(variables.size()); variables.forEach((key, value) -> escapedVars.put(key, StringEscapeUtils.escapeXml10(value))); strSubstitutor = new StrSubstitutor(StrLookup.mapLookup(escapedVars), PREFIX, StrSubstitutor.DEFAULT_SUFFIX, StrSubstitutor.DEFAULT_ESCAPE); }