Example usage for javax.servlet ServletConfig getInitParameterNames

List of usage examples for javax.servlet ServletConfig getInitParameterNames

Introduction

In this page you can find the example usage for javax.servlet ServletConfig getInitParameterNames.

Prototype

public Enumeration<String> getInitParameterNames();

Source Link

Document

Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters.

Usage

From source file:info.magnolia.cms.util.ServletUtil.java

/**
 * Returns the init parameters for a {@link javax.servlet.ServletConfig} object as a Map, preserving the order in which they are exposed
 * by the {@link javax.servlet.ServletConfig} object.
 *//*from   www.j a  va  2s . c  o  m*/
public static LinkedHashMap<String, String> initParametersToMap(ServletConfig config) {
    LinkedHashMap<String, String> initParameters = new LinkedHashMap<String, String>();
    Enumeration parameterNames = config.getInitParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        initParameters.put(parameterName, config.getInitParameter(parameterName));
    }
    return initParameters;
}

From source file:org.dmb.trueprice.utils.internal.InitContextListener.java

public static void getServletConfig(String servletName, HttpServlet servlet) {
    log.warn("\n\t >>> \t Servlet [" + servletName + "] request for config \n");
    log.warn("\n\t >>> \t Can we get it's init param names ? ["
            //                 + servletsContext.getServletRegistration(servletName).getInitParameters().keySet().toString()  + "] "                
            + servletsContext.containsKey(servletName) + "] "

    );//from   w ww .  j  a  v  a2s  .c  o  m
    if (servletsContext.containsKey(servletName)) {
        log.debug("\t >>>\t SHOW INIT PARAMS of SERVLET CONTEXT");
        ServletConfig config = servlet.getServletConfig();
        Enumeration<String> e;
        try {
            e = config.getInitParameterNames();
            while (e.hasMoreElements()) {
                String attName = e.nextElement();
                String attValue = servlet.getInitParameter(attName).toString();
                log.info("New init param [" + (attName == null ? "???" : attName) + "] > "
                        + (attValue == null ? "???" : attValue));
            }
        } catch (Exception ex) {
            log.error("\t >>>\t        FAILURE       > " + ex.getMessage());
            ex.printStackTrace();
        }

    }
}

From source file:mondrian.xmla.impl.Olap4jXmlaServlet.java

/**
 * Obtains connection properties from the
 * ServletConfig init parameters and from System properties.
 *
 * <p>The properties found in the System properties override the ones in
 * the ServletConfig.//  www  . ja va 2 s  .  c  om
 *
 * <p>copies the values of init parameters / properties which
 * start with the given prefix to a target Map object stripping out the
 * configured prefix from the property name.
 *
 * <p>The following example uses prefix "olapConn.":
 *
 * <code><pre>
 *  &lt;init-param&gt;
 *      &lt;param-name&gt;olapConn.User&lt;/param-name&gt;
 *      &lt;param-value&gt;mrossi&lt;/param-value&gt;
 *  &lt;/init-param&gt;
 *  &lt;init-param&gt;
 *      &lt;param-name&gt;olapConn.Password&lt;/param-name&gt;
 *      &lt;param-value&gt;manhattan&lt;/param-value&gt;
 *  &lt;/init-param&gt;
 *
 * </pre></code>
 *
 * <p>This will result in a connection properties object with entries
 * <code>{("User", "mrossi"), ("Password", "manhattan")}</code>.
 *
 * @param prefix Prefix to property name
 * @param servletConfig Servlet config
 * @return Map containing property names and values
 */
private static Map<String, String> getOlap4jConnectionProperties(final ServletConfig servletConfig,
        final String prefix) {
    Map<String, String> options = new LinkedHashMap<String, String>();

    // Get properties from servlet config.
    @SuppressWarnings({ "unchecked" })
    java.util.Enumeration<String> en = servletConfig.getInitParameterNames();
    while (en.hasMoreElements()) {
        String paramName = en.nextElement();
        if (paramName.startsWith(prefix)) {
            String paramValue = servletConfig.getInitParameter(paramName);
            String prefixRemovedParamName = paramName.substring(prefix.length());
            options.put(prefixRemovedParamName, paramValue);
        }
    }

    // Get system properties.
    final Map<String, String> systemProps = Util.toMap(System.getProperties());
    for (Map.Entry<String, String> entry : systemProps.entrySet()) {
        String sk = entry.getKey();
        if (sk.startsWith(prefix)) {
            String value = entry.getValue();
            String prefixRemovedKey = sk.substring(prefix.length());
            options.put(prefixRemovedKey, value);
        }
    }

    return options;
}

From source file:org.opensubsystems.core.util.servlet.WebUtils.java

/**
 * Get names and values for all the init parameters from the specified 
 * servlet config.//from w  w  w.j a  v a 2  s.c  o m
 * 
 * @param  scConfig - config from where to retrieve the init parameters
 * @return Properties - names and values of the init parameters or empty
 *                      properties if no init parameters are specified
 */
public static Properties getInitParameters(ServletConfig scConfig) {
    Properties prpSettings = new Properties();
    String strName;
    String strValue;

    for (Enumeration paramNames = scConfig.getInitParameterNames(); paramNames.hasMoreElements();) {
        strName = (String) paramNames.nextElement();
        strValue = scConfig.getInitParameter(strName);
        prpSettings.put(strName, strValue);
    }

    return prpSettings;
}

From source file:org.opensubsystems.core.util.servlet.WebUtils.java

/**
 * Create debug string containing all parameter names and their values from
 * the config.//  w w  w.j  a  va  2  s  .c  o m
 *
 * @param  scConfig - config to print out
 * @return String - debug string containing all parameter names and their
 *                  values from the config
 */
public static String debug(ServletConfig scConfig) {
    Enumeration enumNames;
    String strParam;
    StringBuilder sbfReturn = new StringBuilder();

    sbfReturn.append("ServletConfig=[ServletName=");
    sbfReturn.append(scConfig.getServletName());
    sbfReturn.append(";");
    for (enumNames = scConfig.getInitParameterNames(); enumNames.hasMoreElements();) {
        strParam = (String) enumNames.nextElement();
        sbfReturn.append("Param=");
        sbfReturn.append(strParam);
        sbfReturn.append(" value=");
        sbfReturn.append(scConfig.getInitParameter(strParam));
        if (enumNames.hasMoreElements()) {
            sbfReturn.append(";");
        }
    }
    sbfReturn.append("]");

    return sbfReturn.toString();
}

From source file:org.apache.jackrabbit.j2ee.AbstractConfig.java

public void init(ServletConfig ctx) throws ServletException {
    Enumeration names = ctx.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String mapName = toMapName(name, '-');
        try {//from  ww w .j av  a 2s.  com
            if (map.containsKey(mapName)) {
                map.put(mapName, ctx.getInitParameter(name));
            }
        } catch (Exception e) {
            throw new ServletExceptionWithCause("Invalid servlet configuration option: " + name, e);
        }
    }
}

From source file:net.unit8.longadeseo.servlet.AbstractConfig.java

public void init(ServletConfig ctx) throws ServletException {
    Enumeration<String> names = ctx.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String mapName = toMapName(name, '-');
        try {/*  w  w w .j  a va2s  .c om*/
            if (map.containsKey(mapName)) {
                map.put(mapName, ctx.getInitParameter(name));
            }
        } catch (Exception e) {
            throw new ServletExceptionWithCause("Invalid servlet configuration option: " + name, e);
        }
    }
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.Forward.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);

    Enumeration enm = config.getInitParameterNames();
    while (enm.hasMoreElements()) {
        String path = (String) enm.nextElement();
        String forward = config.getInitParameter(path);
        _forwardMap.put(path, forward);/*w  ww.ja v  a 2  s  .  c o  m*/
    }

}

From source file:fr.norad.servlet.sample.html.template.IndexTemplateServlet.java

void loadProperties(ServletConfig config) {
    @SuppressWarnings("unchecked")
    Enumeration<String> initParameterNames = config.getInitParameterNames();
    while (initParameterNames.hasMoreElements()) {
        String initParamName = initParameterNames.nextElement();
        if (initParamName.endsWith(".property")) {
            String initParamValue = config.getInitParameter(initParamName);
            String value = loadValue(initParamValue);
            String name = initParamNameToName(initParamName);
            properties.put(name, value);
        }//from  w ww.ja  v a2  s  .  com
    }
}

From source file:org.apache.abdera.protocol.server.servlet.AbderaServlet.java

protected Map<String, String> getProperties(ServletConfig config) {
    Map<String, String> properties = new HashMap<String, String>();
    Enumeration<String> e = config.getInitParameterNames();
    while (e.hasMoreElements()) {
        String key = e.nextElement();
        String val = config.getInitParameter(key);
        properties.put(key, val);
    }/*  w ww.  j a va  2  s . c o m*/
    return properties;
}