List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:org.springframework.batch.core.jsr.launch.JsrJobOperator.java
protected Properties getJobRestartProperties(Properties params, org.springframework.batch.core.JobExecution previousJobExecution) { Properties jobRestartProperties = new Properties(); if (previousJobExecution != null) { JobParameters previousJobParameters = previousJobExecution.getJobParameters(); if (previousJobParameters != null && !previousJobParameters.isEmpty()) { jobRestartProperties.putAll(previousJobParameters.toProperties()); }// w ww . j a v a2s . co m } if (params != null) { Enumeration<?> propertyNames = params.propertyNames(); while (propertyNames.hasMoreElements()) { String curName = (String) propertyNames.nextElement(); jobRestartProperties.setProperty(curName, params.getProperty(curName)); } } return jobRestartProperties; }
From source file:org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener.java
/** * Creates a service factory./* w ww . j a v a 2 s. c o m*/ */ private CmisServiceFactory createServiceFactory(String filename) { // load properties InputStream stream = this.getClass().getResourceAsStream(filename); if (stream == null) { log.warn("Cannot find configuration!"); return null; } Properties props = new Properties(); try { props.load(stream); } catch (IOException e) { log.warn("Cannot load configuration: " + e, e); return null; } finally { try { stream.close(); } catch (IOException ioe) { } } // get 'class' property String className = props.getProperty(PROPERTY_CLASS); if (className == null) { log.warn("Configuration doesn't contain the property 'class'!"); return null; } // create a factory instance Object object = null; try { object = Class.forName(className).newInstance(); } catch (Exception e) { log.warn("Could not create a services factory instance: " + e, e); return null; } if (!(object instanceof CmisServiceFactory)) { log.warn("The provided class is not an instance of CmisServiceFactory!"); } CmisServiceFactory factory = (CmisServiceFactory) object; // initialize factory instance Map<String, String> parameters = new HashMap<String, String>(); for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = props.getProperty(key); parameters.put(key, value); } factory.init(parameters); log.info("Initialized Services Factory: " + factory.getClass().getName()); return factory; }
From source file:org.dspace.content.crosswalk.MODSDisseminationCrosswalk.java
/** * Initialize Crosswalk table from a properties file * which itself is the value of the DSpace configuration property * "crosswalk.mods.properties.X", where "X" is the alias name of this instance. * Each instance may be configured with a separate mapping table. * * The MODS crosswalk configuration properties follow the format: * * {field-name} = {XML-fragment} | {XPath} * * 1. qualified DC field name is of the form * {MDschema}.{element}.{qualifier} * * e.g. dc.contributor.author/*from ww w . j a v a 2s . c om*/ * * 2. XML fragment is prototype of metadata element, with empty or "%s" * placeholders for value(s). NOTE: Leave the %s's in becaue * it's much easier then to see if something is broken. * * 3. XPath expression listing point(s) in the above XML where * the value is to be inserted. Context is the element itself. * * Example properties line: * * dc.description.abstract = <mods:abstract>%s</mods:abstract> | text() * */ private void initMap() throws CrosswalkInternalException { if (modsMap != null) { return; } String myAlias = getPluginInstanceName(); if (myAlias == null) { log.error( "Must use PluginManager to instantiate MODSDisseminationCrosswalk so the class knows its name."); return; } String cmPropName = CONFIG_PREFIX + myAlias; String propsFilename = ConfigurationManager.getProperty(cmPropName); if (propsFilename == null) { String msg = "MODS crosswalk missing " + "configuration file for crosswalk named \"" + myAlias + "\""; log.error(msg); throw new CrosswalkInternalException(msg); } else { String parent = ConfigurationManager.getProperty("dspace.dir") + File.separator + "config" + File.separator; File propsFile = new File(parent, propsFilename); Properties modsConfig = new Properties(); FileInputStream pfs = null; try { pfs = new FileInputStream(propsFile); modsConfig.load(pfs); } catch (IOException e) { log.error("Error opening or reading MODS properties file: " + propsFile.toString() + ": " + e.toString()); throw new CrosswalkInternalException("MODS crosswalk cannot " + "open config file: " + e.toString(), e); } finally { if (pfs != null) { try { pfs.close(); } catch (IOException ioe) { } } } modsMap = new HashMap<String, modsTriple>(); Enumeration<String> pe = (Enumeration<String>) modsConfig.propertyNames(); while (pe.hasMoreElements()) { String qdc = pe.nextElement(); String val = modsConfig.getProperty(qdc); String pair[] = val.split("\\s+\\|\\s+", 2); if (pair.length < 2) { log.warn("Illegal MODS mapping in " + propsFile.toString() + ", line = " + qdc + " = " + val); } else { modsTriple trip = modsTriple.create(qdc, pair[0], pair[1]); if (trip != null) { modsMap.put(qdc, trip); } } } } }
From source file:org.dspace.content.crosswalk.QDCCrosswalk.java
/** * Initialize Crosswalk table from a properties file * which itself is the value of the DSpace configuration property * "crosswalk.qdc.properties.X", where "X" is the alias name of this instance. * Each instance may be configured with a separate mapping table. * * The QDC crosswalk configuration properties follow the format: * * {qdc-element} = {XML-fragment}/*from w ww.j av a2 s .co m*/ * * 1. qualified DC field name is of the form (qualifier is optional) * {MDschema}.{element}.{qualifier} * * e.g. dc.contributor.author * dc.title * * 2. XML fragment is prototype of metadata element, with empty * placeholders for value). * * Example properties line: * * dc.coverage.temporal = <dcterms:temporal /> */ private void init() throws CrosswalkException, IOException { if (inited) { return; } inited = true; myName = getPluginInstanceName(); if (myName == null) { throw new CrosswalkInternalException("Cannot determine plugin name, " + "You must use PluginManager to instantiate QDCCrosswalk so the instance knows its name."); } // grovel DSpace configuration for namespaces List<Namespace> nsList = new ArrayList<Namespace>(); Enumeration<String> pe = (Enumeration<String>) ConfigurationManager.propertyNames(); String propname = CONFIG_PREFIX + ".namespace." + myName + "."; while (pe.hasMoreElements()) { String key = pe.nextElement(); if (key.startsWith(propname)) { nsList.add(Namespace.getNamespace(key.substring(propname.length()), ConfigurationManager.getProperty(key))); } } nsList.add(Namespace.XML_NAMESPACE); namespaces = (Namespace[]) nsList.toArray(new Namespace[nsList.size()]); // get XML schemaLocation fragment from config schemaLocation = ConfigurationManager.getProperty(CONFIG_PREFIX + ".schemaLocation." + myName); // read properties String cmPropName = CONFIG_PREFIX + ".properties." + myName; String propsFilename = ConfigurationManager.getProperty(cmPropName); if (propsFilename == null) { throw new CrosswalkInternalException("Configuration error: " + "No properties file configured for QDC crosswalk named \"" + myName + "\""); } String parent = ConfigurationManager.getProperty("dspace.dir") + File.separator + "config" + File.separator; File propsFile = new File(parent, propsFilename); Properties qdcProps = new Properties(); FileInputStream pfs = null; try { pfs = new FileInputStream(propsFile); qdcProps.load(pfs); } finally { if (pfs != null) { try { pfs.close(); } catch (IOException ioe) { } } } // grovel properties to initialize qdc->element and element->qdc maps. // evaluate the XML fragment with a wrapper including namespaces. String postlog = "</wrapper>"; StringBuffer prologb = new StringBuffer("<wrapper"); for (int i = 0; i < namespaces.length; ++i) { prologb.append(" xmlns:"); prologb.append(namespaces[i].getPrefix()); prologb.append("=\""); prologb.append(namespaces[i].getURI()); prologb.append("\""); } prologb.append(">"); String prolog = prologb.toString(); pe = (Enumeration<String>) qdcProps.propertyNames(); while (pe.hasMoreElements()) { String qdc = pe.nextElement(); String val = qdcProps.getProperty(qdc); try { Document d = builder.build(new StringReader(prolog + val + postlog)); Element element = (Element) d.getRootElement().getContent(0); qdc2element.put(qdc, element); element2qdc.put(makeQualifiedTagName(element), qdc); log.debug("Building Maps: qdc=\"" + qdc + "\", element=\"" + element.toString() + "\""); } catch (org.jdom.JDOMException je) { throw new CrosswalkInternalException("Failed parsing XML fragment in properties file: \"" + prolog + val + postlog + "\": " + je.toString(), je); } } }
From source file:com.netflix.blitz4j.LoggingConfiguration.java
/** * Kick start the blitz4j implementation. * //from w w w . j a v a2 s. c om * @param props * - The overriding <em>log4j</em> properties if any. */ public void configure(Properties props) { this.originalAsyncAppenderNameMap.clear(); // First try to load the log4j configuration file from the classpath String log4jConfigurationFile = System.getProperty(PROP_LOG4J_CONFIGURATION); if (log4jConfigurationFile != null) { InputStream in = null; try { URL url = new URL(log4jConfigurationFile); in = url.openStream(); this.props.load(in); } catch (Throwable t) { throw new RuntimeException( "Cannot load log4 configuration file specified in " + PROP_LOG4J_CONFIGURATION, t); } finally { if (in != null) { try { in.close(); } catch (IOException ignore) { } } } } if (props != null) { Enumeration enumeration = props.propertyNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); this.props.setProperty(key, props.getProperty(key)); ConfigurationManager.getConfigInstance().setProperty(key, props.getProperty(key)); } } NFHierarchy nfHierarchy = null; // Make log4j use blitz4j implementations if (blitz4jConfig.shouldUseLockFree() && (!NFHierarchy.class.equals(LogManager.getLoggerRepository().getClass()))) { nfHierarchy = new NFHierarchy(new NFRootLogger(org.apache.log4j.Level.INFO)); org.apache.log4j.LogManager.setRepositorySelector(new NFRepositorySelector(nfHierarchy), guard); } String log4jLoggerFactory = System.getProperty(PROP_LOG4J_LOGGER_FACTORY); if (log4jLoggerFactory != null) { this.props.setProperty(PROP_LOG4J_LOGGER_FACTORY, log4jLoggerFactory); if (nfHierarchy != null) { try { LoggerFactory loggerFactory = (LoggerFactory) Class.forName(log4jLoggerFactory).newInstance(); nfHierarchy.setLoggerFactory(loggerFactory); } catch (Throwable e) { System.err.println("Cannot set the logger factory. Hence reverting to default."); e.printStackTrace(); } } } else { if (blitz4jConfig.shouldUseLockFree()) { this.props.setProperty(PROP_LOG4J_LOGGER_FACTORY, BLITZ_LOGGER_FACTORY); } } String[] asyncAppenderArray = blitz4jConfig.getAsyncAppenders(); if (asyncAppenderArray == null) { return; } for (int i = 0; i < asyncAppenderArray.length; i++) { String oneAppenderName = asyncAppenderArray[i]; if (i == 0) { continue; } String oneAsyncAppenderName = oneAppenderName + ASYNC_APPENDERNAME_SUFFIX; originalAsyncAppenderNameMap.put(oneAppenderName, oneAsyncAppenderName); } try { convertConfiguredAppendersToAsync(this.props); } catch (Throwable e) { throw new RuntimeException("Could not configure async appenders ", e); } PropertyConfigurator.configure(this.props); closeNonexistingAsyncAppenders(); this.logger = org.slf4j.LoggerFactory.getLogger(LoggingConfiguration.class); ConfigurationManager.getConfigInstance() .addConfigurationListener(new ExpandedConfigurationListenerAdapter(this)); }
From source file:org.jboss.dashboard.ui.resources.GraphicElement.java
/** * Process the element descriptor inside the zip file, and set properties for given graphic element. * * @throws java.io.IOException// w ww . j a v a2s. c o m */ protected void deploy() throws Exception { Properties prop = new Properties(); resources = new HashMap<String, Map<String, String>>(); InputStream in = new BufferedInputStream(new FileInputStream(tmpZipFile)); ZipInputStream zin = null; try { zin = new ZipInputStream(in); ZipEntry e; while ((e = zin.getNextEntry()) != null) { if (getDescriptorFileName().equals(e.getName())) { prop.load(zin); } } } finally { if (zin != null) zin.close(); } if (prop.isEmpty()) { log.error("No properties inside descriptor " + getDescriptorFileName() + " for item with id " + id); } Enumeration properties = prop.propertyNames(); String[] languages = getLocaleManager().getAllLanguages(); while (properties.hasMoreElements()) { String propName = (String) properties.nextElement(); if (propName.startsWith("name.")) { String lang = propName.substring(propName.lastIndexOf(".") + 1); setDescription(prop.getProperty(propName), lang); log.debug("Look-and-feel name (" + lang + "): " + prop.getProperty(propName)); } else if (propName.startsWith("resource.")) { String resourceName = propName.substring("resource.".length()); String langId = null; for (int i = 0; i < languages.length; i++) { String lngId = languages[i]; if (resourceName.startsWith(lngId + ".")) { langId = lngId; resourceName = resourceName.substring(langId.length() + 1); break; } } String resourcePath = prop.getProperty(propName); Map<String, String> existingResource = resources.get(resourceName); if (existingResource == null) resources.put(resourceName, existingResource = new HashMap<String, String>()); existingResource.put(langId, resourcePath); } else { log.error("Unknown property in descriptor " + propName); } } log.debug("Loaded Graphic element description" + getDescription()); log.debug("Loaded Graphic element resources: " + resources); }
From source file:org.lnicholls.galleon.server.Server.java
private void printSystemProperties() { Properties properties = System.getProperties(); Enumeration Enumeration = properties.propertyNames(); for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { String propertyName = (String) e.nextElement(); log.info(propertyName + "=" + System.getProperty(propertyName)); }//from www . jav a 2 s. c om }
From source file:org.apache.directory.fortress.core.ldap.ApacheDsDataProvider.java
/** * Given a collection of {@link java.util.Properties}, convert to raw data name-value format and load into ldap * modification set in preparation for ldap modify. * * @param props contains {@link java.util.Properties} targeted for removal from ldap. * @param mods ldap modification set containing name-value pairs in raw ldap format to be removed. * @param attrName contains the name of the ldap attribute to be removed. *///from w w w . j av a 2 s . c o m protected void removeProperties(Properties props, List<Modification> mods, String attrName) { if (props != null && props.size() > 0) { for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String val = props.getProperty(key); // This LDAP attr is stored as a name-value pair separated by a ':'. mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attrName, key + GlobalIds.PROP_SEP + val)); } } }
From source file:org.executequery.gui.browser.ConnectionPanel.java
/** * Sets the values of the current database connection * within the jdbc properties table./*from ww w .j a va 2 s . com*/ */ private void setJdbcProperties() { advancedProperties = new String[20][2]; Properties properties = databaseConnection.getJdbcProperties(); if (properties == null || properties.size() == 0) { model.fireTableDataChanged(); return; } int count = 0; for (Enumeration<?> i = properties.propertyNames(); i.hasMoreElements();) { String name = (String) i.nextElement(); if (!name.equalsIgnoreCase("password")) { advancedProperties[count][0] = name; advancedProperties[count][1] = properties.getProperty(name); count++; } } model.fireTableDataChanged(); }
From source file:com.krawler.portal.util.SystemProperties.java
private SystemProperties() { Properties p = new Properties(); ClassLoader classLoader = getClass().getClassLoader(); // system.properties try {//from w ww. j a v a 2s . c o m URL url = classLoader.getResource("system.properties"); if (url != null) { InputStream is = url.openStream(); p.load(is); is.close(); logger.debug("Loading " + url); } } catch (Exception e) { logger.warn(e.getMessage(), e); } // system-ext.properties try { URL url = classLoader.getResource("system-ext.properties"); if (url != null) { InputStream is = url.openStream(); p.load(is); is.close(); logger.debug("Loading " + url); } } catch (Exception e) { logger.warn(e.getMessage(), e); } // Set environment properties SystemEnv.setProperties(p); // Set system properties boolean systemPropertiesLoad = GetterUtil.getBoolean(System.getProperty(SYSTEM_PROPERTIES_LOAD), true); boolean systemPropertiesFinal = GetterUtil.getBoolean(System.getProperty(SYSTEM_PROPERTIES_FINAL), true); if (systemPropertiesLoad) { Enumeration<String> enu = (Enumeration<String>) p.propertyNames(); while (enu.hasMoreElements()) { String key = enu.nextElement(); if (systemPropertiesFinal || Validator.isNull(System.getProperty(key))) { System.setProperty(key, p.getProperty(key)); } } } _props = new ConcurrentHashMap<String, String>(); // Use a fast concurrent hash map implementation instead of the slower // java.util.Properties PropertiesUtil.fromProperties(p, _props); }