/** * recursively resolve any ${varName} in the value */ private String resolveVariables(String value) { int startVar = 0; while ((startVar = value.indexOf("${", startVar)) >= 0) { int endVar = value.indexOf("}", startVar); if (endVar <= 0) { break; } String varName = value.substring(startVar + 2, endVar); if (varName.isEmpty()) { break; } String variableValue = new TypedResolverImpl<String>(this.config, varName) .withCurrentProjectStage(this.projectStageAware) .evaluateVariables(true) .getValue(); if (variableValue != null) { value = value.replace("${" + varName + "}", variableValue); } startVar++; } return value; }
public <T> ConfigResolver.TypedResolver<T> asResolver(final String key, final String stringDefault, final Type ipCls, final Class<? extends ConfigResolver.Converter> converterType, final String parameterizedBy, final boolean projectStageAware, final boolean evaluate) { final ConfigResolver.UntypedResolver<String> untypedResolver = ConfigResolver.resolve(key); final ConfigResolver.TypedResolver<T> resolver = (ConfigResolver.Converter.class == converterType ? untypedResolver.as(Class.class.cast(ipCls)) : untypedResolver.as(ipCls, BeanProvider.getContextualReference(converterType))) .withCurrentProjectStage(projectStageAware); if (!ConfigProperty.NULL.equals(stringDefault)) { resolver.withStringDefault(stringDefault); } if (!ConfigProperty.NULL.equals(parameterizedBy)) { resolver.parameterizedBy(parameterizedBy); } return resolver.evaluateVariables(evaluate); } }
public <T> ConfigResolver.TypedResolver<T> asResolver(final String key, final String stringDefault, final Type ipCls, final Class<? extends ConfigResolver.Converter> converterType, final String parameterizedBy, final boolean projectStageAware, final boolean evaluate) { final ConfigResolver.UntypedResolver<String> untypedResolver = ConfigResolver.resolve(key); final ConfigResolver.TypedResolver<T> resolver = (ConfigResolver.Converter.class == converterType ? untypedResolver.as(Class.class.cast(ipCls)) : untypedResolver.as(ipCls, BeanProvider.getContextualReference(converterType))) .withCurrentProjectStage(projectStageAware); if (!ConfigProperty.NULL.equals(stringDefault)) { resolver.withStringDefault(stringDefault); } if (!ConfigProperty.NULL.equals(parameterizedBy)) { resolver.parameterizedBy(parameterizedBy); } return resolver.evaluateVariables(evaluate); } }
.withCurrentProjectStage(true) .parameterizedBy(property) .evaluateVariables(true) .getValue();
.withCurrentProjectStage(true) .parameterizedBy(property) .evaluateVariables(true) .getValue();
/** * Resolves the value configured for the given key in the current * {@link org.apache.deltaspike.core.api.projectstage.ProjectStage}. * * <p> * First, it will search for a value configured for the given key suffixed with the current ProjectStage (e.g. * 'myproject.myconfig.Production'), and in case this value is not found (null or empty), it will look up the given * key without any suffix.</p> * * <p> * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be * used to determine the ProjectStage itself.</p> * * @param key * * @return the value configured for {@code <given key>.<current project stage>}, or just the configured value of * {@code <given key>} if the project-stage-specific value is not found (null or empty) * */ public static String getProjectStageAwarePropertyValue(String key) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .evaluateVariables(true) .getValue(); } /**
/** * Resolves the value configured for the given key in the current * {@link org.apache.deltaspike.core.api.projectstage.ProjectStage}. * * <p> * First, it will search for a value configured for the given key suffixed with the current ProjectStage (e.g. * 'myproject.myconfig.Production'), and in case this value is not found (null or empty), it will look up the given * key without any suffix.</p> * * <p> * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be * used to determine the ProjectStage itself.</p> * * @param key * * @return the value configured for {@code <given key>.<current project stage>}, or just the configured value of * {@code <given key>} if the project-stage-specific value is not found (null or empty) * */ public static String getProjectStageAwarePropertyValue(String key) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .evaluateVariables(true) .getValue(); } /**
/** * {@link #getPropertyAwarePropertyValue(java.lang.String, java.lang.String)} which returns the provided default * value if no configured value can be found (<code>null</code> or empty). * * <p> * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be * used to determine the ProjectStage itself.</p> * * @param key * @param property the property to look up first and use as the parameter for the main lookup * @param defaultValue fallback value * * @return the configured value or if non found the defaultValue * */ public static String getPropertyAwarePropertyValue(String key, String property, String defaultValue) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .parameterizedBy(property) .withDefault(defaultValue) .evaluateVariables(true) .getValue(); }
/** * {@link #getPropertyAwarePropertyValue(java.lang.String, java.lang.String)} which returns the provided default * value if no configured value can be found (<code>null</code> or empty). * * <p> * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be * used to determine the ProjectStage itself.</p> * * @param key * @param property the property to look up first and use as the parameter for the main lookup * @param defaultValue fallback value * * @return the configured value or if non found the defaultValue * */ public static String getPropertyAwarePropertyValue(String key, String property, String defaultValue) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .parameterizedBy(property) .withDefault(defaultValue) .evaluateVariables(true) .getValue(); }
/** * {@link #getProjectStageAwarePropertyValue(String)} which returns the provided default value if no configured * value can be found (<code>null</code> or empty). * * @param key * @param defaultValue fallback value * * @return the configured value or if non found the defaultValue * */ public static String getProjectStageAwarePropertyValue(String key, String defaultValue) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .withDefault(defaultValue) .evaluateVariables(true) .getValue(); }
/** * {@link #getProjectStageAwarePropertyValue(String)} which returns the provided default value if no configured * value can be found (<code>null</code> or empty). * * @param key * @param defaultValue fallback value * * @return the configured value or if non found the defaultValue * */ public static String getProjectStageAwarePropertyValue(String key, String defaultValue) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .withDefault(defaultValue) .evaluateVariables(true) .getValue(); }
public static String getPropertyValue(String key, String defaultValue, boolean evaluateVariables) { return getConfigProvider().getConfig().resolve(key) .withDefault(defaultValue) .evaluateVariables(evaluateVariables) .withCurrentProjectStage(false) .getValue(); }
public static String getPropertyValue(String key, String defaultValue, boolean evaluateVariables) { return getConfigProvider().getConfig().resolve(key) .withDefault(defaultValue) .evaluateVariables(evaluateVariables) .withCurrentProjectStage(false) .getValue(); }