Example usage for javax.servlet FilterConfig getInitParameterNames

List of usage examples for javax.servlet FilterConfig getInitParameterNames

Introduction

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

Prototype

public Enumeration<String> getInitParameterNames();

Source Link

Document

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

Usage

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

/**
 * Get names and values for all the init parameters from the specified 
 * filter config./*from   w w w  .  j ava 2 s .c  om*/
 * 
 * @param  fcConfig - 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(FilterConfig fcConfig) {
    Properties prpSettings = new Properties();
    String strName;
    String strValue;

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

    return prpSettings;
}

From source file:org.sakaiproject.util.ResponseHeaderFilter.java

@SuppressWarnings("unchecked")
public void init(FilterConfig filterConfig) throws ServletException {
    String webappName = filterConfig.getServletContext().getServletContextName();
    // storing the header information in a local map
    for (Enumeration<String> paramNames = filterConfig.getInitParameterNames(); paramNames.hasMoreElements();) {
        String paramName = paramNames.nextElement();
        String paramValue = filterConfig.getInitParameter(paramName);
        if (paramName != null && paramValue != null) {
            this.headerMap.put(paramName, paramValue);
        }// w w  w . j  av a2  s. c  o  m
    }
    // adding the configured ones from sakai config
    ServerConfigurationService serverConfigurationService = org.sakaiproject.component.cover.ServerConfigurationService
            .getInstance();
    if (serverConfigurationService != null) {
        String[] headerStrings = serverConfigurationService.getStrings("response.headers");
        if (headerStrings != null) {
            for (String headerString : headerStrings) {
                if (headerString != null && !"".equals(headerString)) {
                    int loc = headerString.indexOf("::");
                    if (loc <= 0) {
                        log.warn("Invalid header string in sakai config (must contain '::', e.g. key::value): "
                                + headerString);
                        continue;
                    }
                    String name = headerString.substring(0, loc);
                    if (name == null || "".equals(name)) {
                        log.warn("Invalid header string in sakai config (name must not be empty): "
                                + headerString);
                        continue;
                    }
                    String value = null;
                    if (headerString.length() > loc + 2) {
                        value = headerString.substring(loc + 2);
                    }
                    addHeader(name, value);
                    if (value == null) {
                        log.info("Removing header (" + name + ") from all responses for current webapp: "
                                + webappName);
                    } else {
                        log.info("Adding header (" + name + " -> " + value
                                + ") to all responses for current webapp: " + webappName);
                    }
                }
            }
        }
    }
    log.info("INIT: for webapp " + webappName);
}

From source file:org.teiid.olingo.web.ODataFilter.java

@Override
public void init(FilterConfig config) throws ServletException {
    // handle proxy-uri in the case of cloud environments
    String proxyURI = config.getInitParameter("proxy-base-uri"); //$NON-NLS-1$
    if (proxyURI != null && proxyURI.startsWith("${") && proxyURI.endsWith("}")) { //$NON-NLS-1$ //$NON-NLS-2$
        proxyURI = proxyURI.substring(2, proxyURI.length() - 1);
        proxyURI = System.getProperty(proxyURI);
    }/*from   w w w  .  j a va2s. co  m*/

    if (proxyURI != null) {
        this.proxyBaseURI = proxyURI;
    }

    Properties props = new Properties();
    Enumeration<String> names = config.getServletContext().getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        props.setProperty(name, config.getServletContext().getInitParameter(name));
    }
    names = config.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        props.setProperty(name, config.getInitParameter(name));
    }
    this.initProperties = props;
}