本文整理汇总了Java中org.apache.commons.lang.text.StrSubstitutor类的典型用法代码示例。如果您正苦于以下问题:Java StrSubstitutor类的具体用法?Java StrSubstitutor怎么用?Java StrSubstitutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StrSubstitutor类属于org.apache.commons.lang.text包,在下文中一共展示了StrSubstitutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessage
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private String getMessage(ApprovalStatusUpdateEvent event, IOrderApprovalMapping orderApproval,
IUserAccount requester, IKiosk kiosk, IUserAccount updatedBy) {
String message = getMessage(event.getStatus(), requester);
Map<String, String> values = new HashMap<>();
values.put("approvalType", ApprovalUtils.getApprovalType(orderApproval.getApprovalType()));
values.put("requestorName", requester.getFullName());
values.put("requestorPhone", requester.getMobilePhoneNumber());
values.put("eName", kiosk.getName());
values.put("eCity", kiosk.getCity());
values.put("orderId", event.getTypeId());
values.put("statusChangedTime", LocalDateUtil.format(event.getUpdatedAt(),
requester.getLocale(), requester.getTimezone()));
values.put("updatedBy", updatedBy.getFullName());
values.put("updatedByPhone", updatedBy.getMobilePhoneNumber());
StrSubstitutor sub = new StrSubstitutor(values);
return sub.replace(message);
}
示例2: interpolate
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
public static void interpolate(File file) {
String content;
try {
content = new String(Files.readAllBytes(file.toPath()));
String replace = StrSubstitutor.replace(content, new ConfigurationMap( configuration()));
Files.write(file.toPath(), replace.getBytes());
} catch (IOException e) {
LOGGER.error( file + " interpolation error ", e);
}
}
示例3: notifyStockEditors
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
/**
* Notify user with "Edit stock inventories" right for the facility/program that
* facility has stocked out of a product.
*
* @param stockCard StockCard for a product
*/
public void notifyStockEditors(StockCard stockCard) {
Collection<UserDto> recipients = getEditors(stockCard);
String subject = getMessage(EMAIL_ACTION_REQUIRED_SUBJECT);
String content = getMessage(EMAIL_ACTION_REQUIRED_CONTENT);
Map<String, String> valuesMap = getValuesMap(stockCard);
StrSubstitutor sub = new StrSubstitutor(valuesMap);
for (UserDto recipient : recipients) {
if (recipient.getHomeFacilityId().equals(stockCard.getFacilityId())
&& canBeNotified(recipient)) {
valuesMap.put("username", recipient.getUsername());
notificationService.notify(recipient, sub.replace(subject), sub.replace(content));
}
}
}
示例4: resolveJsonPaths
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
@Override
public String resolveJsonPaths(String jsonString, String scenarioState) {
List<String> jsonPaths = getAllJsonPathTokens(jsonString);
Map<String, String> paramMap = new HashMap<>();
jsonPaths.forEach(thisPath -> {
try {
paramMap.put(thisPath, JsonPath.read(scenarioState, thisPath));
} catch (Exception e) {
throw new RuntimeException("\nJSON:" + jsonString + "\nPossibly comments in the JSON found or bad JSON path found: " + thisPath + ", Details: " + e);
}
});
StrSubstitutor sub = new StrSubstitutor(paramMap);
return sub.replace(jsonString);
}
示例5: createStepWith
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
protected String createStepWith(String stepName) {
Map<String, String> parammap = new HashMap<>();
parammap.put("STEP.NAME", stepName);
parammap.put("STEP.REQUEST", "{\n" +
" \"customer\": {\n" +
" \"firstName\": \"FIRST_NAME\"\n" +
" }\n" +
"}");
parammap.put("STEP.RESPONSE", "{\n" +
" \"id\" : 10101\n" +
"}");
StrSubstitutor sub = new StrSubstitutor(parammap);
return sub.replace((new StepExecutionState()).getRequestResponseState());
}
示例6: initHomeDir
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
protected void initHomeDir() {
String homeDir = System.getProperty(DesktopAppContextLoader.HOME_DIR_SYS_PROP);
if (StringUtils.isBlank(homeDir)) {
homeDir = getDefaultHomeDir();
}
homeDir = StrSubstitutor.replaceSystemProperties(homeDir);
System.setProperty(DesktopAppContextLoader.HOME_DIR_SYS_PROP, homeDir);
File file = new File(homeDir);
if (!file.exists()) {
boolean success = file.mkdirs();
if (!success) {
System.out.println("Unable to create home dir: " + homeDir);
System.exit(-1);
}
}
if (!file.isDirectory()) {
System.out.println("Invalid home dir: " + homeDir);
System.exit(-1);
}
}
示例7: getFileName
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
/**
* Get the final filename of the generated .ass subtitle
*
* @return the name of the first subtitle
*/
private String getFileName() {
String filename = this.userConfig.getFilename();
if (StringUtils.isEmpty(filename)) {
filename = this.userConfig.getFirstSubtitle().getFileName();
filename = FilenameUtils.getBaseName(filename);
} else {
Map<String, String> substitutes = new HashMap<>();
String oneN = FilenameUtils.getBaseName(this.userConfig.getFirstSubtitle().getFileName());
String twoN = FilenameUtils.getBaseName(this.userConfig.getSecondSubtitle().getFileName());
substitutes.put("one", oneN);
substitutes.put("two", twoN);
substitutes.put("baseOne", StringUtils.substringBeforeLast(oneN, "."));
substitutes.put("baseTwo", StringUtils.substringBeforeLast(twoN, "."));
StrSubstitutor substitutor = new StrSubstitutor(substitutes);
filename = substitutor.replace(filename);
}
return filename;
}
示例8: serialize
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
@Override
public Iterable<Record> serialize(Event event) {
RecordKey key = new RecordKey();
Text value = new Text();
try {
value.set(new String(event.getBody(), Charsets.UTF_8.name()));
key.setHash(event.getHeaders().get(HEADER_TIMESTAMP).hashCode());
key.setType(event.getHeaders().get(HEADER_BATCH_TYPE));
key.setCodec(DFS_CODEC);
key.setContainer(DFS_CONTAINER);
key.setBatch(new StrSubstitutor(event.getHeaders(), "%{", "}").replace(DFS_BATCH_PATTERN));
key.setTimestamp(Long.parseLong(event.getHeaders().get(HEADER_TIMESTAMP)));
key.setValid(true);
} catch (Exception exception) {
key.setValid(false);
}
return Collections.singletonList(new Record(key, value));
}
示例9: replaceProperties
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private void replaceProperties(Properties props) {
StrSubstitutor substitutor = new StrSubstitutor(sqlProperties);
// we must delete slash(it is added to the ${sql.url}) from connection string -> ${sql.url}/database
if (props.getProperty(CONNECTION_URL_KEY) != null) {
String connectionUrl = parseConnectionString(props.getProperty(CONNECTION_URL_KEY));
props.put(CONNECTION_URL_KEY, connectionUrl);
}
for (Map.Entry<Object, Object> entry : props.entrySet()) {
if (entry.getValue() instanceof String) {
String substituted = substitutor.replace(entry.getValue());
entry.setValue(substituted);
}
}
}
示例10: goArtifact
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private Function<File, GoArtifact> goArtifact(final UriConfig config, final Map<String, String> properties, final TaskExecutionContext context) {
return new Function<File, GoArtifact>() {
@Override
public GoArtifact apply(File file) {
GoArtifact artifact = new GoArtifact(file.getAbsolutePath(), artifactUri(file.getName()));
artifact.properties(properties);
return artifact;
}
private String artifactUri(String artifactName) {
String uri = config.isFolder() ? config.uri() + "/" + artifactName : config.uri();
StrSubstitutor sub = new StrSubstitutor(context.environment().asMap());
return sub.replace(uri);
}
};
}
示例11: impliesURI
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
public static boolean impliesURI(String privilege, String request) {
try {
URI privilegeURI = new URI(new StrSubstitutor(System.getProperties()).replace(privilege));
URI requestURI = new URI(request);
if (privilegeURI.getScheme() == null || privilegeURI.getPath() == null) {
LOGGER.warn("Privilege URI " + request + " is not valid. Either no scheme or no path.");
return false;
}
if (requestURI.getScheme() == null || requestURI.getPath() == null) {
LOGGER.warn("Request URI " + request + " is not valid. Either no scheme or no path.");
return false;
}
return PathUtils.impliesURI(privilegeURI, requestURI);
} catch (URISyntaxException e) {
LOGGER.warn("Request URI " + request + " is not a URI", e);
return false;
}
}
示例12: renderBlock
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
/**
* Loads the template with the specified name from the classloader and uses
* it to templatize the properties using Apache Commons Lang's
* StrSubstitutor and writes it to the response.
*
* @param res
* the response to write to
* @param template
* the template file to load from the classpath
* @param properties
* the properties to templatize
* @throws IOException
*/
private void renderBlock(HttpServletResponse res, String templateName,
Map<String, String> properties) throws IOException {
InputStream is = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String template = null;
try {
is = getClass().getClassLoader().getResourceAsStream(templateName);
if (is != null) {
IOUtils.copy(is, baos);
template = baos.toString();
} else {
throw new IOException("Unable to load template " + templateName);
}
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(baos);
}
StrSubstitutor sub = new StrSubstitutor(properties);
res.getWriter().write(sub.replace(template));
}
开发者ID:SixDimensions,项目名称:Component-Bindings-Provider,代码行数:34,代码来源:ComponentBindingsProviderWebConsole.java
示例13: testProperty
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private void testProperty( String propertyName, boolean containsSubstitution ) {
String propertyValue = setup.get( propertyName );
assertTrue( propertyName + " was not found", isNotBlank( propertyValue ) );
logger.info( propertyName + "=" + propertyValue );
if ( containsSubstitution ) {
Map<String, String> valuesMap = new HashMap<String, String>();
valuesMap.put( "reset_url", "test-url" );
valuesMap.put( "organization_name", "test-org" );
valuesMap.put( "activation_url", "test-url" );
valuesMap.put( "confirmation_url", "test-url" );
valuesMap.put( "user_email", "test-email" );
valuesMap.put( "pin", "test-pin" );
StrSubstitutor sub = new StrSubstitutor( valuesMap );
String resolvedString = sub.replace( propertyValue );
assertNotSame( propertyValue, resolvedString );
}
}
示例14: getCommitMessage
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private String getCommitMessage(final Project project) {
String templateString = TemplateFileHandler.loadFile(project);
Map<String, String> valuesMap = new HashMap<>();
String branchName = CommitMessage.extractBranchName(project);
String[] branchParts = CommitMessage.splitBranchName(branchName);
if (branchParts.length > 1) {
valuesMap.put(Consts.TICKET, branchParts[1]);
}
valuesMap.put(Consts.SHORT_DESCRIPTION, "");
valuesMap.put(Consts.LONG_DESCRIPTION, "");
StrSubstitutor sub = new StrSubstitutor(valuesMap);
return sub.replace(templateString);
}
示例15: getCommitMessage
import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
String getCommitMessage(Project project) {
String templateString = TemplateFileHandler.loadFile(project);
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put(Consts.TICKET, getBranch());
valuesMap.put(Consts.SHORT_DESCRIPTION, panel.getShortDescription());
valuesMap.put(Consts.LONG_DESCRIPTION, getLongDescription(templateString));
StrSubstitutor sub = new StrSubstitutor(valuesMap);
return sub.replace(templateString);
}