List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:edu.indiana.lib.osid.base.loader.OsidLoader.java
/** * Returns an instance of the org.osid.OsidManager of the OSID specified by the OSID * package org.osid.OsidManager interface name and the implementation package name. * The implementation class name is constructed from the SID package * Manager interface name. A configuration file name is constructed in a * similar manner and if the file exists it is loaded into the * implementation's org.osid.OsidManager's configuration. * * <p>/*from w w w . j a v a2 s . c o m*/ * Example: To load an implementation of the org.osid.Filing OSID * implemented in a package "xyz", one would use: * </p> * * <p> * org.osid.filing.FilingManager fm = * (org.osid.filing.FilingManager)org.osid.OsidLoader.getManager( * </p> * * <p> * "org.osid.filing.FilingManager" , * </p> * * <p> * "xyz" , * </p> * * <p> * new org.osid.OsidContext()); * </p> * * @param osidPackageManagerName osidPackageManagerName is a fully * qualified org.osid.OsidManager interface name * @param implPackageName implPackageName is a fully qualified * implementation package name * @param context * @param additionalConfiguration * * @return org.osid.OsidManager * * @throws org.osid.OsidException An exception with one of the following * messages defined in org.osid.OsidException: {@link * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED}, * {@link org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}, * {@link org.osid.OsidException#VERSION_ERROR VERSION_ERROR}, * ={@link org.osid.OsidException#INTERFACE_NOT_FOUND * INTERFACE_NOT_FOUND}, ={@link * org.osid.OsidException#MANAGER_NOT_FOUND MANAGER_NOT_FOUND}, * ={@link org.osid.OsidException#MANAGER_INSTANTIATION_ERROR * MANAGER_INSTANTIATION_ERROR}, ={@link * org.osid.OsidException#ERROR_ASSIGNING_CONTEXT * ERROR_ASSIGNING_CONTEXT}, ={@link * org.osid.OsidException#ERROR_ASSIGNING_CONFIGURATION * ERROR_ASSIGNING_CONFIGURATION} */ public static org.osid.OsidManager getManager(String osidPackageManagerName, String implPackageName, org.osid.OsidContext context, java.util.Properties additionalConfiguration) throws org.osid.OsidException { try { if ((null != context) && (null != osidPackageManagerName) && (null != implPackageName)) { String osidInterfaceName = osidPackageManagerName; String className = makeClassName(osidPackageManagerName); String managerClassName = makeFullyQualifiedClassName(implPackageName, className); Class osidInterface = Class.forName(osidInterfaceName); if (null != osidInterface) { Class managerClass = Class.forName(managerClassName); if (null != managerClass) { if (osidInterface.isAssignableFrom(managerClass)) { org.osid.OsidManager manager = (org.osid.OsidManager) managerClass.newInstance(); if (null != manager) { try { manager.osidVersion_2_0(); } catch (Throwable ex) { throw new org.osid.OsidException(org.osid.OsidException.VERSION_ERROR); } try { manager.assignOsidContext(context); } catch (Exception ex) { throw new org.osid.OsidException( org.osid.OsidException.ERROR_ASSIGNING_CONTEXT); } try { java.util.Properties configuration = getConfiguration(manager); if (null == configuration) { configuration = new java.util.Properties(); } if (null != additionalConfiguration) { java.util.Enumeration enumer = additionalConfiguration.propertyNames(); while (enumer.hasMoreElements()) { java.io.Serializable key = (java.io.Serializable) enumer.nextElement(); if (null != key) { java.io.Serializable value = (java.io.Serializable) additionalConfiguration .get(key); if (null != value) { configuration.put(key, value); } } } } manager.assignConfiguration(configuration); return manager; } catch (Exception ex) { throw new org.osid.OsidException( org.osid.OsidException.ERROR_ASSIGNING_CONFIGURATION); } } throw new org.osid.OsidException(org.osid.OsidException.MANAGER_INSTANTIATION_ERROR); } throw new org.osid.OsidException(org.osid.OsidException.MANAGER_NOT_OSID_IMPLEMENTATION); } throw new org.osid.OsidException(org.osid.OsidException.MANAGER_NOT_FOUND); } throw new org.osid.OsidException(org.osid.OsidException.INTERFACE_NOT_FOUND); } throw new org.osid.OsidException(org.osid.OsidException.NULL_ARGUMENT); } catch (org.osid.OsidException oex) { oex.printStackTrace(); throw new org.osid.OsidException(oex.getMessage()); } catch (java.lang.Throwable ex) { ex.printStackTrace(); throw new org.osid.OsidException(org.osid.OsidException.OPERATION_FAILED); } }
From source file:org.smartfrog.avalanche.client.sf.apps.gnubuild.BuildUtils.java
public void configure(Properties confOptions, String envp[]) throws GNUBuildException { if (!instDir.exists()) { log.error("The directory " + installerDir + " does not exist"); throw new GNUBuildException("The directory " + installerDir + " does not exist"); }/* w w w . j av a 2s. c o m*/ if (!instDir.isDirectory()) { log.error(installerDir + " is not a directory"); throw new GNUBuildException(installerDir + " is not a directory"); } if (!instDir.canRead()) { log.error("The directory " + installerDir + " does not have read permissions"); throw new GNUBuildException("The directory " + installerDir + " does not have read permissions"); } if (!instDir.canWrite()) { log.error("The directory " + installerDir + " does not have write permissions"); throw new GNUBuildException("The directory " + installerDir + " does not have write permissions"); } String cmd = new String(installerDir + File.separatorChar + "configure"); File f = new File(cmd); if (!f.exists()) { // This is to make sure if configure is not present then config is used cmd = installerDir + File.separatorChar + "config"; } Enumeration e = confOptions.propertyNames(); String options = null; while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = confOptions.getProperty(key); if (value.length() != 0) options = " " + key + "=" + value + " "; else options = " " + key + " "; cmd = cmd + options; } log.info("Command : " + cmd); boolean success = true; BufferedReader cmdError = null; BufferedReader cmdOutput = null; try { Process p = rt.exec(cmd, envp, instDir); /*String line = null; while ((line = cmdError.readLine()) != null) { log.info("CmdError : " + line); } while ((line = cmdOutput.readLine()) != null) { log.info("CmdOutput : " + line); }*/ cmdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); cmdOutput = new BufferedReader(new InputStreamReader(p.getInputStream())); StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR"); StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT"); errorGobbler.start(); outputGobbler.start(); int exitVal = 0; exitVal = p.waitFor(); //log.info("Exit Value : " + exitVal); if (exitVal != 0) { log.error("Error in running configure"); throw new GNUBuildException("Error in running configure"); } } catch (InterruptedException ie) { log.error(ie); throw new GNUBuildException(ie); } catch (IOException ioe) { success = false; log.error(ioe); throw new GNUBuildException(ioe); } finally { try { cmdError.close(); cmdOutput.close(); } catch (IOException ioe) { success = false; log.error(ioe); throw new GNUBuildException(ioe); } } }
From source file:org.rhq.bundle.ant.AntMain.java
/** Load the property files specified by -propertyfile */ private void loadPropertyFiles() { for (int propertyFileIndex = 0; propertyFileIndex < propertyFiles.size(); propertyFileIndex++) { String filename = (String) propertyFiles.elementAt(propertyFileIndex); Properties props = new Properties(); FileInputStream fis = null; try {/* ww w . jav a 2 s . c o m*/ 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 propertyNames = props.propertyNames(); while (propertyNames.hasMoreElements()) { String name = (String) propertyNames.nextElement(); if (definedProps.getProperty(name) == null) { definedProps.put(name, props.getProperty(name)); } } } }
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 add. * * @param props contains {@link java.util.Properties} targeted for adding to ldap. * @param entry contains ldap entry to push attrs into. * @param attrName contains the name of the ldap attribute to be added. * @param separator contains the char value used to separate name and value in ldap raw format. * @throws LdapException//from w ww.j ava 2s. com */ protected void loadProperties(Properties props, Entry entry, String attrName, char separator) throws LdapException { if (props != null && props.size() > 0) { Attribute attr = null; for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) { // This LDAP attr is stored as a name-value pair separated by a ':'. String key = (String) e.nextElement(); String val = props.getProperty(key); String prop = key + separator + val; if (attr == null) { attr = new DefaultAttribute(attrName); } else { attr.add(prop); } } if (attr != null) { entry.add(attr); } } }
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 add. * * @param props contains {@link java.util.Properties} targeted for adding to ldap. * @param entry contains ldap entry to pull attrs from. * @param attrName contains the name of the ldap attribute to be added. * @throws LdapException//from www.j a v a 2s. c o m */ protected void loadProperties(Properties props, Entry entry, String attrName) throws LdapException { if ((props != null) && (props.size() > 0)) { Attribute attr = new DefaultAttribute(attrName); for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) { // This LDAP attr is stored as a name-value pair separated by a ':'. String key = (String) e.nextElement(); String val = props.getProperty(key); String prop = key + GlobalIds.PROP_SEP + val; attr.add(prop); } if (attr.size() != 0) { entry.add(attr); } } }
From source file:org.jahia.utils.maven.plugin.osgi.BuildFrameworkPackageListMojoTest.java
@Test public void testPackageListBuilding() throws IOException, MojoFailureException, MojoExecutionException, Exception { BuildFrameworkPackageListMojo mojo = new BuildFrameworkPackageListMojo(); String tmpDirLocation = System.getProperty("java.io.tmpdir"); File tmpDirTestLocation = new File(tmpDirLocation, "test-" + System.currentTimeMillis()); tmpDirTestLocation.mkdirs();/*from w w w . j a v a2s . co m*/ File manifestFile = new File(tmpDirTestLocation, "MANIFEST.MF"); File propertiesInputFile = new File(tmpDirTestLocation, "felix-framework.properties"); File propertiesOutputFile = new File(tmpDirTestLocation, "felix-framework-generated.properties"); copyClassLoaderResourceToFile("org/jahia/utils/maven/plugin/osgi/MANIFEST.MF", manifestFile); copyClassLoaderResourceToFile("org/jahia/utils/maven/plugin/osgi/felix-framework.properties", propertiesInputFile); mojo.inputManifestFile = manifestFile; mojo.propertiesInputFile = propertiesInputFile; mojo.propertiesOutputFile = propertiesOutputFile; List<String> manualPackageList = new ArrayList<String>(); manualPackageList.add("javax.servlet;version=\"3.0\""); mojo.manualPackageList = manualPackageList; List<String> artifactExcludes = new ArrayList<String>(); artifactExcludes.add("org.jahia.modules:*"); artifactExcludes.add("org.jahia.templates:*"); artifactExcludes.add("org.jahia.test:*"); artifactExcludes.add("*.jahia.modules"); mojo.artifactExcludes = artifactExcludes; List<String> packageExcludes = new ArrayList<String>(); packageExcludes.add("groovy.grape*"); packageExcludes.add("org.jahia.taglibs.*"); packageExcludes.add("org.apache.taglibs.*"); packageExcludes.add("javax.servlet.jsp*"); mojo.packageExcludes = packageExcludes; mojo.execute(); manifestFile.delete(); propertiesInputFile.delete(); Properties properties = new Properties(); FileReader reader = new FileReader(propertiesOutputFile); try { properties.load(reader); } finally { IOUtils.closeQuietly(reader); } String systemPackagePropValue = properties.getProperty(mojo.propertyFilePropertyName); Assert.assertTrue("Couldn't find system package list property value ", systemPackagePropValue != null); Assert.assertTrue("System package list should not end with comma", systemPackagePropValue.charAt(systemPackagePropValue.length() - 1) != ','); ManifestElement[] manifestElements = ManifestElement.parseHeader("Export-Package", systemPackagePropValue); for (ManifestElement manifestElement : manifestElements) { String[] packageNames = manifestElement.getValueComponents(); manifestElement.getAttribute("version"); for (String packageName : packageNames) { Assert.assertTrue("Package should have been excluded", !packageName.contains("groovy.grape")); Assert.assertTrue("Package should have been excluded", !packageName.contains("javax.servlet.jsp")); Assert.assertTrue("Package should have been excluded", !packageName.contains("org.jahia.taglibs*")); // System.out.println(packageName + " version=" + version); } } Enumeration<?> propertyNames = properties.propertyNames(); while (propertyNames.hasMoreElements()) { String propertyName = (String) propertyNames.nextElement(); if (propertyName.contains(";version")) { Assert.assertTrue( "Found property with ;version in it, probably a missing comma from another multi-valued property: " + propertyName, false); } } FileUtils.deleteDirectory(tmpDirTestLocation); }
From source file:com.npower.dm.hibernate.management.ModelManagementBeanImpl.java
/** * Store the properties into ModelEntity's DM Properties. Old properties will * be replaced by the props./*www. j a va 2s . c om*/ * * @param props * Properties * @throws DMException */ public void setDMProperties(Model model, Properties props) throws DMException { Properties newProps = props; Set<ModelDMProperty> set = ((ModelEntity) model).getModelDMProps(); Session session = this.getHibernateSession(); if (!set.isEmpty()) { for (Iterator<ModelDMProperty> i = set.iterator(); i.hasNext();) { session.delete(i.next()); } } set.clear(); Enumeration<?> names = newProps.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = newProps.getProperty(name); ModelDMPropertyID id = new ModelDMPropertyID(); id.setModelId(model.getID()); id.setPropName(name); ModelDMProperty prop = new ModelDMProperty(id, model, value); session.save(prop); set.add(prop); } }
From source file:com.ecyrd.jspwiki.parser.JSPWikiMarkupParser.java
/** * Figure out which image suffixes should be inlined. * @return Collection of Strings with patterns. * /* ww w. java2 s.c o m*/ * @param engine The WikiEngine from which the patterns are read. */ // FIXME: Does not belong here; should be elsewhere public static Collection getImagePatterns(WikiEngine engine) { Properties props = engine.getWikiProperties(); ArrayList<String> ptrnlist = new ArrayList<String>(); for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); if (name.startsWith(PROP_INLINEIMAGEPTRN)) { String ptrn = TextUtil.getStringProperty(props, name, null); ptrnlist.add(ptrn); } } if (ptrnlist.size() == 0) { ptrnlist.add(DEFAULT_INLINEPATTERN); } return ptrnlist; }
From source file:com.npower.dm.hibernate.management.ModelManagementBeanImpl.java
/** * Store the properties into ModelEntity's DMBootstrap Properties. Old * properties will be replaced by the props. * //from ww w . ja v a 2 s . c o m * @param props * Properties * @throws DMException */ public void setDMBootstrapProperties(Model model, Properties props) throws DMException { Properties newProps = props; Set<DMBootstrapProperty> set = ((ModelEntity) model).getModelDMBootProps(); Session session = this.getHibernateSession(); if (!set.isEmpty()) { for (Iterator<DMBootstrapProperty> i = set.iterator(); i.hasNext();) { session.delete(i.next()); } } set.clear(); Enumeration<?> names = newProps.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = newProps.getProperty(name); DMBootstrapPropertyID id = new DMBootstrapPropertyID(); id.setModelId(model.getID()); id.setPropName(name); DMBootstrapProperty prop = new DMBootstrapProperty(id, model, value); session.save(prop); set.add(prop); } }
From source file:org.apache.ode.daohib.bpel.BpelDAOConnectionFactoryImpl.java
/** * @see org.apache.ode.bpel.dao.BpelDAOConnectionFactory#init(java.util.Properties) *///from ww w . j a v a 2 s . c o m public void init(Properties initialProps) { if (_ds == null) { String errmsg = "setDataSource() not called!"; __log.fatal(errmsg); throw new IllegalStateException(errmsg); } if (_tm == null) { String errmsg = "setTransactionManager() not called!"; __log.fatal(errmsg); throw new IllegalStateException(errmsg); } if (initialProps == null) initialProps = new Properties(); // Don't want to pollute original properties Properties properties = new Properties(); for (Object prop : initialProps.keySet()) { properties.put(prop, initialProps.get(prop)); } // Note that we don't allow the following properties to be overriden by // the client. if (properties.containsKey(Environment.CONNECTION_PROVIDER)) __log.warn("Ignoring user-specified Hibernate property: " + Environment.CONNECTION_PROVIDER); if (properties.containsKey(Environment.TRANSACTION_MANAGER_STRATEGY)) __log.warn("Ignoring user-specified Hibernate property: " + Environment.TRANSACTION_MANAGER_STRATEGY); if (properties.containsKey(Environment.SESSION_FACTORY_NAME)) __log.warn("Ignoring user-specified Hibernate property: " + Environment.SESSION_FACTORY_NAME); properties.put(Environment.CONNECTION_PROVIDER, DataSourceConnectionProvider.class.getName()); properties.put(Environment.TRANSACTION_MANAGER_STRATEGY, HibernateTransactionManagerLookup.class.getName()); properties.put(Environment.TRANSACTION_STRATEGY, "org.hibernate.transaction.JTATransactionFactory"); properties.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta"); // Isolation levels override; when you use a ConnectionProvider, this has no effect String level = System.getProperty("ode.connection.isolation", "2"); properties.put(Environment.ISOLATION, level); if (__log.isDebugEnabled()) { Enumeration<?> names = properties.propertyNames(); __log.debug("Properties passed to Hibernate:"); while (names.hasMoreElements()) { String name = (String) names.nextElement(); __log.debug(name + "=" + properties.getProperty(name)); } } _sessionManager = createSessionManager(properties, _ds, _tm); }