List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:org.onecmdb.ui.gwt.desktop.server.service.model.mdr.MDRSetupService.java
private void updateDataSource(IContentService svc, String token, ContentData data, TransformConfig config) { svc.stat(data);// ww w . ja v a 2s. c o m if (!data.isExists() || data.isDirectory()) { return; } String content = svc.get(token, data); Properties p = new Properties(); try { ByteArrayInputStream array = new ByteArrayInputStream(content.getBytes()); p.loadFromXML(array); } catch (Exception e) { log.error("Can't read '" + data.getPath() + "'", e); // Ignore this. return; } Enumeration<?> keys = p.propertyNames(); BaseModel dataSource = new BaseModel(); String type = (String) p.get("type"); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = p.getProperty(key); if (key.startsWith(type + ".")) { key = key.substring((type + ".").length()); } dataSource.set(key, value); } config.setDataSourceType(type); config.setDataSource(type, dataSource); }
From source file:uk.ac.sanger.cgp.dbcon.support.NanoHttpd.java
/** * Override this to customize the server. * <p>//from w ww.jav a2 s .c om * * (By default, this delegates to serveFile() and allows directory listing.) * * @parm uri Percent-decoded URI without parameters, for example "/index.cgi" * @parm method "GET", "POST" etc. * @parm parms Parsed, percent decoded parameters from URI and, in case of * POST, data. * @parm header Header entries, percent decoded * @return HTTP response, see class Response for details */ public Response serve(String uri, String method, Properties header, Properties parms) { getLog().debug(method + " '" + uri + "' "); Enumeration e = header.propertyNames(); while (e.hasMoreElements()) { String value = (String) e.nextElement(); getLog().debug(" HDR: '" + value + "' = '" + header.getProperty(value) + "'"); } e = parms.propertyNames(); while (e.hasMoreElements()) { String value = (String) e.nextElement(); getLog().debug(" PRM: '" + value + "' = '" + parms.getProperty(value) + "'"); } return serveFile(uri, header, new File("."), true); }
From source file:org.apache.velocity.util.ExtProperties.java
/** * Convert a standard properties class into a configuration class. * <p>/*w w w .java 2s .com*/ * NOTE: From Commons Collections 3.2 this method will pick up * any default parent Properties of the specified input object. * * @param props the properties object to convert * @return new ExtProperties created from props */ public static ExtProperties convertProperties(Properties props) { ExtProperties c = new ExtProperties(); for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String s = (String) e.nextElement(); c.setProperty(s, props.getProperty(s)); } return c; }
From source file:PropsToXML.java
/** * <p> This will handle the detail of conversion from a Java * <code>Properties</code> object to an XML document. </p> * * @param props <code>Properties</code> object to use as input. * @param xmlFilename file to output XML to. * @throws <code>IOException</code> - when errors occur. */// w w w. j av a 2 s.co m private void convertToXML(Properties props, String xmlFilename) throws IOException { // Create a new JDOM Document with a root element "properties" Element root = new Element("properties"); Document doc = new Document(root); // Get the property names Enumeration propertyNames = props.propertyNames(); while (propertyNames.hasMoreElements()) { String propertyName = (String) propertyNames.nextElement(); String propertyValue = props.getProperty(propertyName); createXMLRepresentation(root, propertyName, propertyValue); } // Output document to supplied filename XMLOutputter outputter = new XMLOutputter(" ", true); FileOutputStream output = new FileOutputStream(xmlFilename); outputter.output(doc, output); }
From source file:org.intermine.bio.ontology.OboParser.java
/** * Parses config file for valid prefixes, eg. FBbt FMA. Only valid xrefs will be processed, * eg. FBbt:0000001/*from w ww .j a v a 2s . c om*/ */ protected void readConfig() { Properties props = new Properties(); try { 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 xref = (String) propNames.nextElement(); oboXrefs.add(xref); } }
From source file:ORG.oclc.os.SRW.SRWDatabase.java
/** * Look for indexes with context sets and construct a new index entry * without the context set. If the new index is unique, keep it. */// w ww .j a va 2s .co m static protected void makeUnqualifiedIndexes(Properties props) { Enumeration enumer = props.propertyNames(); Hashtable<String, String> newIndexes = new Hashtable<String, String>(); int start; String name, newName, value; while (enumer.hasMoreElements()) { name = (String) enumer.nextElement(); if (name.startsWith("qualifier.")) { if ((start = name.indexOf('.', 11)) > 0) { newName = "hiddenQualifier." + name.substring(start + 1); log.debug("checking for " + newName); if (newIndexes.get(newName) != null) { // already got one log.debug("dropping " + newName); newIndexes.remove(newName); // so throw it away } else { log.debug("keeping " + newName); newIndexes.put(newName, (String) props.get(name)); } } } } enumer = newIndexes.keys(); while (enumer.hasMoreElements()) { name = (String) enumer.nextElement(); value = newIndexes.get(name); if (value != null) { log.debug("adding: " + name + "=" + value); props.put(name, value); } } }
From source file:org.intermine.bio.dataconversion.InparanoidConverter.java
private void readConfig() { Properties props = new Properties(); try {//from www . ja v a 2 s . 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 code = (String) propNames.nextElement(); code = code.substring(0, code.indexOf(".")); Properties codeProps = PropertiesUtil.stripStart(code, PropertiesUtil.getPropertiesStartingWith(code, props)); String taxonId = codeProps.getProperty("taxonid"); if (taxonId == null) { throw new IllegalArgumentException( "Unable to find 'taxonId' property for code: " + code + " in file: " + PROP_FILE); } taxonId = taxonId.trim(); String source = codeProps.getProperty("source"); if (source == null) { throw new IllegalArgumentException( "Unable to find 'source' property for code: " + code + " in file: " + PROP_FILE); } String attribute = codeProps.getProperty("attribute"); if (attribute == null) { attribute = "primaryIdentifier"; } String object = codeProps.getProperty("object"); if (object == null) { object = "transcript"; } source = source.trim(); taxonId = taxonId.trim(); attribute = attribute.trim(); code = code.trim(); taxonIds.put(code, taxonId); orgSources.put(taxonId, source); attributes.put(code, attribute); createObjects.put(code, object); } }
From source file:org.springframework.osgi.extender.internal.support.ExtenderConfiguration.java
/** * Constructs a new <code>ExtenderConfiguration</code> instance. Locates the extender configuration, creates an * application context which will returned the extender items. * //from w w w . ja v a 2 s. co m * @param bundleContext extender OSGi bundle context */ public ExtenderConfiguration(BundleContext bundleContext, Log log) { this.log = log; Bundle bundle = bundleContext.getBundle(); Properties properties = new Properties(createDefaultProperties()); Enumeration<?> enm = bundle.findEntries(EXTENDER_CFG_LOCATION, XML_PATTERN, false); if (enm == null) { log.info("No custom extender configuration detected; using defaults..."); synchronized (lock) { taskExecutor = createDefaultTaskExecutor(); shutdownTaskExecutor = createDefaultShutdownTaskExecutor(); eventMulticaster = createDefaultEventMulticaster(); contextCreator = createDefaultApplicationContextCreator(); contextEventListener = createDefaultApplicationContextListener(); } classLoader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle); } else { String[] configs = copyEnumerationToList(enm); log.info("Detected extender custom configurations at " + ObjectUtils.nullSafeToString(configs)); // create OSGi specific XML context ConfigurableOsgiBundleApplicationContext extenderAppCtx = new OsgiBundleXmlApplicationContext(configs); extenderAppCtx.setBundleContext(bundleContext); extenderAppCtx.refresh(); synchronized (lock) { extenderConfiguration = extenderAppCtx; // initialize beans taskExecutor = extenderConfiguration.containsBean(TASK_EXECUTOR_NAME) ? (TaskExecutor) extenderConfiguration.getBean(TASK_EXECUTOR_NAME, TaskExecutor.class) : createDefaultTaskExecutor(); shutdownTaskExecutor = extenderConfiguration.containsBean(SHUTDOWN_TASK_EXECUTOR_NAME) ? (TaskExecutor) extenderConfiguration.getBean(SHUTDOWN_TASK_EXECUTOR_NAME, TaskExecutor.class) : createDefaultShutdownTaskExecutor(); eventMulticaster = extenderConfiguration.containsBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME) ? (OsgiBundleApplicationContextEventMulticaster) extenderConfiguration.getBean( APPLICATION_EVENT_MULTICASTER_BEAN_NAME, OsgiBundleApplicationContextEventMulticaster.class) : createDefaultEventMulticaster(); contextCreator = extenderConfiguration.containsBean(CONTEXT_CREATOR_NAME) ? (OsgiApplicationContextCreator) extenderConfiguration.getBean(CONTEXT_CREATOR_NAME, OsgiApplicationContextCreator.class) : createDefaultApplicationContextCreator(); contextEventListener = extenderConfiguration.containsBean(CONTEXT_LISTENER_NAME) ? (OsgiBundleApplicationContextListener) extenderConfiguration .getBean(CONTEXT_LISTENER_NAME, OsgiBundleApplicationContextListener.class) : createDefaultApplicationContextListener(); } // get post processors postProcessors .addAll(extenderConfiguration.getBeansOfType(OsgiBeanFactoryPostProcessor.class).values()); // get dependency factories dependencyFactories .addAll(extenderConfiguration.getBeansOfType(OsgiServiceDependencyFactory.class).values()); classLoader = extenderConfiguration.getClassLoader(); // extender properties using the defaults as backup if (extenderConfiguration.containsBean(PROPERTIES_NAME)) { Properties customProperties = (Properties) extenderConfiguration.getBean(PROPERTIES_NAME, Properties.class); Enumeration<?> propertyKey = customProperties.propertyNames(); while (propertyKey.hasMoreElements()) { String property = (String) propertyKey.nextElement(); properties.setProperty(property, customProperties.getProperty(property)); } } } synchronized (lock) { shutdownWaitTime = getShutdownWaitTime(properties); dependencyWaitTime = getDependencyWaitTime(properties); processAnnotation = getProcessAnnotations(properties); } // load default dependency factories addDefaultDependencyFactories(); // allow post processing contextCreator = postProcess(contextCreator); }
From source file:org.apache.directory.fortress.core.model.Permission.java
/** * Add new collection of name/value pairs to attributes associated with Permission. These values are not constrained by Fortress. * Properties are optional.//from w w w. jav a2 s . co m * * @param props contains collection of name/value pairs and maps to 'ftProps' attribute in 'ftProperties' aux object class. */ public void addProperties(Properties props) { if (props != 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); addProperty(key, val); } } }
From source file:org.opentaps.domain.container.ConstantsGeneratorContainer.java
private TreeMap<String, ConstantModel> readConstantConfiguration(Properties config) throws ContainerException { TreeMap<String, ConstantModel> models = new TreeMap<String, ConstantModel>(); // first collect the entity names Enumeration<?> propertyNames = config.propertyNames(); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); if (GENERATE_VALUE.equals(config.getProperty(key))) { if (models.containsKey(key)) { throw new ContainerException("Entity: [" + key + "] already defined in the configuration."); }/*w ww. j a v a 2 s . co m*/ models.put(key, new ConstantModel(key)); } } // then for each entity read the configuration for (String key : models.keySet()) { ConstantModel model = models.get(key); model.setClassName(config.getProperty(key + ".className")); model.setDescription(config.getProperty(key + ".description")); model.setTypeField(config.getProperty(key + ".typeField")); model.setNameField(config.getProperty(key + ".nameField")); model.setDescriptionField(config.getProperty(key + ".descriptionField")); model.setConstantField(config.getProperty(key + ".constantField")); model.setWhere(config.getProperty(key + ".where")); } return models; }