Example usage for org.apache.commons.configuration HierarchicalConfiguration clearTree

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration clearTree

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration clearTree.

Prototype

public void clearTree(String key) 

Source Link

Document

Removes all values of the property with the given name and of keys that start with this name.

Usage

From source file:com.wrmsr.neurosis.util.Configs.java

public static Map<String, String> stripSubconfig(Map<String, String> properties, String prefix) {
    HierarchicalConfiguration hierarchicalProperties = toHierarchical(properties);
    Configuration subconfig;/*w  w  w .  j a  va 2 s  . c  om*/
    try {
        subconfig = hierarchicalProperties.configurationAt(prefix);
    } catch (IllegalArgumentException e) {
        return ImmutableMap.of();
    }

    Map<String, String> subproperties = new ConfigurationMap(subconfig).entrySet().stream()
            .collect(ImmutableCollectors.toImmutableMap(e -> checkNotNull(e.getKey()).toString(),
                    e -> checkNotNull(e.getValue()).toString()));

    hierarchicalProperties.clearTree(prefix);
    for (String key : Sets.newHashSet(properties.keySet())) {
        if (!hierarchicalProperties.containsKey(key)) {
            properties.remove(key);
        }
    }

    return subproperties;
}

From source file:org.zaproxy.zap.control.AddOnLoader.java

private static void saveAddOnsRunState(Map<AddOn, List<String>> runnableAddOns) {
    HierarchicalConfiguration config = (HierarchicalConfiguration) Model.getSingleton().getOptionsParam()
            .getConfig();/*  w  ww .j  a va 2  s  .c  o m*/
    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);
    }
}