Search in sources :

Example 1 with XmlParser

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();
        }
    }
}
Also used : XmlParser(org.ff4j.conf.XmlParser) ServletOutputStream(javax.servlet.ServletOutputStream) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature)

Example 2 with XmlParser

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;
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) InputStream(java.io.InputStream) Property(org.ff4j.property.Property) Map(java.util.Map)

Example 3 with XmlParser

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();
}
Also used : XmlParser(org.ff4j.conf.XmlParser)

Example 4 with XmlParser

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);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 5 with XmlParser

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);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

XmlParser (org.ff4j.conf.XmlParser)19 InputStream (java.io.InputStream)16 Test (org.junit.Test)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 Feature (org.ff4j.core.Feature)10 XmlConfig (org.ff4j.conf.XmlConfig)8 Property (org.ff4j.property.Property)7 Map (java.util.Map)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 FeatureStore (org.ff4j.core.FeatureStore)1 PropertyLogLevel (org.ff4j.property.PropertyLogLevel)1 PropertyStore (org.ff4j.property.store.PropertyStore)1