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:gov.nih.nci.cabig.ctms.web.WebTools.java

@SuppressWarnings({ "unchecked" })
public static SortedMap<String, Object> contextInitializationParametersToMap(final ServletContext context) {
    return namedAttributesToMap(context.getInitParameterNames(), new AttributeAccessor<Object>() {
        public Object getAttribute(String name) {
            return context.getInitParameter(name);
        }//  w  w w.j  a v  a 2  s .com
    });
}

From source file:gov.nih.nci.protexpress.util.ConfigurationHelper.java

/**
 * @return the ldap context parameters./*from  w w  w.j a  v  a  2s.c  o m*/
 */
public static Hashtable<String, String> getLdapContextParameters() {
    if (ldapContextParams == null) {
        ldapContextParams = new Hashtable<String, String>();

        ServletContext context = ServletActionContext.getServletContext();
        Enumeration<String> e = context.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = e.nextElement();
            if (param.startsWith("ldap")) {
                ldapContextParams.put(param, context.getInitParameter(param));
            }
        }
    }
    return ldapContextParams;
}

From source file:net.testdriven.psiprobe.tools.ApplicationUtils.java

public static List getApplicationInitParams(Context context) {
    // We'll try to determine if a parameter value comes from a deployment descriptor or a context descriptor.
    // assumption: Context.findParameter() returns only values of parameters that are declared in a deployment descriptor.
    // If a parameter is declared in a context descriptor with override=false and redeclared in a deployment descriptor,
    // Context.findParameter() still returns its value, even though the value is taken from a context descriptor.
    // context.findApplicationParameters() returns all parameters that are declared in a context descriptor regardless
    // of whether they are overridden in a deployment descriptor or not or not.

    // creating a set of parameter names that are declared in a context descriptor
    // and can not be ovevridden in a deployment descriptor.
    Set nonOverridableParams = new HashSet();
    ApplicationParameter[] appParams = context.findApplicationParameters();
    for (int i = 0; i < appParams.length; i++) {
        if (appParams[i] != null && !appParams[i].getOverride()) {
            nonOverridableParams.add(appParams[i].getName());
        }// ww w  .  ja  v  a 2  s .co  m
    }

    List initParams = new ArrayList();
    ServletContext servletCtx = context.getServletContext();
    for (Enumeration e = servletCtx.getInitParameterNames(); e.hasMoreElements();) {
        String paramName = (String) e.nextElement();

        ApplicationParam param = new ApplicationParam();
        param.setName(paramName);
        param.setValue(servletCtx.getInitParameter(paramName));
        // if the parameter is declared in a deployment descriptor
        // and it is not declared in a context descriptor with override=false,
        // the value comes from the deployment descriptor
        param.setFromDeplDescr(
                context.findParameter(paramName) != null && !nonOverridableParams.contains(paramName));
        initParams.add(param);
    }

    return initParams;
}

From source file:net.community.chest.gitcloud.facade.ServletUtils.java

public static final NamedExtendedPlaceholderResolver toPlaceholderResolver(final ServletContext context) {
    if (context == null) {
        return ExtendedPlaceholderResolverUtils.EMPTY_RESOLVER;
    } else {/*from   www .  ja v  a 2  s. c om*/
        return new NamedExtendedPlaceholderResolver() {

            @Override
            public String resolvePlaceholder(String placeholderName, String defaultValue) {
                String value = resolvePlaceholder(placeholderName);
                if (value == null) {
                    return defaultValue;
                } else {
                    return value;
                }
            }

            @Override
            public String resolvePlaceholder(String placeholderName) {
                return context.getInitParameter(placeholderName);
            }

            @Override
            public Collection<String> getPlaceholderNames() {
                return Collections.list(context.getInitParameterNames());
            }
        };
    }
}

From source file:fr.univlorraine.mondossierweb.Initializer.java

/**
 * Ajoute les paramtres de contexte aux proprits systmes, de manire  les rendre accessibles dans logback.xml
 * @param servletContext/*  ww w  . j a v a2  s . com*/
 */
private void addContextParametersToSystemProperties(ServletContext servletContext) {
    Enumeration<String> e = servletContext.getInitParameterNames();
    while (e.hasMoreElements()) {
        String parameterName = e.nextElement();
        System.setProperty("context." + parameterName, servletContext.getInitParameter(parameterName));
    }
}

From source file:com.qualogy.qafe.webservice.servlet.GenericWebServiceServlet.java

protected Map<String, String> extractWebservices(ServletContext servletContext) {
    Map<String, String> webservices = new HashMap<String, String>();

    Enumeration<String> paramNames = (Enumeration<String>) servletContext.getInitParameterNames();

    while (paramNames.hasMoreElements()) {
        String parameterName = paramNames.nextElement();
        extractWebserviceParameter(webservices, parameterName, servletContext.getInitParameter(parameterName));
    }/*from  w w w  . j  av  a2  s  . com*/
    return webservices;
}

From source file:gov.nih.nci.caarray.web.action.registration.RegistrationAction.java

/**
 * {@inheritDoc}//from w  ww.j av a  2s. co  m
 */
public void prepare() {
    setCountryList(ServiceLocatorFactory.getGenericDataService().retrieveAll(Country.class, Order.asc("name")));
    setStateList(ServiceLocatorFactory.getGenericDataService().retrieveAll(State.class, Order.asc("name")));
    ServletContext context = ServletActionContext.getServletContext();
    Enumeration<String> e = context.getInitParameterNames();
    while (e.hasMoreElements()) {
        String param = e.nextElement();
        if (param.startsWith("ldap")) {
            ldapContextParams.put(param, context.getInitParameter(param));
        }
    }
    registrationRequest = new RegistrationRequest();
    ldapAuthenticate = Boolean.TRUE;
}

From source file:com.alfaariss.oa.OAContextListener.java

/**
 * Starts the engine before all servlets are initialized.
 * //from  ww  w. j a va  2s.  c  om
 * Searches for the properties needed for the configuration in:
 * <code>[Servlet context dir]/WEB-INF/[PROPERTIES_FILENAME]</code>
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
@Override
public void contextInitialized(ServletContextEvent oServletContextEvent) {
    Properties pConfig = new Properties();
    try {
        _logger.info("Starting Asimba");

        Package pCurrent = OAContextListener.class.getPackage();

        String sSpecVersion = pCurrent.getSpecificationVersion();
        if (sSpecVersion != null)
            _logger.info("Specification-Version: " + sSpecVersion);

        String sImplVersion = pCurrent.getImplementationVersion();
        if (sImplVersion != null)
            _logger.info("Implementation-Version: " + sImplVersion);

        ServletContext oServletContext = oServletContextEvent.getServletContext();

        Enumeration enumContextAttribs = oServletContext.getInitParameterNames();
        while (enumContextAttribs.hasMoreElements()) {
            String sName = (String) enumContextAttribs.nextElement();
            pConfig.put(sName, oServletContext.getInitParameter(sName));
        }

        if (pConfig.size() > 0) {
            _logger.info("Using configuration items found in servlet context: " + pConfig);
        }

        // Add MountingPoint to PathTranslator
        PathTranslator.getInstance().addKey(MP_WEBAPP_ROOT, oServletContext.getRealPath(""));

        // Try to see whether there is a system property with the location of the properties file:
        String sPropertiesFilename = System.getProperty(PROPERTIES_FILENAME_PROPERTY);
        if (null != sPropertiesFilename && !"".equals(sPropertiesFilename)) {
            File fConfig = new File(sPropertiesFilename);
            if (fConfig.exists()) {
                _logger.info("Reading Asimba properties from " + fConfig.getAbsolutePath());
                pConfig.putAll(getProperties(fConfig));
            }
        }

        String sWebInf = oServletContext.getRealPath("WEB-INF");
        if (sWebInf != null) {
            _logger.info("Cannot find path in ServletContext for WEB-INF");
            StringBuffer sbConfigFile = new StringBuffer(sWebInf);
            if (!sbConfigFile.toString().endsWith(File.separator))
                sbConfigFile.append(File.separator);
            sbConfigFile.append(PROPERTIES_FILENAME);

            File fConfig = new File(sbConfigFile.toString());
            if (fConfig.exists()) {
                _logger.info("Updating configuration items with the items in file: " + fConfig.toString());
                pConfig.putAll(getProperties(fConfig));
            } else {
                _logger.info("No optional configuration properties (" + PROPERTIES_FILENAME
                        + ") file found at: " + fConfig.toString());
            }
        }
        //Search for PROPERTIES_FILENAME file in servlet context classloader classpath 
        //it looks first at this location: ./<context>/web-inf/classes/[PROPERTIES_FILENAME]
        //if previous location didn't contain PROPERTIES_FILENAME then checking: 
        //./tomcat/common/classes/PROPERTIES_FILENAME
        URL urlProperties = oServletContext.getClass().getClassLoader().getResource(PROPERTIES_FILENAME);
        if (urlProperties != null) {
            String sProperties = urlProperties.getFile();
            _logger.debug("Found '" + PROPERTIES_FILENAME + "' file in classpath: " + sProperties);
            File fProperties = new File(sProperties);
            if (fProperties != null && fProperties.exists()) {
                _logger.info("Updating configuration items with the items in file: "
                        + fProperties.getAbsolutePath());
                pConfig.putAll(getProperties(fProperties));
            } else
                _logger.info("Could not resolve: " + fProperties.getAbsolutePath());
        } else
            _logger.info("No optional '" + PROPERTIES_FILENAME
                    + "' configuration file found in servlet context classpath");

        if (!pConfig.containsKey("configuration.handler.filename")) {
            StringBuffer sbOAConfigFile = new StringBuffer(sWebInf);
            if (!sbOAConfigFile.toString().endsWith(File.separator))
                sbOAConfigFile.append(File.separator);
            sbOAConfigFile.append("conf");
            sbOAConfigFile.append(File.separator);
            sbOAConfigFile.append("asimba.xml");
            File fOAConfig = new File(sbOAConfigFile.toString());
            if (fOAConfig.exists()) {
                pConfig.put("configuration.handler.filename", sbOAConfigFile.toString());
                _logger.info(
                        "Setting 'configuration.handler.filename' configuration property with configuration file found at: "
                                + fOAConfig.toString());
            }
        }

        _oEngineLauncher.start(pConfig);

        _logger.info("Started Engine with OAContextListener");
    } catch (Exception e) {
        _logger.error("Can't start Engine with OAContextListener", e);

        _logger.debug("try stopping the server");
        _oEngineLauncher.stop();
    }

}

From source file:com.googlecode.psiprobe.Tomcat55ContainerAdaptor.java

public List getApplicationInitParams(Context context) {
    // We'll try to determine if a parameter value comes from a deployment descriptor or a context descriptor.
    // assumption: Context.findParameter() returns only values of parameters that are declared in a deployment descriptor.
    // If a parameter is declared in a context descriptor with override=false and redeclared in a deployment descriptor,
    // Context.findParameter() still returns its value, even though the value is taken from a context descriptor.
    // context.findApplicationParameters() returns all parameters that are declared in a context descriptor regardless
    // of whether they are overridden in a deployment descriptor or not or not.

    // creating a set of parameter names that are declared in a context descriptor
    // and can not be ovevridden in a deployment descriptor.
    Set nonOverridableParams = new HashSet();
    ApplicationParameter[] appParams = context.findApplicationParameters();
    for (int i = 0; i < appParams.length; i++) {
        if (appParams[i] != null && !appParams[i].getOverride()) {
            nonOverridableParams.add(appParams[i].getName());
        }/*from  w  ww  .  j a v a2 s . c om*/
    }

    List initParams = new ArrayList();
    ServletContext servletCtx = context.getServletContext();
    for (Enumeration e = servletCtx.getInitParameterNames(); e.hasMoreElements();) {
        String paramName = (String) e.nextElement();

        ApplicationParam param = new ApplicationParam();
        param.setName(paramName);
        param.setValue(servletCtx.getInitParameter(paramName));
        // if the parameter is declared in a deployment descriptor
        // and it is not declared in a context descriptor with override=false,
        // the value comes from the deployment descriptor
        param.setFromDeplDescr(
                context.findParameter(paramName) != null && !nonOverridableParams.contains(paramName));
        initParams.add(param);
    }

    return initParams;

}

From source file:com.googlecode.psiprobe.Tomcat80ContainerAdaptor.java

public List getApplicationInitParams(Context context) {
    // We'll try to determine if a parameter value comes from a deployment descriptor or a context descriptor.
    // assumption: Context.findParameter() returns only values of parameters that are declared in a deployment descriptor.
    // If a parameter is declared in a context descriptor with override=false and redeclared in a deployment descriptor,
    // Context.findParameter() still returns its value, even though the value is taken from a context descriptor.
    // context.findApplicationParameters() returns all parameters that are declared in a context descriptor regardless
    // of whether they are overridden in a deployment descriptor or not or not.

    // creating a set of parameter names that are declared in a context descriptor
    // and can not be ovevridden in a deployment descriptor.
    Set nonOverridableParams = new HashSet();
    ApplicationParameter[] appParams = context.findApplicationParameters();
    for (int i = 0; i < appParams.length; i++) {
        if (appParams[i] != null && !appParams[i].getOverride()) {
            nonOverridableParams.add(appParams[i].getName());
        }/*w  ww.  j a va 2  s  .c o  m*/
    }

    List initParams = new ArrayList();
    ServletContext servletCtx = context.getServletContext();
    for (Enumeration e = servletCtx.getInitParameterNames(); e.hasMoreElements();) {
        String paramName = (String) e.nextElement();

        ApplicationParam param = new ApplicationParam();
        param.setName(paramName);
        param.setValue(servletCtx.getInitParameter(paramName));
        // if the parameter is declared in a deployment descriptor
        // and it is not declared in a context descriptor with override=false,
        // the value comes from the deployment descriptor
        param.setFromDeplDescr(
                context.findParameter(paramName) != null && !nonOverridableParams.contains(paramName));
        initParams.add(param);
    }

    return initParams;
}