List of usage examples for org.springframework.util PropertyPlaceholderHelper PropertyPlaceholderHelper
public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix, @Nullable String valueSeparator, boolean ignoreUnresolvablePlaceholders)
From source file:com.evolveum.midpoint.web.util.PropertyUrlUriLocator.java
private String replaceProperties(String uri) { if (uri == null) { return null; }//from ww w.j a va 2 s. c o 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:org.settings4j.helper.spring.Settings4jPlaceholderConfigurer.java
/** * Parse the given String with Placeholder "${...}" and returns the result. * <p>/*from www .j av a 2 s .c o m*/ * 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: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 .ja v a 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: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 w ww . j a v a 2 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:de.acosix.alfresco.utility.common.spring.BeanDefinitionFromPropertiesPostProcessor.java
@Override public void afterPropertiesSet() { if (this.propertyPrefix == null || this.propertyPrefix.trim().isEmpty()) { throw new IllegalStateException("propertyPrefix has not been set"); }/*from www . j a v a 2 s . c o m*/ if (this.beanTypes == null || this.beanTypes.isEmpty()) { throw new IllegalStateException("beanTypes has not been set"); } if (this.propertiesSource == null || this.propertiesSource.isEmpty()) { throw new IllegalStateException("propertiesSource has not been set"); } this.placeholderHelper = new PropertyPlaceholderHelper(this.placeholderPrefix, this.placeholderSuffix, this.valueSeparator, true); }
From source file:jun.learn.scene.propertysource.AbstractPropertyResolver.java
private PropertyPlaceholderHelper createPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) { return new PropertyPlaceholderHelper(this.placeholderPrefix, this.placeholderSuffix, this.valueSeparator, ignoreUnresolvablePlaceholders); }
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 ww w . j a v a 2s .c om return attrSet.getFirst(arg0); } }); }
From source file:ome.system.PreferenceContext.java
/** * By default, configures this instance for * {@link PropertyPlaceholderConfigurer#SYSTEM_PROPERTIES_MODE_OVERRIDE} as * well as ignoring unfound resources./*from w w w . ja va 2s . c o m*/ */ public PreferenceContext() { setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_OVERRIDE); setIgnoreResourceNotFound(true); helper = new PropertyPlaceholderHelper(PropertyPlaceholderConfigurer.DEFAULT_PLACEHOLDER_PREFIX, PropertyPlaceholderConfigurer.DEFAULT_PLACEHOLDER_SUFFIX, PropertyPlaceholderConfigurer.DEFAULT_VALUE_SEPARATOR, false); // Note, we want the IllegalArgumentThrown for catching. }