use of org.ff4j.conf.XmlParser in project ff4j by ff4j.
the class ConsoleOperations method exportFile.
/**
* Build Http response when invoking export features.
*
* @param res
* http response
* @throws IOException
* error when building response
*/
public static void exportFile(FF4j ff4j, HttpServletResponse res) throws IOException {
Map<String, Feature> features = ff4j.getFeatureStore().readAll();
InputStream in = new XmlParser().exportFeatures(features);
ServletOutputStream sos = null;
try {
sos = res.getOutputStream();
res.setContentType("text/xml");
res.setHeader("Content-Disposition", "attachment; filename=\"ff4j.xml\"");
// res.setContentLength()
org.apache.commons.io.IOUtils.copy(in, sos);
LOGGER.info(features.size() + " features have been exported.");
} finally {
if (in != null) {
in.close();
}
if (sos != null) {
sos.flush();
sos.close();
}
}
}
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 InMemoryFeatureStore method loadConf.
/**
* Load configuration through FF4J.vml file.
*
* @param conf
* xml filename
*/
private void loadConf(InputStream xmlIN) {
if (xmlIN == null) {
throw new IllegalArgumentException("Cannot parse feature stream");
}
this.featuresMap = new XmlParser().parseConfigurationFile(xmlIN).getFeatures();
buildGroupsFromFeatures();
}
use of org.ff4j.conf.XmlParser in project ff4j by ff4j.
the class FeatureXmlParserTest method testSaxException.
@Test(expected = IllegalArgumentException.class)
public void testSaxException() {
InputStream in = new ByteArrayInputStream("<TOTO>Invalid</TOTO2>".getBytes());
new XmlParser().parseConfigurationFile(in);
}
use of org.ff4j.conf.XmlParser in project ff4j by ff4j.
the class FeatureXmlParserTest method testLoaderRequiredUid.
@Test(expected = IllegalArgumentException.class)
public void testLoaderRequiredUid() {
InputStream in = getClass().getClassLoader().getResourceAsStream("test-featureXmlParserTest-ko-uidrequired.xml");
new XmlParser().parseConfigurationFile(in);
}
Aggregations