import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
+import org.springframework.util.SystemPropertyUtils;
import org.xml.sax.InputSource;
/**
}
RepositoryConfig config;
+ Properties vars = getConfigurationProperties();
InputStream in = configuration.getInputStream();
- InputStream propsIn = null;
try {
- Properties vars = new Properties();
- if (variables != null) {
- propsIn = variables.getInputStream();
- vars.load(propsIn);
- }
- // override with system properties
- vars.putAll(System.getProperties());
vars.put(RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE,
homeDirectory.getCanonicalPath());
config = RepositoryConfig.create(new InputSource(in), vars);
throw new RuntimeException("Cannot read configuration", e);
} finally {
IOUtils.closeQuietly(in);
- IOUtils.closeQuietly(propsIn);
}
if (inMemory)
+ homeDirectory + " with config " + configuration);
}
+ protected Properties getConfigurationProperties() {
+ InputStream propsIn = null;
+ Properties vars;
+ try {
+ vars = new Properties();
+ if (variables != null) {
+ propsIn = variables.getInputStream();
+ vars.load(propsIn);
+ }
+ // resolve system properties
+ for (Object key : vars.keySet()) {
+ // TODO: implement a smarter mechanism to resolve nested ${}
+ String newValue = SystemPropertyUtils.resolvePlaceholders(vars
+ .getProperty(key.toString()));
+ vars.put(key, newValue);
+ }
+ // override with system properties
+ vars.putAll(System.getProperties());
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot read configuration properties", e);
+ } finally {
+ IOUtils.closeQuietly(propsIn);
+ }
+ return vars;
+ }
+
/**
* Import declared node type definitions, trying to update them if they have
* changed. In case of failures an error will be logged but no exception