List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:com.googlecode.t7mp.steps.CopyUserConfigStep.java
private void mergeProperties(Properties target, Properties source, Collection<String> excludes) { for (Object key : source.keySet()) { if (!excludes.contains(key)) { target.setProperty((String) key, (String) source.get(key)); } else {//from w ww . j av a2 s . co m log.debug("Skip property " + key + " from user catalina.properties"); } } }
From source file:org.wso2.msf4j.spring.property.YamlFileApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { Resource resource = applicationContext.getResource("classpath:" + YAML_CONFIG_FILE_NAME); if (!resource.exists()) { resource = applicationContext.getResource("file:" + YAML_CONFIG_FILE_NAME); }//ww w . j av a2 s . c o m if (resource.exists()) { List<Properties> applicationYmlProperties = new ArrayList<>(); String[] activeProfileNames = null; try (InputStream input = resource.getInputStream()) { Yaml yml = new Yaml(new SafeConstructor()); Iterable<Object> objects = yml.loadAll(input); for (Object obj : objects) { Map<String, Object> flattenedMap = getFlattenedMap(asMap(obj)); Properties properties = new Properties(); properties.putAll(flattenedMap); Object activeProfile = properties.get("spring.profiles.active"); if (activeProfile != null) { activeProfileNames = activeProfile.toString().split(","); } applicationYmlProperties.add(properties); } } catch (FileNotFoundException e) { throw new RuntimeException("Couldn't find " + YAML_CONFIG_FILE_NAME, e); } catch (IOException e) { throw new RuntimeException("Error while reading " + YAML_CONFIG_FILE_NAME, e); } if (activeProfileNames == null) { activeProfileNames = applicationContext.getEnvironment().getActiveProfiles(); } for (Properties properties : applicationYmlProperties) { String profile = properties.getProperty("spring.profiles"); PropertySource<?> propertySource; if (profile == null) { propertySource = new MapPropertySource(YAML_CONFIG_FILE_NAME, new HashMap(properties)); applicationContext.getEnvironment().getPropertySources().addLast(propertySource); } else if (activeProfileNames != null && ("default".equals(profile) || (activeProfileNames.length == 1 && activeProfileNames[0].equals(profile)))) { propertySource = new MapPropertySource(YAML_CONFIG_FILE_NAME + "[" + profile + "]", new HashMap(properties)); applicationContext.getEnvironment().getPropertySources().addAfter("systemEnvironment", propertySource); } activeProfileNames = applicationContext.getEnvironment().getActiveProfiles(); } } applicationContext.getEnvironment().getActiveProfiles(); }
From source file:com.jkoolcloud.tnt4j.utils.Utils.java
/** * Create and apply a configurable object * * @param classProp/*from w w w . j a v a 2 s.c o m*/ * name of the property that contains class name (must exist in * config) * @param prefix * property prefix to be used for configuring a new object * @param config * a map containing all configuration including class name * @return configuration object * @throws ConfigException * if error instantiating configurable object */ public static Object createConfigurableObject(String classProp, String prefix, Properties config) throws ConfigException { Object className = config.get(classProp); if (className == null) return null; try { Object obj = Utils.createInstance(className.toString()); return Utils.applyConfiguration(prefix, config, obj); } catch (ConfigException ce) { throw ce; } catch (Throwable e) { ConfigException ce = new ConfigException(e.getMessage(), config); ce.initCause(e); throw ce; } }
From source file:com.igormaznitsa.mindmap.model.ModelUtilsTest.java
@Test public void testExtractQueryParameters() throws Exception { final Properties properties = ModelUtils .extractQueryPropertiesFromURI(new URI("file://hello?some=test&other=&misc=%26ffsdsd&h=1")); assertEquals(4, properties.size());// w ww .j a va 2s . c o m assertEquals("test", properties.get("some")); assertEquals("", properties.get("other")); assertEquals("&ffsdsd", properties.get("misc")); assertEquals("1", properties.get("h")); }
From source file:com.mgmtp.jfunk.core.ui.PropertiesComboBoxModel.java
private void initItems() { File dir = new File(path); if (items.isEmpty()) { List<File> files = Arrays.asList(dir.listFiles(new FileFilter() { @Override//from w ww .j a v a 2 s. co m public boolean accept(final File file) { if (file.getName().matches(propsPrefix + ".*\\." + propsSuffix)) { if (StringUtils.isNotBlank(filter)) { InputStream is = null; try { Properties props = new Properties(); is = new FileInputStream(file); props.load(is); if (props.get(filter) == null) { return false; } } catch (IOException ex) { return false; } finally { IOUtils.closeQuietly(is); } } return true; } return false; } })); for (File file : files) { String fileName = file.getName(); String itemName; itemName = includeSuffix ? fileName : fileName.substring(0, fileName.indexOf("." + propsSuffix)); items.add(itemName); } } }
From source file:org.duracloud.snapshot.bridge.rest.GeneralResource.java
/** * Returns a list of snapshots.//ww w . ja va2 s . c om * * @return */ @Path("version") @GET @Produces(MediaType.APPLICATION_JSON) public Response version() { try { InputStream is = getClass().getResourceAsStream("/application.properties"); Properties props = new Properties(); props.load(is); String version = props.get("version").toString(); return Response.ok().entity("{\"version\":\"" + version + "\"}").build(); } catch (IOException e) { //should never happen throw new RuntimeException(e); } }
From source file:com.jivesoftware.os.upena.uba.service.InstancePath.java
InstanceDescriptor readInstanceDescriptor() throws FileNotFoundException, IOException { Properties properties = new Properties(); properties.load(new FileInputStream(instanceProperties())); Object enabled = properties.get(instancePrefix + "enabled"); if (enabled == null) { enabled = "true"; }/*from w w w. j ava2s.com*/ Object datacenter = properties.get(instancePrefix + "datacenter"); Object rack = properties.get(instancePrefix + "rack"); Object publicHost = properties.get(instancePrefix + "publicHost"); InstanceDescriptor id = new InstanceDescriptor( (datacenter == null) ? "unknownDatacenter" : datacenter.toString(), (rack == null) ? "unknownRack" : rack.toString(), (publicHost == null) ? "unknown" : publicHost.toString(), properties.get(instancePrefix + "clusterKey").toString(), properties.get(instancePrefix + "clusterName").toString(), properties.get(instancePrefix + "serviceKey").toString(), properties.get(instancePrefix + "serviceName").toString(), properties.get(instancePrefix + "releaseGroupKey").toString(), properties.get(instancePrefix + "releaseGroupName").toString(), properties.get(instancePrefix + "instanceKey").toString(), Integer.parseInt(properties.get(instancePrefix + "instanceName").toString()), properties.get(instancePrefix + "version").toString(), properties.get(instancePrefix + "repository").toString(), -1, Boolean.parseBoolean(enabled.toString())); for (Object key : properties.keySet()) { String portKey = key.toString(); if (portKey.endsWith("Port")) { if (!portKey.endsWith("routesPort")) { // ignore injected upena String portName = portKey.substring(instancePrefix.length(), portKey.length() - 4); id.ports.put(portName, new InstanceDescriptor.InstanceDescriptorPort( Integer.parseInt(properties.getProperty(key.toString())))); } } } LOG.debug("Read instance descriptor:" + id + " from:" + instanceProperties()); return id; }
From source file:de.awtools.config.PropertiesGlueConfigTest.java
@Test public void testPropertiesGlueConfigGetter() { Properties props = config.getProperties(); for (int index = 0; index < PROPERTIES.length; index++) { String key = PROPERTIES[index][0]; Assert.assertEquals(PROPERTIES[index][1], props.get(key)); }/*from w w w . j av a 2 s .co m*/ GlueConfigTestUtils.assertProperties(config, PROPERTIES); }
From source file:org.opentides.util.FileUtilTest.java
/** * Test method for {@link org.opentides.util.FileUtil#readProperty(java.lang.String)}. */// w w w . j a va 2 s . co m @Test public void testReadProperty() { Properties props = FileUtil.readProperty(new File("src/test/resources/test.properties")); Assert.assertEquals(2, props.size()); Assert.assertEquals("test", props.get("run.environment")); Assert.assertEquals("true", props.get("application.mode.debug")); }
From source file:org.apache.syncope.core.init.ContentLoader.java
@Transactional public void load() { // 1. Check wether we are allowed to load default content into the DB final List<SyncopeConf> res = confDAO.findAll(); if (res == null || res.size() > 0) { LOG.info("Data found in the database, leaving untouched"); return;//from w ww . j a va 2 s . c o m } LOG.info("Empty database found, loading default content"); // 2. Create views LOG.debug("Creating views"); try { InputStream viewsStream = getClass().getResourceAsStream("/views.xml"); Properties views = new Properties(); views.loadFromXML(viewsStream); for (String idx : views.stringPropertyNames()) { LOG.debug("Creating view {}", views.get(idx).toString()); final String updateViews = views.get(idx).toString().replaceAll("\\n", " "); entityManager.createNativeQuery(updateViews).executeUpdate(); } LOG.debug("Views created, go for indexes"); } catch (Exception e) { LOG.error("While creating views", e); } // 3. Create indexes LOG.debug("Creating indexes"); try { InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml"); Properties indexes = new Properties(); indexes.loadFromXML(indexesStream); for (String idx : indexes.stringPropertyNames()) { LOG.debug("Creating index {}", indexes.get(idx).toString()); final String updateIndexed = indexes.get(idx).toString(); entityManager.createNativeQuery(updateIndexed).executeUpdate(); } LOG.debug("Indexes created, go for default content"); } catch (Exception e) { LOG.error("While creating indexes", e); } // noop workflow // entityManager.createNativeQuery("DELETE FROM ACT_GE_PROPERTY").executeUpdate(); // 4. Load default content SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); parser.parse(getClass().getResourceAsStream("/content.xml"), importExport); LOG.debug("Default content successfully loaded"); } catch (Exception e) { LOG.error("While loading default content", e); } }