List of usage examples for org.apache.commons.configuration PropertiesConfiguration containsKey
public boolean containsKey(String key)
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java
@SuppressWarnings("unchecked") @Test// w ww . j av a2 s . co m public void testSaveGraphNeo4jResourceNeo4jTypeOption() throws IOException, ConfigurationException { options.clear(); options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE, BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_TYPE_NEO4J); resource.save(options); File configFile = new File(testFilePath + configFileName); assert configFile.exists(); PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assert configuration.containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE); assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE) .equals(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_TYPE_NEO4J); /* * Check the configuration file contains the store_dir property (computed by * blueprints at graph creation) */ assert configuration.containsKey(OPTIONS_GRAPH_NEO4J_STORE_DIR); assert configuration.getString(OPTIONS_GRAPH_NEO4J_STORE_DIR).equals(testFile.getAbsolutePath()); assert getKeyCount( configuration) == defaultPropertyCount : "The number of properties in the configuration file is not consistent with the given options"; }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java
/** * Test the existence of relationships_mapped_memory and properties_mapped_memory properties * in the configuration file (with a positive value). * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J} * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}) * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()} *//*from w w w . jav a 2 s . c o m*/ @SuppressWarnings("unchecked") @Test public void testSaveGraphNeo4jResourcePositiveRelationshipMappedMemoryPositivePropertiesMappedMemoryOption() throws IOException, ConfigurationException { options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_RELATIONSHIPS_MAPPED_MEMORY, "64M"); options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_PROPERTIES_MAPPED_MEMORY, "64M"); resource.save(options); File configFile = new File(testFile + configFileName); assert configFile.exists(); PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assert configuration .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_RELATIONSHIPS_MAPPED_MEMORY); assert configuration .getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_RELATIONSHIPS_MAPPED_MEMORY) .equals("64M"); assert configuration .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_PROPERTIES_MAPPED_MEMORY); assert configuration .getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_PROPERTIES_MAPPED_MEMORY) .equals("64M"); assert getKeyCount(configuration) == defaultPropertyCount + 2 : "The number of properties in the configuration file is not consistent with the given options"; }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java
/** * Test the existence of all the properties in the configuration file (all options given to the * resource are valid).//ww w . j a va 2s . c om * Tested options are: * - cache_type * - use_memory_mapped_buffers * - strings_mapped_memory * - arrays_mapped_memory * - nodes_mapped_memory * - properties_mapped_memory * - relationships_mapped_memory * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J} * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}) * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()} */ @SuppressWarnings("unchecked") @Test public void testSaveGraphNeo4jResourceAllOptionsValid() throws IOException, ConfigurationException { options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE, BlueprintsNeo4jResourceOptions.CACHE_TYPE.SOFT); options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_USE_MEMORY_MAPPED_BUFFERS, BlueprintsNeo4jResourceOptions.USE_MEMORY_MAPPED_BUFFER.TRUE); options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_STRINGS_MAPPED_MEMORY, "64M"); options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY, "64M"); options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY, "64M"); options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_PROPERTIES_MAPPED_MEMORY, "64M"); options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_RELATIONSHIPS_MAPPED_MEMORY, "64M"); resource.save(options); File configFile = new File(testFile + configFileName); assert configFile.exists(); PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assert configuration.containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE); assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE) .equals(BlueprintsNeo4jResourceOptions.CACHE_TYPE.SOFT.toString()); assert configuration .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_USE_MEMORY_MAPPED_BUFFERS); assert configuration .getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_USE_MEMORY_MAPPED_BUFFERS) .equals(BlueprintsNeo4jResourceOptions.USE_MEMORY_MAPPED_BUFFER.TRUE.toString()); assert configuration .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_STRINGS_MAPPED_MEMORY); assert configuration .getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_STRINGS_MAPPED_MEMORY) .equals("64M"); assert configuration .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY); assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY) .equals("64M"); assert configuration .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY); assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY) .equals("64M"); assert configuration .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_PROPERTIES_MAPPED_MEMORY); assert configuration .getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_PROPERTIES_MAPPED_MEMORY) .equals("64M"); assert configuration .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_RELATIONSHIPS_MAPPED_MEMORY); assert configuration .getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_RELATIONSHIPS_MAPPED_MEMORY) .equals("64M"); assert getKeyCount(configuration) == defaultPropertyCount + 7 : "The number of properties in the configuration file is not consistent with the given options"; }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.BlueprintsPersistenceBackendFactory.java
@Override public BlueprintsPersistenceBackend createPersistentBackend(File file, Map<?, ?> options) throws InvalidDataStoreException { BlueprintsPersistenceBackend graphDB = null; PropertiesConfiguration neoConfig = null; PropertiesConfiguration configuration = null; try {/* w w w . j a va 2s .c om*/ // Try to load previous configurations Path path = Paths.get(file.getAbsolutePath()).resolve(CONFIG_FILE); try { configuration = new PropertiesConfiguration(path.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } // Initialize value if the config file has just been created if (!configuration.containsKey(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE)) { configuration.setProperty(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE, BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE_DEFAULT); } else if (options.containsKey(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE)) { // The file already existed, check that the issued options // are not conflictive String savedGraphType = configuration .getString(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE); String issuedGraphType = options.get(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE) .toString(); if (!savedGraphType.equals(issuedGraphType)) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, "Unable to create graph as type " + issuedGraphType + ", expected graph type was " + savedGraphType + ")"); throw new InvalidDataStoreException("Unable to create graph as type " + issuedGraphType + ", expected graph type was " + savedGraphType + ")"); } } // Copy the options to the configuration for (Entry<?, ?> e : options.entrySet()) { configuration.setProperty(e.getKey().toString(), e.getValue().toString()); } // Check we have a valid graph type, it is needed to get the // graph name String graphType = configuration.getString(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE); if (graphType == null) { throw new InvalidDataStoreException("Graph type is undefined for " + file.getAbsolutePath()); } String[] segments = graphType.split("\\."); if (segments.length >= 2) { String graphName = segments[segments.length - 2]; String upperCaseGraphName = Character.toUpperCase(graphName.charAt(0)) + graphName.substring(1); String configClassQualifiedName = MessageFormat.format( "fr.inria.atlanmod.neoemf.graph.blueprints.{0}.config.Blueprints{1}Config", graphName, upperCaseGraphName); try { ClassLoader classLoader = BlueprintsPersistenceBackendFactory.class.getClassLoader(); Class<?> configClass = classLoader.loadClass(configClassQualifiedName); Field configClassInstanceField = configClass.getField("eINSTANCE"); AbstractBlueprintsConfig configClassInstance = (AbstractBlueprintsConfig) configClassInstanceField .get(configClass); Method configMethod = configClass.getMethod("putDefaultConfiguration", Configuration.class, File.class); configMethod.invoke(configClassInstance, configuration, file); Method setGlobalSettingsMethod = configClass.getMethod("setGlobalSettings"); setGlobalSettingsMethod.invoke(configClassInstance); } catch (ClassNotFoundException e1) { NeoLogger.log(NeoLogger.SEVERITY_WARNING, "Unable to find the configuration class " + configClassQualifiedName); e1.printStackTrace(); } catch (NoSuchFieldException e2) { NeoLogger.log(NeoLogger.SEVERITY_WARNING, MessageFormat.format( "Unable to find the static field eINSTANCE in class Blueprints{0}Config", upperCaseGraphName)); e2.printStackTrace(); } catch (NoSuchMethodException e3) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, MessageFormat.format( "Unable to find configuration methods in class Blueprints{0}Config", upperCaseGraphName)); e3.printStackTrace(); } catch (InvocationTargetException e4) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, MessageFormat.format( "An error occured during the exection of a configuration method", upperCaseGraphName)); e4.printStackTrace(); } catch (IllegalAccessException e5) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, MessageFormat.format( "An error occured during the exection of a configuration method", upperCaseGraphName)); e5.printStackTrace(); } } else { NeoLogger.log(NeoLogger.SEVERITY_WARNING, "Unable to compute graph type name from " + graphType); } Graph baseGraph = null; try { baseGraph = GraphFactory.open(configuration); } catch (RuntimeException e) { throw new InvalidDataStoreException(e); } if (baseGraph instanceof KeyIndexableGraph) { graphDB = new BlueprintsPersistenceBackend((KeyIndexableGraph) baseGraph); } else { NeoLogger.log(NeoLogger.SEVERITY_ERROR, "Graph type " + file.getAbsolutePath() + " does not support Key Indices"); throw new InvalidDataStoreException( "Graph type " + file.getAbsolutePath() + " does not support Key Indices"); } // Save the neoconfig file Path neoConfigPath = Paths.get(file.getAbsolutePath()).resolve(NEO_CONFIG_FILE); try { neoConfig = new PropertiesConfiguration(neoConfigPath.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } if (!neoConfig.containsKey(BACKEND_PROPERTY)) { neoConfig.setProperty(BACKEND_PROPERTY, BLUEPRINTS_BACKEND); } } finally { if (configuration != null) { try { configuration.save(); } catch (ConfigurationException e) { // Unable to save configuration, supposedly it's a minor error, // so we log it without rising an exception NeoLogger.log(NeoLogger.SEVERITY_ERROR, e); } } if (neoConfig != null) { try { neoConfig.save(); } catch (ConfigurationException e) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, e); } } } return graphDB; }
From source file:com.mirth.connect.server.migration.ServerMigrator.java
private void runConfigurationMigrator(ConfigurationMigrator configurationMigrator, PropertiesConfiguration mirthConfig, Version version) { configurationMigrator.updateConfiguration(mirthConfig); HashMap<String, Object> addedProperties = new LinkedHashMap<String, Object>(); Map<String, Object> propertiesToAdd = configurationMigrator.getConfigurationPropertiesToAdd(); if (propertiesToAdd != null) { for (Entry<String, Object> propertyToAdd : propertiesToAdd.entrySet()) { if (!mirthConfig.containsKey(propertyToAdd.getKey())) { PropertiesConfigurationLayout layout = mirthConfig.getLayout(); String key = propertyToAdd.getKey(); Object value;/*from w w w. j a v a 2s. c om*/ String comment = ""; if (propertyToAdd.getValue() instanceof Pair) { // If a pair is used, get both the value and comment Pair<Object, String> pair = (Pair<Object, String>) propertyToAdd.getValue(); value = pair.getLeft(); comment = pair.getRight(); } else { // Only the value was specified value = propertyToAdd.getValue(); } mirthConfig.setProperty(key, value); // If this is the first added property, add a general comment about the added properties before it if (addedProperties.isEmpty()) { if (StringUtils.isNotEmpty(comment)) { comment = "\n\n" + comment; } comment = "The following properties were automatically added on startup for version " + version + comment; } if (StringUtils.isNotEmpty(comment)) { // When a comment is specified, always put a blank line before it layout.setBlancLinesBefore(key, 1); layout.setComment(key, comment); } addedProperties.put(key, value); } } } List<String> removedProperties = new ArrayList<String>(); String[] propertiesToRemove = configurationMigrator.getConfigurationPropertiesToRemove(); if (propertiesToRemove != null) { for (String propertyToRemove : propertiesToRemove) { if (mirthConfig.containsKey(propertyToRemove)) { mirthConfig.clearProperty(propertyToRemove); removedProperties.add(propertyToRemove); } } } if (!addedProperties.isEmpty() || !removedProperties.isEmpty()) { if (!addedProperties.isEmpty()) { logger.info("Adding properties in mirth.properties: " + addedProperties); } if (!removedProperties.isEmpty()) { logger.info("Removing properties in mirth.properties: " + removedProperties); } try { mirthConfig.save(); } catch (ConfigurationException e) { logger.error("There was an error updating mirth.properties.", e); if (!addedProperties.isEmpty()) { logger.error("The following properties should be added to mirth.properties manually: " + addedProperties.toString()); } if (!removedProperties.isEmpty()) { logger.error("The following properties should be removed from mirth.properties manually: " + removedProperties.toString()); } } } }
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"); }// www. ja v 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.linkedin.pinot.core.segment.index.ColumnMetadata.java
public static ColumnMetadata fromPropertiesConfiguration(String column, PropertiesConfiguration config) { Builder builder = new Builder(); builder.setColumnName(column);/* w w w . ja v a2 s . c om*/ builder.setCardinality(config.getInt(getKeyFor(column, CARDINALITY))); int totalDocs = config.getInt(getKeyFor(column, TOTAL_DOCS)); builder.setTotalDocs(totalDocs); builder.setTotalRawDocs(config.getInt(getKeyFor(column, TOTAL_RAW_DOCS), totalDocs)); builder.setTotalAggDocs(config.getInt(getKeyFor(column, TOTAL_AGG_DOCS), 0)); builder.setDataType(DataType.valueOf(config.getString(getKeyFor(column, DATA_TYPE)).toUpperCase())); builder.setBitsPerElement(config.getInt(getKeyFor(column, BITS_PER_ELEMENT))); builder.setStringColumnMaxLength(config.getInt(getKeyFor(column, DICTIONARY_ELEMENT_SIZE))); builder.setFieldType(FieldType.valueOf(config.getString(getKeyFor(column, COLUMN_TYPE)).toUpperCase())); builder.setIsSorted(config.getBoolean(getKeyFor(column, IS_SORTED))); builder.setContainsNulls(config.getBoolean(getKeyFor(column, HAS_NULL_VALUE))); builder.setHasDictionary(config.getBoolean(getKeyFor(column, HAS_DICTIONARY), true)); builder.setHasInvertedIndex(config.getBoolean(getKeyFor(column, HAS_INVERTED_INDEX))); builder.setSingleValue(config.getBoolean(getKeyFor(column, IS_SINGLE_VALUED))); builder.setMaxNumberOfMultiValues(config.getInt(getKeyFor(column, MAX_MULTI_VALUE_ELEMTS))); builder.setTotalNumberOfEntries(config.getInt(getKeyFor(column, TOTAL_NUMBER_OF_ENTRIES))); builder.setAutoGenerated(config.getBoolean(getKeyFor(column, IS_AUTO_GENERATED), false)); builder.setDefaultNullValueString(config.getString(getKeyFor(column, DEFAULT_NULL_VALUE), null)); builder.setTimeUnit(TimeUnit.valueOf(config.getString(TIME_UNIT, "DAYS").toUpperCase())); char paddingCharacter = V1Constants.Str.LEGACY_STRING_PAD_CHAR; if (config.containsKey(SEGMENT_PADDING_CHARACTER)) { String padding = config.getString(SEGMENT_PADDING_CHARACTER); paddingCharacter = StringEscapeUtils.unescapeJava(padding).charAt(0); } builder.setPaddingCharacter(paddingCharacter); // DERIVED_METRIC_TYPE property is used to check whether this field is derived or not // ORIGIN_COLUMN property is used to indicate the origin field of this derived metric String typeStr = config.getString(getKeyFor(column, DERIVED_METRIC_TYPE), null); DerivedMetricType derivedMetricType = (typeStr == null) ? null : DerivedMetricType.valueOf(typeStr.toUpperCase()); if (derivedMetricType != null) { switch (derivedMetricType) { case HLL: try { final int hllLog2m = config.getInt(V1Constants.MetadataKeys.Segment.SEGMENT_HLL_LOG2M); builder.setFieldSize(HllUtil.getHllFieldSizeFromLog2m(hllLog2m)); final String originColumnName = config.getString(getKeyFor(column, ORIGIN_COLUMN)); builder.setOriginColumnName(originColumnName); } catch (RuntimeException e) { LOGGER.error("Column: " + column + " is HLL derived column, but missing log2m, fieldSize or originColumnName."); throw e; } break; default: throw new IllegalArgumentException("Column: " + column + " with derived metric Type: " + derivedMetricType + " is not supported in building column metadata."); } builder.setDerivedMetricType(derivedMetricType); } return builder.build(); }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private HashMap<String, String> getPropsFromFile(String fileName, String vmId) { Object product_propsList = ""; HashMap<String, String> hmap = new HashMap<String, String>(); String[] product_props = {};/*from w ww. ja v a 2 s . c om*/ try { PropertiesConfiguration props_config = new PropertiesConfiguration(new File(fileName)); if (props_config.containsKey(vmId)) { log.debug("getting the product properties for vm: " + vmId); product_propsList = props_config.getProperty(vmId); if (product_propsList.toString().contains(",")) { product_props = product_propsList.toString() .substring(1, product_propsList.toString().length() - 1).split(","); for (String product_prop : product_props) { if (product_prop.contains("=")) { String[] product_property = product_prop.split("="); hmap.put(product_property[0], product_property[1]); log.debug("adding product property " + product_property[0] + " " + product_property[1]); } } } else { String[] product_property = product_propsList.toString() .substring(1, product_propsList.toString().length() - 1).split("="); if (product_property.length == 2) { hmap.put(product_property[0], product_property[1]); log.debug("adding product property " + product_property[0] + " " + product_property[1]); } else { log.error("error in the product property, does nt contain a valid key value pair.."); } } } else { log.debug("no such key exists " + vmId); } } catch (Exception e) { log.error(e.getMessage(), e); } return hmap; }
From source file:org.apache.wookie.server.ContextListener.java
public void contextInitialized(ServletContextEvent event) { try {//from w w w.j a v a 2 s.c o m ServletContext context = event.getServletContext(); /* * load the widgetserver.properties file and put it into this context * as an attribute 'properties' available to all resources */ PropertiesConfiguration configuration; File localPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.widgetserver.properties"); if (localPropsFile.exists()) { configuration = new PropertiesConfiguration(localPropsFile); _logger.info("Using local widget server properties file: " + localPropsFile.toString()); } else { configuration = new PropertiesConfiguration("widgetserver.properties"); configuration.setFile(localPropsFile); configuration.save(); _logger.info("Using default widget server properties, configure your local server using: " + localPropsFile.toString()); } context.setAttribute("properties", (Configuration) configuration); /* * Merge in system properties overrides */ Iterator<Object> systemKeysIter = System.getProperties().keySet().iterator(); while (systemKeysIter.hasNext()) { String key = systemKeysIter.next().toString(); if (configuration.containsKey(key) || key.startsWith("widget.")) { String setting = configuration.getString(key); String override = System.getProperty(key); if ((override != null) && (override.length() > 0) && !override.equals(setting)) { configuration.setProperty(key, override); if (setting != null) { _logger.info("Overridden server configuration property: " + key + "=" + override); } } } } /* * Initialize persistence manager factory now, not on first request */ PersistenceManagerFactory.initialize(configuration); /* * Initialise the locale handler */ LocaleHandler.getInstance().initialize(configuration); final Locale locale = new Locale(configuration.getString("widget.default.locale")); final Messages localizedMessages = LocaleHandler.getInstance().getResourceBundle(locale); /* * load the opensocial.properties file and put it into this context * as an attribute 'opensocial' available to all resources */ PropertiesConfiguration opensocialConfiguration; File localOpenSocialPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.opensocial.properties"); if (localOpenSocialPropsFile.exists()) { opensocialConfiguration = new PropertiesConfiguration(localOpenSocialPropsFile); _logger.info("Using local open social properties file: " + localOpenSocialPropsFile.toString()); } else { opensocialConfiguration = new PropertiesConfiguration("opensocial.properties"); opensocialConfiguration.setFile(localOpenSocialPropsFile); opensocialConfiguration.save(); _logger.info("Using default open social properties, configure your local server using: " + localOpenSocialPropsFile.toString()); } context.setAttribute("opensocial", (Configuration) opensocialConfiguration); /* * Load installed features */ PropertiesConfiguration featuresConfiguration; File localFeaturesPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.features.properties"); if (localFeaturesPropsFile.exists()) { featuresConfiguration = new PropertiesConfiguration(localFeaturesPropsFile); _logger.info("Loading local features file: " + localOpenSocialPropsFile.toString()); } else { featuresConfiguration = new PropertiesConfiguration("features.properties"); featuresConfiguration.setFile(localFeaturesPropsFile); featuresConfiguration.save(); _logger.info("Loading default features, configure your local server using: " + localFeaturesPropsFile.toString()); } FeatureLoader.loadFeatures(featuresConfiguration); /* * Run diagnostics */ Diagnostics.run(context, configuration); /* * Start hot-deploy widget watcher */ if (configuration.getBoolean("widget.hot_deploy")) { startWatcher(context, configuration, localizedMessages); } else { _logger.info(localizedMessages.getString("WidgetHotDeploy.0")); } } catch (ConfigurationException ex) { _logger.error("ConfigurationException thrown: " + ex.toString()); } }
From source file:org.kontalk.util.Tr.java
public static void init() { // get language String lang = Locale.getDefault().getLanguage(); if (lang.equals(DEFAULT_LANG)) { return;// w w w . ja va 2s . co m } LOGGER.info("Setting language: " + lang); // load string keys file String path = Kontalk.RES_PATH + I18N_DIR + STRING_FILE + PROP_EXT; PropertiesConfiguration stringKeys; try { stringKeys = new PropertiesConfiguration(ClassLoader.getSystemResource(path)); } catch (ConfigurationException ex) { LOGGER.log(Level.WARNING, "can't load string key file", ex); return; } // load translation file path = Kontalk.RES_PATH + I18N_DIR + STRING_FILE + "_" + lang + PROP_EXT; URL url = ClassLoader.getSystemResource(path); if (url == null) { LOGGER.info("can't find translation file: " + path); return; } PropertiesConfiguration tr = new PropertiesConfiguration(); tr.setEncoding("UTF-8"); try { tr.load(url); } catch (ConfigurationException ex) { LOGGER.log(Level.WARNING, "can't load translation file", ex); return; } TR_MAP = new HashMap<>(); Iterator<String> it = tr.getKeys(); while (it.hasNext()) { String k = it.next(); if (!stringKeys.containsKey(k)) { LOGGER.warning("key in translation but not in key file: " + k); continue; } TR_MAP.put(stringKeys.getString(k), tr.getString(k)); } }