List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:com.mirth.connect.client.core.UpdateClient.java
public List<IgnoredComponent> getIgnoredComponents() throws ClientException { Properties userPreferences = client.getUserPreferences(requestUser); if (userPreferences == null) { return new ArrayList<IgnoredComponent>(); } else {/*from w w w .j a v a2s . co m*/ String ignoredComponentsPreference = (String) userPreferences.get(USER_PREF_IGNORED_IDS); if (ignoredComponentsPreference == null) { return new ArrayList<IgnoredComponent>(); } else { List<IgnoredComponent> ignoredComponents = new ArrayList<IgnoredComponent>(); for (String component : Arrays .asList(ignoredComponentsPreference.split(COMPONENT_PREFERENCE_SEPARATOR))) { if ((component != null) && (component.length() > 0)) { String name = component.split(IgnoredComponent.COMPONENT_NAME_VERSION_SEPARATOR)[0]; String version = component.split(IgnoredComponent.COMPONENT_NAME_VERSION_SEPARATOR)[1]; ignoredComponents.add(new IgnoredComponent(name, version)); } } return ignoredComponents; } } }
From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java
/** * Test to load java properties files with a BOM, when the first line starts with a comment. * @throws Exception any error//from w w w.j a v a 2s .c o m */ @Test public void testPropertiesWithBOMandComment() throws Exception { Properties properties = new Properties(); InputStream in = ExploratoryEncodingTest.class.getResourceAsStream("/UTF8BOMwithComment.properties"); properties.load(new InputStreamReader(in, "UTF-8")); Assert.assertEquals(4, properties.size()); Assert.assertEquals("", properties.get("\ufeff#abc")); Assert.assertEquals("first key", properties.getProperty("testkey1")); Assert.assertEquals("second key", properties.getProperty("testkey2")); Assert.assertEquals("This file is encoded as UTF-8 with BOM .", properties.getProperty("description")); }
From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java
/** * Test to load java properties with a BOM, when the first line is blank. * @throws Exception any error/* w ww .j a va 2 s . c o m*/ */ @Test public void testPropertiesWithBOMandBlankLine() throws Exception { Properties properties = new Properties(); InputStream in = ExploratoryEncodingTest.class.getResourceAsStream("/UTF8BOMwithBlankLine.properties"); properties.load(new InputStreamReader(in, "UTF-8")); Assert.assertEquals(4, properties.size()); Assert.assertEquals("", properties.get("\ufeff")); Assert.assertEquals("first key", properties.getProperty("testkey1")); Assert.assertEquals("second key", properties.getProperty("testkey2")); Assert.assertEquals("This file is encoded as UTF-8 with BOM .", properties.getProperty("description")); }
From source file:ch.entwine.weblounge.common.impl.site.I18nDictionaryImpl.java
/** * {@inheritDoc}/*from w w w. j av a 2s . c o m*/ * * @see ch.entwine.weblounge.common.site.I18nDictionary#add(java.lang.String, * java.lang.String, ch.entwine.weblounge.common.language.Language) */ public void add(String key, String value, Language language) { if (key == null) throw new IllegalArgumentException("I18n key cannot be null"); if (value == null) throw new IllegalArgumentException("I18n value cannot be null"); Properties p = null; if (language != null) { p = i18n.get(language); if (p == null) { p = new Properties(); i18n.put(language, p); } } else { p = defaults; } if (p.get(key) == null) { p.put(key, value); } else { logger.warn("I18n key '{}' already defined", key); } }
From source file:com.kdgregory.pathfinder.spring.context.TestSpringContext.java
@Test public void testGetProperty() throws Exception { logger.info("testGetProperty()"); SpringContext context = new SpringContext(null, "classpath:contexts/propContext.xml"); BeanDefinition bean = context.getBean("example"); assertNotNull("able to find bean", bean); assertEquals("extracted property as string in attribute", "foo", bean.getPropertyAsString("propAsStringAttribute")); assertEquals("extracted property as string in value", "bar", bean.getPropertyAsString("propAsStringValue")); assertEquals("extracted property as ref", "example", bean.getPropertyAsRefId("propAsRefId")); // FIXME - add test for explicit <ref> element Properties propsProp1 = bean.getPropertyAsProperties("propAsSingleValue"); assertNotNull("able to extract property with name-value props", propsProp1); assertEquals("extracted property for 'foo'", "bar", propsProp1.get("foo")); assertEquals("extracted property for 'argle'", "bargle", propsProp1.get("argle")); Properties propsProp2 = bean.getPropertyAsProperties("propAsExplicitProperties"); assertNotNull("able to extract property with explicit props", propsProp2); assertEquals("extracted property for 'foo'", "bar", propsProp2.get("foo")); assertEquals("extracted property for 'argle'", "bargle", propsProp2.get("argle")); }
From source file:com.kdgregory.pathfinder.spring.context.TestSpringContext.java
@Test public void testInheritProperty() throws Exception { logger.info("testInheritProperty()"); SpringContext context = new SpringContext(null, "classpath:contexts/inheritProp.xml"); BeanDefinition bean = context.getBean("inherited"); assertNotNull("able to find bean", bean); assertEquals("extracted property as string in attribute", "foo", bean.getPropertyAsString("propAsStringAttribute")); assertEquals("extracted property as string in value", "bar", bean.getPropertyAsString("propAsStringValue")); assertEquals("extracted property as ref", "example", bean.getPropertyAsRefId("propAsRefId")); // FIXME - add test for explicit <ref> element Properties propsProp1 = bean.getPropertyAsProperties("propAsSingleValue"); assertNotNull("able to extract property with name-value props", propsProp1); assertEquals("extracted property for 'foo'", "bar", propsProp1.get("foo")); assertEquals("extracted property for 'argle'", "bargle", propsProp1.get("argle")); Properties propsProp2 = bean.getPropertyAsProperties("propAsExplicitProperties"); assertNotNull("able to extract property with explicit props", propsProp2); assertEquals("extracted property for 'foo'", "bar", propsProp2.get("foo")); assertEquals("extracted property for 'argle'", "bargle", propsProp2.get("argle")); }
From source file:jetbrains.buildServer.torrent.TorrentConfigurator.java
private void loadConfiguration(@NotNull File configFile) { Properties properties = new Properties(); FileReader fileReader = null; try {//w w w . j a va 2s. c o m fileReader = new FileReader(configFile); properties.load(fileReader); if (properties.get(TRANSPORT_ENABLED) == null) { properties.put(TRANSPORT_ENABLED, Boolean.FALSE.toString()); } if (properties.get(DOWNLOAD_ENABLED) == null) { properties.put(DOWNLOAD_ENABLED, Boolean.FALSE.toString()); } myConfiguration = properties; myConfiguration.put(TORRENT_ENABLED, String.valueOf(isDownloadEnabled() || isTransportEnabled())); } catch (IOException e) { Loggers.SERVER.warn("Failed to load configuration file: " + configFile.getAbsolutePath() + ", error: " + e.toString()); } finally { FileUtil.close(fileReader); } }
From source file:org.pentaho.pat.plugin.PatLifeCycleListener.java
public void loaded() throws PluginLifecycleException { ClassLoader origContextClassloader = Thread.currentThread().getContextClassLoader(); IServiceManager serviceManager = (IServiceManager) PentahoSystem.get(IServiceManager.class, PentahoSessionHolder.getSession()); try {// www. j av a 2 s. c om sessionBean = (SessionServlet) serviceManager.getServiceBean("gwt", "session.rpc"); //$NON-NLS-1$ queryBean = (QueryServlet) serviceManager.getServiceBean("gwt", "query.rpc"); //$NON-NLS-1$ discoveryBean = (DiscoveryServlet) serviceManager.getServiceBean("gwt", "discovery.rpc"); //$NON-NLS-1$ platformBean = (PlatformServlet) serviceManager.getServiceBean("gwt", "platform.rpc"); //$NON-NLS-1$ final IPluginManager pluginManager = (IPluginManager) PentahoSystem.get(IPluginManager.class, PentahoSessionHolder.getSession()); final PluginClassLoader pluginClassloader = (PluginClassLoader) pluginManager .getClassLoader(PAT_PLUGIN_NAME); final String hibernateConfigurationFile = PentahoSystem .getSystemSetting("hibernate/hibernate-settings.xml", "settings/config-file", null); //$NON-NLS-1$ final String pentahoHibConfigPath = PentahoSystem.getApplicationContext() .getSolutionPath(hibernateConfigurationFile); if (pluginClassloader == null) throw new ServiceException(Messages.getString("LifeCycleListener.NoPluginClassloader")); //$NON-NLS-1$ Thread.currentThread().setContextClassLoader(pluginClassloader); final URL contextUrl = pluginClassloader.getResource(PAT_APP_CONTEXT); final URL patHibConfigUrl = pluginClassloader.getResource(PAT_HIBERNATE_CONFIG); final URL patPluginPropertiesUrl = pluginClassloader.getResource(PAT_PLUGIN_PROPERTIES); if (patHibConfigUrl == null) throw new ServiceException("File not found: PAT Hibernate Config : " + PAT_HIBERNATE_CONFIG); else LOG.debug(PAT_PLUGIN_NAME + ": PAT Hibernate Config:" + patHibConfigUrl.toString()); if (patPluginPropertiesUrl == null) throw new ServiceException("File not found: PAT Plugin properties : " + PAT_PLUGIN_PROPERTIES); else LOG.debug(PAT_PLUGIN_NAME + ": PAT Plugin Properties:" + patPluginPropertiesUrl.toString()); if (contextUrl != null) { String appContextUrl = contextUrl.toString(); final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { appContextUrl }, false); applicationContext.setClassLoader(pluginClassloader); applicationContext.setConfigLocation(appContextUrl); applicationContext.setAllowBeanDefinitionOverriding(true); final Configuration pentahoHibConfig = new Configuration(); pentahoHibConfig.configure(new File(pentahoHibConfigPath)); final AnnotationConfiguration patHibConfig = new AnnotationConfiguration(); patHibConfig.configure(patHibConfigUrl); Properties properties = new Properties(); properties.load(pluginClassloader.getResourceAsStream(PAT_PLUGIN_PROPERTIES)); String hibernateDialectCfg = (String) properties.get("pat.plugin.datasource.hibernate.dialect"); String hibernateDialect = null; if (StringUtils.isNotBlank(hibernateDialectCfg)) { if (hibernateDialectCfg.equals("auto")) { hibernateDialect = pentahoHibConfig.getProperty("dialect"); } else { hibernateDialect = hibernateDialectCfg; } } if (StringUtils.isNotBlank(hibernateDialect)) { patHibConfig.setProperty("hibernate.dialect", hibernateDialect); LOG.info(PAT_PLUGIN_NAME + " : using hibernate dialect: " + hibernateDialect); } String dataSourceType = (String) properties.get("pat.plugin.datasource.type"); String datasourceResource = null; if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jdbc")) { datasourceResource = PAT_DATASOURCE_JDBC; LOG.info(PAT_PLUGIN_NAME + " : using JDBC connection"); } if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jndi")) { datasourceResource = PAT_DATASOURCE_JNDI; LOG.info(PAT_PLUGIN_NAME + " : using JNDI : " + (String) properties.get("jndi.name")); } XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(datasourceResource)); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(new ClassPathResource(PAT_PLUGIN_PROPERTIES)); cfg.postProcessBeanFactory(factory); XmlBeanFactory bfSession = new XmlBeanFactory(new ClassPathResource(PAT_SESSIONFACTORY), factory); PropertyPlaceholderConfigurer cfgSession = new PropertyPlaceholderConfigurer(); cfgSession.setProperties(patHibConfig.getProperties()); cfgSession.postProcessBeanFactory(bfSession); ClassPathXmlApplicationContext tmpCtxt = new ClassPathXmlApplicationContext(); tmpCtxt.refresh(); DefaultListableBeanFactory tmpBf = (DefaultListableBeanFactory) tmpCtxt.getBeanFactory(); tmpBf.setParentBeanFactory(bfSession); applicationContext.setClassLoader(pluginClassloader); applicationContext.setParent(tmpCtxt); applicationContext.refresh(); sessionBean.setStandalone(true); SessionServlet.setApplicationContext(applicationContext); sessionBean.init(); queryBean.setStandalone(true); QueryServlet.setApplicationContext(applicationContext); queryBean.init(); discoveryBean.setStandalone(true); DiscoveryServlet.setApplicationContext(applicationContext); discoveryBean.init(); platformBean.setStandalone(true); PlatformServlet.setApplicationContext(applicationContext); platformBean.init(); injectPentahoXmlaUrl(); } else { throw new Exception(Messages.getString("LifeCycleListener.AppContextNotFound")); } } catch (ServiceException e1) { LOG.error(e1.getMessage(), e1); } catch (ServletException e) { LOG.error(e.getMessage(), e); } catch (Exception e) { LOG.error(e.getMessage(), e); } finally { // reset the classloader of the current thread if (origContextClassloader != null) { Thread.currentThread().setContextClassLoader(origContextClassloader); } } }
From source file:edu.utah.further.core.util.io.DataSourceConfig.java
/** * Set a new value for the properties property. * * @param properties/*w ww. ja va 2 s . c o m*/ * the properties to set */ public void setProperties(final Properties properties, final String prefix) { // Set the data sources' properties according the properties object; // basically, we are following the Adapter Pattern. setUrl((String) properties.get(prefix + PROPERTIES.URL)); setDriverClassName((String) properties.get(prefix + PROPERTIES.DRIVER)); setUsername((String) properties.get(prefix + PROPERTIES.USER)); setPassword((String) properties.get(prefix + PROPERTIES.PASSWORD)); setPort((String) properties.get(prefix + PROPERTIES.PORT)); }
From source file:com.sonymobile.backlogtool.HibernateConfiguration.java
@Bean public AnnotationSessionFactoryBean sessionFactoryBean() { Properties propertiesFile = new Properties(); try {//from w w w. ja v a 2 s . co m String backlogconf = System.getProperty("catalina.home") + File.separator + "conf/backlogtool.properties"; InputStream input = new FileInputStream(backlogconf); propertiesFile.load(input); } catch (Exception e) { e.printStackTrace(); } Properties props = new Properties(); props.put("hibernate.dialect", propertiesFile.get("db.hibernate.dialect")); props.put("hibernate.format_sql", "true"); props.put("hibernate.show_sql", "false"); AnnotationSessionFactoryBean bean = new AnnotationSessionFactoryBean(); bean.setAnnotatedClasses(new Class[] { Story.class, Task.class, User.class, Area.class, Theme.class, Epic.class, Attribute.class, AttributeOption.class }); bean.setHibernateProperties(props); bean.setDataSource(this.dataSource); bean.setSchemaUpdate(true); return bean; }