Search in sources :

Example 1 with StrSubstitutor

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()));
    }
}
Also used : StrSubstitutor(org.apache.commons.lang.text.StrSubstitutor) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 2 with StrSubstitutor

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();
}
Also used : InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) ExternalResource(org.junit.rules.ExternalResource) IOException(java.io.IOException) StrSubstitutor(org.apache.commons.lang.text.StrSubstitutor) StrLookup(org.apache.commons.lang.text.StrLookup) File(java.io.File) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 3 with StrSubstitutor

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);
        }
    }
}
Also used : StrSubstitutor(org.apache.commons.lang.text.StrSubstitutor) Map(java.util.Map)

Example 4 with StrSubstitutor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StrSubstitutor(org.apache.commons.lang.text.StrSubstitutor)

Example 5 with StrSubstitutor

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);
}
Also used : StrSubstitutor(org.apache.commons.lang.text.StrSubstitutor) IOException(java.io.IOException)

Aggregations

StrSubstitutor (org.apache.commons.lang.text.StrSubstitutor)16 File (java.io.File)4 StrLookup (org.apache.commons.lang.text.StrLookup)4 IOException (java.io.IOException)3 Map (java.util.Map)3 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 ResolveResult (javax.naming.spi.ResolveResult)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Context (com.datatorrent.api.Context)1 StreamingContainer (com.datatorrent.stram.engine.StreamingContainer)1 PTOperator (com.datatorrent.stram.plan.physical.PTOperator)1 Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 AnnotatedFieldProperty (com.thinkbiganalytics.annotations.AnnotatedFieldProperty)1 MetadataFieldAnnotationFieldNameResolver (com.thinkbiganalytics.feedmgr.MetadataFieldAnnotationFieldNameResolver)1