Example usage for javax.servlet ServletContext getInitParameterNames

List of usage examples for javax.servlet ServletContext getInitParameterNames

Introduction

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

Prototype

public Enumeration<String> getInitParameterNames();

Source Link

Document

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

Usage

From source file:org.yes.cart.cluster.node.impl.AbstractWsNodeServiceImpl.java

void initNodeFromServletContext(final ServletContext servletContext) {

    final Enumeration parameters = servletContext.getInitParameterNames();
    while (parameters.hasMoreElements()) {

        final String key = String.valueOf(parameters.nextElement());
        final String value = servletContext.getInitParameter(key);

        configuration.put(key, value);//from www.  j  a  va  2 s  .com

    }

    final String luceneDisabled = configuration.get(LUCENE_INDEX_DISABLED);
    final String luceneDisabledValue = luceneDisabled != null ? Boolean.valueOf(luceneDisabled).toString()
            : Boolean.FALSE.toString();
    configuration.put(LUCENE_INDEX_DISABLED, luceneDisabledValue);

    NodeImpl node = new NodeImpl(true, configuration.get(NODE_ID), configuration.get(NODE_TYPE),
            configuration.get(NODE_CONFIG), configuration.get(CLUSTER_ID),
            Boolean.valueOf(luceneDisabledValue));
    node.setChannel(configuration.get(CHANNEL_URI));
    this.node = node;
    this.cluster.add(node);

    LOG = LoggerFactory.getLogger(node.getClusterId() + "." + node.getNodeId());

    if (LOG.isInfoEnabled()) {

        final StringBuilder stats = new StringBuilder();

        stats.append("\nLoading configuration for node...");
        stats.append("\nNode: ").append(node.getId());

        for (final Map.Entry<String, String> entry : configuration.entrySet()) {
            stats.append('\n').append(entry.getKey()).append(": ").append(entry.getValue());
        }

        LOG.info(stats.toString());
    }

}

From source file:org.yes.cart.cluster.node.impl.JGroupsNodeServiceImpl.java

void initNodeFromServletContext(final ServletContext servletContext) {

    final Enumeration parameters = servletContext.getInitParameterNames();
    while (parameters.hasMoreElements()) {

        final String key = String.valueOf(parameters.nextElement());
        final String value = servletContext.getInitParameter(key);

        configuration.put(key, value);//from   ww w .j  a v  a  2 s  .c  om

    }

    final String luceneDisabled = configuration.get(LUCENE_INDEX_DISABLED);
    final String luceneDisabledValue = luceneDisabled != null ? Boolean.valueOf(luceneDisabled).toString()
            : Boolean.FALSE.toString();
    configuration.put(LUCENE_INDEX_DISABLED, luceneDisabledValue);

    node = new NodeImpl(true, configuration.get(NODE_ID), configuration.get(NODE_TYPE),
            configuration.get(NODE_CONFIG), configuration.get(CLUSTER_ID),
            Boolean.valueOf(luceneDisabledValue));
    this.cluster.add(node);

    LOG = LoggerFactory.getLogger(node.getClusterId() + "." + node.getNodeId());

    if (LOG.isInfoEnabled()) {

        final StringBuilder stats = new StringBuilder();

        stats.append("\nLoading configuration for node...");
        stats.append("\nNode: ").append(node.getId());

        for (final Map.Entry<String, String> entry : configuration.entrySet()) {
            stats.append('\n').append(entry.getKey()).append(": ").append(entry.getValue());
        }

        LOG.info(stats.toString());
    }

}

From source file:thinwire.render.web.WebServlet.java

private Set<String> getStartArguments(HttpServletRequest request) {
    Set<String> args = new TreeSet<String>();
    StringBuilder sb = new StringBuilder();

    for (Map.Entry<String, String[]> e : ((Map<String, String[]>) request.getParameterMap()).entrySet()) {
        String key = e.getKey();//from  www. j  av  a 2s  .  com
        String[] values = e.getValue();

        if (values.length > 1) {
            for (int i = 0; i < values.length; i++) {
                sb.append(key).append(i).append('=').append(values[i]);
            }
        } else {
            sb.append(key).append('=').append(values[0]);
        }

        args.add(sb.toString());
        sb.setLength(0);
    }

    String extraArguments = getInitParameter(InitParam.EXTRA_ARGUMENTS.mixedCaseName());
    if (extraArguments == null)
        extraArguments = "";
    extraArguments = "," + extraArguments + ",";

    if (extraArguments.indexOf(",contextParam,") >= 0) {
        ServletContext sc = getServletContext();

        for (Enumeration<String> ipn = sc.getInitParameterNames(); ipn.hasMoreElements();) {
            String name = ipn.nextElement();
            sb.append("CONTEXT_PARAM_").append(name).append('=').append(sc.getInitParameter(name));
            args.add(sb.toString());
            sb.setLength(0);
        }
    }

    if (extraArguments.indexOf(",initParam,") >= 0) {
        InitParam[] initParams = InitParam.values();

        ipn_loop: for (Enumeration<String> ipn = getInitParameterNames(); ipn.hasMoreElements();) {
            String name = ipn.nextElement();

            for (InitParam ip : initParams) {
                if (ip.mixedCaseName().equals(name))
                    continue ipn_loop;
            }

            sb.append("INIT_PARAM_").append(name).append('=').append(getInitParameter(name));
            args.add(sb.toString());
            sb.setLength(0);
        }
    }

    if (extraArguments.indexOf(",header,") >= 0) {
        for (Enumeration<String> hn = request.getHeaderNames(); hn.hasMoreElements();) {
            String name = hn.nextElement();
            sb.append("HEADER_").append(name.toUpperCase()).append('=').append(request.getHeader(name));
            args.add(sb.toString());
            sb.setLength(0);
        }
    }

    if (extraArguments.indexOf(",clientInfo,") >= 0) {
        sb.append("CLIENT_INFO_USER").append('=').append(request.getRemoteUser());
        args.add(sb.toString());
        sb.setLength(0);
        sb.append("CLIENT_INFO_HOST").append('=').append(request.getRemoteHost());
        args.add(sb.toString());
        sb.setLength(0);
        sb.append("CLIENT_INFO_ADDRESS").append('=').append(request.getRemoteAddr());
        args.add(sb.toString());
        sb.setLength(0);
    }

    return args;
}