Example usage for org.apache.commons.configuration PropertiesConfiguration getKeys

List of usage examples for org.apache.commons.configuration PropertiesConfiguration getKeys

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration getKeys.

Prototype

public Iterator getKeys() 

Source Link

Document

Returns an Iterator with the keys contained in this configuration.

Usage

From source file:se.vgregion.portal.rss.client.chain.UserOrganizationProcessor.java

/**
 * Load the replace value map.//from   w ww  .  j  a  v  a  2 s. com
 * 
 * @param mapFile
 *            - File reference to the replace value property file.
 * @throws ConfigurationException
 *             an ConfigurationException has occurred
 * @throws UnsupportedEncodingException
 *             an UnsupportedEncodingException has occurred
 */
public void setReplaceValues(File mapFile) throws ConfigurationException, UnsupportedEncodingException {
    try {
        LOGGER.debug("Map: {}", mapFile.getAbsolutePath());
        PropertiesConfiguration pc = new PropertiesConfiguration();
        pc.setEncoding(ENCODING);
        pc.load(mapFile);

        replaceValues = new HashMap<String, String>();
        for (@SuppressWarnings("unchecked")
        Iterator<String> it = pc.getKeys(); it.hasNext();) {
            String key = it.next();
            String value = pc.getString(key);
            LOGGER.debug("Key: {} Value: {}", new Object[] { key, value });

            if (!StringUtils.isBlank(value)) {
                value = (urlValueEncoding) ? URLEncoder.encode(value, ENCODING) : value;
                key = key.toLowerCase(LOCALE);
                replaceValues.put(key, value);
            }
        }
    } catch (UnsupportedEncodingException e) {
        String msg = "Encoding failure in mapping";
        LOGGER.error(msg + " file [" + mapFilePathErrorMessage(mapFile) + "]", e);
    } catch (ConfigurationException e) {
        String msg = "Failed to load replaceValues mapping";
        LOGGER.error(msg + " file [" + mapFilePathErrorMessage(mapFile) + "]", e);
    }
}

From source file:services.plugins.atlassian.jira.jira1.JiraPluginRunner.java

@Override
public void start() throws PluginException {

    PropertiesConfiguration properties = getPluginContext().getPropertiesConfigurationFromByteArray(
            getPluginContext().getConfigurationAndMergeWithDefault(getPluginContext().getPluginDescriptor()
                    .getConfigurationBlockDescriptors().get(MAIN_CONFIGURATION_NAME)));

    properties.setThrowExceptionOnMissing(true);

    this.hostUrl = removeLastSlash(properties.getString(HOST_URL_PROPERTY));

    this.authenticationKey = properties.getString(AUTHENTICATION_KEY);
    this.apiVersion = properties.getString(API_VERSION);

    if (!isAvailable()) {
        throw new PluginException("Server not available : stopping");
    }/*from   w  ww. j av a2s.c  o  m*/

    this.peLoadStartTime = properties.getString(PE_LOAD_START_TIME_PROPERTY);
    if (this.peLoadStartTime == null || !this.peLoadStartTime.matches("^([01]?[0-9]|2[0-3])h[0-5][0-9]$")) {
        throw new IllegalArgumentException(
                "Invalid time format for the " + PE_LOAD_START_TIME_PROPERTY + " parameter");
    }
    this.peLoadFrequency = FiniteDuration.create(properties.getLong(PE_LOAD_FREQUENCY_PROPERTY),
            TimeUnit.MINUTES);
    if (properties.getLong(PE_LOAD_FREQUENCY_PROPERTY) < MINIMAL_FREQUENCY) {
        throw new IllegalArgumentException(
                "Invalid frequency " + PE_LOAD_FREQUENCY_PROPERTY + " must be more than 5 minutes");
    }

    this.peIssuesPatternUrl = this.hostUrl + "/browse/{externalId}";

    try {
        long howMuchMinutesUntilStartTime = howMuchMinutesUntilStartTime();
        currentScheduler = getSysAdminUtils().scheduleRecurring(true,
                "JiraPlugin PortfolioEntry load " + getPluginContext().getPluginConfigurationName(),
                Duration.create(howMuchMinutesUntilStartTime, TimeUnit.MINUTES), this.peLoadFrequency,
                new Runnable() {
                    @Override
                    public void run() {
                        runPortfolioEntryLoad();
                    }
                });
        String startTimeMessage = String.format("Scheduler programmed to run in %d minutes",
                howMuchMinutesUntilStartTime);
        getPluginContext().log(LogLevel.INFO, startTimeMessage);
    } catch (Exception e) {
        if (e instanceof PluginException) {
            throw (PluginException) e;
        }
        throw new PluginException(e);
    }

    // get the requirement status mapping
    this.requirementStatusMapping = new HashMap<String, Long>();
    PropertiesConfiguration statusMapping = getPluginContext().getPropertiesConfigurationFromByteArray(
            getPluginContext().getConfigurationAndMergeWithDefault(getPluginContext().getPluginDescriptor()
                    .getConfigurationBlockDescriptors().get(REQUIREMENT_STATUS_MAPPING_CONFIGURATION_NAME)));
    for (Iterator<String> iter = statusMapping.getKeys(); iter.hasNext();) {
        String key = iter.next();
        if (!statusMapping.getString(key).equals("")) {
            this.requirementStatusMapping.put(key, statusMapping.getLong(key));
        }
    }

    // get the requirement priority mapping
    this.requirementPriorityMapping = new HashMap<String, Long>();
    PropertiesConfiguration priorityMapping = getPluginContext().getPropertiesConfigurationFromByteArray(
            getPluginContext().getConfigurationAndMergeWithDefault(getPluginContext().getPluginDescriptor()
                    .getConfigurationBlockDescriptors().get(REQUIREMENT_PRIORITY_MAPPING_CONFIGURATION_NAME)));
    for (Iterator<String> iter = priorityMapping.getKeys(); iter.hasNext();) {
        String key = iter.next();
        if (!priorityMapping.getString(key).equals("")) {
            this.requirementPriorityMapping.put(key, priorityMapping.getLong(key));
        }
    }

    // get the requirement severity mapping
    this.requirementSeverityMapping = new HashMap<String, Long>();
    PropertiesConfiguration severityMapping = getPluginContext().getPropertiesConfigurationFromByteArray(
            getPluginContext().getConfigurationAndMergeWithDefault(getPluginContext().getPluginDescriptor()
                    .getConfigurationBlockDescriptors().get(REQUIREMENT_SEVERITY_MAPPING_CONFIGURATION_NAME)));
    for (Iterator<String> iter = severityMapping.getKeys(); iter.hasNext();) {
        String key = iter.next();
        if (!severityMapping.getString(key).equals("")) {
            this.requirementSeverityMapping.put(key, severityMapping.getLong(key));
        }
    }

    getPluginContext().log(LogLevel.INFO, "Jira plugin started");

}

From source file:services.plugins.redmine.RedminePluginRunner.java

/**
 * Start the plugin.//w ww .j  a  va 2s  .co m
 * 
 * @param properties
 *            the main properties
 */
public void start(PropertiesConfiguration properties) throws PluginException {
    getPluginContext().log(LogLevel.DEBUG, "Redmine plugin checking properties");
    properties.setThrowExceptionOnMissing(true);
    this.apiAccessKey = properties.getString(REDMINE_API_KEY_PROPERTY);
    this.redmineHost = properties.getString(REDMINE_HOST_URL_PROPERTY);

    try {
        this.isScopedCustomFieldId = properties.getInt(IS_SCOPED_CUSTOM_FIELD_ID);
    } catch (Exception e) {
        this.isScopedCustomFieldId = null;
    }
    try {
        this.storyPointsCustomFieldId = properties.getInt(STORY_POINTS_CUSTOM_FIELD_ID);
    } catch (Exception e) {
        this.storyPointsCustomFieldId = null;
    }
    try {
        this.remainingEffortFieldId = properties.getInt(REMAINING_EFFORT_CUSTOM_FIELD_ID);
    } catch (Exception e) {
        this.remainingEffortFieldId = null;
    }

    this.peLoadStartTime = properties.getString(PE_LOAD_START_TIME_PROPERTY);
    if (this.peLoadStartTime == null || !this.peLoadStartTime.matches("^([01]?[0-9]|2[0-3])h[0-5][0-9]$")) {
        throw new IllegalArgumentException(
                "Invalid time format for the " + PE_LOAD_START_TIME_PROPERTY + " parameter");
    }
    this.peLoadFrequency = FiniteDuration.create(properties.getLong(PE_LOAD_FREQUENCY_PROPERTY),
            TimeUnit.MINUTES);
    if (properties.getLong(PE_LOAD_FREQUENCY_PROPERTY) < MINIMAL_FREQUENCY) {
        throw new IllegalArgumentException(
                "Invalid frequency " + PE_LOAD_FREQUENCY_PROPERTY + " must be more than 5 minutes");
    }

    this.peIterationsFilter = null;
    String peIterationsFilterString = properties.getString(PE_ITERATIONS_FILTER_PROPERTY);
    if (peIterationsFilterString != null && !peIterationsFilterString.equals("")) {
        String[] peIterationsFilter = peIterationsFilterString.split("=");
        if (peIterationsFilter.length == 2) {
            this.peIterationsFilter = peIterationsFilter;
        }
    }

    this.peNeedsFilter = null;
    String peNeedsFilterString = properties.getString(PE_NEEDS_FILTER_PROPERTY);
    if (peNeedsFilterString != null && !peNeedsFilterString.equals("")) {
        String[] peNeedsFilter = peNeedsFilterString.split("=");
        if (peNeedsFilter.length == 2) {
            this.peNeedsFilter = peNeedsFilter;
        }
    }

    this.peNeedsTrackers = null;
    String peNeedsTrackersString = properties.getString(PE_NEEDS_TRACKERS_PROPERTY);
    if (peNeedsTrackersString != null && !peNeedsTrackersString.equals("")) {
        this.peNeedsTrackers = peNeedsTrackersString.split(";");
    }

    this.peDefectsFilter = null;
    String peDefectsFilterString = properties.getString(PE_DEFECTS_FILTER_PROPERTY);
    if (peDefectsFilterString != null && !peDefectsFilterString.equals("")) {
        String[] peDefectsFilter = peDefectsFilterString.split("=");
        if (peDefectsFilter.length == 2) {
            this.peDefectsFilter = peDefectsFilter;
        }
    }

    this.peDefectsTrackers = null;
    String peDefectsTrackersString = properties.getString(PE_DEFECTS_TRACKERS_PROPERTY);
    if (peDefectsTrackersString != null && !peDefectsTrackersString.equals("")) {
        this.peDefectsTrackers = peDefectsTrackersString.split(";");
    }

    this.peIssuesPatternUrl = properties.getString(REDMINE_HOST_URL_PROPERTY) + "/issues/{externalId}";

    if (!isAvailable()) {
        throw new PluginException("Server not available : stopping");
    }

    getPluginContext().log(LogLevel.DEBUG, "Preparing the scheduler");
    try {
        long howMuchMinutesUntilStartTime = howMuchMinutesUntilStartTime();
        currentScheduler = getSysAdminUtils().scheduleRecurring(true,
                "RedminePlugin PortfolioEntry load " + getPluginContext().getPluginConfigurationName(),
                Duration.create(howMuchMinutesUntilStartTime, TimeUnit.MINUTES), this.peLoadFrequency,
                new Runnable() {
                    @Override
                    public void run() {
                        runPortfolioEntryLoad();
                    }
                });
        String startTimeMessage = String.format("Scheduler programmed to run in %d minutes",
                howMuchMinutesUntilStartTime);
        getPluginContext().log(LogLevel.INFO, startTimeMessage);
    } catch (Exception e) {
        if (e instanceof PluginException) {
            throw (PluginException) e;
        }
        throw new PluginException(e);
    }

    // get the requirement status mapping
    this.requirementStatusMapping = new HashMap<Integer, Long>();
    PropertiesConfiguration statusMapping = getPluginContext().getPropertiesConfigurationFromByteArray(
            getPluginContext().getConfigurationAndMergeWithDefault(getPluginContext().getPluginDescriptor()
                    .getConfigurationBlockDescriptors().get(REQUIREMENT_STATUS_MAPPING_CONFIGURATION_NAME)));
    for (Iterator<String> iter = statusMapping.getKeys(); iter.hasNext();) {
        String key = iter.next();
        Integer redmineStatusId = Integer.parseInt(key);
        this.requirementStatusMapping.put(redmineStatusId, statusMapping.getLong(key));
    }

    // get the requirement priority mapping
    this.requirementPriorityMapping = new HashMap<Integer, Long>();
    PropertiesConfiguration priorityMapping = getPluginContext().getPropertiesConfigurationFromByteArray(
            getPluginContext().getConfigurationAndMergeWithDefault(getPluginContext().getPluginDescriptor()
                    .getConfigurationBlockDescriptors().get(REQUIREMENT_PRIORITY_MAPPING_CONFIGURATION_NAME)));
    for (Iterator<String> iter = priorityMapping.getKeys(); iter.hasNext();) {
        String key = iter.next();
        Integer redminePriorityId = Integer.parseInt(key);
        this.requirementPriorityMapping.put(redminePriorityId, priorityMapping.getLong(key));
    }

    // get the requirement severity mapping
    this.requirementSeverityMapping = new HashMap<Integer, Long>();
    PropertiesConfiguration severityMapping = getPluginContext().getPropertiesConfigurationFromByteArray(
            getPluginContext().getConfigurationAndMergeWithDefault(getPluginContext().getPluginDescriptor()
                    .getConfigurationBlockDescriptors().get(REQUIREMENT_SEVERITY_MAPPING_CONFIGURATION_NAME)));
    for (Iterator<String> iter = severityMapping.getKeys(); iter.hasNext();) {
        String key = iter.next();
        Integer redminePriorityId = Integer.parseInt(key);
        this.requirementSeverityMapping.put(redminePriorityId, severityMapping.getLong(key));
    }

    getPluginContext().log(LogLevel.INFO, "Redmine plugin started");

}

From source file:ubic.gemma.core.loader.expression.AffyPowerToolsProbesetSummarize.java

/**
 * @return Map of configuration strings from a configuration file
 *//*ww w.j a  v  a2 s  .com*/
static Map<String, String> loadMapFromConfig(String fileName) {
    try {
        PropertiesConfiguration pc = ConfigUtils.loadClasspathConfig(fileName);
        Map<String, String> result = new HashMap<>();

        for (Iterator<String> it = pc.getKeys(); it.hasNext();) {
            String k = it.next();
            result.put(k, pc.getString(k));
        }
        return result;

    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:ubic.gemma.core.loader.expression.AffyPowerToolsProbesetSummarize.java

/**
 * @return Map of GPLXXXX to {mps, pgc, qcc, clf} to file name
 *//* www .  j  av  a 2 s.  co m*/
protected Map<String, Map<String, String>> loadMpsNames() {
    try {
        PropertiesConfiguration pc = ConfigUtils
                .loadClasspathConfig(AffyPowerToolsProbesetSummarize.AFFY_MPS_PROPERTIES_FILE_NAME);
        Map<String, Map<String, String>> result = new HashMap<>();

        for (Iterator<String> it = pc.getKeys(); it.hasNext();) {
            String k = it.next();
            String[] k2 = k.split("\\.");
            String platform = k2[0];
            String type = k2[1];

            if (!result.containsKey(platform)) {
                result.put(platform, new HashMap<String, String>());
            }
            result.get(platform).put(type, pc.getString(k));

        }
        return result;

    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
}