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

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

Introduction

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

Prototype

public boolean getBoolean(String key, boolean defaultValue) 

Source Link

Usage

From source file:org.topology.bgp_ls.config.nodes.impl.CapabilitiesParser.java

public Capabilities parseConfig(HierarchicalConfiguration hierarchicalConfiguration)
        throws ConfigurationException {
    CapabilitiesList caps = new CapabilitiesList();

    int as4Number = hierarchicalConfiguration.getInt("LargeAutonomousSystem[@local]", -1);

    if (as4Number > 0) {
        if (hierarchicalConfiguration.getBoolean("LargeAutonomousSystem[@optional]", false))
            caps.addOptionalCapability(new AutonomousSystem4Capability(as4Number));
        else/*ww w .ja  va  2 s .  c  o m*/
            caps.addRequiredCapability(new AutonomousSystem4Capability(as4Number));
    }

    if (hierarchicalConfiguration.containsKey("RouteRefresh")) {
        if (hierarchicalConfiguration.getBoolean("RouteRefresh[@optional]", false))
            caps.addOptionalCapability(new RouteRefreshCapability());
        else
            caps.addRequiredCapability(new RouteRefreshCapability());
    }
    parseMultiprotocolCapabilities(hierarchicalConfiguration.configurationsAt("MultiProtocol"), caps);
    parseOutboundRouteFilteringCapabilities(
            hierarchicalConfiguration.configurationsAt("OutboundRouteFiltering"), caps);

    return caps;
}

From source file:org.topology.bgp_ls.config.nodes.impl.CapabilitiesParser.java

private void parseMultiprotocolCapabilities(List<HierarchicalConfiguration> capabilityConfigs,
        CapabilitiesList caps) throws ConfigurationException {
    for (HierarchicalConfiguration config : capabilityConfigs) {
        try {//from  w ww.  j a v  a2s  . c  om
            MultiProtocolCapability mp = new MultiProtocolCapability(
                    AddressFamily.fromString(config.getString("[@addressFamily]")),
                    SubsequentAddressFamily.fromString(config.getString("[@subsequentAddressFamily]")));

            if (config.getBoolean("[@optional]", false))
                caps.addOptionalCapability(mp);
            else
                caps.addRequiredCapability(mp);
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException(e);
        }
    }
}

From source file:org.topology.bgp_ls.config.nodes.impl.CapabilitiesParser.java

private void parseOutboundRouteFilteringCapabilities(List<HierarchicalConfiguration> capabilityConfigs,
        CapabilitiesList caps) throws ConfigurationException {
    for (HierarchicalConfiguration config : capabilityConfigs) {
        try {/*from  ww w  . ja v a2 s.  c  o m*/
            Map<ORFType, ORFSendReceive> filters = new HashMap<ORFType, ORFSendReceive>();

            for (HierarchicalConfiguration entryConfig : config.configurationsAt("Entry")) {
                filters.put(ORFType.fromString(entryConfig.getString("[@type]")),
                        ORFSendReceive.fromString(entryConfig.getString("[@direction]")));
            }

            if (filters.size() == 0)
                throw new ConfigurationException("filter type/direction pair required");

            OutboundRouteFilteringCapability orfc = new OutboundRouteFilteringCapability(
                    AddressFamily.fromString(config.getString("[@addressFamily]")),
                    SubsequentAddressFamily.fromString(config.getString("[@subsequentAddressFamily]")),
                    filters);

            if (config.getBoolean("[@optional]", false))
                caps.addOptionalCapability(orfc);
            else
                caps.addRequiredCapability(orfc);
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException(e);
        }
    }
}

From source file:org.topology.bgp_ls.config.nodes.impl.PeerConfigurationParser.java

public PeerConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException {
    PeerConfigurationImpl peerConfig = new PeerConfigurationImpl();
    List<HierarchicalConfiguration> clientConfigs = config.configurationsAt("Client");
    List<HierarchicalConfiguration> capabilityConfigs = config.configurationsAt("Capabilities");

    try {//from   w w w . j av a 2  s . c  o m
        peerConfig.setPeerName(config.getString("[@name]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("peer name not set", e);
    }

    if (clientConfigs.size() > 1) {
        throw new ConfigurationException("duplicate <Client/> element");
    } else if (clientConfigs.size() == 0) {
        throw new ConfigurationException("missing <Client/> element");
    } else
        peerConfig.setClientConfig(clientConfigurationParser.parseConfig(clientConfigs.get(0)));

    if (capabilityConfigs.size() > 1) {
        throw new ConfigurationException("duplicate <Capabilities/> element");
    } else if (capabilityConfigs.size() == 1)
        peerConfig.setCapabilities(capabilityParser.parseConfig(capabilityConfigs.get(0)));

    try {
        peerConfig.setLocalAS(config.getInt("AutonomousSystem[@local]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("local AS number not given", e);
    }
    try {
        peerConfig.setRemoteAS(config.getInt("AutonomousSystem[@remote]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("remote AS number not given", e);
    }

    try {
        long identifier = config.getLong("BgpIdentifier[@local]");

        if (!isValidBgpIdentifier(identifier))
            throw new ConfigurationException("Invalid local BGP identifier: " + identifier);

        peerConfig.setLocalBgpIdentifier(identifier);
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("local BGP identifier not given", e);
    }
    try {
        long identifier;
        String idString = config.getString("BgpIdentifier[@remote]");
        try {
            InetAddress addr = Inet4Address.getByName(idString);
            byte[] idArray = addr.getAddress();
            identifier = ((long) idArray[3] & 0xFF) | (((long) idArray[2] & 0xFF) << 8)
                    | (((long) idArray[1] & 0xFF) << 16) | (((long) idArray[0] & 0xFF) << 24);

        } catch (Exception e) {
            identifier = Long.parseLong(idString);
        }

        if (!isValidBgpIdentifier(identifier))
            throw new ConfigurationException("Invalid remote BGP identifier: " + identifier);

        peerConfig.setRemoteBgpIdentifier(identifier);
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("remote BGP identifier not given", e);
    }
    peerConfig.setHoldTime(config.getInt("Timers[@holdTime]", 0));
    peerConfig.setIdleHoldTime(config.getInt("Timers[@idleHoldTime]", 0));
    peerConfig.setDelayOpenTime(config.getInt("Timers[@delayOpenTime]", 0));
    peerConfig.setConnectRetryTime(config.getInt("Timers[@connectRetryTime]", 0));
    peerConfig.setAutomaticStartInterval(config.getInt("Timers[@automaticStartInterval]", 0));

    peerConfig.setAllowAutomaticStart(config.getBoolean("Options[@allowAutomaticStart]", true));
    peerConfig.setAllowAutomaticStop(config.getBoolean("Options[@allowAutomaticStop]", false));
    peerConfig.setDampPeerOscillation(config.getBoolean("Options[@dampPeerOscillation]", false));
    peerConfig.setCollisionDetectEstablishedState(
            config.getBoolean("Options[@collisionDetectEstablishedState]", false));
    peerConfig.setDelayOpen(config.getBoolean("Options[@delayOpen]", false));
    peerConfig.setPassiveTcpEstablishment(config.getBoolean("Options[@passiveTcpEstablishment]", false));
    peerConfig.setHoldTimerDisabled(config.getBoolean("Options[@holdTimerDisabled]", false));

    return peerConfig;
}

From source file:org.zaproxy.zap.extension.anticsrf.AntiCsrfParam.java

@Override
protected void parse() {
    try {//from w  w  w. ja  v  a  2 s .  co m
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_TOKENS_KEY);
        this.tokens = new ArrayList<>(fields.size());
        enabledTokensNames = new ArrayList<>(fields.size());
        List<String> tempTokensNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(TOKEN_NAME_KEY, "");
            if (!"".equals(name) && !tempTokensNames.contains(name)) {
                boolean enabled = sub.getBoolean(TOKEN_ENABLED_KEY, true);
                this.tokens.add(new AntiCsrfParamToken(name, enabled));
                tempTokensNames.add(name);
                if (enabled) {
                    enabledTokensNames.add(name);
                }
            }
        }
    } catch (ConversionException e) {
        logger.error("Error while loading anti CSRF tokens: " + e.getMessage(), e);
        this.tokens = new ArrayList<>(DEFAULT_TOKENS_NAMES.length);
        this.enabledTokensNames = new ArrayList<>(DEFAULT_TOKENS_NAMES.length);
    }

    if (this.tokens.size() == 0) {
        for (String tokenName : DEFAULT_TOKENS_NAMES) {
            this.tokens.add(new AntiCsrfParamToken(tokenName));
            this.enabledTokensNames.add(tokenName);
        }
    }

    try {
        this.confirmRemoveToken = getConfig().getBoolean(CONFIRM_REMOVE_TOKEN_KEY, true);
    } catch (ConversionException e) {
        logger.error("Error while loading the confirm remove token option: " + e.getMessage(), e);
    }
}

From source file:org.zaproxy.zap.extension.ext.ExtensionParam.java

@Override
protected void parse() {
    try {/*from www.jav a 2  s.  c om*/
        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();
    }
}

From source file:org.zaproxy.zap.extension.formhandler.FormHandlerParam.java

@Override
protected void parse() {
    try {/*from   w w w . j a v a2  s .  co  m*/
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_TOKENS_KEY);
        this.fields = new ArrayList<>(fields.size());
        enabledFieldsNames = new ArrayList<>(fields.size());
        List<String> tempFieldsNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String value = sub.getString(TOKEN_VALUE_KEY, "");
            String name = sub.getString(TOKEN_NAME_KEY, "");
            if (!"".equals(name) && !tempFieldsNames.contains(name)) {
                boolean enabled = sub.getBoolean(TOKEN_ENABLED_KEY, true);
                this.fields.add(new FormHandlerParamField(name, value, enabled));
                tempFieldsNames.add(name);
                if (enabled) {
                    enabledFieldsNames.add(name);
                }
            }
        }
    } catch (ConversionException e) {
        logger.error("Error while loading key-value pair fields: " + e.getMessage(), e);
        this.fields = new ArrayList<>(DEFAULT_KEY_VALUE_PAIRS.size());
        this.enabledFieldsNames = new ArrayList<>(DEFAULT_KEY_VALUE_PAIRS.size());
    }

    if (this.fields.size() == 0) {
        // Grab the entry for every set in the map
        for (Map.Entry<String, String> entry : DEFAULT_KEY_VALUE_PAIRS.entrySet()) {
            // Store the key and value of that entry in variables
            String name = entry.getKey();
            String value = entry.getValue();
            this.fields.add(new FormHandlerParamField(name, value));
            this.enabledFieldsNames.add(name);
        }
    }

    try {
        this.confirmRemoveField = getConfig().getBoolean(CONFIRM_REMOVE_TOKEN_KEY, true);
    } catch (ConversionException e) {
        logger.error("Error while loading the confirm remove field option: " + e.getMessage(), e);
    }
}

From source file:org.zaproxy.zap.extension.globalexcludeurl.GlobalExcludeURLParam.java

@Override
protected void parse() {
    try {//from   w ww.  j a  v  a 2 s .  co  m
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_TOKENS_KEY);
        this.tokens = new ArrayList<>(fields.size());
        enabledTokensNames = new ArrayList<>(fields.size());
        List<String> tempTokensNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String regex = sub.getString(TOKEN_REGEX_KEY, "");
            if (!"".equals(regex) && !tempTokensNames.contains(regex)) {
                boolean enabled = sub.getBoolean(TOKEN_ENABLED_KEY, true);
                String desc = sub.getString(TOKEN_DESCRIPTION_KEY, "");
                this.tokens.add(new GlobalExcludeURLParamToken(regex, desc, enabled));
                tempTokensNames.add(regex);
                if (enabled) {
                    enabledTokensNames.add(regex);
                }
            }
        }
    } catch (ConversionException e) {
        logger.error("Error while loading Global Exclude URL tokens: " + e.getMessage(), e);
        this.tokens = new ArrayList<>(defaultList.size());
        this.enabledTokensNames = new ArrayList<>(defaultList.size());
    }

    if (this.tokens.size() == 0) {
        for (GlobalExcludeURLParamToken geu : defaultList) {
            this.tokens.add(new GlobalExcludeURLParamToken(geu));
        }
    }

    try {
        this.confirmRemoveToken = getConfig().getBoolean(CONFIRM_REMOVE_TOKEN_KEY, true);
    } catch (ConversionException e) {
        logger.error("Error while loading the confirm remove token option: " + e.getMessage(), e);
    }
}

From source file:org.zaproxy.zap.extension.httpsessions.HttpSessionsParam.java

@Override
protected void parse() {
    // Parse the default token names
    try {/*from   w  w w. ja v  a 2 s  .  c o  m*/
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_DEFAULT_TOKENS_KEY);
        this.defaultTokens = new ArrayList<>(fields.size());
        this.defaultTokensEnabled = new ArrayList<>(fields.size());
        List<String> tempTokensNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(TOKEN_NAME_KEY, "");
            if (!"".equals(name) && !tempTokensNames.contains(name)) {
                boolean enabled = sub.getBoolean(TOKEN_ENABLED_KEY, true);
                this.defaultTokens.add(new HttpSessionToken(name, enabled));
                tempTokensNames.add(name);
                if (enabled) {
                    this.defaultTokensEnabled.add(name);
                }
            }
        }
    } catch (ConversionException e) {
        this.defaultTokens = new ArrayList<>(DEFAULT_TOKENS.length);
        log.error("Error while parsing config file: " + e.getMessage(), e);
    }
    if (this.defaultTokens.size() == 0) {
        for (String tokenName : DEFAULT_TOKENS) {
            this.defaultTokens.add(new HttpSessionToken(tokenName));
            this.defaultTokensEnabled.add(tokenName);
        }
    }

    try {
        this.enabledProxyOnly = getConfig().getBoolean(PROXY_ONLY_KEY, false);
    } catch (ConversionException e) {
        log.error("Error while parsing config file: " + e.getMessage(), e);
    }

    try {
        this.confirmRemove = getConfig().getBoolean(CONFIRM_REMOVE_TOKEN_KEY, true);
    } catch (ConversionException e) {
        log.error("Error while parsing config file: " + e.getMessage(), e);
    }
}

From source file:org.zaproxy.zap.extension.invoke.InvokeParam.java

@Override
protected void parse() {
    listInvoke.clear();/*from   w w w  .  j  a v a  2 s .c  o m*/

    ArrayList<InvokableApp> enabledApps = null;
    try {
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_APPS_KEY);
        this.listInvoke = new ArrayList<>(fields.size());
        enabledApps = new ArrayList<>(fields.size());
        List<String> tempListNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(APP_NAME_KEY, "");
            if (!"".equals(name) && !tempListNames.contains(name)) {
                tempListNames.add(name);

                File dir = null;
                String directory = sub.getString(APP_DIRECTORY_KEY, "");
                if (directory.length() > 0) {
                    dir = new File(directory);
                }

                InvokableApp app = new InvokableApp(name, dir, sub.getString(APP_COMMAND_KEY),
                        sub.getString(APP_PARAMS_KEY), sub.getBoolean(APP_OUTPUT_KEY, true),
                        sub.getBoolean(APP_NOTE_KEY, false));

                app.setEnabled(sub.getBoolean(APP_ENABLED_KEY, true));

                listInvoke.add(app);

                if (app.isEnabled()) {
                    enabledApps.add(app);
                }
            }
        }
        enabledApps.trimToSize();
        this.listInvokeEnabled = enabledApps;
    } catch (ConversionException e) {
        logger.error("Error while loading invoke applications: " + e.getMessage(), e);
    }

    try {
        this.confirmRemoveApp = getConfig().getBoolean(CONFIRM_REMOVE_APP_KEY, true);
    } catch (ConversionException e) {
        logger.error("Error while loading the confirm remove option: " + e.getMessage(), e);
    }
}