List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:org.apache.util.PropertyMessageResources.java
/** * Load the messages associated with the specified Locale key. For this * implementation, the <code>config</code> property should contain a fully * qualified package and resource name, separated by periods, of a series * of property resources to be loaded from the class loader that created * this PropertyMessageResources instance. This is exactly the same name * format you would use when utilizing the * <code>java.util.PropertyResourceBundle</code> class. * * @param localeKey Locale key for the messages to be retrieved *//*from www.j av a2 s.c o m*/ protected synchronized void loadLocale(String localeKey) { if (log.isTraceEnabled()) { log.trace("loadLocale(" + localeKey + ")"); } // Have we already attempted to load messages for this locale? if (locales.get(localeKey) != null) { return; } locales.put(localeKey, localeKey); // Set up to load the property resource for this locale key, if we can String name = config.replace('.', '/'); if (localeKey.length() > 0) { name += "_" + localeKey; } name += ".properties"; InputStream is = null; Properties props = new Properties(); // Load the specified property resource if (log.isTraceEnabled()) { log.trace(" Loading resource '" + name + "'"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } is = classLoader.getResourceAsStream(name); if (is != null) { try { props.load(is); } catch (IOException e) { log.error("loadLocale()", e); } finally { try { is.close(); } catch (IOException e) { log.error("loadLocale()", e); } } } if (log.isTraceEnabled()) { log.trace(" Loading resource completed"); } // Copy the corresponding values into our cache if (props.size() < 1) { return; } synchronized (messages) { Iterator names = props.keySet().iterator(); while (names.hasNext()) { String key = (String) names.next(); if (log.isTraceEnabled()) { log.trace(" Saving message key '" + messageKey(localeKey, key)); } messages.put(messageKey(localeKey, key), props.getProperty(key)); } } }
From source file:net.sf.navigator.util.PropertyMessageResources.java
/** * Load the messages associated with the specified Locale key. For this * implementation, the <code>config</code> property should contain a fully * qualified package and resource name, separated by periods, of a series * of property resources to be loaded from the class loader that created * this PropertyMessageResources instance. This is exactly the same name * format you would use when utilizing the * <code>java.util.PropertyResourceBundle</code> class. * * @param localeKey Locale key for the messages to be retrieved *///from w ww. j a va 2 s . c o m protected synchronized void loadLocale(String localeKey) { if (log.isTraceEnabled()) { log.trace("loadLocale(" + localeKey + ")"); } // Have we already attempted to load messages for this locale? if (locales.get(localeKey) != null) { return; } locales.put(localeKey, localeKey); // Set up to load the property resource for this locale key, if we can String name = config.replace('.', '/'); if (localeKey.length() > 0) { name += "_" + localeKey; } name += ".properties"; InputStream is = null; Properties props = new Properties(); // Load the specified property resource if (log.isTraceEnabled()) { log.trace(" Loading resource '" + name + "'"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } is = classLoader.getResourceAsStream(name); if (is != null) { try { props.load(is); } catch (IOException e) { log.error("loadLocale()", e); } finally { try { is.close(); } catch (IOException e) { log.error("loadLocale()", e); } } } if (log.isTraceEnabled()) { log.trace(" Loading resource completed"); } // Copy the corresponding values into our cache if (props.size() < 1) { return; } synchronized (messages) { Iterator names = props.keySet().iterator(); while (names.hasNext()) { String key = (String) names.next(); if (log.isTraceEnabled()) { log.trace(" Saving message key '" + messageKey(localeKey, key)); } messages.put(messageKey(localeKey, key), props.getProperty(key)); } } }
From source file:com.npower.dm.util.PropertyMessageResources.java
/** * Load the messages associated with the specified Locale key. For this * implementation, the <code>config</code> property should contain a fully * qualified package and resource name, separated by periods, of a series * of property resources to be loaded from the class loader that created * this PropertyMessageResources instance. This is exactly the same name * format you would use when utilizing the * <code>java.util.PropertyResourceBundle</code> class. * * @param localeKey Locale key for the messages to be retrieved *///from www . j a v a 2s. c o m protected synchronized void loadLocale(String localeKey) { if (log.isTraceEnabled()) { log.trace("loadLocale(" + localeKey + ")"); } // Have we already attempted to load messages for this locale? if (locales.get(localeKey) != null) { return; } locales.put(localeKey, localeKey); // Set up to load the property resource for this locale key, if we can String name = config.replace('.', '/'); if (localeKey.length() > 0) { name += "_" + localeKey; } name += ".properties"; InputStream is = null; Properties props = new Properties(); // Load the specified property resource if (log.isTraceEnabled()) { log.trace(" Loading resource '" + name + "'"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } is = classLoader.getResourceAsStream(name); if (is != null) { try { props.load(is); } catch (IOException e) { log.error("loadLocale()", e); } finally { try { is.close(); } catch (IOException e) { log.error("loadLocale()", e); } } } if (log.isTraceEnabled()) { log.trace(" Loading resource completed"); } // Copy the corresponding values into our cache if (props.size() < 1) { return; } synchronized (messages) { Iterator<Object> names = props.keySet().iterator(); while (names.hasNext()) { String key = (String) names.next(); if (log.isTraceEnabled()) { log.trace(" Saving message key '" + messageKey(localeKey, key)); } messages.put(messageKey(localeKey, key), props.getProperty(key)); } } }
From source file:com.haulmont.cuba.web.testsupport.TestContainer.java
protected void initAppProperties() { final Properties properties = new Properties(); List<String> locations = getAppPropertiesFiles(); DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); for (String location : locations) { Resource resource = resourceLoader.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); properties.load(stream); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); }//from w ww . j a va2 s . c o m } else { log.warn("Resource " + location + " not found, ignore it"); } } StrSubstitutor substitutor = new StrSubstitutor(new StrLookup() { @Override public String lookup(String key) { String subst = properties.getProperty(key); return subst != null ? subst : System.getProperty(key); } }); for (Object key : properties.keySet()) { String value = substitutor.replace(properties.getProperty((String) key)); appProperties.put((String) key, value); } File dir; dir = new File(appProperties.get("cuba.confDir")); dir.mkdirs(); dir = new File(appProperties.get("cuba.logDir")); dir.mkdirs(); dir = new File(appProperties.get("cuba.tempDir")); dir.mkdirs(); dir = new File(appProperties.get("cuba.dataDir")); dir.mkdirs(); AppContext.setProperty(AppConfig.CLIENT_TYPE_PROP, ClientType.WEB.toString()); }
From source file:org.apache.archiva.metadata.repository.file.FileMetadataRepository.java
@Override public void updateProjectVersion(String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata) { try {/*from ww w . java 2 s. co m*/ updateProject(repoId, namespace, projectId); File directory = new File(getDirectory(repoId), namespace + "/" + projectId + "/" + versionMetadata.getId()); Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY); // remove properties that are not references or artifacts for (Object key : new ArrayList(properties.keySet())) { String name = (String) key; if (!name.contains(":") && !name.equals("facetIds")) { properties.remove(name); } // clear the facet contents so old properties are no longer written clearMetadataFacetProperties(versionMetadata.getFacetList(), properties, ""); } properties.setProperty("id", versionMetadata.getId()); setProperty(properties, "name", versionMetadata.getName()); setProperty(properties, "description", versionMetadata.getDescription()); setProperty(properties, "url", versionMetadata.getUrl()); setProperty(properties, "incomplete", String.valueOf(versionMetadata.isIncomplete())); if (versionMetadata.getScm() != null) { setProperty(properties, "scm.connection", versionMetadata.getScm().getConnection()); setProperty(properties, "scm.developerConnection", versionMetadata.getScm().getDeveloperConnection()); setProperty(properties, "scm.url", versionMetadata.getScm().getUrl()); } if (versionMetadata.getCiManagement() != null) { setProperty(properties, "ci.system", versionMetadata.getCiManagement().getSystem()); setProperty(properties, "ci.url", versionMetadata.getCiManagement().getUrl()); } if (versionMetadata.getIssueManagement() != null) { setProperty(properties, "issue.system", versionMetadata.getIssueManagement().getSystem()); setProperty(properties, "issue.url", versionMetadata.getIssueManagement().getUrl()); } if (versionMetadata.getOrganization() != null) { setProperty(properties, "org.name", versionMetadata.getOrganization().getName()); setProperty(properties, "org.url", versionMetadata.getOrganization().getUrl()); } int i = 0; for (License license : versionMetadata.getLicenses()) { setProperty(properties, "license." + i + ".name", license.getName()); setProperty(properties, "license." + i + ".url", license.getUrl()); i++; } i = 0; for (MailingList mailingList : versionMetadata.getMailingLists()) { setProperty(properties, "mailingList." + i + ".archive", mailingList.getMainArchiveUrl()); setProperty(properties, "mailingList." + i + ".name", mailingList.getName()); setProperty(properties, "mailingList." + i + ".post", mailingList.getPostAddress()); setProperty(properties, "mailingList." + i + ".unsubscribe", mailingList.getUnsubscribeAddress()); setProperty(properties, "mailingList." + i + ".subscribe", mailingList.getSubscribeAddress()); setProperty(properties, "mailingList." + i + ".otherArchives", join(mailingList.getOtherArchives())); i++; } i = 0; ProjectVersionReference reference = new ProjectVersionReference(); reference.setNamespace(namespace); reference.setProjectId(projectId); reference.setProjectVersion(versionMetadata.getId()); reference.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY); for (Dependency dependency : versionMetadata.getDependencies()) { setProperty(properties, "dependency." + i + ".classifier", dependency.getClassifier()); setProperty(properties, "dependency." + i + ".scope", dependency.getScope()); setProperty(properties, "dependency." + i + ".systemPath", dependency.getSystemPath()); setProperty(properties, "dependency." + i + ".artifactId", dependency.getArtifactId()); setProperty(properties, "dependency." + i + ".groupId", dependency.getGroupId()); setProperty(properties, "dependency." + i + ".version", dependency.getVersion()); setProperty(properties, "dependency." + i + ".type", dependency.getType()); setProperty(properties, "dependency." + i + ".optional", String.valueOf(dependency.isOptional())); updateProjectReference(repoId, dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), reference); i++; } Set<String> facetIds = new LinkedHashSet<String>(versionMetadata.getFacetIds()); facetIds.addAll(Arrays.asList(properties.getProperty("facetIds", "").split(","))); properties.setProperty("facetIds", join(facetIds)); updateProjectVersionFacets(versionMetadata, properties); writeProperties(properties, directory, PROJECT_VERSION_METADATA_KEY); } catch (IOException e) { // TODO log.error(e.getMessage(), e); } }
From source file:com.dtolabs.rundeck.plugin.resources.gcp.InstanceToNodeMapper.java
/** * Convert an GCP GCE Instance to a RunDeck INodeEntry based on the mapping input *//*from www . j a v a 2 s. c om*/ @SuppressWarnings("unchecked") static INodeEntry instanceToNode(final Instance inst, final Properties mapping) throws GeneratorException { final NodeEntryImpl node = new NodeEntryImpl(); logger.error("instancetoNode call"); //evaluate single settings.selector=tags/* mapping if ("tags/*".equals(mapping.getProperty("attributes.selector"))) { //iterate through instance tags and generate settings /*for (final String tag : inst.getTags().getItems()) { if (null == node.getAttributes()) { node.setAttribute(new HashMap<String, String>()); } node.getAttribute().put(tag.getKey(), tag.getValue()); }*/ } if (null != mapping.getProperty("tags.selector")) { final String selector = mapping.getProperty("tags.selector"); final String value = applySelector(inst, selector, mapping.getProperty("tags.default"), true); if (null != value) { final String[] values = value.split(","); final HashSet<String> tagset = new HashSet<String>(); for (final String s : values) { tagset.add(s.trim()); } if (null == node.getTags()) { node.setTags(tagset); } else { final HashSet orig = new HashSet(node.getTags()); orig.addAll(tagset); node.setTags(orig); } } } if (null == node.getTags()) { node.setTags(new HashSet()); } final HashSet orig = new HashSet(node.getTags()); //apply specific tag selectors final Pattern tagPat = Pattern.compile("^tag\\.(.+?)\\.selector$"); //evaluate tag selectors for (final Object o : mapping.keySet()) { final String key = (String) o; final String selector = mapping.getProperty(key); //split selector by = if present final String[] selparts = selector.split("="); final Matcher m = tagPat.matcher(key); if (m.matches()) { final String tagName = m.group(1); if (null == node.getAttributes()) { node.setAttributes(new HashMap<String, String>()); } final String value = applySelector(inst, selparts[0], null); if (null != value) { if (selparts.length > 1 && !value.equals(selparts[1])) { continue; } //use add the tag if the value is not null orig.add(tagName); } } } node.setTags(orig); //apply default values which do not have corresponding selector final Pattern attribDefPat = Pattern.compile("^([^.]+?)\\.default$"); //evaluate selectors for (final Object o : mapping.keySet()) { final String key = (String) o; final String value = mapping.getProperty(key); final Matcher m = attribDefPat.matcher(key); if (m.matches() && (!mapping.containsKey(key + ".selector") || "".equals(mapping.getProperty(key + ".selector")))) { final String attrName = m.group(1); if (null == node.getAttributes()) { node.setAttributes(new HashMap<String, String>()); } if (null != value) { node.getAttributes().put(attrName, value); } } } final Pattern attribPat = Pattern.compile("^([^.]+?)\\.selector$"); //evaluate selectors for (final Object o : mapping.keySet()) { final String key = (String) o; final String selector = mapping.getProperty(key); final Matcher m = attribPat.matcher(key); if (m.matches()) { final String attrName = m.group(1); if (attrName.equals("tags")) { //already handled continue; } if (null == node.getAttributes()) { node.setAttributes(new HashMap<String, String>()); } final String value = applySelector(inst, selector, mapping.getProperty(attrName + ".default")); if (null != value) { //use nodename-settingname to make the setting unique to the node node.getAttributes().put(attrName, value); } } } String hostSel = mapping.getProperty("hostname.selector"); //logger.error("This is the hostSel variable " + hostSel); String host = applySelector(inst, hostSel, mapping.getProperty("hostname.default")); //logger.error("This is the host variable " + host); //logger.error("This is the hostname.default mapping param " + mapping.getProperty("hostname.default")); if (null == node.getHostname()) { System.err.println("Unable to determine hostname for instance: " + inst.getId()); return null; } String name = node.getNodename(); if (null == name || "".equals(name)) { name = node.getHostname(); } if (null == name || "".equals(name)) { name = inst.getId().toString(); } node.setNodename(name); // Set ssh port on hostname if not 22 String sshport = node.getAttributes().get("sshport"); if (sshport != null && !sshport.equals("") && !sshport.equals("22")) { node.setHostname(node.getHostname() + ":" + sshport); } return node; }
From source file:org.apache.maven.plugin.resources.remote.ProcessRemoteResourcesMojo.java
@SuppressWarnings("unchecked") public void execute() throws MojoExecutionException { if (skip) {/* ww w . j ava2 s .com*/ getLog().info("Skipping remote resources execution."); return; } if (StringUtils.isEmpty(encoding)) { getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!"); } if (runOnlyAtExecutionRoot && !project.isExecutionRoot()) { getLog().info( "Skipping remote-resource generation in this project because it's not the Execution Root"); return; } if (resolveScopes == null) { if (excludeScope == null || "".equals(excludeScope)) { resolveScopes = new String[] { this.includeScope }; } else { resolveScopes = new String[] { Artifact.SCOPE_TEST }; } } velocity = new VelocityEngine(); velocity.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this); velocity.setProperty("resource.loader", "classpath"); velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); velocity.init(); if (supplementalModels == null) { File sups = new File(appendedResourcesDirectory, "supplemental-models.xml"); if (sups.exists()) { try { supplementalModels = new String[] { sups.toURI().toURL().toString() }; } catch (MalformedURLException e) { // ignore getLog().debug("URL issue with supplemental-models.xml: " + e.toString()); } } } addSupplementalModelArtifacts(); locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath()); if (appendedResourcesDirectory != null) { locator.addSearchPath(FileResourceLoader.ID, appendedResourcesDirectory.getAbsolutePath()); } locator.addSearchPath("url", ""); locator.setOutputDirectory(new File(project.getBuild().getDirectory())); if (includeProjectProperties) { final Properties projectProperties = project.getProperties(); for (Object key : projectProperties.keySet()) { properties.put(key.toString(), projectProperties.get(key).toString()); } } ClassLoader origLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); validate(); List<File> resourceBundleArtifacts = downloadBundles(resourceBundles); supplementModels = loadSupplements(supplementalModels); VelocityContext context = new VelocityContext(properties); configureVelocityContext(context); RemoteResourcesClassLoader classLoader = new RemoteResourcesClassLoader(null); initalizeClassloader(classLoader, resourceBundleArtifacts); Thread.currentThread().setContextClassLoader(classLoader); processResourceBundles(classLoader, context); try { if (outputDirectory.exists()) { // ---------------------------------------------------------------------------- // Push our newly generated resources directory into the MavenProject so that // these resources can be picked up by the process-resources phase. // ---------------------------------------------------------------------------- Resource resource = new Resource(); resource.setDirectory(outputDirectory.getAbsolutePath()); // MRRESOURCES-61 handle main and test resources separately if (attachToMain) { project.getResources().add(resource); } if (attachToTest) { project.getTestResources().add(resource); } // ---------------------------------------------------------------------------- // Write out archiver dot file // ---------------------------------------------------------------------------- File dotFile = new File(project.getBuild().getDirectory(), ".plxarc"); FileUtils.mkdir(dotFile.getParentFile().getAbsolutePath()); FileUtils.fileWrite(dotFile.getAbsolutePath(), outputDirectory.getName()); } } catch (IOException e) { throw new MojoExecutionException("Error creating dot file for archiving instructions.", e); } } finally { Thread.currentThread().setContextClassLoader(origLoader); } }
From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java
@Override public void setUpdateSettings(UpdateSettings settings) throws ControllerException { Properties properties = settings.getProperties(); for (Object name : properties.keySet()) { saveProperty(PROPERTIES_CORE, (String) name, (String) properties.get(name)); }/*w ww . java 2 s .c o m*/ }
From source file:dk.statsbiblioteket.util.XPropertiesTest.java
public void testCast() throws Exception { Properties sysProps = new Properties(); sysProps.setProperty("XProperty:true", "true"); sysProps.setProperty("XProperty:false", "false"); sysProps.setProperty("XProperty:sub/int", "88"); sysProps.setProperty("XProperty:uboat/deep/s", "flam"); System.getProperties().putAll(sysProps); XProperties properties = new XProperties(); assertEquals("Requesting a boolean as boolean should work fine", false, properties.getBoolean("false")); try {/*from ww w. j av a2 s. c om*/ properties.getString("false"); Assert.fail("Requesting a boolean as a String should raise exception"); } catch (ClassCastException e) { // Expected } // Clean up for (Object prop : sysProps.keySet()) { System.clearProperty((String) prop); } assertEquals("System XProperties was not cleaned up", 0, new XProperties().size()); }