List of usage examples for java.util Properties remove
@Override public synchronized Object remove(Object key)
From source file:com.streamsets.datacollector.main.RuntimeInfo.java
/** * Store configuration from control hub in persistent manner inside data directory. This configuration will be * loaded on data collector start and will override any configuration from sdc.properties. * * This method call is able to remove existing properties if the value is "null". Please note that the removal will * only happen from the 'override' file. This method does not have the capability to remove configuration directly * from sdc.properties.// ww w .ja va2 s. c om * * @param runtimeInfo RuntimeInfo instance * @param newConfigs New set of config properties * @throws IOException */ public static void storeControlHubConfigs(RuntimeInfo runtimeInfo, Map<String, String> newConfigs) throws IOException { File configFile = new File(runtimeInfo.getDataDir(), SCH_CONF_OVERRIDE); Properties properties = new Properties(); // Load existing properties from disk if they exists if (configFile.exists()) { try (FileReader reader = new FileReader(configFile)) { properties.load(reader); } } // Propagate updated configuration for (Map.Entry<String, String> entry : newConfigs.entrySet()) { if (entry.getValue() == null) { properties.remove(entry.getKey()); } else { properties.setProperty(entry.getKey(), entry.getValue()); } } // Store the new updated configuration back to disk try (FileWriter writer = new FileWriter(configFile)) { properties.store(writer, null); } }
From source file:org.wso2.carbon.identity.event.EventManagementUtils.java
/** * Returns a sub set of properties which has the given prefix key. ie properties which has numbers at the end * * @param prefix Prefix of the key/*from w ww .ja v a 2 s.com*/ * @param properties Set of properties which needs be filtered for the given prefix * @return Set of sub properties which has keys starting with given prefix */ public static Properties getSubProperties(String prefix, Properties properties) { // Stop proceeding if required arguments are not present if (StringUtils.isEmpty(prefix) || properties == null) { throw new IllegalArgumentException("Prefix and Properties should not be null to get sub properties"); } int i = 1; Properties subProperties = new Properties(); while (properties.getProperty(prefix + "." + i) != null) { // Remove from original properties to hold property schema. ie need to get the set of properties which // remains after consuming all required specific properties subProperties.put(prefix + "." + i, properties.remove(prefix + "." + i++)); } return subProperties; }
From source file:org.artifactory.common.property.ArtifactorySystemProperties.java
private static Map<String, String> fillRepoKeySubstitute(Properties artProps) { Map<String, String> result = new HashMap<>(); String prefix = ConstantValues.substituteRepoKeys.getPropertyName(); for (Object o : artProps.keySet()) { String key = (String) o; if (key.startsWith(prefix)) { String oldRepoKey = key.substring(prefix.length()); String newRepoKey = (String) artProps.get(key); result.put(oldRepoKey, newRepoKey); }//from ww w. j av a2 s. c o m } // Remove the keys used for (String key : result.keySet()) { artProps.remove(prefix + key); } return result; }
From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java
public static void removeProxyConfig() { Properties prop = System.getProperties(); prop.remove("proxySet"); prop.remove("http.proxyHost"); prop.remove("http.proxyPort"); prop.remove("http.nonProxyHosts"); prop.remove("https.proxyHost"); prop.remove("https.proxyPort"); prop.remove("https.nonProxyHosts"); prop.remove("http.proxyUser"); prop.remove("http.proxyPassword"); proxy = null;//ww w. j a va 2 s .co m }
From source file:org.mule.api.registry.ServiceDescriptorFactory.java
/** * Factory method to create a new service descriptor. * * @param type the service type to create * @param name the name of the service. In the case of a stransport service, the full endpoint sheme should be used here * i.e. 'cxf:http'// w w w. ja v a 2s . c o m * @param props The properties defined by this service type * @param overrides any overrides that should be configured on top of the standard propertiers for the service * @param muleContext the MuleContext for this mule instance * @param classLoader the ClassLoader to use when loading classes * @return a ServiceDescriptor instance that can be used to create the service objects associated with the service name * @throws ServiceException if the service cannot be located */ public static ServiceDescriptor create(ServiceType type, String name, Properties props, Properties overrides, MuleContext muleContext, ClassLoader classLoader) throws ServiceException { if (overrides != null) { props.putAll(overrides); } String scheme = name; String metaScheme = null; int i = name.indexOf(":"); if (i > -1) { scheme = name.substring(i + 1); metaScheme = name.substring(0, i); } //TODO we currently need to filter out transports that implement the meta scheme the old way if (isFilteredMetaScheme(metaScheme)) { //handle things the old way for now metaScheme = null; } else if (name.startsWith("jetty:http")) { scheme = "jetty"; } String serviceFinderClass = (String) props.remove(MuleProperties.SERVICE_FINDER); ServiceDescriptor sd; if (type.equals(ServiceType.TRANSPORT)) { try { if (metaScheme != null) { sd = new MetaTransportServiceDescriptor(metaScheme, scheme, props, classLoader); } else { sd = new DefaultTransportServiceDescriptor(scheme, props, classLoader); } } catch (ServiceException e) { throw e; } catch (Exception e) { throw new ServiceException(CoreMessages.failedToCreate("Transport: " + name)); } Properties exceptionMappingProps = SpiUtils.findServiceDescriptor(ServiceType.EXCEPTION, name + "-exception-mappings"); ((TransportServiceDescriptor) sd).setExceptionMappings(exceptionMappingProps); } else if (type.equals(ServiceType.MODEL)) { logger.warn(CoreMessages.modelDeprecated()); sd = new DefaultModelServiceDescriptor(name, props); } else { throw new ServiceException(CoreMessages.unrecognisedServiceType(type)); } // If there is a finder service, use it to find the "real" service. if (StringUtils.isNotBlank(serviceFinderClass)) { ServiceFinder finder; try { finder = (ServiceFinder) ClassUtils.instanciateClass(serviceFinderClass); } catch (Exception e) { throw new ServiceException(CoreMessages.cannotInstanciateFinder(serviceFinderClass), e); } String realService = finder.findService(name, sd, props); if (realService != null) { // Recursively look up the service descriptor for the real service. return muleContext.getRegistry().lookupServiceDescriptor(ServiceType.TRANSPORT, realService, overrides); } else { throw new ServiceException(CoreMessages.serviceFinderCantFindService(name)); } } return sd; }
From source file:org.wso2.carbon.identity.event.EventManagementUtils.java
/** * Returns a set of properties which has keys starting with the given prefix * * @param prefix prefix of the property key * @param properties Set of properties which needs be filtered for the given prefix * @return A set of properties which has keys starting with given prefix *///from www . j a v a 2 s. c o m public static Properties getPropertiesWithPrefix(String prefix, Properties properties) { if (StringUtils.isEmpty(prefix) || properties == null) { throw new IllegalArgumentException( "Prefix and properties should not be null to extract properties with " + "certain prefix"); } Properties subProperties = new Properties(); Enumeration propertyNames = properties.propertyNames(); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); if (key.startsWith(prefix)) { // Remove from original properties to hold property schema. ie need to get the set of properties which // remains after consuming all required specific properties subProperties.setProperty(key, (String) properties.remove(key)); } } return subProperties; }
From source file:org.nuxeo.theme.themes.ThemeRepairer.java
private static void cleanupLayouts(Element element) { Layout layout = (Layout) ElementFormatter.getFormatFor(element, "layout"); String xpath = element.computeXPath(); Properties layoutProperties = layout.getProperties(); List<String> layoutPropertiesToRemove = new ArrayList<String>(); for (Object key : layoutProperties.keySet()) { String propertyName = (String) key; if ((element instanceof PageElement && !Utils.contains(PAGE_LAYOUT_PROPERTIES, propertyName)) || (element instanceof SectionElement && !Utils.contains(SECTION_LAYOUT_PROPERTIES, propertyName)) || (element instanceof CellElement && !Utils.contains(CELL_LAYOUT_PROPERTIES, propertyName))) { layoutPropertiesToRemove.add(propertyName); }//from www .ja v a 2s. c o m } for (String propertyName : layoutPropertiesToRemove) { layoutProperties.remove(propertyName); log.debug("Removed property '" + propertyName + "' from <layout> for element " + xpath); } }
From source file:adalid.util.i18n.Merger.java
public static void merge(String project) { logger.info(project);//from w w w.j av a2s .co m Mapper mapper = Mapper.map(project); // mapper.info(); String name, locale, tag, filename; List<File> list; File baseBundle; Properties baseProperties, localeProperties, mergedProperties; Map<String, List<File>> map = mapper.getMap(); Set<String> keySet = map.keySet(); for (String key : keySet) { logger.info(key); list = map.get(key); baseBundle = null; for (File bundle : list) { name = bundle.getName(); locale = locale(name); if (locale == null) { baseBundle = bundle; } } if (baseBundle == null) { continue; } baseProperties = PropertiesHandler.loadProperties(baseBundle, true); tag = baseProperties.getProperty(LOCALE_LANGUAGE_TAG); if (tag == null) { continue; } baseProperties.remove(LOCALE_LANGUAGE_TAG); logger.debug("\t" + baseBundle.getName() + " " + baseProperties.size()); for (File bundle : list) { name = bundle.getName(); locale = locale(name); if (locale != null) { localeProperties = PropertiesHandler.loadProperties(bundle, true); logger.debug("\t" + bundle.getName() + " " + localeProperties.size()); filename = TEST_DIR + locale + FILE_SEPARATOR + key + "_" + locale + ".properties"; if (locale.equals(tag)) { mergedProperties = baseProperties; } else { mergedProperties = merge(bundle, baseProperties, localeProperties); } PropertiesHandler.storeProperties(mergedProperties, filename); } } } }
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoContainer.java
/** * revert naming factory to original settings * * @since 5.6// w ww . ja va 2 s . c om */ protected static void revertSetAsInitialContext() { Iterator<Entry<String, Object>> iterator = parentEnvironment.entrySet().iterator(); Properties props = System.getProperties(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); iterator.remove(); String key = entry.getKey(); String value = (String) entry.getValue(); if (value == null) { props.remove(key); } else { props.setProperty(key, value); } } }
From source file:org.eclipse.gemini.blueprint.test.internal.util.PropertiesUtil.java
/** * Filter/Eliminate keys that start with the given prefix. * /* w w w.j a va 2s. co m*/ * @param properties * @param prefix * @return */ public static Properties filterKeysStartingWith(Properties properties, String prefix) { if (!StringUtils.hasText(prefix)) return EMPTY_PROPERTIES; Assert.notNull(properties); Properties excluded = (properties instanceof OrderedProperties ? new OrderedProperties() : new Properties()); // filter ignore keys out for (Enumeration enm = properties.keys(); enm.hasMoreElements();) { String key = (String) enm.nextElement(); if (key.startsWith(prefix)) { excluded.put(key, properties.get(key)); } } for (Enumeration enm = excluded.keys(); enm.hasMoreElements();) { properties.remove(enm.nextElement()); } return excluded; }