List of usage examples for java.util Properties remove
@Override public synchronized Object remove(Object key)
From source file:net.sourceforge.pmd.util.database.DBType.java
/** * Load properties from one or more files or resources. * * <p>/*from ww w. j a v a 2 s . c o m*/ * This method recursively finds property files or JAR resources matching * {@matchstring}. * </p> * . * <p> * The method is intended to be able to use , so any * * @param matchString * @return "current" set of properties (from one or more resources/property * files) */ private Properties loadDBProperties(String matchString) throws IOException { LOGGER.entering(DBType.class.getCanonicalName(), matchString); // Locale locale = Control.g; ResourceBundle resourceBundle = null; InputStream stream = null; if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("class_path+" + System.getProperty("java.class.path")); } /* * Attempt to match properties files in this order:- File path with * properties suffix File path without properties suffix Resource * without class prefix Resource with class prefix */ try { File propertiesFile = new File(matchString); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Attempting File no file suffix: " + matchString); } stream = new FileInputStream(propertiesFile); resourceBundle = new PropertyResourceBundle(stream); propertiesSource = propertiesFile.getAbsolutePath(); LOGGER.finest("FileSystemWithoutExtension"); } catch (FileNotFoundException notFoundOnFilesystemWithoutExtension) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("notFoundOnFilesystemWithoutExtension"); LOGGER.finest("Attempting File with added file suffix: " + matchString + ".properties"); } try { File propertiesFile = new File(matchString + ".properties"); stream = new FileInputStream(propertiesFile); resourceBundle = new PropertyResourceBundle(stream); propertiesSource = propertiesFile.getAbsolutePath(); LOGGER.finest("FileSystemWithExtension"); } catch (FileNotFoundException notFoundOnFilesystemWithExtensionTackedOn) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Attempting JARWithoutClassPrefix: " + matchString); } try { resourceBundle = ResourceBundle.getBundle(matchString); propertiesSource = "[" + INTERNAL_SETTINGS + "]" + File.separator + matchString + ".properties"; LOGGER.finest("InJarWithoutPath"); } catch (Exception notInJarWithoutPath) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Attempting JARWithClass prefix: " + DBType.class.getCanonicalName() + "." + matchString); } try { resourceBundle = ResourceBundle .getBundle(DBType.class.getPackage().getName() + "." + matchString); propertiesSource = "[" + INTERNAL_SETTINGS + "]" + File.separator + matchString + ".properties"; LOGGER.finest("found InJarWithPath"); } catch (Exception notInJarWithPath) { notInJarWithPath.printStackTrace(); notFoundOnFilesystemWithExtensionTackedOn.printStackTrace(); throw new RuntimeException(" Could not locate DBTYpe settings : " + matchString, notInJarWithPath); } } } } finally { IOUtils.closeQuietly(stream); } // Properties in this matched resource Properties matchedProperties = getResourceBundleAsProperties(resourceBundle); resourceBundle = null; String saveLoadedFrom = getPropertiesSource(); /* * If the matched properties contain the "extends" key, use the value as * a matchstring, to recursively set the properties before overwriting * any previous properties with the matched properties. */ String extendedPropertyFile = (String) matchedProperties.remove("extends"); if (null != extendedPropertyFile && !"".equals(extendedPropertyFile.trim())) { Properties extendedProperties = loadDBProperties(extendedPropertyFile.trim()); // Overwrite extended properties with properties in the matched // resource extendedProperties.putAll(matchedProperties); matchedProperties = extendedProperties; } /* * Record the location of the original matched resource/property file, * and the current set of properties secured. */ propertiesSource = saveLoadedFrom; setProperties(matchedProperties); return matchedProperties; }
From source file:org.structr.bolt.BoltDatabaseService.java
@Override public void setProperty(final String name, final Object value) { final Properties properties = getProperties(); boolean hasChanges = false; if (value == null) { if (properties.containsKey(name)) { properties.remove(name); hasChanges = true;//www .j av a2s. c o m } } else { properties.setProperty(name, value.toString()); hasChanges = true; } if (hasChanges) { final File propertiesFile = new File(databasePath + "/graph.properties"); try (final Writer writer = new FileWriter(propertiesFile)) { properties.store(writer, "Created by Structr at " + new Date()); } catch (IOException ioex) { logger.warn("Unable to write properties file", ioex); } } }
From source file:org.hyperic.hq.common.server.session.ServerConfigManagerImpl.java
/** * Set the server Configuration//from w w w. j a v a2s . com * @param prefix The config prefix to use when setting properties. The * prefix is used for namespace protection and property scoping. * @param newProps The Properties to set. * @throws ConfigPropertyException - if the props object is missing a key * that's currently in the database * */ @Transactional public void setConfig(AuthzSubject subject, String prefix, Properties newProps) throws ApplicationException, ConfigPropertyException { Properties tempProps = new Properties(); tempProps.putAll(newProps); // get all properties Collection<ConfigProperty> allProps = serverConfigCache.getProps(prefix); createChangeAudits(subject, allProps, newProps); for (ConfigProperty configProp : allProps) { // check if the props object has a key matching String key = configProp.getKey(); if (newProps.containsKey(key)) { tempProps.remove(key); String propValue = (String) newProps.get(key); // delete null values from prefixed properties if (prefix != null && (propValue == null || propValue.equals("NULL"))) { configPropertyDAO.remove(configProp); serverConfigCache.remove(key); } else { // non-prefixed properties never get deleted. configProp.setValue(propValue); serverConfigCache.put(key, propValue); // Fix Bug 1285064/HQ-4793: Save the property in DB configPropertyDAO.save(configProp); if (HQConstants.HQGUID.equals(key)) { // Came from read only method so need to flush the session configPropertyDAO.flushSession(); if (log.isDebugEnabled()) log.debug("Saving HQ-GUID in DB [" + propValue + "]"); } } } else if (prefix == null) { // Bomb out if props are missing for non-prefixed properties throw new ConfigPropertyException("Updated configuration missing required key: " + key); } } // create properties that are still left in tempProps if (tempProps.size() > 0) { Enumeration propsToAdd = tempProps.propertyNames(); while (propsToAdd.hasMoreElements()) { String key = (String) propsToAdd.nextElement(); String propValue = tempProps.getProperty(key); // create the new property configPropertyDAO.create(prefix, key, propValue, propValue); serverConfigCache.put(key, propValue); } } }
From source file:org.pentaho.reporting.ui.datasources.jdbc.connection.JdbcConnectionDefinitionManager.java
/** * package-local visibility for testing purposes *///from ww w . j a v a 2 s . co m JdbcConnectionDefinitionManager(final Preferences externalPreferences, final String node) { userPreferences = externalPreferences; // Load the list of JNDI Sources try { final String[] childNodeNames = userPreferences.childrenNames(); for (int i = 0; i < childNodeNames.length; i++) { final String name = childNodeNames[i]; final Preferences p = userPreferences.node(name); final String type = p.get("type", null); if (type == null) { p.removeNode(); } else if (type.equals("local")) { final Properties props = new Properties(); if (p.nodeExists("properties")) { final Preferences preferences = p.node("properties"); final String[] strings = preferences.keys(); for (int j = 0; j < strings.length; j++) { final String string = strings[j]; final String value = preferences.get(string, null); if (value != null) { props.setProperty(string, value); } else { props.remove(string); } } } final DriverConnectionDefinition driverConnection = new DriverConnectionDefinition(name, p.get(DRIVER_KEY, null), p.get(URL_KEY, null), p.get(USERNAME_KEY, null), p.get(PASSWORD_KEY, null), p.get(HOSTNAME_KEY, null), p.get(DATABASE_NAME_KEY, null), p.get(DATABASE_TYPE_KEY, null), p.get(PORT_KEY, null), props); connectionDefinitions.put(name, driverConnection); } else if (type.equals("jndi")) { final JndiConnectionDefinition connectionDefinition = new JndiConnectionDefinition(name, p.get(JNDI_LOCATION, null), p.get(DATABASE_TYPE_KEY, null), p.get(USERNAME_KEY, null), p.get(PASSWORD_KEY, null)); connectionDefinitions.put(name, connectionDefinition); } else { p.removeNode(); } } } catch (BackingStoreException e) { // The system preferences system is not working - log this as a message and use defaults log.warn("Could not access the user prefererences while loading the " + "JNDI connection information - using default JNDI connection entries", e); } catch (final Exception e) { log.warn("Configuration information was invalid.", e); } // If the connectionDefinitions is empty, add any default entries if (connectionDefinitions.isEmpty() && DATASOURCE_PREFERENCES_NODE.equals(node)) { if (userPreferences.getBoolean("sample-data-created", false) == true) { // only create the sample connections once, if we work on a totally fresh config. return; } updateSourceList(SAMPLE_DATA_JNDI_SOURCE); updateSourceList(SAMPLE_DATA_DRIVER_SOURCE); updateSourceList(SAMPLE_DATA_MEMORY_SOURCE); updateSourceList(LOCAL_SAMPLE_DATA_DRIVER_SOURCE); updateSourceList(MYSQL_SAMPLE_DATA_DRIVER_SOURCE); userPreferences.putBoolean("sample-data-created", true); try { userPreferences.flush(); } catch (BackingStoreException e) { // ignored .. } } }
From source file:org.adblockplus.android.ProxyService.java
/** * Sets user proxy settings in proxy service properties. *//* w w w .j ava 2s . c om*/ private void configureUserProxy(Properties config, String proxyHost, String proxyPort, String proxyExcl, String proxyUser, String proxyPass) { // Clean previous settings config.remove("adblock.proxyHost"); config.remove("adblock.proxyPort"); config.remove("adblock.auth"); config.remove("adblock.proxyExcl"); if (!transparent) { config.remove("https.proxyHost"); config.remove("https.proxyPort"); config.remove("https.auth"); } if (nativeProxyAutoConfigured) passProxySettings(proxyHost, proxyPort, proxyExcl); // Check if there are any settings if (proxyHost == null || "".equals(proxyHost)) return; // Check for dirty proxy settings - this indicated previous crash: // proxy points to ourselves // proxy port is null, 0 or not a number // proxy is 127.0.0.1:8080 if (proxyPort == null) return; int p = 0; try { p = Integer.valueOf(proxyPort); } catch (NumberFormatException e) { return; } if (p == 0 || isLocalHost(proxyHost) && (p == port || p == 8080)) { if (nativeProxyAutoConfigured) passProxySettings(null, null, null); return; } config.put("adblock.proxyHost", proxyHost); config.put("adblock.proxyPort", proxyPort); if (!transparent) { config.put("https.proxyHost", proxyHost); config.put("https.proxyPort", proxyPort); } // TODO Not implemented in our proxy but needed to restore settings if (proxyExcl != null) config.put("adblock.proxyExcl", proxyExcl); if (proxyUser != null && !"".equals(proxyUser) && proxyPass != null && !"".equals(proxyPass)) { // Base64 encode user:password String proxyAuth = "Basic " + new String(Base64.encode(proxyUser + ":" + proxyPass)); config.put("adblock.auth", proxyAuth); if (!transparent) config.put("https.auth", proxyAuth); } }
From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverter.java
private boolean doRelocation(Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model, ArtifactRepository repository, FileTransaction transaction) throws IOException { Properties properties = v3Model.getProperties(); if (properties.containsKey("relocated.groupId") || properties.containsKey("relocated.artifactId") //$NON-NLS-1$ //$NON-NLS-2$ || properties.containsKey("relocated.version")) //$NON-NLS-1$ {//www . java2 s . c om String newGroupId = properties.getProperty("relocated.groupId", v3Model.getGroupId()); //$NON-NLS-1$ properties.remove("relocated.groupId"); //$NON-NLS-1$ String newArtifactId = properties.getProperty("relocated.artifactId", v3Model.getArtifactId()); //$NON-NLS-1$ properties.remove("relocated.artifactId"); //$NON-NLS-1$ String newVersion = properties.getProperty("relocated.version", v3Model.getVersion()); //$NON-NLS-1$ properties.remove("relocated.version"); //$NON-NLS-1$ String message = properties.getProperty("relocated.message", ""); //$NON-NLS-1$ //$NON-NLS-2$ properties.remove("relocated.message"); //$NON-NLS-1$ if (properties.isEmpty()) { v3Model.setProperties(null); } writeRelocationPom(v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId, newArtifactId, newVersion, message, repository, transaction); v3Model.setGroupId(newGroupId); v3Model.setArtifactId(newArtifactId); v3Model.setVersion(newVersion); artifact.setGroupId(newGroupId); artifact.setArtifactId(newArtifactId); artifact.setVersion(newVersion); return true; } else { return false; } }
From source file:com.webpagebytes.cms.local.WPBLocalFileStorage.java
public WPBFileInfo getFileInfo(WPBFilePath file) { String metaPath = getLocalFullMetaPath(file); String dataPath = getLocalFullDataPath(file); Properties props = new Properties(); try {/*from w ww . j av a 2 s .c om*/ props = getFileProperties(metaPath); String contentType = props.getProperty("contentType"); int size = Integer.valueOf(props.getProperty("size")); String md5 = props.getProperty("md5"); long crc32 = Long.valueOf(props.getProperty("crc32")); long creationTime = Long.valueOf(props.getProperty("creationTime")); boolean fileExists = checkIfFileExists(dataPath); WPBFileInfo fileInfo = new WPBDefaultCloudFileInfo(file, contentType, fileExists, size, md5, crc32, creationTime); props.remove("path"); props.remove("contentType"); props.remove("size"); props.remove("md5"); props.remove("crc32"); props.remove("creationTime"); props.remove("filePath"); // add the custom properties of the file for (Object key : props.keySet()) { String strKey = (String) key; fileInfo.setProperty(strKey, props.getProperty(strKey)); } return fileInfo; } catch (Exception e) { return null; } }
From source file:pl.project13.maven.git.GitCommitIdMojo.java
void maybeGeneratePropertiesFile(@NotNull Properties localProperties, File base, String propertiesFilename) throws GitCommitIdExecutionException { try {/* w w w.j av a 2 s . com*/ final File gitPropsFile = craftPropertiesOutputFile(base, propertiesFilename); final boolean isJsonFormat = "json".equalsIgnoreCase(format); boolean shouldGenerate = true; if (gitPropsFile.exists()) { final Properties persistedProperties; try { if (isJsonFormat) { log.info("Reading existing json file [{}] (for module {})...", gitPropsFile.getAbsolutePath(), project.getName()); persistedProperties = readJsonProperties(gitPropsFile); } else { log.info("Reading existing properties file [{}] (for module {})...", gitPropsFile.getAbsolutePath(), project.getName()); persistedProperties = readProperties(gitPropsFile); } final Properties propertiesCopy = (Properties) localProperties.clone(); final String buildTimeProperty = prefixDot + BUILD_TIME; propertiesCopy.remove(buildTimeProperty); persistedProperties.remove(buildTimeProperty); shouldGenerate = !propertiesCopy.equals(persistedProperties); } catch (CannotReadFileException ex) { // Read has failed, regenerate file log.info("Cannot read properties file [{}] (for module {})...", gitPropsFile.getAbsolutePath(), project.getName()); shouldGenerate = true; } } if (shouldGenerate) { Files.createParentDirs(gitPropsFile); Writer outputWriter = null; boolean threw = true; try { outputWriter = new OutputStreamWriter(new FileOutputStream(gitPropsFile), sourceCharset); if (isJsonFormat) { log.info("Writing json file to [{}] (for module {})...", gitPropsFile.getAbsolutePath(), project.getName()); ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(outputWriter, localProperties); } else { log.info("Writing properties file to [{}] (for module {})...", gitPropsFile.getAbsolutePath(), project.getName()); localProperties.store(outputWriter, "Generated by Git-Commit-Id-Plugin"); } threw = false; } catch (final IOException ex) { throw new RuntimeException("Cannot create custom git properties file: " + gitPropsFile, ex); } finally { Closeables.close(outputWriter, threw); } } else { log.info("Properties file [{}] is up-to-date (for module {})...", gitPropsFile.getAbsolutePath(), project.getName()); } } catch (IOException e) { throw new GitCommitIdExecutionException(e); } }
From source file:org.multibit.file.FileHandler.java
public static void writeUserPreferences(BitcoinController bitcoinController) { final Controller controller = bitcoinController; // Save all the wallets' filenames in the user preferences. if (bitcoinController.getModel().getPerWalletModelDataList() != null) { List<WalletData> perWalletModelDataList = bitcoinController.getModel().getPerWalletModelDataList(); List<String> orderList = new ArrayList<String>(); List<String> earlyList = new ArrayList<String>(); List<String> protobuf3List = new ArrayList<String>(); for (WalletData perWalletModelData : perWalletModelDataList) { // Check if this is the initial empty WalletData if ("".equals(perWalletModelData.getWalletFilename()) || perWalletModelData.getWalletFilename() == null || perWalletModelData.getWalletInfo() == null) { continue; }//www . j av a 2 s . c o m // Do not save deleted wallets if (perWalletModelData.getWalletInfo().isDeleted()) { log.debug("Not writing out info about wallet '" + perWalletModelData.getWalletFilename() + "' as it has been deleted"); continue; } if (!orderList.contains(perWalletModelData.getWalletFilename())) { orderList.add(perWalletModelData.getWalletFilename()); } if (perWalletModelData.getWalletInfo() .getWalletVersion() == MultiBitWalletVersion.PROTOBUF_ENCRYPTED) { if (!protobuf3List.contains(perWalletModelData.getWalletFilename())) { protobuf3List.add(perWalletModelData.getWalletFilename()); } } else if (perWalletModelData.getWalletInfo().getWalletVersion() == null || perWalletModelData.getWalletInfo().getWalletVersion() == MultiBitWalletVersion.SERIALIZED || perWalletModelData.getWalletInfo() .getWalletVersion() == MultiBitWalletVersion.PROTOBUF) { if (!earlyList.contains(perWalletModelData.getWalletFilename())) { earlyList.add(perWalletModelData.getWalletFilename()); } } } int orderCount = 1; for (String walletFilename : orderList) { controller.getModel().setUserPreference(BitcoinModel.WALLET_ORDER_PREFIX + orderCount, walletFilename); orderCount++; } controller.getModel().setUserPreference(BitcoinModel.WALLET_ORDER_TOTAL, "" + orderList.size()); int earlyCount = 1; for (String walletFilename : earlyList) { controller.getModel().setUserPreference(BitcoinModel.EARLY_WALLET_FILENAME_PREFIX + earlyCount, walletFilename); earlyCount++; } controller.getModel().setUserPreference(BitcoinModel.NUMBER_OF_EARLY_WALLETS, "" + earlyList.size()); int protobuf3Count = 1; for (String walletFilename : protobuf3List) { controller.getModel().setUserPreference( BitcoinModel.PROTOBUF3_WALLET_FILENAME_PREFIX + protobuf3Count, walletFilename); protobuf3Count++; } controller.getModel().setUserPreference(BitcoinModel.NUMBER_OF_PROTOBUF3_WALLETS, "" + protobuf3List.size()); controller.getModel().setUserPreference(BitcoinModel.ACTIVE_WALLET_FILENAME, bitcoinController.getModel().getActiveWalletFilename()); } Properties userPreferences = controller.getModel().getAllUserPreferences(); // If the view is marked as also requiring a backwards compatible // numeric field write that. @SuppressWarnings("deprecation") int currentViewNumericFormat = View.toOldViewNumeric(controller.getCurrentView()); if (currentViewNumericFormat != 0) { userPreferences.put(CoreModel.SELECTED_VIEW, "" + currentViewNumericFormat); } else { // Make sure the old numeric value for a view is not in the user // properties. userPreferences.remove(CoreModel.SELECTED_VIEW); } // Write the user preference properties. OutputStream outputStream = null; try { String userPropertiesFilename; if ("".equals(controller.getApplicationDataDirectoryLocator().getApplicationDataDirectory())) { userPropertiesFilename = USER_PROPERTIES_FILE_NAME; } else { userPropertiesFilename = controller.getApplicationDataDirectoryLocator() .getApplicationDataDirectory() + File.separator + USER_PROPERTIES_FILE_NAME; } outputStream = new FileOutputStream(userPropertiesFilename); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(bufferedOutputStream, "UTF8"); userPreferences.store(outputStreamWriter, USER_PROPERTIES_HEADER_TEXT); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } finally { if (outputStream != null) { try { outputStream.flush(); outputStream.close(); } catch (IOException e) { log.error(e.getClass().getCanonicalName() + " " + e.getMessage()); } finally { outputStream = null; } } } }
From source file:com.tesora.dve.sql.transexec.CatalogHelper.java
protected DBHelper createDBHelper() throws PEException { checkURLAvailable();//from w w w .jav a2 s.co m Properties props = (Properties) catalogProperties.clone(); props.remove(DBHelper.CONN_DBNAME); return new DBHelper(props); }