Example usage for javax.servlet ServletContext getInitParameter

List of usage examples for javax.servlet ServletContext getInitParameter

Introduction

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

Prototype

public String getInitParameter(String name);

Source Link

Document

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

Usage

From source file:com.ocpsoft.pretty.faces.config.spi.AnnotationConfigurationProvider.java

public PrettyConfig loadConfiguration(ServletContext servletContext) {
    String packageFilters = servletContext.getInitParameter(CONFIG_BASE_PACKAGES);

    if ((packageFilters != null) && packageFilters.trim().equalsIgnoreCase("none")) {
        log.debug("Annotation scanning has is disabled!");
        return null;
    }//from w  ww.  j  ava 2  s .c om

    PackageFilter packageFilter = new PackageFilter(packageFilters);
    LazyBeanNameFinder beanNameFinder = new LazyBeanNameFinder(servletContext);
    PrettyAnnotationHandler annotationHandler = new PrettyAnnotationHandler(beanNameFinder);

    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    if (classloader == null) {
        classloader = this.getClass().getClassLoader();
    }

    List<ClassFinder> classFinders = new ArrayList<ClassFinder>();

    // we will always scan /WEB-INF/classes
    classFinders.add(new WebClassesFinder(servletContext, classloader, packageFilter));

    // does the user want to scan /WEB-INF/lib ?
    String jarConfig = servletContext.getInitParameter(CONFIG_SCAN_LIB_DIR);
    if ((jarConfig != null) && jarConfig.trim().equalsIgnoreCase("true")) {
        classFinders.add(new WebLibFinder(servletContext, classloader, packageFilter));
    }

    for (ClassFinder finder : classFinders) {
        finder.findClasses(annotationHandler);
    }

    PrettyConfigBuilder builder = new PrettyConfigBuilder();
    annotationHandler.build(builder);
    return builder.build();
}

From source file:de.ingrid.iplug.web.BusClientContextListener.java

public void contextInitialized(ServletContextEvent servletcontextevent) {
    ServletContext servletContext = servletcontextevent.getServletContext();
    String communicationFile = servletContext.getInitParameter("communication.xml");
    BusClient busClient = null;/*  www  .ja v a2  s  .  co m*/
    try {
        busClient = connectIBus(communicationFile);
        BeanFactory beanFactory = (BeanFactory) servletContext.getAttribute("beanFactory");
        beanFactory.addBean("busClient", busClient);
    } catch (Exception e1) {
        LOG.error("can not connect to ibus", e1);
    }

}

From source file:com.appeligo.config.ConfigurationInitializer.java

/**
 * Expected to initialize n servlet initializaton.
 *//*w  w  w. j  ava2 s  . c  o m*/
public void contextInitialized(ServletContextEvent event) {

    ServletContext context = event.getServletContext();
    String rootPath = context.getInitParameter("ConfigurationRootDir");
    if (rootPath == null) {
        rootPath = "WEB-INF/config";
    }
    File rootDir = new File(context.getRealPath(rootPath));
    ConfigurationService.setRootDir(rootDir);

    String baseName = context.getInitParameter("ConfigurationBaseName");
    if (baseName != null) {
        ConfigurationService.setBaseName(baseName);
    }

    //configure the environment
    String envName = new EnvironmentLookup().getEnvironmentName();

    if (envName == null) {
        //look it up in the web.xml
        envName = context.getInitParameter("ConfigurationEnvName");
    }

    if (envName != null) {
        ConfigurationService.setEnvName(envName);
    } else {
        log.warn(
                "Cannot find envName from \"deploymentEnvironment\" JNDI variable or \"ConfigurationEnvName\" init param in web.xml. Using default name...");
    }

    ConfigurationService.init();
}

From source file:org.impalaframework.web.spring.WebappPropertyPlaceholderConfigurer.java

public String getWebContextName(ServletContext servletContext) {
    Assert.notNull(servletContext);/*from www . j  a  v  a 2 s.  co  m*/
    String webContextName = servletContext.getInitParameter(WEBAPP_CONFIG_PROPERTY_NAME);

    if (webContextName == null) {
        logger.warn("web.xml for " + servletContext.getServletContextName()
                + " does not define the context parameter (using the element 'context-param' with name "
                + WEBAPP_CONFIG_PROPERTY_NAME + ")");
    }
    return webContextName;
}

From source file:org.apache.shindig.common.servlet.GuiceServletContextListener.java

/**
 * This method sets all the (key,value) properties specified in the web.xml <contextparam> system.properties element
 * if they are not empty./*from  w  w w.java2s .  com*/
 * @param context
 */
private void setSystemProperties(ServletContext context) {
    String systemProperties = context.getInitParameter(SYSTEM_PROPERTIES);
    String key = null;
    String value = null;
    if (systemProperties != null && systemProperties.trim().length() > 0) {
        for (String aProperty : StringUtils.split(systemProperties, '\n')) {
            String[] keyAndvalue = StringUtils.split(aProperty.trim(), "=", 2);
            if (keyAndvalue.length == 2) {
                key = keyAndvalue[0];
                value = keyAndvalue[1];
                //set the system property if they are not empty
                if (key != null && key.trim().length() > 0 && value != null && value.trim().length() > 0) {
                    System.setProperty(key, value);
                }
            }
        }
    }
}

From source file:org.simbasecurity.core.spring.SimbaContextLoaderListener.java

@Override
protected void customizeContext(ServletContext servletContext,
        ConfigurableWebApplicationContext applicationContext) {
    SpringAwareLocator.contextConfigLocation = servletContext.getInitParameter(LOCATOR_FACTORY_SELECTOR_PARAM);
}

From source file:org.mule.config.builders.DeployableMuleXmlContextListener.java

public void initialize(ServletContext context) {
    String config = context.getInitParameter(MuleXmlBuilderContextListener.INIT_PARAMETER_MULE_CONFIG);
    if (config == null) {
        config = MuleServer.DEFAULT_CONFIGURATION;
        if (logger.isDebugEnabled()) {
            logger.debug("No Mule config file(s) specified, using default: " + config);
        }//from   www  .ja  v  a  2 s.c o  m
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Mule config file(s): " + config);
        }
    }

    if (muleContext == null) {
        throw new RuntimeException("MuleContext is not available");
    }

    try {
        configurationBuilder = new WebappMuleXmlConfigurationBuilder(context, config);
        configurationBuilder.setUseDefaultConfigResource(false);

        // Support Spring-first configuration in webapps
        final ApplicationContext parentContext = (ApplicationContext) context
                .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        if (parentContext != null) {
            configurationBuilder.setParentContext(parentContext);
        }
        configurationBuilder.configure(muleContext);
    } catch (MuleException ex) {
        context.log(ex.getMessage(), ex);
        // Logging is not configured OOTB for Tomcat, so we'd better make a
        // start-up failure plain to see.
        ex.printStackTrace();
    } catch (Error error) {
        // WSAD doesn't always report the java.lang.Error, log it
        context.log(error.getMessage(), error);
        // Logging is not configured OOTB for Tomcat, so we'd better make a
        // start-up failure plain to see.
        error.printStackTrace();
        throw error;
    }
}

From source file:org.sakaiproject.tool.gradebook.ui.EntryServlet.java

private void handleMyFacesSecret(ServletContext servletContext) {
    String secret = servletContext.getInitParameter(INIT_SECRET);
    if (secret == null) { // this means that org.apache.myfaces.secret context param was removed from gradebook web.xml
        if (logger.isWarnEnabled())
            logger.warn(/*from   w  w w  .java2  s  .c  o  m*/
                    "MyFaces ViewState encryption has been disabled.  See the MyFaces Wiki for encryption options.");
    } else if (secret.equalsIgnoreCase(GENERATE_RANDOM_SECRET)) {
        int length = 8;
        byte[] bytes = new byte[length];
        new Random().nextBytes(bytes);
        SecretKey secretKey = new SecretKeySpec(bytes, DEFAULT_ALGORITHM);
        servletContext.setAttribute("org.apache.myfaces.secret.CACHE", secretKey);
        if (logger.isDebugEnabled())
            logger.debug("generated random MyFaces secret");
    } // else if this is not true, then org.apache.myfaces.secret context param was customized in web.xml, so let MyFaces StateUtils handle secret
}

From source file:org.aon.esolutions.appconfig.client.web.SystemPropertiesListener.java

private void loadPropsFromClasspath(ServletContext sc) {
    String propertiesLocationProp = sc.getInitParameter("classpath.file.location");

    Properties systemProps = System.getProperties();
    Properties loadedProps = new Properties();
    ClassPathResource appConfigResource = new ClassPathResource(propertiesLocationProp);
    if (appConfigResource.exists()) {

        try {/*from   w w w  . j  ava 2 s  .c  o  m*/
            loadedProps.load(appConfigResource.getInputStream());

            for (Map.Entry<Object, Object> e : loadedProps.entrySet()) {
                if (systemProps.containsKey(e.getKey()) == false)
                    systemProps.put(e.getKey(), e.getValue());
            }
        } catch (Exception e) {
            logger.error("Error loading properties", e);
        }
    }
}

From source file:org.taverna.server.master.notification.atom.AtomFeed.java

@Override
public void setServletContext(ServletContext servletContext) {
    String base = servletContext.getInitParameter(PREFERRED_URI_PARAM);
    if (base == null)
        base = servletContext.getContextPath() + "/rest";
    baseURI = URI.create(base);/*from w  ww.jav  a2  s  . com*/
}