http://www.code-thrill.com/2012/05/configuration-that-rocks-with-apache.html
http://commons.apache.org/proper/commons-configuration/userguide/howto_configurationbuilder.html#Using_DefaultConfigurationBuilder
@Test
public void getDbUrl() throws ConfigurationException {
final String appPropertiesFile = System.getProperty("jboss.server.config.url")
+ "external-connector-config/config.xml";
try {
DefaultConfigurationBuilder builder =
new DefaultConfigurationBuilder(appPropertiesFile);
boolean load = true;
CombinedConfiguration config = builder.getConfiguration(load);
config.setExpressionEngine(new XPathExpressionEngine());
String xpath1 = "application/name";
String xpath2 = "web-services/web-service[vender-id = 'solid-tumor']/url";
String xpath3 = "databases/database[name = 'dev']/url";
List<AbstractConfiguration> abstractConfigurations = config.getConfigurations();
for (AbstractConfiguration abstractConfiguration : abstractConfigurations) {
if (abstractConfiguration instanceof EnvironmentConfiguration) {
for (ConfigurationListener configurationListener : abstractConfiguration
.getConfigurationListeners()) {
Set<String> configurationNames = ((CombinedConfiguration)
configurationListener).getConfigurationNames();
if (configurationNames.equals(ApplicationProperties.CONFIG_NAME_APPLICATION)) {
System.out.println();
}
System.out.println(((CombinedConfiguration) configurationListener).getConfigurationNames());
}
}
else if (abstractConfiguration instanceof XMLConfiguration) {
int lastIndex = ((XMLConfiguration) abstractConfiguration).getDocument().getBaseURI()
.split("/").length - 1;
String fileName = ((XMLConfiguration) abstractConfiguration).getDocument().getBaseURI()
.split("/")[lastIndex];
if (fileName.startsWith(ApplicationProperties.CONFIG_NAME_APPLICATION)) {
System.out.println((((XMLConfiguration) abstractConfiguration).getDocument().getDocumentURI()));
}
}
}
//System.out.println(config.getString(xpath));
}
catch (Exception e) {
e.printStackTrace();
}
}