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:com.linkedin.pinot.integration.tests.FileBasedServerBrokerStarters.java

@SuppressWarnings("unchecked")
private void log(PropertiesConfiguration props, String configsFor) {
    LOGGER.info("******************************* configs for : " + configsFor
            + " : ********************************************");

    final Iterator<String> keys = props.getKeys();

    while (keys.hasNext()) {
        final String key = keys.next();
        LOGGER.info(key + " : " + props.getProperty(key));
    }/*from   w  w  w. ja v a2 s. com*/

    LOGGER.info("******************************* configs end for : " + configsFor
            + " : ****************************************");
}

From source file:com.linkedin.pinot.core.segment.store.SingleFileIndexDirectory.java

private void loadMap() throws ConfigurationException {
    File mapFile = new File(segmentDirectory, INDEX_MAP_FILE);

    PropertiesConfiguration mapConfig = new PropertiesConfiguration(mapFile);
    Iterator keys = mapConfig.getKeys();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        // column names can have '.' in it hence scan from backwards
        // parsing names like "column.name.dictionary.startOffset"
        // or, "column.name.dictionary.endOffset" where column.name is the key
        int lastSeparatorPos = key.lastIndexOf(MAP_KEY_SEPARATOR);
        Preconditions.checkState(lastSeparatorPos != -1,
                "Key separator not found: " + key + ", segment: " + segmentDirectory);
        String propertyName = key.substring(lastSeparatorPos + 1);

        int indexSeparatorPos = key.lastIndexOf(MAP_KEY_SEPARATOR, lastSeparatorPos - 1);
        Preconditions.checkState(indexSeparatorPos != -1,
                "Index separator not found: " + key + " , segment: " + segmentDirectory);
        String indexName = key.substring(indexSeparatorPos + 1, lastSeparatorPos);
        String columnName = key.substring(0, indexSeparatorPos);
        IndexKey indexKey = new IndexKey(columnName, ColumnIndexType.getValue(indexName));
        IndexEntry entry = columnEntries.get(indexKey);
        if (entry == null) {
            entry = new IndexEntry(indexKey);
            columnEntries.put(indexKey, entry);
        }/*  w  w w . j av  a  2  s .  co  m*/

        if (propertyName.equals(MAP_KEY_NAME_START_OFFSET)) {
            entry.startOffset = mapConfig.getLong(key);
        } else if (propertyName.equals(MAP_KEY_NAME_SIZE)) {
            entry.size = mapConfig.getLong(key);
        } else {
            throw new ConfigurationException(
                    "Invalid map file key: " + key + ", segmentDirectory: " + segmentDirectory.toString());
        }
    }

    // validation
    for (Map.Entry<IndexKey, IndexEntry> colIndexEntry : columnEntries.entrySet()) {
        IndexEntry entry = colIndexEntry.getValue();
        if (entry.size < 0 || entry.startOffset < 0) {
            throw new ConfigurationException("Invalid map entry for key: " + colIndexEntry.getKey().toString()
                    + ", segment: " + segmentDirectory.toString());
        }
    }
}

From source file:com.konakartadmin.apiexamples.GetCustomerExamples.java

private String[] getPropertiesFromFile(String fileName, String keysStartingWith)
        throws KKAdminException, KKException, ConfigurationException {
    /*//from  ww w . ja va  2s  .c om
     * Find the specified properties file which is guaranteed to return the URL of
     * the properties file or throw an exception.
     */
    URL configFileURL = PropertyFileFinder.findPropertiesURL(fileName);

    PropertiesConfiguration conf = new PropertiesConfiguration(configFileURL);

    if (conf.isEmpty()) {
        throw new KKAdminException(
                "The configuration file: " + configFileURL + " does not appear to contain any keys");
    }

    // Now create the array of properties

    Iterator<?> keys = (conf.getKeys());
    int keyCount = 0;
    while (keys.hasNext()) {
        String key = (String) keys.next();
        String value = (String) conf.getProperty(key);
        if (keysStartingWith == null || key.startsWith(keysStartingWith)) {
            System.out.println(keyCount + ") " + key + " => " + value);
            keyCount++;
        }
    }

    String[] properties = new String[keyCount * 2];
    keys = (conf.getKeys());
    int propIdx = 0;
    while (keys.hasNext()) {
        String key = (String) keys.next();
        String value = (String) conf.getProperty(key);
        if (keysStartingWith == null || key.startsWith(keysStartingWith)) {
            properties[propIdx++] = key;
            properties[propIdx++] = value;
        }
    }

    return properties;
}

From source file:com.uber.hoodie.utilities.sources.KafkaSource.java

public KafkaSource(PropertiesConfiguration config, JavaSparkContext sparkContext, SourceDataFormat dataFormat,
        SchemaProvider schemaProvider) {
    super(config, sparkContext, dataFormat, schemaProvider);

    kafkaParams = new HashMap<>();
    Stream<String> keys = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(config.getKeys(), Spliterator.NONNULL), false);
    keys.forEach(k -> kafkaParams.put(k, config.getString(k)));

    UtilHelpers.checkRequiredProperties(config, Arrays.asList(Config.KAFKA_TOPIC_NAME));
    topicName = config.getString(Config.KAFKA_TOPIC_NAME);
}

From source file:com.baidu.cc.configuration.service.impl.ConfigItemServiceImpl.java

/**
 * properties??./*  w  w w .  j a va2s  . c  om*/
 * 
 * @param groupId
 *            ?groupId
 * @param versionId
 *            ?versionId
 * @param content
 *            properties
 */
@Override
public void batchInsertConfigItems(Long groupId, Long versionId, String content) {

    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
    Properties properties = new Properties();

    try {
        propertiesConfiguration.load(new StringReader(content));
        properties.load(new StringReader(content));

        Date now = new Date();
        Iterator<String> keys = propertiesConfiguration.getKeys();
        List<ConfigItem> configItems = new ArrayList<ConfigItem>();

        while (keys.hasNext()) {
            String key = keys.next();
            String value = properties.getProperty(key);

            ConfigItem configItem = new ConfigItem();
            configItem.setName(key);
            configItem.setVal(value);
            configItem.setCreateTime(now);
            configItem.setUpdateTime(now);
            configItem.setGroupId(groupId);
            configItem.setVersionId(versionId);
            configItem.setShareable(false);
            configItem.setRef(false);
            configItems.add(configItem);
        }

        configItemDao.deleteByGroupId(groupId);
        saveOrUpdateAll(configItems);

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

}

From source file:net.sf.mpaxs.spi.server.settings.Settings.java

private void addConfigFile(String path) {
    if (path != null) {
        PropertiesConfiguration prop;
        try {/* www .j a va  2  s. com*/
            prop = new PropertiesConfiguration(path);
            Iterator keyIter = prop.getKeys();
            while (keyIter.hasNext()) {
                Object obj = keyIter.next();
                String s = (String) obj;
                config.setProperty(s, prop.getProperty(s));
            }
        } catch (ConfigurationException ex) {
            Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:eu.trentorise.game.managers.DroolsEngine.java

private StatelessKieSession loadGameConstants(StatelessKieSession kSession, String gameId) {

    // load game constants
    InputStream constantsFileStream = null;
    Game g = gameSrv.loadGameDefinitionById(gameId);
    if (g != null && g.getRules() != null) {
        for (String ruleUrl : g.getRules()) {
            Rule r = gameSrv.loadRule(gameId, ruleUrl);
            if ((r != null && r.getName() != null && r.getName().equals("constants"))
                    || r instanceof UrlRule && ((UrlRule) r).getUrl().contains("constants")) {
                try {
                    constantsFileStream = r.getInputStream();
                } catch (IOException e) {
                    logger.error("Exception loading constants file", e);
                }// w w w .j a v a 2 s  . co m
            }
        }
    }

    if (constantsFileStream != null) {
        try {
            PropertiesConfiguration constants = new PropertiesConfiguration();
            constants.load(constantsFileStream);
            constants.setListDelimiter(',');
            logger.debug("constants file loaded for game {}", gameId);
            Iterator<String> constantsIter = constants.getKeys();
            while (constantsIter.hasNext()) {
                String constant = constantsIter.next();
                kSession.setGlobal(constant, numberConversion(constants.getProperty(constant)));
                logger.debug("constant {} loaded", constant);
            }
        } catch (ConfigurationException e) {
            logger.error("constants loading exception");
        }
    } else {
        logger.info("Rule constants file not found");
    }
    return kSession;
}

From source file:com.mirth.connect.client.ui.SettingsPanelMap.java

public void doImportMap() {
    File file = getFrame().browseForFile("PROPERTIES");

    if (file != null) {
        try {/*from w  w w  .j av a2  s .co m*/
            PropertiesConfiguration properties = new PropertiesConfiguration();
            properties.setDelimiterParsingDisabled(true);
            properties.setListDelimiter((char) 0);
            properties.load(file);

            Map<String, ConfigurationProperty> configurationMap = new HashMap<String, ConfigurationProperty>();
            Iterator<String> iterator = properties.getKeys();

            while (iterator.hasNext()) {
                String key = iterator.next();
                String value = properties.getString(key);
                String comment = properties.getLayout().getCanonicalComment(key, false);

                configurationMap.put(key, new ConfigurationProperty(value, comment));
            }

            updateConfigurationTable(configurationMap);
            setSaveEnabled(true);
        } catch (Exception e) {
            getFrame().alertThrowable(getFrame(), e, "Error importing configuration map");
        }
    }
}

From source file:com.liferay.portal.deploy.hot.ExtHotDeployListener.java

protected void mergePortalProperties(String portalWebDir, ServletContext servletContext) throws Exception {
    URL pluginPropsURL = servletContext
            .getResource("WEB-INF/ext-web/docroot/WEB-INF/classes/portal-ext.properties");
    if (pluginPropsURL == null) {
        if (_log.isDebugEnabled()) {
            _log.debug("Ext Plugin's portal-ext.properties not found");
        }/*from   w ww  . jav  a 2  s  . c o  m*/
        return;
    }
    if (_log.isDebugEnabled()) {
        _log.debug("Loading portal-ext.properties from " + pluginPropsURL);
    }
    PropertiesConfiguration pluginProps = new PropertiesConfiguration(pluginPropsURL);

    PropertiesConfiguration portalProps = new PropertiesConfiguration(
            this.getClass().getClassLoader().getResource("portal.properties"));

    File extPluginPropsFile = new File(portalWebDir + "WEB-INF/classes/portal-ext-plugin.properties");
    PropertiesConfiguration extPluginPortalProps = new PropertiesConfiguration();
    if (extPluginPropsFile.exists()) {
        extPluginPortalProps.load(extPluginPropsFile);
    }

    for (Iterator it = pluginProps.getKeys(); it.hasNext();) {
        String key = (String) it.next();
        List value = pluginProps.getList(key);
        if (key.endsWith("+")) {
            key = key.substring(0, key.length() - 1);
            List newValue = new ArrayList();
            if (extPluginPortalProps.containsKey(key)) {
                // already rewrited
                newValue.addAll(extPluginPortalProps.getList(key));
            } else {
                newValue.addAll(portalProps.getList(key));
            }

            newValue.addAll(value);
            extPluginPortalProps.setProperty(key, newValue);
        } else {
            extPluginPortalProps.setProperty(key, value);
        }
    }

    extPluginPortalProps.save(extPluginPropsFile);
}

From source file:com.aurel.track.admin.user.userLevel.UserLevelsFromFile.java

/**
 * Loads the user levels// w  w w.j  av  a2 s .c  o m
 * This is a map of maps. The outer map is for each user level, and the inner
 * map contains the settings for each user level
 * @return
 */
public Map<Integer, SortedMap<String, Boolean>> loadUserLevels() {
    Map<Integer, SortedMap<String, Boolean>> locUserLevelsMap = new HashMap<Integer, SortedMap<String, Boolean>>();
    userDefinedExtraUserLevelsMap = new HashMap<String, Integer>();
    localeMap = new HashMap<Integer, Map<String, String>>();
    String ON = "on";
    String OFF = "off";
    PropertiesConfiguration propertiesConfiguration = null;
    if (this.initDataDir == null) {
        //get from <TRACKPLUS_HOME> probably migrate
        propertiesConfiguration = PropertiesConfigurationHelper
                .getPathnamePropFile(HandleHome.getTrackplus_Home(), HandleHome.USER_LEVELS_FILE);
    } else {
        //get from application context
        try {
            propertiesConfiguration = PropertiesConfigurationHelper.loadServletContextPropFile(
                    ApplicationBean.getInstance().getServletContext(), initDataDir,
                    HandleHome.USER_LEVELS_FILE);
        } catch (ServletException e) {
        }
    }
    Pattern LEVEL_PATTERN = Pattern.compile("Level([0-9]+)");
    if (propertiesConfiguration != null) {
        Iterator<String> keys = propertiesConfiguration.getKeys();
        // First path through, we cannot assume it is sorted
        while (keys.hasNext()) {
            String key = keys.next();
            Matcher match = LEVEL_PATTERN.matcher(key);
            if (match.matches()) {
                Integer levelNumber = Integer.parseInt(match.group(1));
                String value = propertiesConfiguration.getString(key);
                userDefinedExtraUserLevelsMap.put(value, levelNumber);
                Map<String, String> localizedLevelsMap = new HashMap<String, String>();
                localeMap.put(levelNumber, localizedLevelsMap);
            }
        }
        keys = propertiesConfiguration.getKeys();
        while (keys.hasNext()) {
            String key = keys.next();
            Matcher match = LEVEL_PATTERN.matcher(key);
            if (match.matches()) {
                Integer levelNumber = Integer.parseInt(match.group(1));
                String value = propertiesConfiguration.getString(key);
                userDefinedExtraUserLevelsMap.put(value, levelNumber);
            } else {
                String[] keyParts = key.split("\\.");
                if (keyParts != null && keyParts.length > 1) {
                    String userLevelName = keyParts[0];
                    if (userLevelName != null && !"".equals(userLevelName)) {
                        String userLevelRightName = key.substring(userLevelName.length() + 1);
                        Integer userLevelID = userLevelNameToID(userLevelName);
                        if (userLevelID == null) {
                            LOGGER.info("No user level specified for " + userLevelName + " (key: " + key + ")");
                            continue;
                        }
                        SortedMap<String, Boolean> userLevelMap = locUserLevelsMap.get(userLevelID);
                        if (userLevelMap == null) {
                            userLevelMap = new TreeMap<String, Boolean>();
                            locUserLevelsMap.put(userLevelID, userLevelMap);
                        }
                        String value = propertiesConfiguration.getString(key);

                        if (keyParts[1] != null && "locale".equals(keyParts[1])) {
                            if (keyParts[2] != null && userLevelID != null) {
                                if (localeMap.get(userLevelID) != null) {
                                    localeMap.get(userLevelID).put(keyParts[2], value);
                                    continue;
                                }
                            }
                        }
                        if (value != null && !"".equals(value) && userLevelRightName != null
                                && !"".equals(userLevelRightName)) {
                            if (ON.equals(value)) {
                                userLevelMap.put(userLevelRightName, Boolean.TRUE);
                            } else {
                                if (OFF.equals(value)) {
                                    userLevelMap.put(userLevelRightName, Boolean.FALSE);
                                } else {
                                    try {
                                        userLevelMap.put(userLevelRightName, Boolean.valueOf(value));
                                    } catch (Exception e) {
                                        LOGGER.info("The value " + value + " for key " + key
                                                + " can't be converted to a boolean " + e.getMessage());
                                        LOGGER.debug(ExceptionUtils.getStackTrace(e));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    this.userLevelsMap = locUserLevelsMap;
    return locUserLevelsMap;
}