Search in sources :

Example 1 with HierarchicalConfiguration

use of org.apache.commons.configuration.HierarchicalConfiguration in project archaius by Netflix.

the class ConcurrentMapConfigurationTest method testPerformance.

@Test
public void testPerformance() {
    MyListener listener = new MyListener();
    BaseConfiguration baseConfig = new BaseConfiguration();
    baseConfig.addConfigurationListener(listener);
    HierarchicalConfiguration hConfig = new HierarchicalConfiguration();
    hConfig.addConfigurationListener(listener);
    ConcurrentMapConfiguration conf = new ConcurrentMapConfiguration();
    conf.addConfigurationListener(listener);
    testConfigurationSet(baseConfig);
    testConfigurationSet(hConfig);
    testConfigurationSet(conf);
    testConfigurationAdd(baseConfig);
    testConfigurationAdd(hConfig);
    testConfigurationAdd(conf);
    testConfigurationGet(baseConfig);
    testConfigurationGet(hConfig);
    testConfigurationGet(conf);
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) Test(org.junit.Test)

Example 2 with HierarchicalConfiguration

use of org.apache.commons.configuration.HierarchicalConfiguration in project blueprints by tinkerpop.

the class Neo4j2GraphConfiguration method configureGraphInstance.

public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException {
    final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION);
    if (graphFile == null || graphFile.length() == 0) {
        throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION);
    }
    final boolean highAvailabilityMode = context.getProperties().getBoolean(Tokens.REXSTER_GRAPH_HA, false);
    // get the <properties> section of the xml configuration
    final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties();
    SubnodeConfiguration neo4jSpecificConfiguration;
    try {
        neo4jSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES);
    } catch (IllegalArgumentException iae) {
        throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES);
    }
    try {
        // properties to initialize the neo4j instance.
        final HashMap<String, String> neo4jProperties = new HashMap<String, String>();
        // read the properties from the xml file and convert them to properties
        // to be injected into neo4j.
        final Iterator<String> neo4jSpecificConfigurationKeys = neo4jSpecificConfiguration.getKeys();
        while (neo4jSpecificConfigurationKeys.hasNext()) {
            String key = neo4jSpecificConfigurationKeys.next();
            // replace the ".." put in play by apache commons configuration.  that's expected behavior
            // due to parsing key names to xml.
            neo4jProperties.put(key.replace("..", "."), neo4jSpecificConfiguration.getString(key));
        }
        if (highAvailabilityMode) {
            if (!neo4jProperties.containsKey("ha.machine_id")) {
                throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.machine_id] in the <properties> of the configuration");
            }
            if (!neo4jProperties.containsKey("ha.server")) {
                throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.server] <properties> of the configuration");
            }
            if (!neo4jProperties.containsKey("ha.initial_hosts")) {
                throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.initial_hosts] <properties> of the configuration");
            }
            return new Neo4j2HaGraph(graphFile, neo4jProperties);
        } else {
            return new Neo4j2Graph(graphFile, neo4jProperties);
        }
    } catch (GraphConfigurationException gce) {
        throw gce;
    } catch (Exception ex) {
        throw new GraphConfigurationException(ex);
    }
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration) HashMap(java.util.HashMap) GraphConfigurationException(com.tinkerpop.rexster.config.GraphConfigurationException) Neo4j2HaGraph(com.tinkerpop.blueprints.impls.neo4j2.Neo4j2HaGraph) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) GraphConfigurationException(com.tinkerpop.rexster.config.GraphConfigurationException) Neo4j2Graph(com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph)

Example 3 with HierarchicalConfiguration

use of org.apache.commons.configuration.HierarchicalConfiguration in project zaproxy by zaproxy.

the class OptionsParamApi method setPermittedAddresses.

/**
     * Sets the client addresses that will be allowed to access the API.
     * 
     * @param addrs the client addresses that will be allowed to access the API.
     * @since TODO Add Version
     */
public void setPermittedAddresses(List<DomainMatcher> addrs) {
    if (addrs == null || addrs.isEmpty()) {
        ((HierarchicalConfiguration) getConfig()).clearTree(ADDRESS_KEY);
        this.permittedAddresses = Collections.emptyList();
        this.permittedAddressesEnabled = Collections.emptyList();
        return;
    }
    this.permittedAddresses = new ArrayList<>(addrs);
    ((HierarchicalConfiguration) getConfig()).clearTree(ADDRESS_KEY);
    int size = addrs.size();
    ArrayList<DomainMatcher> enabledAddrs = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        String elementBaseKey = ADDRESS_KEY + "(" + i + ").";
        DomainMatcher addr = addrs.get(i);
        getConfig().setProperty(elementBaseKey + ADDRESS_VALUE_KEY, addr.getValue());
        getConfig().setProperty(elementBaseKey + ADDRESS_REGEX_KEY, Boolean.valueOf(addr.isRegex()));
        getConfig().setProperty(elementBaseKey + ADDRESS_ENABLED_KEY, Boolean.valueOf(addr.isEnabled()));
        if (addr.isEnabled()) {
            enabledAddrs.add(addr);
        }
    }
    enabledAddrs.trimToSize();
    this.permittedAddressesEnabled = enabledAddrs;
}
Also used : ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) DomainMatcher(org.zaproxy.zap.network.DomainMatcher)

Example 4 with HierarchicalConfiguration

use of org.apache.commons.configuration.HierarchicalConfiguration in project zaproxy by zaproxy.

the class ExtensionParam method parse.

@Override
protected void parse() {
    try {
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_EXTENSIONS_KEY);
        Map<String, Boolean> extensions = new HashMap<>();
        for (HierarchicalConfiguration sub : fields) {
            if (!sub.getBoolean(EXTENSION_ENABLED_KEY, true)) {
                extensions.put(sub.getString(EXTENSION_NAME_KEY, ""), Boolean.FALSE);
            }
        }
        extensionsState = Collections.unmodifiableMap(extensions);
    } catch (ConversionException e) {
        LOGGER.error("Error while loading extensions' state: " + e.getMessage(), e);
        extensionsState = Collections.emptyMap();
    }
}
Also used : ConversionException(org.apache.commons.configuration.ConversionException) HashMap(java.util.HashMap) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 5 with HierarchicalConfiguration

use of org.apache.commons.configuration.HierarchicalConfiguration in project zaproxy by zaproxy.

the class AddOnLoader method saveAddOnsRunState.

private static void saveAddOnsRunState(Map<AddOn, List<String>> runnableAddOns) {
    HierarchicalConfiguration config = (HierarchicalConfiguration) Model.getSingleton().getOptionsParam().getConfig();
    config.clearTree(ADDONS_RUNNABLE_BASE_KEY);
    int i = 0;
    for (Map.Entry<AddOn, List<String>> runnableAddOnEntry : runnableAddOns.entrySet()) {
        String elementBaseKey = ADDONS_RUNNABLE_KEY + "(" + i + ").";
        AddOn addOn = runnableAddOnEntry.getKey();
        config.setProperty(elementBaseKey + ADDON_RUNNABLE_ID_KEY, addOn.getId());
        config.setProperty(elementBaseKey + ADDON_RUNNABLE_VERSION_KEY, Integer.valueOf(addOn.getFileVersion()));
        String extensionBaseKey = elementBaseKey + ADDON_RUNNABLE_ALL_EXTENSIONS_KEY;
        for (String extension : runnableAddOnEntry.getValue()) {
            config.addProperty(extensionBaseKey, extension);
        }
        i++;
    }
    try {
        Model.getSingleton().getOptionsParam().getConfig().save();
    } catch (ConfigurationException e) {
        logger.error("Failed to save state of runnable add-ons:", e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)34 ArrayList (java.util.ArrayList)17 ConversionException (org.apache.commons.configuration.ConversionException)7 SiteContext (org.craftercms.engine.service.context.SiteContext)6 HashMap (java.util.HashMap)4 DomainMatcher (org.zaproxy.zap.network.DomainMatcher)4 List (java.util.List)3 Pattern (java.util.regex.Pattern)3 ConfigurationException (org.apache.commons.configuration.ConfigurationException)3 SubnodeConfiguration (org.apache.commons.configuration.SubnodeConfiguration)3 Callback (org.craftercms.commons.lang.Callback)3 ConfigurationException (org.craftercms.engine.exception.ConfigurationException)3 GraphConfigurationException (com.tinkerpop.rexster.config.GraphConfigurationException)2 Map (java.util.Map)2 SiteContextCreationException (org.craftercms.engine.exception.SiteContextCreationException)2 ScriptFactory (org.craftercms.engine.scripting.ScriptFactory)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 RegexAutoTagScanner (org.zaproxy.zap.extension.pscan.scanner.RegexAutoTagScanner)2 Neo4j2Graph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph)1 Neo4j2HaGraph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2HaGraph)1