List of usage examples for java.util Properties remove
@Override public synchronized Object remove(Object key)
From source file:org.quartz.impl.StdSchedulerFactory.java
private void setBeanProps(Object obj, Properties props) throws NoSuchMethodException, IllegalAccessException, java.lang.reflect.InvocationTargetException, IntrospectionException, SchedulerConfigException { props.remove("class"); BeanInfo bi = Introspector.getBeanInfo(obj.getClass()); PropertyDescriptor[] propDescs = bi.getPropertyDescriptors(); PropertiesParser pp = new PropertiesParser(props); java.util.Enumeration keys = props.keys(); while (keys.hasMoreElements()) { String name = (String) keys.nextElement(); String c = name.substring(0, 1).toUpperCase(Locale.US); String methName = "set" + c + name.substring(1); java.lang.reflect.Method setMeth = getSetMethod(methName, propDescs); try {//from w ww. jav a 2s .c o m if (setMeth == null) { throw new NoSuchMethodException("No setter for property '" + name + "'"); } Class[] params = setMeth.getParameterTypes(); if (params.length != 1) { throw new NoSuchMethodException("No 1-argument setter for property '" + name + "'"); } if (params[0].equals(int.class)) { setMeth.invoke(obj, new Object[] { new Integer(pp.getIntProperty(name)) }); } else if (params[0].equals(long.class)) { setMeth.invoke(obj, new Object[] { new Long(pp.getLongProperty(name)) }); } else if (params[0].equals(float.class)) { setMeth.invoke(obj, new Object[] { new Float(pp.getFloatProperty(name)) }); } else if (params[0].equals(double.class)) { setMeth.invoke(obj, new Object[] { new Double(pp.getDoubleProperty(name)) }); } else if (params[0].equals(boolean.class)) { setMeth.invoke(obj, new Object[] { new Boolean(pp.getBooleanProperty(name)) }); } else if (params[0].equals(String.class)) { setMeth.invoke(obj, new Object[] { pp.getStringProperty(name) }); } else { throw new NoSuchMethodException("No primitive-type setter for property '" + name + "'"); } } catch (NumberFormatException nfe) { throw new SchedulerConfigException( "Could not parse property '" + name + "' into correct data type: " + nfe.toString()); } } }
From source file:edu.amc.sakai.user.SimpleLdapCandidateAttributeMapper.java
/** * Straightforward {@link LdapUserData} to * {@link org.sakaiproject.user.api.UserEdit} field-to-field mapping, including * properties./* ww w . j a v a2 s . c om*/ */ public void mapUserDataOntoUserEdit(LdapUserData userData, UserEdit userEdit) { Properties userDataProperties = userData.getProperties(); ResourceProperties userEditProperties = userEdit.getProperties(); if (userDataProperties != null) { Object o_prop = userDataProperties.get(AttributeMappingConstants.CANDIDATE_ID_ATTR_MAPPING_KEY); if (o_prop != null) { if (o_prop instanceof String) { userEditProperties.addProperty(USER_PROP_CANDIDATE_ID, encryption.encrypt((String) o_prop, candidateIdLength)); } else if (o_prop instanceof List) { Set<String> propertySet = new HashSet<String>(); //remove duplicate values for (String value : (List<String>) o_prop) { propertySet.add(value); } //add candidate ID, if there is only one value if (propertySet.size() == 1) { for (String value : propertySet) { userEditProperties.addProperty(USER_PROP_CANDIDATE_ID, encryption.encrypt(value, candidateIdLength)); } } } userDataProperties.remove(AttributeMappingConstants.CANDIDATE_ID_ATTR_MAPPING_KEY); } o_prop = userDataProperties.get(AttributeMappingConstants.ADDITIONAL_INFO_ATTR_MAPPING_KEY); if (o_prop != null) { if (o_prop instanceof String) { userEditProperties.addPropertyToList(USER_PROP_ADDITIONAL_INFO, encryption.encrypt((String) o_prop, additionalInfoLength)); } else if (o_prop instanceof List) { List<String> propertyList = new ArrayList<String>(); //remove duplicate values (maintain order) for (String value : (List<String>) o_prop) { if (!propertyList.contains(value)) propertyList.add(value); } for (String value : propertyList) { userEditProperties.addPropertyToList(USER_PROP_ADDITIONAL_INFO, encryption.encrypt(value, additionalInfoLength)); } } userDataProperties.remove(AttributeMappingConstants.ADDITIONAL_INFO_ATTR_MAPPING_KEY); } o_prop = userDataProperties.get(AttributeMappingConstants.STUDENT_NUMBER_ATTR_MAPPING_KEY); if (o_prop != null) { if (o_prop instanceof String) { addStudentNumberProperty((String) o_prop, userEditProperties); } else if (o_prop instanceof List) { Set<String> propertySet = new HashSet<>(); //remove duplicate values for (String value : (List<String>) o_prop) { propertySet.add(value); } //add student number, if there is only one value if (propertySet.size() == 1) { for (String value : propertySet) { addStudentNumberProperty(value, userEditProperties); } } } userDataProperties.remove(AttributeMappingConstants.STUDENT_NUMBER_ATTR_MAPPING_KEY); } // Make sure we have a value for the encrypted properties. if (StringUtils.isEmpty(userEditProperties.getProperty(USER_PROP_CANDIDATE_ID))) { userEditProperties.addProperty(USER_PROP_CANDIDATE_ID, encryption.encrypt(EMPTY, candidateIdLength)); } if (userEditProperties.getPropertyList(USER_PROP_ADDITIONAL_INFO) != null && userEditProperties.getPropertyList(USER_PROP_ADDITIONAL_INFO).isEmpty()) { userEditProperties.addPropertyToList(USER_PROP_ADDITIONAL_INFO, encryption.encrypt(EMPTY, additionalInfoLength)); } if (userEditProperties.getPropertyList(USER_PROP_STUDENT_NUMBER) != null && userEditProperties.getPropertyList(USER_PROP_STUDENT_NUMBER).isEmpty()) { addStudentNumberProperty(EMPTY, userEditProperties); } super.mapUserDataOntoUserEdit(userData, userEdit); } }
From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.MergePropertiesMojo.java
private Properties removeEmptyBindings(Properties properties) { ArrayList<String> pars = new ArrayList<String>(); Pattern pNotEmptyBinding = Pattern.compile(regexNotEmptyBinding); Pattern pEmptyBinding = Pattern.compile(regexEmptyBinding); String parName;/* w ww. j a va 2s.c o m*/ Enumeration<Object> e = properties.keys(); // first check if there is at least one non empty binding (non default) while (e.hasMoreElements()) { String key = (String) e.nextElement(); Matcher mNotEmptyBinding = pNotEmptyBinding.matcher(key); if (mNotEmptyBinding.matches()) { parName = mNotEmptyBinding.group(1); if (pars.contains(parName)) continue; pars.add(parName); } } // then delete e = properties.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); Matcher mEmptyBinding = pEmptyBinding.matcher(key); if (mEmptyBinding.matches()) { parName = mEmptyBinding.group(1); if (pars.contains(parName)) { properties.remove(key); } } } return properties; }
From source file:org.apache.openjpa.persistence.AnnotationPersistenceMetaDataSerializer.java
/** * Serialize sequence metadata.//w w w . java2 s . c o m */ protected void serializeSequence(SequenceMetaData meta) { Log log = getLog(); if (log.isInfoEnabled()) log.info(_loc.get("ser-sequence", meta.getName())); AnnotationBuilder ab = addAnnotation(SequenceGenerator.class, meta); ab.add("name", meta.getName()); // parse out the datastore sequence name, if any String plugin = meta.getSequencePlugin(); String clsName = Configurations.getClassName(plugin); String props = Configurations.getProperties(plugin); String ds = null; if (props != null) { Properties map = Configurations.parseProperties(props); ds = (String) map.remove("Sequence"); if (ds != null) { props = Configurations.serializeProperties(map); plugin = Configurations.getPlugin(clsName, props); } } if (ds != null) ab.add("sequenceName", ds); else if (plugin != null && !SequenceMetaData.IMPL_NATIVE.equals(plugin)) ab.add("sequenceName", plugin); if (meta.getInitialValue() != 0 && meta.getInitialValue() != -1) ab.add("initialValue", meta.getInitialValue()); if (meta.getAllocate() != 50 && meta.getAllocate() != -1) ab.add("allocationSize", meta.getAllocate()); if (meta.getSchema() != null) ab.add("schema", meta.getSchema()); if (meta.getCatalog() != null) ab.add("catalog", meta.getCatalog()); }
From source file:org.hyperledger.fabric.sdk.NetworkConfig.java
private Node createNode(String nodeName, JsonObject jsonNode, String urlPropName) throws NetworkConfigurationException { // jsonNode. // if (jsonNode.isNull(urlPropName)) { // return null; // }//from w w w . j a va2s.c o m String url = jsonNode.getString(urlPropName, null); if (url == null) { return null; } Properties props = extractProperties(jsonNode, "grpcOptions"); if (null != props) { String value = props.getProperty("grpc.keepalive_time_ms"); if (null != value) { props.remove("grpc.keepalive_time_ms"); props.put("grpc.NettyChannelBuilderOption.keepAliveTime", new Object[] { new Long(value), TimeUnit.MILLISECONDS }); } value = props.getProperty("grpc.keepalive_timeout_ms"); if (null != value) { props.remove("grpc.keepalive_timeout_ms"); props.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[] { new Long(value), TimeUnit.MILLISECONDS }); } } // Extract the pem details getTLSCerts(nodeName, jsonNode, props); return new Node(nodeName, url, props); }
From source file:org.rhq.enterprise.installer.ServerInformation.java
private void clearNullProperties(Properties props) { // some properties, if blank, must be removed so their defaults are picked up String bindAddr = props.getProperty(ServerProperties.PROP_SERVER_BIND_ADDRESS); if ((bindAddr != null) && (bindAddr.trim().length() == 0)) { props.remove(ServerProperties.PROP_SERVER_BIND_ADDRESS); }//from ww w. j a v a 2s . c o m return; }
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 . j av a 2 s . c om*/ 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.izforge.izpack.util.LogUtils.java
public static void loadConfiguration(final Properties configuration) throws IOException { if (OVERRIDE) { LogManager manager = LogManager.getLogManager(); // Merge global logging properties InputStream baseResourceStream = null; try {/*w w w. ja va 2 s.co m*/ baseResourceStream = LogUtils.class.getResourceAsStream(LOGGING_BASE_CONFIGURATION); final Properties baseProps = new Properties(); baseProps.load(baseResourceStream); mergeLoggingConfiguration(configuration, baseProps); } finally { IOUtils.closeQuietly(baseResourceStream); } boolean mkdirs = false; String pattern = null; if (configuration.getProperty("handlers") != null && configuration.getProperty("handlers").contains(FILEHANDLER_CLASSNAME) && manager.getProperty("handlers").contains(FILEHANDLER_CLASSNAME)) { // IzPack maintains just one log file, don't override the existing handler type of it. // Special use case: Command line argument -logfile "wins" over the <log-file> tag. // Assumption at the moment for optimization: Just FileHandler is used for configurations from install.xml. return; } for (String key : configuration.stringPropertyNames()) { if (key.equals(FILEHANDLER_CLASSNAME + ".pattern")) { // Workaround for not normalized file paths, for example ${INSTALL_PATH}/../install_log/name.log // to get them working before creating ${INSTALL_PATH} in the // com.izforge.izpack.installer.unpacker.UnpackerBase.preUnpack phase // otherwise the FileHandler will fail when opening files already in constructor and not recover from that. pattern = FilenameUtils.normalize(configuration.getProperty(key)); configuration.setProperty(key, pattern); } else if (key.equals(FILEHANDLER_CLASSNAME + ".mkdirs")) { // This key goes beyond the capabilities of java.util.logging.FileHandler mkdirs = Boolean.parseBoolean(configuration.getProperty(key)); configuration.remove(key); } } if (mkdirs && pattern != null) { FileUtils.forceMkdirParent(new File(pattern)); } // Merge user settings compiled in final Properties userProps = new Properties(); InputStream userPropsStream = LogUtils.class .getResourceAsStream(ResourceManager.getInstallLoggingConfigurationResourceName()); try { if (userPropsStream != null) { userProps.load(userPropsStream); for (String userPropName : userProps.stringPropertyNames()) { if (userPropName.endsWith(".level") && !userPropName.startsWith(FILEHANDLER_CLASSNAME)) { String level = userProps.getProperty(userPropName); if (level != null) { configuration.setProperty(userPropName, level); } } } } } finally { IOUtils.closeQuietly(userPropsStream); } InputStream defaultResourceStream = null; try { defaultResourceStream = LogUtils.class.getResourceAsStream(LOGGING_CONFIGURATION); final Properties defaultProps = new Properties(); defaultProps.load(defaultResourceStream); mergeLoggingConfiguration(configuration, defaultProps); } finally { IOUtils.closeQuietly(defaultResourceStream); } if (Debug.isDEBUG()) { configuration.setProperty(FILEHANDLER_CLASSNAME + ".level", Level.FINE.toString()); configuration.setProperty(ConsoleHandler.class.getName() + ".level", Level.FINE.toString()); } // Set general log level which acts as filter in front of all handlers String fileLevelName = configuration.getProperty(FILEHANDLER_CLASSNAME + ".level", Level.ALL.toString()); Level fileLevel = Level.ALL; if (fileLevelName != null) { fileLevel = Level.parse(fileLevelName); } String consoleLevelName = configuration.getProperty(CONSOLEHANDLER_CLASSNAME + ".level", Level.INFO.toString()); Level consoleLevel = Level.INFO; if (consoleLevelName != null) { consoleLevel = Level.parse(consoleLevelName); } configuration.setProperty(".level", (fileLevel.intValue() < consoleLevel.intValue()) ? fileLevelName : consoleLevelName); final PipedOutputStream out = new PipedOutputStream(); final PipedInputStream in = new PipedInputStream(out); try { new Thread(new Runnable() { public void run() { try { configuration.store(out, null); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(out); } } }).start(); manager.readConfiguration(in); } finally { IOUtils.closeQuietly(in); } } }
From source file:org.sonatype.nexus.rt.prefs.FilePreferences.java
@Override protected void flushSpi() throws BackingStoreException { final File file = FilePreferencesFactory.getPreferencesFile(); synchronized (file) { Properties p = new Properties(); try {//w w w. j a va2 s. c o m StringBuilder sb = new StringBuilder(); getPath(sb); String path = sb.toString(); if (file.exists()) { final FileInputStream in = new FileInputStream(file); try { p.load(in); } finally { IOUtils.closeQuietly(in); } List<String> toRemove = new ArrayList<String>(); // Make a list of all direct children of this node to be removed final Enumeration<?> pnen = p.propertyNames(); while (pnen.hasMoreElements()) { String propKey = (String) pnen.nextElement(); if (propKey.startsWith(path)) { String subKey = propKey.substring(path.length()); // Only do immediate descendants if (subKey.indexOf('.') == -1) { toRemove.add(propKey); } } } // Remove them now that the enumeration is done with for (String propKey : toRemove) { p.remove(propKey); } } // If this node hasn't been removed, add back in any values if (!isRemoved) { for (String s : root.keySet()) { p.setProperty(path + s, root.get(s)); } } final FileOutputStream out = new FileOutputStream(file); try { p.store(out, "FilePreferences"); } finally { IOUtils.closeQuietly(out); } } catch (IOException e) { throw new BackingStoreException(e); } } }
From source file:org.ejbca.core.model.ca.catoken.CATokenContainerImpl.java
/** * Common operation for both soft and hard keystores, move the sequences and remove the NEXT key keystring * //from w w w. j a v a2 s. com * @param oldSequence the old sequence that will be moved to "previous" sequence in the properties * @param properties properties parameter content is modified with new and removed properties */ private void activateKeyFixProperties(String oldSequence, Properties properties) { // Set new and previous sequence so we can create link certificates String nextSequence = properties.getProperty(ICAToken.NEXT_SEQUENCE_PROPERTY); if (nextSequence != null) { log.info("Set key sequence from nextSequence: " + nextSequence); setKeySequence(nextSequence); } log.info("Set previous sequence: " + oldSequence); properties.setProperty(ICAToken.PREVIOUS_SEQUENCE_PROPERTY, oldSequence); log.info("Remove nextSequence and nextCertSignKey"); properties.remove(ICAToken.NEXT_SEQUENCE_PROPERTY); properties.remove(KeyStrings.CAKEYPURPOSE_CERTSIGN_STRING_NEXT); }