use of org.ff4j.conf.XmlParser in project ff4j by ff4j.
the class AbstractPropertyStore method importPropertiesFromXmlFile.
/**
* Initialize store from XML Configuration File.
*
* @param xmlConfFile
* xml configuration file
*/
public Map<String, Property<?>> importPropertiesFromXmlFile(String xmlConfFile) {
// Argument validation
if (xmlConfFile == null || xmlConfFile.isEmpty()) {
throw new IllegalArgumentException("Configuration filename cannot be null nor empty");
}
// Load as Inputstream
InputStream xmlIS = getClass().getClassLoader().getResourceAsStream(xmlConfFile);
if (xmlIS == null) {
throw new IllegalArgumentException("File " + xmlConfFile + " could not be read, please check path and rights");
}
// Use the Feature Parser
XmlConfig conf = new XmlParser().parseConfigurationFile(xmlIS);
Map<String, Property<?>> properties = conf.getProperties();
// Override existing configuration within database
for (Map.Entry<String, Property<?>> featureName : properties.entrySet()) {
if (existProperty(featureName.getKey())) {
deleteProperty(featureName.getKey());
}
createProperty(featureName.getValue());
}
return properties;
}
use of org.ff4j.conf.XmlParser in project ff4j by ff4j.
the class InMemoryPropertiesStoreTest method testProperty.
public void testProperty() {
FF4j ff4j = new FF4j(new XmlParser(), "ff4j.xml");
ff4j.getPropertiesStore().createProperty(new PropertyDate("property_3", new Date()));
Property<?> ap = ff4j.getPropertiesStore().readProperty("property_3");
PropertyDate pDate = (PropertyDate) ap;
pDate.setValue(new Date());
ff4j.getPropertiesStore().updateProperty(pDate);
ff4j.getPropertiesStore().deleteProperty("property_3");
}
use of org.ff4j.conf.XmlParser in project ff4j by ff4j.
the class ConsoleOperations method importFile.
/**
* User action to import Features from a properties files.
*
* @param in
* inpustream from configuration file
* @throws IOException
* Error raised if the configuration cannot be read
*/
public static void importFile(FF4j ff4j, InputStream in) throws IOException {
FeatureStore store = ff4j.getFeatureStore();
XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(in);
Map<String, Feature> mapsOfFeat = xmlConfig.getFeatures();
for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
if (store.exist(feature.getKey())) {
store.update(feature.getValue());
} else {
store.create(feature.getValue());
}
}
LOGGER.info(mapsOfFeat.size() + " features have been imported.");
PropertyStore pstore = ff4j.getPropertiesStore();
Map<String, Property<?>> mapsOfProperties = xmlConfig.getProperties();
for (Entry<String, Property<?>> p : mapsOfProperties.entrySet()) {
if (pstore.existProperty(p.getKey())) {
pstore.updateProperty(p.getValue());
} else {
pstore.createProperty(p.getValue());
}
}
LOGGER.info(mapsOfProperties.size() + " features have been imported.");
}
use of org.ff4j.conf.XmlParser in project ff4j by ff4j.
the class XmlParserTest method testNullValues.
@Test
public void testNullValues() throws IOException {
new XmlParser().escapeXML(null);
new XmlParser().exportProperties(new HashMap<String, Property<?>>());
}
use of org.ff4j.conf.XmlParser in project ff4j by ff4j.
the class XmlParserTest method parseFile.
private void parseFile(String fileName) {
// Given
InputStream in = getClass().getClassLoader().getResourceAsStream(fileName);
if (in == null)
Assert.fail("Xml file must exist");
// When
new XmlParser().parseConfigurationFile(in);
}
Aggregations