All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thetransactioncompany.util.PropertyConverter Maven / Gradle / Ivy

Go to download

This package provides a Java utility for typed retrieval of java.util.Properties as boolean, integer, floating point, string, URL, URI and enum values.

There is a newer version: 2.0
Show newest version
package com.thetransactioncompany.util;


import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;


/**
 * Static utility methods for converting servlet and context initialisation
 * parameters to Java properties.
 *
 * @author Vladimir Dzhuvinov
 */
public class PropertyConverter {


	/**
	 * Converts the servlet initialisation parameters (typically specified 
	 * in the {@code web.xml} file) to a Java properties hashtable. The 
	 * parameter names become property keys.
	 *
	 * 

Note regarding {@code web.xml} markup: The servlet initialisation * parameters have an XML tag {@code } and are defined * within the {@code } element. * * @param config The servlet configuration. * * @return The servlet initialisation parameters as Java properties. */ public static Properties getServletInitParameters(final ServletConfig config) { Properties props = new Properties(); Enumeration en = config.getInitParameterNames(); while (en.hasMoreElements()) { String key = (String)en.nextElement(); String value = config.getInitParameter(key); props.setProperty(key, value); } return props; } /** * Converts the servlet context initialisation parameters (typically * specified in the {@code web.xml} file) to a Java properties * hashtable. The parameter names become property keys. * *

Note regarding {@code web.xml} markup: The context parameters * have an XML tag {@code } and are defined within the * {@code } element. * * @param ctx The servlet context. * * @return The servlet context parameters as Java properties. */ public static Properties getServletCtxInitParameters(final ServletContext ctx) { Properties props = new Properties(); Enumeration en = ctx.getInitParameterNames(); while (en.hasMoreElements()) { String key = (String)en.nextElement(); String value = ctx.getInitParameter(key); props.setProperty(key, value); } return props; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy