List of usage examples for java.util Properties clear
@Override public synchronized void clear()
From source file:org.apache.geode.distributed.internal.DistributionConfigImpl.java
/** * Creates a new <code>DistributionConfigImpl</code> with the given non-default configuration * properties. See {@link org.apache.geode.distributed.DistributedSystem#connect} for a list of * exceptions that may be thrown./*from ww w . j a va 2 s. c om*/ * * @param nonDefault The configuration properties specified by the caller * @param ignoreGemFirePropsFile whether to skip loading distributed system properties from * gemfire.properties file * @param isConnected whether to skip Validation for SSL properties and copy of ssl properties to * other ssl properties. This parameter will be used till we provide support for ssl-* * properties. * * @since GemFire 8.0 */ public DistributionConfigImpl(Properties nonDefault, boolean ignoreGemFirePropsFile, boolean isConnected) { HashMap props = new HashMap(); if (!ignoreGemFirePropsFile) {// For admin bug #40434 props.putAll(loadPropertiesFromURL(DistributedSystem.getPropertyFileURL(), false)); } props.putAll(loadPropertiesFromURL(DistributedSystem.getSecurityPropertiesFileURL(), true)); // Now override values picked up from the file with values passed // in from the caller's code if (nonDefault != null) { props.putAll(nonDefault); setSource(nonDefault, ConfigSource.api()); } // Now remove all user defined properties from props. for (Object entry : props.entrySet()) { Map.Entry<String, String> ent = (Map.Entry<String, String>) entry; if (((String) ent.getKey()).startsWith(USERDEFINED_PREFIX_NAME)) { userDefinedProps.put(ent.getKey(), ent.getValue()); } } // Now override values picked up from the file or code with values // from the system properties. String[] attNames = getAttributeNames(); // For gemfire.security-* properties, we will need to look at // all the system properties instead of looping through attNames Set attNameSet = new HashSet(); for (int index = 0; index < attNames.length; ++index) { attNameSet.add(GEMFIRE_PREFIX + attNames[index]); } /* clone() is a synchronized method for Properties (actually in Hashtable) */ Properties sysProps = (Properties) System.getProperties().clone(); Iterator<?> sysPropsIter = sysProps.entrySet().iterator(); while (sysPropsIter.hasNext()) { Map.Entry sysEntry = (Map.Entry) sysPropsIter.next(); String sysName = (String) sysEntry.getKey(); if (attNameSet.contains(sysName) || sysName.startsWith(GEMFIRE_PREFIX + SECURITY_PREFIX_NAME) || sysName.startsWith(GEMFIRE_PREFIX + SSL_SYSTEM_PROPS_NAME)) { String sysValue = (String) sysEntry.getValue(); if (sysValue != null) { String attName = sysName.substring(GEMFIRE_PREFIX.length()); props.put(attName, sysValue); this.sourceMap.put(attName, ConfigSource.sysprop()); } } } sysProps.clear(); // clearing cloned SysProps final Properties overriddenDefaults = ProcessLauncherContext.getOverriddenDefaults(); if (!overriddenDefaults.isEmpty()) { for (String key : overriddenDefaults.stringPropertyNames()) { // only apply the overridden default if it's not already specified in props final String property = key.substring(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX.length()); if (!props.containsKey((property))) { props.put(property, overriddenDefaults.getProperty(key)); this.sourceMap.put(property, ConfigSource.launcher()); } } } initialize(props); if (securityPeerAuthInit != null && securityPeerAuthInit.length() > 0) { System.setProperty(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTH_INIT, securityPeerAuthInit); } if (securityPeerAuthenticator != null && securityPeerAuthenticator.length() > 0) { System.setProperty(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTHENTICATOR, securityPeerAuthenticator); } Iterator iter = security.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); System.setProperty(SECURITY_SYSTEM_PREFIX + (String) entry.getKey(), (String) entry.getValue()); } if (!isConnected) { copySSLPropsToServerSSLProps(); copySSLPropsToJMXSSLProps(); copyClusterSSLPropsToGatewaySSLProps(); copySSLPropsToHTTPSSLProps(); } // Make attributes writeable only this.modifiable = true; validateConfigurationProperties(props); validateSSLEnabledComponentsConfiguration(); // Make attributes read only this.modifiable = false; }
From source file:org.apache.jetspeed.modules.actions.portlets.designer.HeaderAction.java
public void editHeader(RunData rundata, Context context, Hashtable ht) throws Exception { try {// w w w .j a va 2 s .co m String logo = (String) ht.get("logo"); String bgImage = (String) ht.get("BgImage"); String bgColor = (String) ht.get("BgColor"); String fontSize = (String) ht.get("FontSize"); String fontColor = (String) ht.get("FontColor"); String title = (String) ht.get("PortalTitle"); boolean setLogo = Boolean.valueOf((String) ht.get("SetLogo")).booleanValue(); boolean setBgImage = Boolean.valueOf((String) ht.get("SetBgImage")).booleanValue(); boolean setBgColor = Boolean.valueOf((String) ht.get("SetBgColor")).booleanValue(); boolean setFontSize = Boolean.valueOf((String) ht.get("SetFontSize")).booleanValue(); boolean setFontColor = Boolean.valueOf((String) ht.get("SetFontColor")).booleanValue(); boolean setPortalTitle = Boolean.valueOf((String) ht.get("SetTitle")).booleanValue(); String DEFAULT_ROOT = File.separator + "WEB-INF" + File.separator + "conf" + File.separator; String root = rundata.getServletConfig().getServletContext().getRealPath(DEFAULT_ROOT) + File.separator; Properties prop = new Properties(); prop.clear(); prop.load(new FileInputStream(root + "JetspeedResources.properties")); TurbineResources trProp = (TurbineResources) TurbineResources .getResources(root + "JetspeedResources.properties"); int counter = 0; if (setBgImage && !setBgColor && (counter == 0)) { setBgColor = true; bgColor = "FFFFFF"; counter = 1; } if (!setBgImage && setBgColor && (counter == 0)) { setBgImage = true; bgImage = ""; counter = 1; } if (setBgImage && setBgColor && (counter == 0)) { setBgColor = true; bgColor = "FFFFFF"; counter = 1; } if (setLogo) { TurbineResources.setProperty("topnav.logo.file", logo); prop.setProperty("topnav.logo.file", logo); } if (setBgImage) { TurbineResources.setProperty("topnav.bg.image", bgImage); prop.setProperty("topnav.bg.image", bgImage); } if (setBgColor) { TurbineResources.setProperty("topnav.bg.color", bgColor); prop.setProperty("topnav.bg.color", bgColor); } if (setFontSize) { TurbineResources.setProperty("topnav.font.size", fontSize); prop.setProperty("topnav.font.size", fontSize); } if (setFontColor) { TurbineResources.setProperty("topnav.font.color", fontColor); prop.setProperty("topnav.font.color", fontColor); } if (setPortalTitle) { TurbineResources.setProperty("portal.title", title); prop.setProperty("portal.title", title); } FileOutputStream stream = new FileOutputStream(root + "JetspeedResources.properties"); prop.store(stream, "topnav.logo.file"); prop.store(stream, "topnav.bg.image"); prop.store(stream, "topnav.bg.color"); prop.store(stream, "topnav.font.size"); prop.store(stream, "topnav.font.color"); stream.close(); String logoJR = prop.getProperty("topnav.logo.file"); String bgImageJR = prop.getProperty("topnav.bg.image"); String bgColorJR = prop.getProperty("topnav.bg.color"); String fontSizeJR = prop.getProperty("topnav.font.size"); String fontColorJR = prop.getProperty("topnav.font.color"); log.info("new Logo : " + logoJR); log.info("new bgImageJR : " + bgImageJR); log.info("new bgColorJR : " + bgColorJR); log.info("new fontSizeJR : " + fontSizeJR); log.info("new fontColorJR : " + fontColorJR); prop = null; System.gc(); context.put("settingStatus", "Successfully changed settings."); } catch (Exception e) { context.put("settingStatus", "Error occurred while changing settings."); log.error(e); } }
From source file:org.apache.pig.backend.hadoop.executionengine.MRExecutionEngine.java
/** * Method to apply pig properties to JobConf (replaces properties with * resulting jobConf values)/*from w w w. j a va2 s . co m*/ * * @param conf * JobConf with appropriate hadoop resource files * @param properties * Pig properties that will override hadoop properties; * properties might be modified */ @SuppressWarnings("deprecation") protected void recomputeProperties(JobConf jobConf, Properties properties) { // We need to load the properties from the hadoop configuration // We want to override these with any existing properties we have. if (jobConf != null && properties != null) { // set user properties on the jobConf to ensure that defaults // and deprecation is applied correctly Enumeration<Object> propertiesIter = properties.keys(); while (propertiesIter.hasMoreElements()) { String key = (String) propertiesIter.nextElement(); String val = properties.getProperty(key); // We do not put user.name, See PIG-1419 if (!key.equals("user.name")) jobConf.set(key, val); } // clear user defined properties and re-populate properties.clear(); Iterator<Map.Entry<String, String>> iter = jobConf.iterator(); while (iter.hasNext()) { Map.Entry<String, String> entry = iter.next(); properties.put(entry.getKey(), entry.getValue()); } } }
From source file:org.apache.pig.backend.hadoop.executionengine.MRExecutionEngine.java
@Override public void setProperty(String property, String value) { // mPigServer.getPigContext().getProperties().setProperty(key, value); // PIG-2508 properties need to be managed through JobConf // since all other code depends on access to properties, // we need to re-populate from updated JobConf // java.util.HashSet<?> keysBefore = new // java.util.HashSet<Object>(mPigServer.getPigContext().getProperties().keySet()); // set current properties on jobConf Properties properties = pigContext.getProperties(); Enumeration<Object> propertiesIter = pigContext.getProperties().keys(); while (propertiesIter.hasMoreElements()) { String pkey = (String) propertiesIter.nextElement(); String val = properties.getProperty(pkey); // We do not put user.name, See PIG-1419 if (!pkey.equals("user.name")) jobConf.set(pkey, val); }//from w w w . jav a2 s . c om // set new value, JobConf will handle deprecation etc. jobConf.set(property, value); // re-initialize to reflect updated JobConf properties.clear(); Iterator<Map.Entry<String, String>> iter = jobConf.iterator(); while (iter.hasNext()) { Map.Entry<String, String> entry = iter.next(); properties.put(entry.getKey(), entry.getValue()); } // keysBefore.removeAll(mPigServer.getPigContext().getProperties().keySet()); // log.info("PIG-2508: keys dropped from properties: " + keysBefore); }
From source file:org.apache.pig.impl.util.Utils.java
/** * Method to apply pig properties to JobConf (replaces properties with * resulting jobConf values)./* w w w . j av a2s . co m*/ * * @param conf JobConf with appropriate hadoop resource files * @param properties Pig properties that will override hadoop properties; * properties might be modified */ public static void recomputeProperties(JobConf jobConf, Properties properties) { // We need to load the properties from the hadoop configuration // We want to override these with any existing properties we have. if (jobConf != null && properties != null) { // set user properties on the jobConf to ensure that defaults // and deprecation is applied correctly Enumeration<Object> propertiesIter = properties.keys(); while (propertiesIter.hasMoreElements()) { String key = (String) propertiesIter.nextElement(); String val = properties.getProperty(key); // We do not put user.name, See PIG-1419 if (!key.equals("user.name")) { jobConf.set(key, val); } } // clear user defined properties and re-populate properties.clear(); Iterator<Map.Entry<String, String>> iter = jobConf.iterator(); while (iter.hasNext()) { Map.Entry<String, String> entry = iter.next(); properties.put(entry.getKey(), entry.getValue()); } } }
From source file:org.apache.sqoop.SqoopOptions.java
protected void parseColumnMapping(String mapping, Properties output) { output.clear(); String[] maps = mapping.split(","); for (String map : maps) { String[] details = map.split("="); output.put(details[0], details[1]); }// ww w. java2 s. co m }
From source file:org.apache.syncope.common.lib.PropertyUtils.java
public static Pair<Properties, String> read(final Class<?> clazz, final String propertiesFileName, final String confDirProp) { Properties props = new Properties(); String confDirName = null;/*from w ww .j av a 2 s .c om*/ try (InputStream is = clazz.getResourceAsStream("/" + propertiesFileName)) { props.load(is); confDirName = props.getProperty(confDirProp); if (confDirName != null) { File confDir = new File(confDirName); if (confDir.exists() && confDir.canRead() && confDir.isDirectory()) { File confDirProps = new File(confDir, propertiesFileName); if (confDirProps.exists() && confDirProps.canRead() && confDirProps.isFile()) { props.clear(); props.load(new FileInputStream(confDirProps)); } } } } catch (Exception e) { throw new RuntimeException("Could not read " + propertiesFileName, e); } return Pair.of(props, confDirName); }
From source file:org.codice.ddf.platform.util.properties.PropertiesLoader.java
/** * Try loading the properties directly from the file system. If the properties file has a * fully-qualified absolute path (which is what the blueprint file should specify) then it can be * loaded directly, using this method. Otherwise the path will be considered relative and attempts * will be made with {@code karaf.home} and {@code ddf.home} property values prepended to the * original path./*from w w w. j a v a2 s . c om*/ */ @SuppressWarnings("squid:S1172" /* Used in bi-function */) @VisibleForTesting static Properties attemptLoadWithFileSystem(String propertiesFile, ClassLoader classLoader) { LOGGER.debug("Attempting to load properties from file system: {}", propertiesFile); Properties properties = new Properties(); String karafHome = System.getProperty("karaf.home"); String ddfHome = System.getProperty("ddf.home"); File propFile; AbsolutePathResolver absPath = new AbsolutePathResolver(propertiesFile); if (StringUtils.isNotBlank(karafHome)) { propFile = new File(absPath.getPath(karafHome)); } else if (StringUtils.isNotBlank(ddfHome)) { propFile = new File(absPath.getPath(ddfHome)); } else { propFile = new File(propertiesFile); } if (propFile.exists()) { try (InputStreamReader reader = new InputStreamReader(new FileInputStream(propFile), StandardCharsets.UTF_8)) { properties.load(reader); } catch (FileNotFoundException e) { LOGGER.debug("Could not find properties file: {}", propFile.getAbsolutePath(), e); } catch (IOException e) { LOGGER.debug("Error reading properties file: {}", propFile.getAbsolutePath(), e); properties.clear(); } } else { LOGGER.debug("Could not find properties file: {}", propFile.getAbsolutePath()); } return properties; }
From source file:org.ebayopensource.turmeric.tools.codegen.CodeGenInfoFinder.java
/** * @param inputOptions , org.ebayopensource.turmeric.runtime.tools.codegen.InputOptions * @return/*from w w w. j a v a 2 s . co m*/ * @throws BadInputValueException * @throws IOException * @throws CodeGenFailedException */ public static boolean updateMetaDataMap(InputOptions inputOptions) throws BadInputValueException, IOException, CodeGenFailedException { String classpath = System.getProperty("java.class.path"); getLogger().log(Level.FINEST, "class path in updateMetaDataMap : " + classpath); boolean isMetaDataMapInitilized = false; String mDestRootPath = null; boolean throwExceptionOnFailure = false; InputStream inStream = null; if (inputOptions == null) return isMetaDataMapInitilized; String serviceAdminName = inputOptions.getServiceAdminName(); Properties metaDataMap = serviceMetaDataPropsMap.get(serviceAdminName); if (metaDataMap == null) { metaDataMap = new Properties(); serviceMetaDataPropsMap.put(serviceAdminName, metaDataMap); } else { metaDataMap.clear(); } /* to get the service_metadata.properties file, follow the following priority * 1. If the caller is plugin then codegen should look for the file both under project root (in both meta-src and gen-meta-src) * 2. if -pr is provided, Look under folder specified thru -pr option (both meta-src and gen-meta-src) * 3. else if -uij is provided Try to load the file from the class path * 4. else (this is for backward compatibility) Look for the file under both the meta files location (meta-src and gen-meta-src) */ String projectRoot = inputOptions.getProjectRoot(); String caller = inputOptions.getCaller(); try { if (m_plugin_caller.equals(caller) || !CodeGenUtil.isEmptyString(projectRoot)) { mDestRootPath = projectRoot; throwExceptionOnFailure = false; inStream = getMetaDataFileFromPath(mDestRootPath, inputOptions, throwExceptionOnFailure); } else if (inputOptions.getUseInterfaceJar()) { throwExceptionOnFailure = true; inStream = getMetaDataFileFromJar(serviceAdminName, throwExceptionOnFailure); } else { mDestRootPath = inputOptions.getMetaSrcDestLocation(); if (CodeGenUtil.isEmptyString(mDestRootPath)) mDestRootPath = inputOptions.getDestLocation(); throwExceptionOnFailure = false; inStream = getMetaDataFileFromPath(mDestRootPath, inputOptions, throwExceptionOnFailure); } if (inStream != null) { metaDataMap.load(inStream); isMetaDataMapInitilized = true; } else { isMetaDataMapInitilized = false; } } finally { CodeGenUtil.closeQuietly(inStream); } return isMetaDataMapInitilized; }
From source file:org.executequery.gui.browser.ConnectionPanel.java
/** * Retrieves the values from the jdbc properties table * and stores them within the current database connection. *///from w w w . ja v a 2s . c o m private void storeJdbcProperties() { Properties properties = databaseConnection.getJdbcProperties(); if (properties == null) { properties = new Properties(); } else { properties.clear(); } for (int i = 0; i < advancedProperties.length; i++) { String key = advancedProperties[i][0]; String value = advancedProperties[i][1]; if (!MiscUtils.isNull(key) && !MiscUtils.isNull(value)) { properties.setProperty(key, value); } } databaseConnection.setJdbcProperties(properties); }