use of org.apache.commons.lang.text.StrSubstitutor in project OpenClinica by OpenClinica.
the class VariableSubstitutionHelper method replaceVariables.
/**
* Replaces the variables in each {@link DisplayItemBean} of the {@link DisplaySectionBean}.
*
* @param section
* The display section to have its items processed.
* @param study
* Study associated with the display section.
* @param studySubject
* Subject associated with the display section.
*/
public static void replaceVariables(DisplaySectionBean section, StudyBean study, StudySubjectBean studySubject, StudyEventDefinitionBean eventDef, StudyEventBean event, DataSource dataSource) {
StrSubstitutor subst = new StrSubstitutor(buildTokensMap(section, studySubject, study, eventDef, event, dataSource));
for (DisplayItemBean displayItem : section.getItems()) {
ItemFormMetadataBean metadata = displayItem.getMetadata();
metadata.setRightItemText(replace(subst, metadata.getRightItemText()));
metadata.setLeftItemText(replace(subst, metadata.getLeftItemText()));
metadata.setHeader(replace(subst, metadata.getHeader()));
metadata.setSubHeader(replace(subst, metadata.getSubHeader()));
}
}
use of org.apache.commons.lang.text.StrSubstitutor in project cuba by cuba-platform.
the class TestContainer method initAppProperties.
protected void initAppProperties() {
final Properties properties = new Properties();
List<String> locations = getAppPropertiesFiles();
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
for (String location : locations) {
Resource resource = resourceLoader.getResource(location);
if (resource.exists()) {
InputStream stream = null;
try {
stream = resource.getInputStream();
properties.load(stream);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(stream);
}
} else {
log.warn("Resource " + location + " not found, ignore it");
}
}
StrSubstitutor substitutor = new StrSubstitutor(new StrLookup() {
@Override
public String lookup(String key) {
String subst = properties.getProperty(key);
return subst != null ? subst : System.getProperty(key);
}
});
for (Object key : properties.keySet()) {
String value = substitutor.replace(properties.getProperty((String) key));
appProperties.put((String) key, value);
}
File dir;
dir = new File(appProperties.get("cuba.confDir"));
dir.mkdirs();
dir = new File(appProperties.get("cuba.logDir"));
dir.mkdirs();
dir = new File(appProperties.get("cuba.tempDir"));
dir.mkdirs();
dir = new File(appProperties.get("cuba.dataDir"));
dir.mkdirs();
}
use of org.apache.commons.lang.text.StrSubstitutor in project motech by motech.
the class SqlDBManagerImpl method replaceProperties.
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);
}
}
}
use of org.apache.commons.lang.text.StrSubstitutor in project clion-embedded-arm by elmot.
the class ConvertProject method writeProjectFile.
private static void writeProjectFile(Project project, ThrowableComputable<String, IOException> template, String fileName, ProjectData projectData, STRATEGY strategy) throws IOException {
VirtualFile projectFile = project.getBaseDir().findChild(fileName);
if (projectFile == null) {
projectFile = project.getBaseDir().createChildData(project, fileName);
} else if (strategy == STRATEGY.CREATEONLY) {
return;
}
String text = new StrSubstitutor(projectData.getAsMap()).replace(template.compute());
VfsUtil.saveText(projectFile, text);
}
use of org.apache.commons.lang.text.StrSubstitutor in project ddf by codice.
the class AbstractIntegrationTest method getFileContent.
/**
* Variables to be replaced in a resource file should be in the format: $variableName$
* The variable to replace in the file should also also match the parameter names of the method calling getFileContent.
*
* @param filePath
* @param params
* @param classRelativeToResource
* @return
*/
public static String getFileContent(String filePath, ImmutableMap<String, String> params, Class classRelativeToResource) {
StrSubstitutor strSubstitutor = new StrSubstitutor(params);
strSubstitutor.setVariablePrefix(RESOURCE_VARIABLE_DELIMETER);
strSubstitutor.setVariableSuffix(RESOURCE_VARIABLE_DELIMETER);
String fileContent;
try {
fileContent = IOUtils.toString(classRelativeToResource.getClassLoader().getResourceAsStream(filePath), "UTF-8");
} catch (IOException e) {
throw new RuntimeException("Failed to read filepath: " + filePath);
}
return strSubstitutor.replace(fileContent);
}
Aggregations