use of io.servicecomb.foundation.common.config.impl.XmlLoader in project java-chassis by ServiceComb.
the class ConfigMgr method init.
public void init() throws Exception {
List<Resource> resArr = PaaSResourceUtils.getSortedResources("classpath*:config/config.inc.xml", ".inc.xml");
IncConfigs incConfigs = new IncConfigs();
incConfigs.setPropertiesList(new ArrayList<>());
incConfigs.setXmlList(new ArrayList<>());
for (Resource resource : resArr) {
IncConfigs tmp = XmlLoaderUtils.load(resource, IncConfigs.class);
if (tmp.getPropertiesList() != null) {
incConfigs.getPropertiesList().addAll(tmp.getPropertiesList());
}
if (tmp.getXmlList() != null) {
incConfigs.getXmlList().addAll(tmp.getXmlList());
}
}
configLoaderMap = new HashMap<>();
for (IncConfig incConfig : incConfigs.getPropertiesList()) {
PropertiesLoader loader = (PropertiesLoader) configLoaderMap.get(incConfig.getId());
if (loader != null) {
loader.getLocationPatternList().addAll(incConfig.getPathList());
continue;
}
configLoaderMap.put(incConfig.getId(), new PropertiesLoader(incConfig.getPathList()));
}
for (IncConfig incConfig : incConfigs.getXmlList()) {
XmlLoader loader = (XmlLoader) configLoaderMap.get(incConfig.getId());
if (loader != null) {
loader.getLocationPatternList().addAll(incConfig.getPathList());
continue;
}
configLoaderMap.put(incConfig.getId(), new XmlLoader(incConfig.getPathList()));
}
}
use of io.servicecomb.foundation.common.config.impl.XmlLoader in project java-chassis by ServiceComb.
the class TestConfig method testXml.
@Test
public void testXml() throws Exception {
List<String> locationPatternList = new ArrayList<>();
locationPatternList.add("classpath*:config/config.test.inc.xml");
ConfigLoader loader = new XmlLoader(locationPatternList, ".inc.xml");
Document doc = loader.load();
Element root = doc.getDocumentElement();
Assert.assertEquals("configs", root.getNodeName());
{
NodeList propList = root.getElementsByTagName("properties");
Assert.assertEquals(2, propList.getLength());
{
Element prop = (Element) propList.item(0);
Assert.assertEquals("pTest", prop.getAttributes().getNamedItem("id").getNodeValue());
NodeList pathList = prop.getElementsByTagName("path");
Assert.assertEquals(1, pathList.getLength());
Assert.assertEquals("classpath*:config/test.properties", pathList.item(0).getTextContent());
}
{
Element prop = (Element) propList.item(1);
Assert.assertEquals("pTest", prop.getAttributes().getNamedItem("id").getNodeValue());
NodeList pathList = prop.getElementsByTagName("path");
Assert.assertEquals(1, pathList.getLength());
Assert.assertEquals("classpath*:config/test.ext.properties", pathList.item(0).getTextContent());
}
}
{
NodeList xmlList = root.getElementsByTagName("xml");
Assert.assertEquals(2, xmlList.getLength());
{
Element xml = (Element) xmlList.item(0);
Assert.assertEquals("xTest", xml.getAttributes().getNamedItem("id").getNodeValue());
NodeList pathList = xml.getElementsByTagName("path");
Assert.assertEquals(1, pathList.getLength());
Assert.assertEquals("classpath*:config/test.xml", pathList.item(0).getTextContent());
}
{
Element xml = (Element) xmlList.item(1);
Assert.assertEquals("xTest", xml.getAttributes().getNamedItem("id").getNodeValue());
NodeList pathList = xml.getElementsByTagName("path");
Assert.assertEquals(1, pathList.getLength());
Assert.assertEquals("classpath*:config/test.ext.xml", pathList.item(0).getTextContent());
}
}
}
Aggregations