List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:org.nuxeo.launcher.config.ConfigurationGenerator.java
/** * @since 5.6//from w w w. j a va2s.c o m * @param props Properties object to be filled * @param propsIS Properties InputStream * @throws IOException */ public static void loadTrimmedProperties(Properties props, InputStream propsIS) throws IOException { if (props == null) { return; } Properties p = new Properties(); p.load(propsIS); @SuppressWarnings("unchecked") Enumeration<String> pEnum = (Enumeration<String>) p.propertyNames(); while (pEnum.hasMoreElements()) { String key = pEnum.nextElement(); String value = p.getProperty(key); props.put(key.trim(), value.trim()); } }
From source file:org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.java
/** * Registers the node types defined in the given input stream depending * on the content type specified for the stream. This will also register * any namespaces identified in the input stream if they have not already * been registered./* ww w . j a va 2 s . c o m*/ * * @param in node type XML stream * @param contentType type of the input stream * @param reregisterExisting flag indicating whether node types should be * reregistered if they already exist * @return registered node types * @throws IOException if the input stream could not be read or parsed * @throws RepositoryException if the node types are invalid or another * repository error occurs */ public NodeType[] registerNodeTypes(InputStream in, String contentType, boolean reregisterExisting) throws IOException, RepositoryException { try { Map namespaceMap = new HashMap(); List nodeTypeDefs = new ArrayList(); if (contentType.equalsIgnoreCase(TEXT_XML) || contentType.equalsIgnoreCase(APPLICATION_XML)) { try { NodeTypeReader ntr = new NodeTypeReader(in); Properties namespaces = ntr.getNamespaces(); if (namespaces != null) { Enumeration prefixes = namespaces.propertyNames(); while (prefixes.hasMoreElements()) { String prefix = (String) prefixes.nextElement(); String uri = namespaces.getProperty(prefix); namespaceMap.put(prefix, uri); } } NodeTypeDef[] defs = ntr.getNodeTypeDefs(); nodeTypeDefs.addAll(Arrays.asList(defs)); } catch (NameException e) { throw new RepositoryException("Illegal JCR name", e); } } else if (contentType.equalsIgnoreCase(TEXT_X_JCR_CND)) { try { NamespaceMapping mapping = new NamespaceMapping(session); CompactNodeTypeDefReader reader = new CompactNodeTypeDefReader(new InputStreamReader(in), "cnd input stream", mapping); namespaceMap.putAll(mapping.getPrefixToURIMapping()); nodeTypeDefs.addAll(reader.getNodeTypeDefs()); } catch (ParseException e) { throw new IOException(e.getMessage()); } } else { throw new UnsupportedRepositoryOperationException("Unsupported content type: " + contentType); } new NamespaceHelper(session).registerNamespaces(namespaceMap); if (reregisterExisting) { // split the node types into new and already registered node types. // this way we can register new node types together with already // registered node types which make circular dependencies possible List newNodeTypeDefs = new ArrayList(); List registeredNodeTypeDefs = new ArrayList(); for (Iterator iter = nodeTypeDefs.iterator(); iter.hasNext();) { NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next(); if (ntReg.isRegistered(nodeTypeDef.getName())) { registeredNodeTypeDefs.add(nodeTypeDef); } else { newNodeTypeDefs.add(nodeTypeDef); } } ArrayList nodeTypes = new ArrayList(); // register new node types nodeTypes.addAll(registerNodeTypes(newNodeTypeDefs)); // reregister already existing node types for (Iterator iter = registeredNodeTypeDefs.iterator(); iter.hasNext();) { NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next(); ntReg.reregisterNodeType(nodeTypeDef); nodeTypes.add(getNodeType(nodeTypeDef.getName())); } return (NodeType[]) nodeTypes.toArray(new NodeType[nodeTypes.size()]); } else { Collection types = registerNodeTypes(nodeTypeDefs); return (NodeType[]) types.toArray(new NodeType[types.size()]); } } catch (InvalidNodeTypeDefException e) { throw new RepositoryException("Invalid node type definition", e); } }
From source file:org.xwiki.localization.internal.AbstractWikiBundle.java
/** * <p>// ww w. jav a 2 s. co m * Loads the translations defined in a document into an existing {@link Properties} object. Old values from the * passed Properties are overwritten when translations are found in the document content. * </p> * <p> * Since the Properties {@link Properties#load(InputStream) load} method always assumes the stream contains only * ISO-8859-1 characters, we need to embed somehow Unicode characters outside the 8859-1 encoding into the input * stream. We achieve this by explicitly splitting the content into UTF-8 bytes, which are then read as a byte * stream. When loaded, the properties are wrongly created by interpreting those bytes are ISO-8859-1 characters, so * we must re-split and re-combine each property back into the UTF-8 encoding. Although this is time consuming, the * alternative is to re-implement the Properties class so that it accepts a proper character input stream. And * besides, resources are supposed to be loaded only once in real live wikis. * </p> * * @param props The {@link Properties} object to enhance. It is modified inside the method body. * @param content The content from which to load translations. * @param documentName The name of the container wiki document. Needed for logging only. * @return The enhanced properties file, the same object as the <tt>props</tt> parameter. */ protected Properties loadPropertiesFromString(Properties props, String content, String documentName) { byte[] bcontent; Properties temp = new Properties(); try { // We force splitting into UTF-8 since it is supposed to be available on all platforms, and it can represent // all unicode characters. bcontent = content.getBytes(UNICODE_BYTE_ENCODING); } catch (UnsupportedEncodingException ex) { // This should not happen, ever! If it does, there is something wrong in the system. getLogger().error("Error splitting a document resource bundle into bytes using the UTF-8 encoding", ex); bcontent = content.getBytes(); } InputStream is = new ByteArrayInputStream(bcontent); try { temp.load(is); // Adds new properties into the existing object, overriding old values, but not clearing completely. for (Enumeration<?> keys = temp.propertyNames(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); props.setProperty(key, new String(temp.getProperty(key).getBytes(DEFAULT_RESOURCE_BYTE_ENCODING), UNICODE_BYTE_ENCODING)); } } catch (IOException ex) { // Cannot do anything more getLogger().error("Invalid document resource bundle: [{0}]", ex, documentName); } return props; }
From source file:org.apache.easyant.core.EasyAntMain.java
/** * Load the property files specified by -propertyfile *//* w w w. j av a 2 s . com*/ private void loadPropertyFiles() { for (String filename : propertyFiles) { Properties props = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(filename); props.load(fis); } catch (IOException e) { System.out.println("Could not load property file " + filename + ": " + e.getMessage()); } finally { FileUtils.close(fis); } // ensure that -D properties take precedence Enumeration<?> properties = props.propertyNames(); while (properties.hasMoreElements()) { String name = (String) properties.nextElement(); if (easyAntConfiguration.getDefinedProps().getProperty(name) == null) { easyAntConfiguration.getDefinedProps().put(name, props.getProperty(name)); } } } }
From source file:org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.java
/** * Registers the node types defined in the given input stream depending * on the content type specified for the stream. This will also register * any namespaces identified in the input stream if they have not already * been registered./*from w ww . ja va 2s. com*/ * * @param in node type XML stream * @param contentType type of the input stream * @param reregisterExisting flag indicating whether node types should be * reregistered if they already exist * @return registered node types * @throws IOException if the input stream could not be read or parsed * @throws RepositoryException if the node types are invalid or another * repository error occurs */ public NodeType[] registerNodeTypes(InputStream in, String contentType, boolean reregisterExisting) throws IOException, RepositoryException { try { Map namespaceMap = new HashMap(); List nodeTypeDefs = new ArrayList(); if (contentType.equalsIgnoreCase(TEXT_XML) || contentType.equalsIgnoreCase(APPLICATION_XML)) { try { NodeTypeReader ntr = new NodeTypeReader(in); Properties namespaces = ntr.getNamespaces(); if (namespaces != null) { Enumeration prefixes = namespaces.propertyNames(); while (prefixes.hasMoreElements()) { String prefix = (String) prefixes.nextElement(); String uri = namespaces.getProperty(prefix); namespaceMap.put(prefix, uri); } } NodeTypeDef[] defs = ntr.getNodeTypeDefs(); nodeTypeDefs.addAll(Arrays.asList(defs)); } catch (NameException e) { throw new RepositoryException("Illegal JCR name", e); } } else if (contentType.equalsIgnoreCase(TEXT_X_JCR_CND)) { try { NamespaceMapping mapping = new NamespaceMapping(nsResolver); CompactNodeTypeDefReader reader = new CompactNodeTypeDefReader(new InputStreamReader(in), "cnd input stream", mapping); namespaceMap.putAll(mapping.getPrefixToURIMapping()); nodeTypeDefs.addAll(reader.getNodeTypeDefs()); } catch (ParseException e) { throw new IOException(e.getMessage()); } } else { throw new UnsupportedRepositoryOperationException("Unsupported content type: " + contentType); } Iterator iterator = namespaceMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry) iterator.next(); nsReg.safeRegisterNamespace((String) entry.getKey(), (String) entry.getValue()); } if (reregisterExisting) { // split the node types into new and already registered node types. // this way we can register new node types together with already // registered node types which make circular dependencies possible List newNodeTypeDefs = new ArrayList(); List registeredNodeTypeDefs = new ArrayList(); for (Iterator iter = nodeTypeDefs.iterator(); iter.hasNext();) { NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next(); if (ntReg.isRegistered(nodeTypeDef.getName())) { registeredNodeTypeDefs.add(nodeTypeDef); } else { newNodeTypeDefs.add(nodeTypeDef); } } ArrayList nodeTypes = new ArrayList(); // register new node types nodeTypes.addAll(registerNodeTypes(newNodeTypeDefs)); // reregister already existing node types for (Iterator iter = registeredNodeTypeDefs.iterator(); iter.hasNext();) { NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next(); ntReg.reregisterNodeType(nodeTypeDef); nodeTypes.add(getNodeType(nodeTypeDef.getName())); } return (NodeType[]) nodeTypes.toArray(new NodeType[nodeTypes.size()]); } else { Collection types = registerNodeTypes(nodeTypeDefs); return (NodeType[]) types.toArray(new NodeType[types.size()]); } } catch (InvalidNodeTypeDefException e) { throw new RepositoryException("Invalid node type definition", e); } }
From source file:org.nuxeo.theme.editor.Main.java
public static List<StyleFieldProperty> getStylePropertiesForSelectedElement() { Style style = getStyleOfSelectedElement(); Style selectedStyleLayer = getSelectedStyleLayer(); if (selectedStyleLayer != null) { style = selectedStyleLayer;/*from w w w . j ava2 s . co m*/ } List<StyleFieldProperty> fieldProperties = new ArrayList<StyleFieldProperty>(); if (style == null) { return fieldProperties; } String path = getSelectedStyleSelector(); if (path == null) { return fieldProperties; } String viewName = getViewNameOfSelectedElement(); if (style.getName() != null) { viewName = "*"; } Properties properties = style.getPropertiesFor(viewName, path); int idx = 0; Properties cssProperties = org.nuxeo.theme.html.CSSUtils.getCssProperties(); if (properties != null) { Enumeration<?> propertyNames = properties.propertyNames(); while (propertyNames.hasMoreElements()) { String name = (String) propertyNames.nextElement(); String value = properties.getProperty(name, ""); String type = cssProperties.getProperty(name, ""); String id = "p" + idx; fieldProperties.add(new StyleFieldProperty(name, value, type, id)); idx += 1; } } return fieldProperties; }
From source file:org.springframework.boot.SpringApplication.java
/** * Convenient alternative to {@link #setDefaultProperties(Map)}. * @param defaultProperties some {@link Properties} *///from w ww .ja v a 2 s . co m public void setDefaultProperties(Properties defaultProperties) { this.defaultProperties = new HashMap<String, Object>(); for (Object key : Collections.list(defaultProperties.propertyNames())) { this.defaultProperties.put((String) key, defaultProperties.get(key)); } }
From source file:org.intermine.bio.dataconversion.GoConverter.java
private void readConfig() { Properties props = new Properties(); try {//w w w.j ava 2s . co m props.load(getClass().getClassLoader().getResourceAsStream(PROP_FILE)); } catch (IOException e) { throw new RuntimeException("Problem loading properties '" + PROP_FILE + "'", e); } Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String key = (String) propNames.nextElement(); // human annotation from UniProt as gene if ("isHumanTypeAnnotatedAsGene".equals(key)) { if ("true".equals((String) props.get(key))) { isHumanTypeAnnotatedAsGene = true; } continue; } String taxonId = key.substring(0, key.indexOf(".")); Properties taxonProps = PropertiesUtil.stripStart(taxonId, PropertiesUtil.getPropertiesStartingWith(taxonId, props)); String identifier = taxonProps.getProperty("identifier"); if (identifier == null) { throw new IllegalArgumentException("Unable to find geneAttribute property for " + "taxon: " + taxonId + " in file: " + PROP_FILE); } if (!("symbol".equals(identifier) || "primaryIdentifier".equals(identifier) || "secondaryIdentifier".equals(identifier) || "primaryAccession".equals(identifier))) { throw new IllegalArgumentException( "Invalid identifier value for taxon: " + taxonId + " was: " + identifier); } String readColumn = taxonProps.getProperty("readColumn"); if (readColumn != null) { readColumn = readColumn.trim(); if (!("symbol".equals(readColumn) || "identifier".equals(readColumn))) { throw new IllegalArgumentException( "Invalid readColumn value for taxon: " + taxonId + " was: " + readColumn); } } String annotationType = taxonProps.getProperty("typeAnnotated"); if (annotationType == null) { LOG.info("Unable to find annotationType property for " + "taxon: " + taxonId + " in file: " + PROP_FILE + ". Creating genes by default."); } Config config = new Config(identifier, readColumn, annotationType); configs.put(taxonId, config); } // human annotation from UniProt as gene if (isHumanTypeAnnotatedAsGene) { configs.put(HUMAN, proteinToGeneConfig); } }
From source file:org.ops4j.gaderian.parse.DescriptorParser.java
private void initializeFromProperties(Properties p) { Enumeration e = p.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = p.getProperty(key); initializeFromProperty(key, value); }/*from w w w.j a va 2 s . com*/ }
From source file:org.owasp.dependencycheck.utils.Settings.java
/** * Logs the properties. This will not log any properties that contain * 'password' in the key./*from w w w . j a v a2s . c o m*/ * * @param header the header to print with the log message * @param properties the properties to log */ private void logProperties(String header, Properties properties) { if (LOGGER.isDebugEnabled()) { final StringWriter sw = new StringWriter(); try (PrintWriter pw = new PrintWriter(sw)) { pw.format("%s:%n%n", header); final Enumeration<?> e = properties.propertyNames(); while (e.hasMoreElements()) { final String key = (String) e.nextElement(); if (key.contains("password")) { pw.format("%s='*****'%n", key); } else { final String value = properties.getProperty(key); if (value != null) { pw.format("%s='%s'%n", key, value); } } } pw.flush(); LOGGER.debug(sw.toString()); } } }