List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:com.puppycrawl.tools.checkstyle.checks.TranslationCheck.java
/** * Loads the keys of the specified property file into a set. * @param file the property file/* w w w . ja v a2 s .com*/ * @return a Set object which holds the loaded keys */ private Set<Object> loadKeys(File file) { final Set<Object> keys = Sets.newHashSet(); InputStream inStream = null; try { // Load file and properties. inStream = new FileInputStream(file); final Properties props = new Properties(); props.load(inStream); // Gather the keys and put them into a set final Enumeration<?> element = props.propertyNames(); while (element.hasMoreElements()) { keys.add(element.nextElement()); } } catch (final IOException e) { logIOException(e, file); } finally { Closeables.closeQuietly(inStream); } return keys; }
From source file:org.sakaiproject.hierarchy.tool.vm.spring.VelocityView.java
/** * Set tool attributes to expose to the view, as attribute name / class name pairs. * An instance of the given class will be added to the Velocity context for each * rendering operation, under the given attribute name. * <p>For example, an instance of MathTool, which is part of the generic package * of Velocity Tools, can be bound under the attribute name "math", specifying the * fully qualified class name "org.apache.velocity.tools.generic.MathTool" as value. * <p>Note that VelocityView can only create simple generic tools or values, that is, * classes with a public default constructor and no further initialization needs. * This class does not do any further checks, to not introduce a required dependency * on a specific tools package.//from w ww . ja va2 s .com * <p>For tools that are part of the view package of Velocity Tools, a special * Velocity context and a special init callback are needed. Use VelocityToolboxView * in such a case, or override <code>createVelocityContext</code> and * <code>initTool</code> accordingly. * <p>For a simple VelocityFormatter instance or special locale-aware instances * of DateTool/NumberTool, which are part of the generic package of Velocity Tools, * specify the "velocityFormatterAttribute", "dateToolAttribute" or * "numberToolAttribute" properties, respectively. * @param toolAttributes attribute names as keys, and tool class names as values * @see org.apache.velocity.tools.generic.MathTool * @see VelocityToolboxView * @see #createVelocityContext * @see #initTool * @see #setVelocityFormatterAttribute * @see #setDateToolAttribute * @see #setNumberToolAttribute */ public void setToolAttributes(Properties toolAttributes) { this.toolAttributes = new HashMap(toolAttributes.size()); for (Enumeration attributeNames = toolAttributes.propertyNames(); attributeNames.hasMoreElements();) { String attributeName = (String) attributeNames.nextElement(); String className = toolAttributes.getProperty(attributeName); Class toolClass = null; try { toolClass = ClassUtils.forName(className); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Invalid definition for tool '" + attributeName + "' - tool class not found: " + ex.getMessage()); } this.toolAttributes.put(attributeName, toolClass); } }
From source file:org.springframework.batch.admin.web.util.HomeController.java
private List<ResourceInfo> buildResourcesFromProperties(Properties properties, Properties defaults) { Set<ResourceInfo> resources = new TreeSet<ResourceInfo>(); if (properties == null) { if (defaults == null) { return new ArrayList<ResourceInfo>(); }/* w w w. j a v a 2 s. c o m*/ properties = defaults; } for (Enumeration<?> iterator = properties.propertyNames(); iterator.hasMoreElements();) { String key = (String) iterator.nextElement(); String method = key.substring(0, key.indexOf("/")); String url = key.substring(key.indexOf("/")); String description = properties.getProperty(key, defaults.getProperty(key)); resources.add(new ResourceInfo(url, RequestMethod.valueOf(method), description)); } return new ArrayList<ResourceInfo>(resources); }
From source file:com.orange.mmp.dao.flf.DeliveryTicketDaoFlfImpl.java
@SuppressWarnings("unchecked") public DeliveryTicket[] find(DeliveryTicket deliveryTicket) throws MMPDaoException { if (deliveryTicket == null) { throw new MMPDaoException("missing or bad data access object"); }/*from w ww .j ava2s .co m*/ //Find by Id if (deliveryTicket.getId() != null) { File toFind = new File(this.path, deliveryTicket.getId().concat(".tmp")); if (toFind.exists()) { InputStream inProps = null; DeliveryTicket[] ticketList = new DeliveryTicket[1]; ticketList[0] = new DeliveryTicket(); try { inProps = new FileInputStream(toFind.getAbsolutePath()); Properties propFile = new Properties(); propFile.load(inProps); ticketList[0].setId(deliveryTicket.getId()); Enumeration propNames = propFile.propertyNames(); HashMap<String, String> serviceSpecificMap = new HashMap<String, String>(); while (propNames.hasMoreElements()) { String currentProp = propNames.nextElement().toString(); if (currentProp.equals(ND_PARAMETER)) ticketList[0].setMsisdn(propFile.getProperty(ND_PARAMETER)); else if (currentProp.equals(SERVICE_PARAMETER)) ticketList[0].setServiceId(propFile.getProperty(SERVICE_PARAMETER)); else if (currentProp.equals(UAKEY_PARAMETER)) ticketList[0].setUaKey(propFile.getProperty(UAKEY_PARAMETER)); else if (currentProp.equals(CALLBACK_PARAMETER)) ticketList[0].setCallback(propFile.getProperty(CALLBACK_PARAMETER)); else if (currentProp.startsWith(JAD_PREFIX_ENTRY)) { serviceSpecificMap.put(currentProp.substring(JAD_PREFIX_ENTRY.length()), propFile.getProperty(currentProp)); } } ticketList[0].setServiceSpecific(serviceSpecificMap); ticketList[0].setCreationDate(toFind.lastModified()); } catch (IOException ioe) { throw new MMPDaoException("failed to load ticket"); } finally { try { if (inProps != null) inProps.close(); } catch (IOException ioe) { //Nop } } return ticketList; } } else { FilenameFilter tmpFilter = new SuffixFileFilter(".tmp"); File ticketsFiles[] = new File(this.path).listFiles(tmpFilter); if (ticketsFiles == null) return new DeliveryTicket[0]; ArrayList<DeliveryTicket> list = new ArrayList<DeliveryTicket>(); InputStream inProps = null; Properties propFile = new Properties(); try { for (File found : ticketsFiles) { inProps = new FileInputStream(found.getAbsolutePath()); propFile.load(inProps); boolean match = (deliveryTicket.getMsisdn() == null); if (!match) { boolean goOnchecking = true; if (deliveryTicket.getMsisdn() != null) { match = (propFile.getProperty(ND_PARAMETER) != null && propFile.getProperty(ND_PARAMETER).equals(deliveryTicket.getMsisdn())); goOnchecking = match; } if (deliveryTicket.getServiceId() != null && goOnchecking) { match = (propFile.getProperty(SERVICE_PARAMETER) != null && propFile .getProperty(SERVICE_PARAMETER).equals(deliveryTicket.getServiceId())); goOnchecking = match; } if (deliveryTicket.getUaKey() != null && goOnchecking) { match = (propFile.getProperty(UAKEY_PARAMETER) != null && propFile.getProperty(UAKEY_PARAMETER).equals(deliveryTicket.getUaKey())); goOnchecking = match; } if (deliveryTicket.getCallback() != null && goOnchecking) { match = (propFile.getProperty(CALLBACK_PARAMETER) != null && propFile .getProperty(CALLBACK_PARAMETER).equals(deliveryTicket.getCallback())); goOnchecking = match; } } if (match) { DeliveryTicket foundTicket = new DeliveryTicket(); foundTicket.setId(found.getName().split("\\.")[0]); Enumeration propNames = propFile.propertyNames(); HashMap<String, String> serviceSpecificMap = new HashMap<String, String>(); while (propNames.hasMoreElements()) { String currentProp = propNames.nextElement().toString(); if (currentProp.equals(ND_PARAMETER)) { foundTicket.setMsisdn(propFile.getProperty(ND_PARAMETER)); } else if (currentProp.equals(SERVICE_PARAMETER)) { foundTicket.setServiceId(propFile.getProperty(SERVICE_PARAMETER)); } else if (currentProp.startsWith(JAD_PREFIX_ENTRY)) { serviceSpecificMap.put(currentProp.substring(JAD_PREFIX_ENTRY.length()), propFile.getProperty(currentProp)); } } foundTicket.setServiceSpecific(serviceSpecificMap); foundTicket.setCreationDate(found.lastModified()); list.add(foundTicket); } } } catch (IOException ioe) { throw new MMPDaoException("failed to load ticket"); } finally { try { if (inProps != null) inProps.close(); } catch (IOException ioe) { //Nop } } DeliveryTicket[] ticketList = new DeliveryTicket[list.size()]; return list.toArray(ticketList); } return new DeliveryTicket[0]; }
From source file:org.rhq.enterprise.gui.startup.Configurator.java
/** * Load the internals properties file and configures the web application. All properties in the file are exposed as * servlet context attributes.//ww w .j a va2 s. c o m */ private void loadConfig(ServletContext ctx) { Properties props; try { props = loadProperties(ctx, SERVER_INTERNALS_FILE); } catch (Exception e) { log.error("unable to load server internals file [" + SERVER_INTERNALS_FILE + "]", e); return; } if (props == null) { log.debug("server internals file [" + SERVER_INTERNALS_FILE + "] does not exist"); return; } Enumeration names = props.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); // this is not currently used, but is interesting, it lets you define system properties in rhq-server-internals.properties if (name.startsWith(SYSPROP_KEY)) { System.setProperty(name, props.getProperty(name)); } else { ctx.setAttribute(name, props.getProperty(name)); } } log.debug("loaded server internals [" + SERVER_INTERNALS_FILE + "]"); return; }
From source file:com.redhat.jenkins.plugins.ci.messaging.FedMsgMessagingWorker.java
@Override public boolean sendMessage(Run<?, ?> build, TaskListener listener, MessageUtils.MESSAGE_TYPE type, String props, String content) {/*from ww w . j ava2 s.co m*/ ZMQ.Context context = ZMQ.context(1); ZMQ.Socket sock = context.socket(ZMQ.PUB); sock.setLinger(0); log.fine("pub address: " + provider.getPubAddr()); sock.connect(provider.getPubAddr()); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } HashMap<String, Object> message = new HashMap<String, Object>(); message.put("CI_NAME", build.getParent().getName()); message.put("CI_TYPE", type.getMessage()); if (!build.isBuilding()) { message.put("CI_STATUS", (build.getResult() == Result.SUCCESS ? "passed" : "failed")); } StrSubstitutor sub = null; try { sub = new StrSubstitutor(build.getEnvironment(listener)); if (props != null && !props.trim().equals("")) { Properties p = new Properties(); p.load(new StringReader(props)); @SuppressWarnings("unchecked") Enumeration<String> e = (Enumeration<String>) p.propertyNames(); while (e.hasMoreElements()) { String key = e.nextElement(); message.put(key, sub.replace(p.getProperty(key))); } } message.put(MESSAGECONTENTFIELD, sub.replace(content)); FedmsgMessage blob = new FedmsgMessage(); blob.setMsg(message); blob.setTopic(getTopic()); blob.setTimestamp((new java.util.Date()).getTime() / 1000); sock.sendMore(blob.getTopic()); sock.send(blob.toJson().toString()); log.fine(blob.toJson().toString()); } catch (Exception e) { log.log(Level.SEVERE, "Unhandled exception: ", e); return false; } finally { sock.close(); context.term(); } return true; }
From source file:org.jboss.dashboard.ui.resources.GraphicElementPreview.java
protected void initDataStructures(File f) throws IOException { ZipFile zfile = new ZipFile(f); ZipEntry descriptorEntry = zfile.getEntry(getDescriptorFilename()); if (descriptorEntry == null) { status = STATUS_MISSING_DESCRIPTOR; return;//from w ww .j a va2 s. c om } Properties prop = new Properties(); try { prop.load(zfile.getInputStream(descriptorEntry)); } catch (IOException ioe) { log.warn("Error processing descriptor file. ", ioe); status = STATUS_DESCRIPTOR_CORRUPT; return; } description = new Properties(); resources = new Properties(); Enumeration properties = prop.propertyNames(); 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("Element preview name (" + lang + "): " + prop.getProperty(propName)); } else if (propName.startsWith("resource.")) { String resourceName = propName.substring("resource.".length()); String resourcePath = prop.getProperty(propName); resources.setProperty(resourceName, resourcePath); } else { log.warn("Unknown property in element " + propName); } } log.debug("Resources inside zip = " + resources); resourcesDeployed = new HashMap(); for (Enumeration en = resources.propertyNames(); en.hasMoreElements();) { String resName = (String) en.nextElement(); String resPath = resources.getProperty(resName); log.debug("Deploying property " + resName + "=" + resPath); ZipEntry resourceEntry = zfile.getEntry(resPath); if (resourceEntry != null) { resourcesDeployed.put(resName, toByteArray(zfile.getInputStream(resourceEntry))); } } }
From source file:org.trpr.platform.servicefw.impl.spring.web.HomeController.java
/** * @param properties//from w ww . ja v a 2 s . c o m * */ private List<ResourceInfo> buildResourcesFromProperties(Properties properties, Properties defaults) { Set<ResourceInfo> resources = new TreeSet<ResourceInfo>(); if (properties == null) { if (defaults == null) { return new ArrayList<ResourceInfo>(); } properties = defaults; } for (Enumeration<?> iterator = properties.propertyNames(); iterator.hasMoreElements();) { String key = (String) iterator.nextElement(); String method = key.substring(0, key.indexOf("/")); String url = key.substring(key.indexOf("/")); String description = properties.getProperty(key, defaults.getProperty(key)); resources.add(new ResourceInfo(url, RequestMethod.valueOf(method), description)); } return new ArrayList<ResourceInfo>(resources); }
From source file:com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean.java
protected Object createInstance() throws Exception { Properties properties = PropsUtil.getProperties(_propertyPrefix, true); String jndiName = properties.getProperty("jndi.name"); if (Validator.isNotNull(jndiName)) { try {/*from w ww. j av a 2s .c o m*/ return JNDIUtil.lookup(new InitialContext(), jndiName); } catch (Exception e) { _log.error("Unable to lookup " + jndiName, e); } } DataSource dataSource = new ComboPooledDataSource(); Enumeration<String> enu = (Enumeration<String>) properties.propertyNames(); while (enu.hasMoreElements()) { String key = enu.nextElement(); String value = properties.getProperty(key); // Map org.apache.commons.dbcp.BasicDataSource to C3PO if (key.equalsIgnoreCase("driverClassName")) { key = "driverClass"; } else if (key.equalsIgnoreCase("url")) { key = "jdbcUrl"; } else if (key.equalsIgnoreCase("username")) { key = "user"; } BeanUtils.setProperty(dataSource, key, value); } if (_log.isDebugEnabled()) { SortedProperties sortedProperties = new SortedProperties(properties); _log.debug("Properties for prefix " + _propertyPrefix); sortedProperties.list(System.out); } return dataSource; }
From source file:org.apache.hadoop.mapred.ClusterWithCapacityScheduler.java
private void setUpSchedulerConfigFile(Properties schedulerConfProps) throws IOException { LocalFileSystem fs = FileSystem.getLocal(new Configuration()); String myResourcePath = System.getProperty("test.build.data"); Path schedulerConfigFilePath = new Path(myResourcePath, CapacitySchedulerConf.SCHEDULER_CONF_FILE); OutputStream out = fs.create(schedulerConfigFilePath); Configuration config = new Configuration(false); for (Enumeration<?> e = schedulerConfProps.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); LOG.debug("Adding " + key + schedulerConfProps.getProperty(key)); config.set(key, schedulerConfProps.getProperty(key)); }//from w w w . j a v a2 s .co m config.writeXml(out); out.close(); LOG.info( "setting resource path where capacity-scheduler's config file " + "is placed to " + myResourcePath); System.setProperty(MY_SCHEDULER_CONF_PATH_PROPERTY, myResourcePath); }