当前位置: 首页>>代码示例>>Java>>正文


Java PropertyPlaceholderHelper.replacePlaceholders方法代码示例

本文整理汇总了Java中org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyPlaceholderHelper.replacePlaceholders方法的具体用法?Java PropertyPlaceholderHelper.replacePlaceholders怎么用?Java PropertyPlaceholderHelper.replacePlaceholders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.util.PropertyPlaceholderHelper的用法示例。


在下文中一共展示了PropertyPlaceholderHelper.replacePlaceholders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processProperties

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
  PropertyPlaceholderHelper helper =
      new PropertyPlaceholderHelper(DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, false);
  for (Entry<Object, Object> entry : props.entrySet()) {
    String stringKey = String.valueOf(entry.getKey());
    String stringValue = String.valueOf(entry.getValue());
    if ((stringKey.contains(DEFAULT_PLACEHOLDER_PREFIX) && stringKey.contains(DEFAULT_PLACEHOLDER_SUFFIX)
        && (stringKey.indexOf(DEFAULT_PLACEHOLDER_PREFIX) < stringKey.indexOf(DEFAULT_PLACEHOLDER_SUFFIX)))) {
      stringKey = getReplacedStringKey(stringKey, helper, props);
    }
    stringValue = helper.replacePlaceholders(stringValue, props);
    //
    if (stringKey.startsWith(this.appPropertiesPrefix)) {
      FileCloudPropertyConfigurer.appProperties.put(stringKey, stringValue);
    }
    properties.put(stringKey, stringValue);
  }
  super.processProperties(beanFactoryToProcess, props);
}
 
开发者ID:devpage,项目名称:fastdfs-quickstart,代码行数:20,代码来源:FileCloudPropertyConfigurer.java

示例2: getReplacedStringKey

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
public String getReplacedStringKey(String stringKey, PropertyPlaceholderHelper helper, Properties props) {
  if (stringKey.contains(DEFAULT_PLACEHOLDER_PREFIX) && stringKey.contains(DEFAULT_PLACEHOLDER_SUFFIX)
      && (stringKey.indexOf(DEFAULT_PLACEHOLDER_PREFIX) < stringKey.indexOf(DEFAULT_PLACEHOLDER_SUFFIX))) {
    // before of target
    String prefix = stringKey.substring(0, stringKey.indexOf(DEFAULT_PLACEHOLDER_PREFIX));
    // replace
    String refString =
        stringKey.substring(stringKey.indexOf(DEFAULT_PLACEHOLDER_PREFIX), stringKey.indexOf(DEFAULT_PLACEHOLDER_SUFFIX) + 1);
    // after of target
    String suffix = stringKey.substring(stringKey.indexOf(DEFAULT_PLACEHOLDER_SUFFIX) + 1);
    // get target from props data
    String refStringValue = helper.replacePlaceholders(refString, props);
    // build a new local key
    String newKey = prefix + refStringValue + suffix;
    // while until the key not contains of ${}
    return getReplacedStringKey(newKey, helper, props);
  }
  return stringKey;
}
 
开发者ID:devpage,项目名称:fastdfs-quickstart,代码行数:20,代码来源:FileCloudPropertyConfigurer.java

示例3: replacePlaceholders

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
 * Replaces each occurence of ${SOME_VALUE} with the varible SOME_VALUE in 'variables'
 * If any error occures during parsing, i.e: variable doesn't exist, bad syntax, etc...
 * a {@link PlaceholderResolutionException} is thrown, otherwise the new string after all replacements have been
 * made will be returned.
 * 
 * @param variables The variables map to match placeholders against
 * @param value the string, possibly containing placeholders
 * @return the value after placeholder replacement have been made
 * @throws PlaceholderResolutionException if an empty placeholder is found 
 *      or a place holder with no suitable value in 'variables'
 */
public static String replacePlaceholders(final Map<String, String> variables, final String value) throws PlaceholderResolutionException {
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${","}");
    return helper.replacePlaceholders(value, new PlaceholderResolver() {
        public String resolvePlaceholder(String key) {
            if (key.isEmpty()) {
                throw new PlaceholderResolutionException("Placeholder in '" + value + "' has to have a length of at least 1");
            }
            
            String result = variables.get(key);
            if (result == null) {
                throw new PlaceholderResolutionException("Missing value for placeholder: '" + key + "' in '" + value + "'");
            }
            
            return result;
        }
    });
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:30,代码来源:PlaceholderReplacer.java

示例4: replaceValuesAndGetTemplateValue

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
 *
 * @param templateResourcePath
 * @param templateProperties
 * @return
 */
private String replaceValuesAndGetTemplateValue(String templateResourcePath,
        Properties templateProperties,RestResponse response) {
    InputStream gradleInitTemplateStream = null;
    try {
        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: ";
        response.error(errorMessage + e.getMessage());
        log.error(errorMessage, e);
    } finally {
        IOUtils.closeQuietly(gradleInitTemplateStream);
    }
    return "";
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:24,代码来源:GetGradleSettingSnippetService.java

示例5: replaceValuesAndGetTemplateValue

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String replaceValuesAndGetTemplateValue(String templateResourcePath, Properties templateProperties) {
    InputStream gradleInitTemplateStream = null;
    try {
        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 "";
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:17,代码来源:GradleBuildScriptPanel.java

示例6: doResolvePlaceholders

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) {
	return helper.replacePlaceholders(text, new PropertyPlaceholderHelper.PlaceholderResolver() {
		@Override
		public String resolvePlaceholder(String placeholderName) {
			return getPropertyAsRawString(placeholderName);
		}
	});
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:AbstractPropertyResolver.java

示例7: render

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    Map<String, Object> map = new HashMap<String, Object>(model);
    String path = ServletUriComponentsBuilder.fromContextPath(request).build()
            .getPath();
    map.put("path", (Object) path==null ? "" : path);
    context.setRootObject(map);
    String maskedTemplate = template.replace("${", prefix);
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(prefix, "}");
    String result = helper.replacePlaceholders(maskedTemplate, resolver);
    result = result.replace(prefix, "${");
    response.setContentType(getContentType());
    response.getWriter().append(result);
}
 
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:15,代码来源:SpelView.java

示例8: injectEnvironmentVars

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
protected int injectEnvironmentVars(BufferedReader reader, PropertyPlaceholderHelper.PlaceholderResolver resolver)
        throws IOException, RunBuildException {
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("{", "}");
    String line;
    int propertiesCount = 0;
    while ((line = reader.readLine()) != null) {
        addDebugMessage("Read line [%s]", line);
        if (!line.contains("=")) {
            throw new RunBuildException("The line [" + line + "] does contain property of the form key=value");
        }
        String[] split = line.split("=", 2);
        addDebugMessage("Will use key [%s] and value [%s]", split[0], split[1]);
        String finalValue = helper.replacePlaceholders(split[1], resolver);
        addDebugMessage("Resolved value of [%s] is [%s]", split[1], finalValue);
        if (split[0].startsWith(ENV_VAR_PREFIX)) {
            addDebugMessage("Will set environment variable");
            getAgentConfiguration().addEnvironmentVariable(split[0].replace(ENV_VAR_PREFIX, ""), finalValue);
        } else if (split[0].startsWith(SYSTEM_VAR_PREFIX)) {
            addDebugMessage("Will set system property");
            getAgentConfiguration().addSystemProperty(split[0].replace(SYSTEM_VAR_PREFIX, ""), finalValue);
        } else {
            addDebugMessage("Will set configuration property");
            getAgentConfiguration().addConfigurationParameter(split[0], finalValue);
        }
        propertiesCount++;
    }
    return propertiesCount;
}
 
开发者ID:kannanekanath,项目名称:teamcity-envinject-plugin,代码行数:29,代码来源:EnvInjectService.java

示例9: replacePlaceholders

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String replacePlaceholders(String value, Properties properties) {
    if (value.contains("$")) {
        LOGGER.debug("replacing placeholders in " + value);
        PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
        String newValue = helper.replacePlaceholders(value, properties);
        LOGGER.debug("after replacement: " + newValue);
        return newValue;
    } else {
        return value;
    }
}
 
开发者ID:SumoLogic,项目名称:sumo-report-generator,代码行数:12,代码来源:SumoDataServiceImpl.java

示例10: replaceProperties

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String replaceProperties(String uri) {
    if (uri == null) {
        return null;
    }

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

        @Override
        public String resolvePlaceholder(String placeholderName) {
            return propertyResolver.getProperty(placeholderName);
        }
    });
}
 
开发者ID:Evolveum,项目名称:midpoint,代码行数:15,代码来源:PropertyUrlUriLocator.java

示例11: doResolvePlaceholders

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) {
	return helper.replacePlaceholders(text, new PropertyPlaceholderHelper.PlaceholderResolver() {
		public String resolvePlaceholder(String placeholderName) {
			return getPropertyAsRawString(placeholderName);
		}
	});
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:8,代码来源:AbstractPropertyResolver.java

示例12: loadJsonFile

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
 * Load the JSON template and perform string substitution on the ${...} tokens
 * @param is
 * @return
 * @throws IOException
 */
@SuppressWarnings("unchecked")
Map<String, Object> loadJsonFile(InputStream is, Properties sliProps) throws IOException {
    StringWriter writer = new StringWriter();
    IOUtils.copy(is, writer);
    String template = writer.toString();
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}"); 
    template = helper.replacePlaceholders(template, sliProps);
    return (Map<String, Object>) JSON.parse(template);
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:16,代码来源:ApplicationInitializer.java

示例13: getFilteredContent

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
public String getFilteredContent(String s, Properties properties) {
    PropertyPlaceholderHelper pph = new PropertyPlaceholderHelper(PREFIX, SUFFIX);
    String filtered = pph.replacePlaceholders(s, properties);
    return filtered;
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:6,代码来源:ResourceUtil.java

示例14: parseStringValue

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
 * Parse the given String value for placeholder resolution.
 * @param strVal the String value to parse
 * @param props the Properties to resolve placeholders against
 * @param visitedPlaceholders the placeholders that have already been visited
 * during the current resolution attempt (ignored in this version of the code)
 * @deprecated as of Spring 3.0, in favor of using {@link #resolvePlaceholder}
 * with {@link org.springframework.util.PropertyPlaceholderHelper}.
 * Only retained for compatibility with Spring 2.5 extensions.
 */
@Deprecated
protected String parseStringValue(String strVal, Properties props, Set<?> visitedPlaceholders) {
	PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
			placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
	PlaceholderResolver resolver = new PropertyPlaceholderConfigurerResolver(props);
	return helper.replacePlaceholders(strVal, resolver);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:PropertyPlaceholderConfigurer.java

示例15: parseStringValue

import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
 * Parse the given String with Placeholder "${...}" and returns the result.
 * <p>
 * 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));
}
 
开发者ID:brabenetz,项目名称:settings4j,代码行数:23,代码来源:Settings4jPlaceholderConfigurer.java


注:本文中的org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。