List of usage examples for org.apache.commons.configuration PropertiesConfiguration getKeys
public Iterator getKeys()
Iterator
with the keys contained in this configuration. From source file:ffx.ui.KeywordPanel.java
private void configToKeywords(FFXSystem newSystem) { CompositeConfiguration properties = newSystem.getProperties(); Hashtable<String, Keyword> keywordHash = new Hashtable<>(); // Create the "Comments" property. Keyword keyword = new Keyword("COMMENTS"); keywordHash.put("COMMENTS", keyword); // Loop over properties from the keyword file. Configuration config = properties.getConfiguration(0); if (config instanceof PropertiesConfiguration) { PropertiesConfiguration prop = (PropertiesConfiguration) config; Iterator<String> keys = prop.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (keywordHash.contains(key)) { keyword = keywordHash.get(key); keyword.append(prop.getStringArray(key)); } else { String[] values = prop.getStringArray(key); keyword = new Keyword(key, values); keywordHash.put(key, keyword); }//w w w. ja va 2 s.c om } } newSystem.setKeywords(keywordHash); }
From source file:net.sf.zekr.common.config.ApplicationConfig.java
@SuppressWarnings("unchecked") private void loadConfig() { logger.info("Load Zekr configuration file."); File uc = new File(ApplicationPath.USER_CONFIG); boolean createConfig = false; String confFile = ApplicationPath.USER_CONFIG; if (!uc.exists()) { logger.info("User config does not exist at " + ApplicationPath.USER_CONFIG); logger.info("Will make user config with default values at " + ApplicationPath.MAIN_CONFIG); confFile = ApplicationPath.MAIN_CONFIG; createConfig = true;/*from w w w . j av a2 s . com*/ } try { logger.debug("Load " + confFile); props = ConfigUtils.loadConfig(new File(confFile), ApplicationPath.CONFIG_DIR, "UTF-8"); String version = props.getString("version"); if (!GlobalConfig.ZEKR_VERSION.equals(version)) { logger.info("User config version (" + version + ") does not match " + GlobalConfig.ZEKR_VERSION); if (StringUtils.isBlank(version) || !isCompatibleVersion(version)) { // config file is too old logger.info(String.format("Previous version (%s) is too old and not compatible with %s", version, GlobalConfig.ZEKR_VERSION)); logger.info("Cannot migrate old settings. Will reset settings."); props = ConfigUtils.loadConfig(new File(ApplicationPath.MAIN_CONFIG), "UTF-8"); } else { logger.info("Will initialize user config with default values, overriding with old config."); PropertiesConfiguration oldProps = props; props = ConfigUtils.loadConfig(new File(ApplicationPath.MAIN_CONFIG), "UTF-8"); for (Iterator<String> iter = oldProps.getKeys(); iter.hasNext();) { String key = iter.next(); if (key.equals("version")) { continue; } props.setProperty(key, oldProps.getProperty(key)); } } createConfig = true; } } catch (Exception e) { logger.warn("IO Error in loading/reading config file " + ApplicationPath.MAIN_CONFIG); logger.log(e); } if (createConfig) { runtime.clearAll(); // create config dir new File(Naming.getConfigDir()).mkdirs(); saveConfig(); } // load shortcuts logger.info("Loading keyboard shortcuts."); File userShortcut = new File(ApplicationPath.USER_SHORTCUT); Document doc = null; if (userShortcut.exists()) { try { logger.info("Loading user keyboard shortcuts: " + ApplicationPath.USER_SHORTCUT); Document userDoc = new XmlReader(userShortcut).getDocument(); String version = userDoc.getDocumentElement().getAttribute("version"); if (GlobalConfig.ZEKR_VERSION.equals(version)) { doc = userDoc; } else { logger.info("User shortcut file version (" + version + ") does not match with " + GlobalConfig.ZEKR_VERSION); List<String> userList = new ArrayList<String>(); Element userRoot = userDoc.getDocumentElement(); NodeList userMappings = userRoot.getElementsByTagName("mapping"); for (int i = 0; i < userMappings.getLength(); i++) { Element mapping = (Element) userMappings.item(i); String action = mapping.getAttribute("action"); userList.add(action); } File mainShortcut = new File(ApplicationPath.MAIN_SHORTCUT); Element mainRoot = new XmlReader(mainShortcut).getDocument().getDocumentElement(); NodeList mainMappings = mainRoot.getElementsByTagName("mapping"); for (int i = 0; i < mainMappings.getLength(); i++) { Element mapping = (Element) mainMappings.item(i); String action = mapping.getAttribute("action"); if (!userList.contains(action)) { logger.debug("Adding new shortcut mapping for action: " + action); Element newMapping = userDoc.createElement("mapping"); newMapping.setAttribute("action", mapping.getAttribute("action")); newMapping.setAttribute("key", mapping.getAttribute("key")); newMapping.setAttribute("rtlKey", mapping.getAttribute("rtlKey")); userRoot.appendChild(newMapping); } } userRoot.setAttribute("version", GlobalConfig.ZEKR_VERSION); doc = userDoc; XmlUtils.writeXml(userDoc, userShortcut); } } catch (Exception e) { logger.warn("Error loading user shortcuts: " + ApplicationPath.USER_SHORTCUT); logger.log(e); } } else { try { logger.info("Loading keyboard shortcuts from original location: " + ApplicationPath.MAIN_SHORTCUT); File mainShortcut = new File(ApplicationPath.MAIN_SHORTCUT); doc = new XmlReader(mainShortcut).getDocument(); FileUtils.copyFile(mainShortcut, new File(ApplicationPath.USER_SHORTCUT)); } catch (Exception e) { logger.log(e); } } if (doc != null) { logger.info("Initialize keyboard shortcuts and mappings."); shortcut = new KeyboardShortcut(props, doc); shortcut.init(); } }
From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java
private void initialize() { try {/*from w w w.ja v a 2 s .c om*/ // Disable delimiter parsing so getString() returns the whole // property, even if there are commas mirthConfig.setDelimiterParsingDisabled(true); mirthConfig.setFile(new File(ClassPathResource.getResourceURI("mirth.properties"))); mirthConfig.load(); MigrationController.getInstance().migrateConfiguration(mirthConfig); // load the server version versionConfig.setDelimiterParsingDisabled(true); InputStream versionPropertiesStream = ResourceUtil.getResourceStream(this.getClass(), "version.properties"); versionConfig.load(versionPropertiesStream); IOUtils.closeQuietly(versionPropertiesStream); if (mirthConfig.getString(PROPERTY_TEMP_DIR) != null) { File tempDataDirFile = new File(mirthConfig.getString(PROPERTY_TEMP_DIR)); if (!tempDataDirFile.exists()) { if (tempDataDirFile.mkdirs()) { logger.debug("created tempdir: " + tempDataDirFile.getAbsolutePath()); } else { logger.error("error creating tempdir: " + tempDataDirFile.getAbsolutePath()); } } System.setProperty("java.io.tmpdir", tempDataDirFile.getAbsolutePath()); logger.debug("set temp data dir: " + tempDataDirFile.getAbsolutePath()); } File appDataDirFile = null; if (mirthConfig.getString(PROPERTY_APP_DATA_DIR) != null) { appDataDirFile = new File(mirthConfig.getString(PROPERTY_APP_DATA_DIR)); if (!appDataDirFile.exists()) { if (appDataDirFile.mkdir()) { logger.debug("created app data dir: " + appDataDirFile.getAbsolutePath()); } else { logger.error("error creating app data dir: " + appDataDirFile.getAbsolutePath()); } } } else { appDataDirFile = new File("."); } appDataDir = appDataDirFile.getAbsolutePath(); logger.debug("set app data dir: " + appDataDir); baseDir = new File(ClassPathResource.getResourceURI("mirth.properties")).getParentFile().getParent(); logger.debug("set base dir: " + baseDir); if (mirthConfig.getString(CHARSET) != null) { System.setProperty(CHARSET, mirthConfig.getString(CHARSET)); } String[] httpsClientProtocolsArray = mirthConfig.getStringArray(HTTPS_CLIENT_PROTOCOLS); if (ArrayUtils.isNotEmpty(httpsClientProtocolsArray)) { // Support both comma separated and multiline values List<String> httpsClientProtocolsList = new ArrayList<String>(); for (String protocol : httpsClientProtocolsArray) { httpsClientProtocolsList.addAll(Arrays.asList(StringUtils.split(protocol, ','))); } httpsClientProtocols = httpsClientProtocolsList .toArray(new String[httpsClientProtocolsList.size()]); } else { httpsClientProtocols = MirthSSLUtil.DEFAULT_HTTPS_CLIENT_PROTOCOLS; } String[] httpsServerProtocolsArray = mirthConfig.getStringArray(HTTPS_SERVER_PROTOCOLS); if (ArrayUtils.isNotEmpty(httpsServerProtocolsArray)) { // Support both comma separated and multiline values List<String> httpsServerProtocolsList = new ArrayList<String>(); for (String protocol : httpsServerProtocolsArray) { httpsServerProtocolsList.addAll(Arrays.asList(StringUtils.split(protocol, ','))); } httpsServerProtocols = httpsServerProtocolsList .toArray(new String[httpsServerProtocolsList.size()]); } else { httpsServerProtocols = MirthSSLUtil.DEFAULT_HTTPS_SERVER_PROTOCOLS; } String[] httpsCipherSuitesArray = mirthConfig.getStringArray(HTTPS_CIPHER_SUITES); if (ArrayUtils.isNotEmpty(httpsCipherSuitesArray)) { // Support both comma separated and multiline values List<String> httpsCipherSuitesList = new ArrayList<String>(); for (String cipherSuite : httpsCipherSuitesArray) { httpsCipherSuitesList.addAll(Arrays.asList(StringUtils.split(cipherSuite, ','))); } httpsCipherSuites = httpsCipherSuitesList.toArray(new String[httpsCipherSuitesList.size()]); } else { httpsCipherSuites = MirthSSLUtil.DEFAULT_HTTPS_CIPHER_SUITES; } String deploy = String.valueOf(mirthConfig.getProperty(STARTUP_DEPLOY)); if (StringUtils.isNotBlank(deploy)) { startupDeploy = Boolean.parseBoolean(deploy); } // Check for server GUID and generate a new one if it doesn't exist PropertiesConfiguration serverIdConfig = new PropertiesConfiguration( new File(getApplicationDataDir(), "server.id")); if ((serverIdConfig.getString("server.id") != null) && (serverIdConfig.getString("server.id").length() > 0)) { serverId = serverIdConfig.getString("server.id"); } else { serverId = generateGuid(); logger.debug("generated new server id: " + serverId); serverIdConfig.setProperty("server.id", serverId); serverIdConfig.save(); } passwordRequirements = PasswordRequirementsChecker.getInstance().loadPasswordRequirements(mirthConfig); apiBypassword = mirthConfig.getString(API_BYPASSWORD); if (StringUtils.isNotBlank(apiBypassword)) { apiBypassword = new String(Base64.decodeBase64(apiBypassword), "US-ASCII"); } statsUpdateInterval = NumberUtils.toInt(mirthConfig.getString(STATS_UPDATE_INTERVAL), DonkeyStatisticsUpdater.DEFAULT_UPDATE_INTERVAL); // Check for configuration map properties if (mirthConfig.getString(CONFIGURATION_MAP_PATH) != null) { configurationFile = mirthConfig.getString(CONFIGURATION_MAP_PATH); } else { configurationFile = getApplicationDataDir() + File.separator + "configuration.properties"; } PropertiesConfiguration configurationMapProperties = new PropertiesConfiguration(); configurationMapProperties.setDelimiterParsingDisabled(true); configurationMapProperties.setListDelimiter((char) 0); try { configurationMapProperties.load(new File(configurationFile)); } catch (ConfigurationException e) { logger.warn("Failed to find configuration map file"); } Map<String, ConfigurationProperty> configurationMap = new HashMap<String, ConfigurationProperty>(); Iterator<String> iterator = configurationMapProperties.getKeys(); while (iterator.hasNext()) { String key = iterator.next(); String value = configurationMapProperties.getString(key); String comment = configurationMapProperties.getLayout().getCanonicalComment(key, false); configurationMap.put(key, new ConfigurationProperty(value, comment)); } setConfigurationProperties(configurationMap, false); } catch (Exception e) { logger.error("Failed to initialize configuration controller", e); } }
From source file:net.sf.zekr.common.config.ApplicationConfig.java
@SuppressWarnings("unchecked") private void extractViewProps() { ThemeData td;/*from ww w . j a v a2s . c o m*/ Reader reader; String def = props.getString("theme.default"); logger.info("Loading theme .properties files."); String[] paths = { ApplicationPath.THEME_DIR, Naming.getThemeDir() }; for (int pathIndex = 0; pathIndex < paths.length; pathIndex++) { File targetThemeDir = new File(paths[pathIndex]); if (!targetThemeDir.exists()) { continue; } logger.info("Loading theme files info from \"" + paths[pathIndex]); File[] targetThemes = targetThemeDir.listFiles(); File origThemeDir = new File(paths[pathIndex]); File[] origThemes = origThemeDir.listFiles(); for (int i = 0; i < origThemes.length; i++) { String targetThemeDesc = Naming.getThemePropsDir() + "/" + origThemes[i].getName() + ".properties"; File origThemeDesc = new File(origThemes[i] + "/" + ApplicationPath.THEME_DESC); File targetThemeFile = new File(targetThemeDesc); if (!origThemeDesc.exists()) { logger.warn("\"" + origThemes[i] + "\" is not a standard theme! Will ignore it."); continue; } try { if (!targetThemeFile.exists() || FileUtils.isFileNewer(origThemeDesc, targetThemeFile)) { logger.info("Copy theme " + origThemes[i].getName() + " to " + Naming.getThemePropsDir()); FileUtils.copyFile(origThemeDesc, targetThemeFile); } FileInputStream fis = new FileInputStream(targetThemeFile); reader = new InputStreamReader(fis, "UTF-8"); PropertiesConfiguration pc = new PropertiesConfiguration(); pc.load(reader); reader.close(); fis.close(); td = new ThemeData(); td.props = new LinkedHashMap<String, String>(); // order is important for options table! for (Iterator<String> iter = pc.getKeys(); iter.hasNext();) { String key = iter.next(); td.props.put(key, CollectionUtils.toString(pc.getList(key), ", ")); } td.author = pc.getString("author"); td.name = pc.getString("name"); td.version = pc.getString("version"); td.id = origThemes[i].getName(); td.fileName = targetThemeFile.getName(); td.baseDir = paths[pathIndex]; td.props.remove("author"); td.props.remove("name"); td.props.remove("version"); // extractTransProps must be called before it! if (getTranslation().getDefault() != null) { td.process(getTranslation().getDefault().locale.getLanguage()); } else { td.process("en"); } theme.add(td); if (td.id.equals(def)) { theme.setCurrent(td); } } catch (Exception e) { logger.warn("Can not load theme \"" + targetThemes[i].getName() + "\", because of the following exception:"); logger.log(e); } } } if (theme.getCurrent() == null) { logger.doFatal(new ZekrBaseException("Could not find default theme: " + def)); } }
From source file:com.mirth.connect.cli.CommandLineInterface.java
private void commandImportMap(Token[] arguments) throws ClientException { if (hasInvalidNumberOfArguments(arguments, 1)) { return;/* w w w . j a v a2s . co m*/ } // file path String path = arguments[1].getText(); File file = new File(path); if (file != null && file.exists()) { try { PropertiesConfiguration properties = new PropertiesConfiguration(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)); } client.setConfigurationMap(configurationMap); out.println("Configuration map import complete"); } catch (ConfigurationException e) { error("Unable to import configuration map", e); } } else { error("Unable to read file " + path, null); } }
From source file:com.linkedin.pinot.queries.TestingServerPropertiesBuilder.java
public PropertiesConfiguration build() throws IOException { final File file = new File("/tmp/" + TestingServerPropertiesBuilder.class.toString()); if (file.exists()) { FileUtils.deleteDirectory(file); }//from ww w . j av a 2s .c om file.mkdir(); final File bootsDir = new File(file, "bootstrap"); final File dataDir = new File(file, "data"); bootsDir.mkdir(); dataDir.mkdir(); final PropertiesConfiguration config = new PropertiesConfiguration(); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "id"), "0"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "bootstrap.segment.dir"), bootsDir.getAbsolutePath()); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "dataDir"), dataDir.getAbsolutePath()); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "bootstrap.segment.dir"), "0"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "data.manager.class"), "com.linkedin.pinot.core.data.manager.InstanceDataManager"); config.addProperty( StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "segment.metadata.loader.class"), "com.linkedin.pinot.core.indexsegment.columnar.ColumnarSegmentMetadataLoader"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "tableName"), StringUtils.join(tableNames, ",")); for (final String table : tableNames) { config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, table, "dataManagerType"), "offline"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, table, "readMode"), "heap"); config.addProperty( StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, table, "numQueryExecutorThreads"), "50"); } config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, EXECUTOR_PREFIX, "class"), "com.linkedin.pinot.core.query.executor.ServerQueryExecutor"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, EXECUTOR_PREFIX, "timeout"), "150000"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, "requestHandlerFactory.class"), "com.linkedin.pinot.server.request.SimpleRequestHandlerFactory"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, "netty.port"), "8882"); config.setDelimiterParsingDisabled(true); final Iterator<String> keys = config.getKeys(); while (keys.hasNext()) { final String key = keys.next(); System.out.println(key + " : " + config.getProperty(key)); } return config; }
From source file:org.apache.atlas.Atlas.java
private static void showStartupInfo(PropertiesConfiguration buildConfiguration, boolean enableTLS, int appPort) { StringBuilder buffer = new StringBuilder(); buffer.append("\n############################################"); buffer.append("############################################"); buffer.append("\n Atlas Server (STARTUP)"); buffer.append("\n"); try {/*from w w w . j av a2 s . c om*/ final Iterator<String> keys = buildConfiguration.getKeys(); while (keys.hasNext()) { String key = keys.next(); buffer.append('\n').append('\t').append(key).append(":\t") .append(buildConfiguration.getProperty(key)); } } catch (Throwable e) { buffer.append("*** Unable to get build info ***"); } buffer.append("\n############################################"); buffer.append("############################################"); LOG.info(buffer.toString()); LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); LOG.info("Server starting with TLS ? {} on port {}", enableTLS, appPort); LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); }
From source file:org.apache.metron.helpers.topology.SettingsLoader.java
public static void printConfigOptions(PropertiesConfiguration config, String path_fragment) { Iterator<String> itr = config.getKeys(); while (itr.hasNext()) { String key = itr.next();/*from w w w . java 2 s .co m*/ if (key.contains(path_fragment)) { System.out.println("[Metron] Key: " + key + " -> " + config.getString(key)); } } }
From source file:org.apache.metron.helpers.topology.SettingsLoader.java
public static Map<String, String> getConfigOptions(PropertiesConfiguration config, String path_fragment) { Iterator<String> itr = config.getKeys(); Map<String, String> settings = new HashMap<String, String>(); while (itr.hasNext()) { String key = itr.next();//from w w w . j ava 2 s. co m if (key.contains(path_fragment)) { String tmp_key = key.replace(path_fragment, ""); settings.put(tmp_key, config.getString(key)); } } return settings; }
From source file:org.apache.reef.tang.formats.ConfigurationFile.java
private static void processConfigFile(ConfigurationBuilder conf, PropertiesConfiguration confFile) throws IOException, BindException { ConfigurationBuilderImpl ci = (ConfigurationBuilderImpl) conf; Iterator<String> it = confFile.getKeys(); Map<String, String> importedNames = new HashMap<>(); while (it.hasNext()) { String key = it.next();//from w w w . j a v a 2 s . c om String longName = importedNames.get(key); String[] values = confFile.getStringArray(key); if (longName != null) { // System.err.println("Mapped " + key + " to " + longName); key = longName; } for (String value : values) { try { if (key.equals(ConfigurationBuilderImpl.IMPORT)) { ci.getClassHierarchy().getNode(value); final String[] tok = value.split(ReflectionUtilities.regexp); final String lastTok = tok[tok.length - 1]; try { // ci.namespace.getNode(lastTok); ci.getClassHierarchy().getNode(lastTok); throw new IllegalArgumentException("Conflict on short name: " + lastTok); } catch (BindException e) { String oldValue = importedNames.put(lastTok, value); if (oldValue != null) { throw new IllegalArgumentException( "Name conflict: " + lastTok + " maps to " + oldValue + " and " + value); } } } else if (value.startsWith(ConfigurationBuilderImpl.INIT)) { String parseValue = value.substring(ConfigurationBuilderImpl.INIT.length(), value.length()); parseValue = parseValue.replaceAll("^[\\s\\(]+", ""); parseValue = parseValue.replaceAll("[\\s\\)]+$", ""); String[] classes = parseValue.split("[\\s\\-]+"); ci.registerLegacyConstructor(key, classes); } else { ci.bind(key, value); } } catch (BindException e) { throw new BindException("Failed to process configuration tuple: [" + key + "=" + value + "]", e); } catch (ClassHierarchyException e) { throw new ClassHierarchyException( "Failed to process configuration tuple: [" + key + "=" + value + "]", e); } } } }