Example usage for org.springframework.util PropertyPlaceholderHelper replacePlaceholders

List of usage examples for org.springframework.util PropertyPlaceholderHelper replacePlaceholders

Introduction

In this page you can find the example usage for org.springframework.util PropertyPlaceholderHelper replacePlaceholders.

Prototype

public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) 

Source Link

Document

Replaces all placeholders of format ${name}} with the value returned from the supplied PlaceholderResolver .

Usage

From source file:org.settings4j.helper.spring.Settings4jPlaceholderConfigurer.java

/**
 * Parse the given String with Placeholder "${...}" and returns the result.
 * <p>//  ww  w.ja v  a  2  s .c  om
 * Placeholders will be resolved with Settings4j.
 * </p>
 *
 * @param strVal
 *        the String with the Paceholders
 * @param prefix
 *        for all placehodlers.
 * @param props
 *        The default Properties if no Value where found
 * @return the parsed String
 * @throws BeanDefinitionStoreException
 *         if invalid values are encountered (Placeholders where no values where found).
 */
public static String parseStringValue(final String strVal, final String prefix, final Properties props)
        throws BeanDefinitionStoreException {
    final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(DEFAULT_PLACEHOLDER_PREFIX,
            DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, false);
    return helper.replacePlaceholders(strVal, new Settings4jPlaceholderConfigurerResolver(prefix, props));
}

From source file:com.baifendian.swordfish.execserver.parameter.placeholder.TimePlaceholderUtil.java

/**
 * ??? <p>//from w ww  . j av a 2 s. c o  m
 *
 * @param text ?
 * @param date ?
 * @param ignoreUnresolvablePlaceholders ????
 * @return ??
 */
public static String resolvePlaceholders(String text, Date date, boolean ignoreUnresolvablePlaceholders) {
    PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper);
    return helper.replacePlaceholders(text, new TimePlaceholderResolver(text, date));
}

From source file:com.evolveum.midpoint.web.util.PropertyUrlUriLocator.java

private String replaceProperties(String uri) {
    if (uri == null) {
        return null;
    }/*  w ww. j  a  va 2 s  .  co  m*/

    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}", ":", true);
    return helper.replacePlaceholders(uri, new PropertyPlaceholderHelper.PlaceholderResolver() {

        @Override
        public String resolvePlaceholder(String placeholderName) {
            return propertyResolver.getProperty(placeholderName);
        }
    });
}

From source file:ch.algotrader.esper.SpringServiceResolver.java

@Override
public void resolve(final EPStatement statement, final String subscriberExpression) {

    if (StringUtils.isBlank(subscriberExpression)) {
        throw new IllegalArgumentException("Subscriber is empty");
    }/*from  w  w  w  . j ava 2  s .  co  m*/

    PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("${", "}", ",", false);
    String s = placeholderHelper.replacePlaceholders(subscriberExpression, name -> {
        if (name.equalsIgnoreCase("strategyName")) {
            return this.strategyName;
        } else {
            return this.configParams.getString(name, "null");
        }
    });

    final Matcher matcher = SUBSCRIBER_NOTATION.matcher(s);
    if (matcher.matches()) {
        // New subscriber notation
        final String beanName = matcher.group(1);
        final String beanMethod = matcher.group(3);
        Object bean = this.applicationContext.getBean(beanName);
        try {
            statement.setSubscriber(bean, beanMethod);
        } catch (EPSubscriberException ex) {
            throw new SubscriberResolutionException("Subscriber expression '" + subscriberExpression
                    + "' could not be resolved to a service method", ex);
        }
    } else {
        // Assuming to be a fully qualified class name otherwise
        try {
            Class<?> cl = Class.forName(s);
            statement.setSubscriber(cl.newInstance());
        } catch (Exception e) {
            // Old notation for backward compatibility
            String serviceName = StringUtils.substringBeforeLast(s, ".");
            if (serviceName.contains(".")) {
                serviceName = StringUtils.remove(StringUtils.remove(
                        StringUtils.uncapitalize(StringUtils.substringAfterLast(serviceName, ".")), "Base"),
                        "Impl");
            }
            String beanMethod = StringUtils.substringAfterLast(s, ".");
            Object bean = this.applicationContext.getBean(serviceName);
            statement.setSubscriber(bean, beanMethod);
        }
    }
}

From source file:com.brienwheeler.lib.spring.beans.PropertyPlaceholderConfigurer.java

/**
  * Resolves any placeholders in the supplied properties map, preferring the use of
  * previously set System properties over the current property map contents for
  * placeholder substitution.// w  ww.j  av a  2s . c  o  m
  * <p>
  * Also sets any resolved properties as System properties, if no System
  * property by that name already exists.
  * 
  * @param properties the merged context properties
  */
public static void processProperties(final Properties properties, String placeholderPrefix,
        String placeholderSuffix) {
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix);
    PropertyPlaceholderHelper.PlaceholderResolver resolver = new PropertyPlaceholderHelper.PlaceholderResolver() {
        @Override
        public String resolvePlaceholder(String placeholderName) {
            // SYSTEM_PROPERTIES_MODE_OVERRIDE means we look at previously set
            // system properties in preference to properties defined in our file
            String value = System.getProperty(placeholderName);
            if (value == null)
                value = properties.getProperty(placeholderName);
            return value;
        }
    };

    for (Object key : properties.keySet()) {
        String propertyName = (String) key;
        // get the value from the map
        String propertyValue = properties.getProperty(propertyName);
        // resolve it against system properties then other properties in the
        // passed-in Properties
        String resolvedValue = helper.replacePlaceholders(propertyValue, resolver);

        // set back into passed-in Properties if changed
        if (!ObjectUtils.nullSafeEquals(propertyValue, resolvedValue)) {
            properties.setProperty(propertyName, resolvedValue);
        }

        // set into System properties if not already set
        setProperty(propertyName, resolvedValue);
    }
}

From source file:com.alvexcore.repo.SimpleKeySelectorResult.java

private File findLicenseFile() {
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
    String sharedLoader = System.getProperty("shared.loader");
    if (sharedLoader == null)
        return null;
    String sharedLoadPaths = helper.replacePlaceholders(sharedLoader, System.getProperties());
    for (String path : sharedLoadPaths.split(",")) { // FIXME is this separator the same for all envs?
        File file = new File(path, "alfresco" + File.separator + "extension" + File.separator + "license");
        if (file.isDirectory())
            for (File elem : file.listFiles())
                if (elem.getAbsolutePath().endsWith("alvex.lic"))
                    return elem;
    }/* ww  w. j av  a 2  s  . c o m*/
    return null;
}

From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java

protected SortedSet<File> ensureFoldersExistence(File appBase, NamedExtendedPlaceholderResolver propsResolver,
        ExtendedPlaceholderResolver sourcesResolver) {
    final SortedSet<File> createdFiles = verifyFolderProperty(ConfigUtils.GITCLOUD_BASE_PROP, appBase,
            ExtendedSetUtils.<File>sortedSet(ExtendedFileUtils.BY_ABSOLUTE_PATH_COMPARATOR));
    final String appBasePrefix = appBase.getAbsolutePath();
    final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
            SystemPropertyUtils.PLACEHOLDER_PREFIX, SystemPropertyUtils.PLACEHOLDER_SUFFIX,
            SystemPropertyUtils.VALUE_SEPARATOR, true);
    final ExtendedPlaceholderResolver resolver = new AggregatedExtendedPlaceholderResolver(propsResolver,
            sourcesResolver);//from ww  w.  ja  v a2  s.c  o  m
    ExtendedPlaceholderResolverUtils.forAllEntriesDo(propsResolver, new Closure<Map.Entry<String, String>>() {
        @Override
        @SuppressWarnings("synthetic-access")
        public void execute(Entry<String, String> e) {
            String propName = e.getKey(), propValue = e.getValue();
            if (StringUtils.isEmpty(propName) || (!propName.endsWith(".dir"))
                    || StringUtils.isEmpty(propValue)) {
                return;
            }

            String resolvedValue = helper.replacePlaceholders(propValue, resolver);
            if (ExtendedCharSequenceUtils.getSafeLength(resolvedValue) < appBasePrefix.length()) {
                return;
            }

            String pathValue = resolvedValue.replace('/', File.separatorChar); // just in case using '/'
            if (logger.isDebugEnabled()) {
                logger.debug("ensureFoldersExistence(" + propName + "): " + pathValue);
            }

            if (pathValue.startsWith(appBasePrefix)) {
                verifyFolderProperty(propName, new File(pathValue), createdFiles);
            }
        }
    });
    return createdFiles;
}

From source file:jun.learn.scene.propertysource.AbstractPropertyResolver.java

private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) {
    return helper.replacePlaceholders(text, new PropertyPlaceholderHelper.PlaceholderResolver() {
        @Override/*from  w  w w  .  j  ava 2  s. c  o  m*/
        public String resolvePlaceholder(String placeholderName) {
            return getPropertyAsRawString(placeholderName);
        }
    });
}

From source file:ome.security.auth.QueryNewUserGroupBean.java

private String parseQuery(final AttributeSet attrSet, final String query) {
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("@{", "}", null, false);
    return helper.replacePlaceholders(query, new PlaceholderResolver() {
        public String resolvePlaceholder(String arg0) {
            if (attrSet.size(arg0) > 1) {
                throw new ValidationException("Multivalued property used in @{} format:" + query + "="
                        + attrSet.getAll(arg0).toString());
            }/*from w  ww.j ava2 s  .c o m*/
            return attrSet.getFirst(arg0);
        }
    });
}

From source file:org.artifactory.webapp.wicket.page.home.settings.ivy.gradle.GradleBuildScriptPanel.java

private String replaceValuesAndGetTemplateValue(String templateResourcePath, Properties templateProperties) {
    InputStream gradleInitTemplateStream = null;
    try {//from w ww.  j  a va 2s.  c  o m
        gradleInitTemplateStream = getClass().getResourceAsStream(templateResourcePath);
        String gradleTemplate = IOUtils.toString(gradleInitTemplateStream);
        PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("${", "}");
        return propertyPlaceholderHelper.replacePlaceholders(gradleTemplate, templateProperties);
    } catch (IOException e) {
        String errorMessage = "An error occurred while preparing the Gradle Init Script template: ";
        error(errorMessage + e.getMessage());
        log.error(errorMessage, e);
    } finally {
        IOUtils.closeQuietly(gradleInitTemplateStream);
    }
    return "";
}