List of usage examples for javax.servlet ServletContext getInitParameter
public String getInitParameter(String name);
String
containing the value of the named context-wide initialization parameter, or null
if the parameter does not exist. From source file:org.openhie.openempi.webapp.listener.StartupListener.java
@SuppressWarnings({ "unchecked" }) public void contextInitialized(ServletContextEvent event) { log.debug("Initializing context..."); ServletContext context = event.getServletContext(); // Orion starts Servlets before Listeners, so check if the config // object already exists Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG); if (config == null) { config = new HashMap<String, Object>(); }/*from w w w .j av a 2 s . c o m*/ if (context.getInitParameter(Constants.CSS_THEME) != null) { config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME)); } ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); /*String[] beans = ctx.getBeanDefinitionNames(); for (String bean : beans) { log.debug(bean); }*/ PasswordEncoder passwordEncoder = null; try { ProviderManager provider = (ProviderManager) ctx.getBean("_authenticationManager"); for (Object o : provider.getProviders()) { AuthenticationProvider p = (AuthenticationProvider) o; if (p instanceof RememberMeAuthenticationProvider) { config.put("rememberMeEnabled", Boolean.TRUE); } else if (ctx.getBean("passwordEncoder") != null) { passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder"); } } } catch (NoSuchBeanDefinitionException n) { log.debug("authenticationManager bean not found, assuming test and ignoring..."); // ignore, should only happen when testing } context.setAttribute(Constants.CONFIG, config); // output the retrieved values for the Init and Context Parameters if (log.isDebugEnabled()) { log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled")); if (passwordEncoder != null) { log.debug("Password Encoder: " + passwordEncoder.getClass().getName()); } log.debug("Populating drop-downs..."); } setupContext(context); }
From source file:org.openmrs.contrib.metadatarepository.webapp.listener.StartupListener.java
/** * {@inheritDoc}/* w w w.ja v a 2 s .c o m*/ */ @SuppressWarnings("unchecked") public void contextInitialized(ServletContextEvent event) { log.debug("Initializing context..."); ServletContext context = event.getServletContext(); // Orion starts Servlets before Listeners, so check if the config // object already exists Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG); if (config == null) { config = new HashMap<String, Object>(); } if (context.getInitParameter(Constants.CSS_THEME) != null) { config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME)); } ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); /*String[] beans = ctx.getBeanDefinitionNames(); for (String bean : beans) { log.debug(bean); }*/ PasswordEncoder passwordEncoder = null; try { ProviderManager provider = (ProviderManager) ctx .getBean("org.springframework.security.authentication.ProviderManager#0"); for (Object o : provider.getProviders()) { AuthenticationProvider p = (AuthenticationProvider) o; if (p instanceof RememberMeAuthenticationProvider) { config.put("rememberMeEnabled", Boolean.TRUE); } else if (ctx.getBean("passwordEncoder") != null) { passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder"); } } } catch (NoSuchBeanDefinitionException n) { log.debug("authenticationManager bean not found, assuming test and ignoring..."); // ignore, should only happen when testing } context.setAttribute(Constants.CONFIG, config); // output the retrieved values for the Init and Context Parameters if (log.isDebugEnabled()) { log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled")); if (passwordEncoder != null) { log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName()); } log.debug("Populating drop-downs..."); } setupContext(context); }
From source file:org.apache.struts2.views.freemarker.FreemarkerManager.java
/** * The default template loader is a MultiTemplateLoader which includes * a ClassTemplateLoader and a WebappTemplateLoader (and a FileTemplateLoader depending on * the init-parameter 'TemplatePath')./*from w w w . j a v a 2 s .co m*/ * <p/> * The ClassTemplateLoader will resolve fully qualified template includes * that begin with a slash. for example /com/company/template/common.ftl * <p/> * The WebappTemplateLoader attempts to resolve templates relative to the web root folder */ protected TemplateLoader getTemplateLoader(ServletContext servletContext) { // construct a FileTemplateLoader for the init-param 'TemplatePath' FileTemplateLoader templatePathLoader = null; String templatePath = servletContext.getInitParameter("TemplatePath"); if (templatePath == null) { templatePath = servletContext.getInitParameter("templatePath"); } if (templatePath != null) { try { templatePathLoader = new FileTemplateLoader(new File(templatePath)); } catch (IOException e) { log.error("Invalid template path specified: " + e.getMessage(), e); } } // presume that most apps will require the class and webapp template loader // if people wish to return templatePathLoader != null ? new MultiTemplateLoader(new TemplateLoader[] { templatePathLoader, new WebappTemplateLoader(servletContext), new StrutsClassTemplateLoader() }) : new MultiTemplateLoader(new TemplateLoader[] { new WebappTemplateLoader(servletContext), new StrutsClassTemplateLoader() }); }
From source file:architecture.ee.component.core.lifecycle.RepositoryImpl.java
public void setServletContext(ServletContext servletContext) { // 1. ?? ? ? ? : ARCHITECTURE_INSTALL_ROOT String value = servletContext.getInitParameter(ApplicationConstants.ARCHITECTURE_PROFILE_ROOT_ENV_KEY); if (!StringUtils.isEmpty(value)) { try {//from ww w. ja va 2 s .co m ServletContextResourceLoader servletResoruceLoader = new ServletContextResourceLoader( servletContext); Resource resource = servletResoruceLoader.getResource(value); if (resource.exists()) { log.debug(L10NUtils.format("003003", ApplicationConstants.ARCHITECTURE_PROFILE_ROOT_ENV_KEY, resource.getURI())); this.rootResource = resource; setState(State.INITIALIZED); initailized = true; } } catch (Throwable e) { this.rootResource = null; } } if (!initailized && !StringUtils.isEmpty(value)) { Resource obj; try { obj = resoruceLoader.getResource(value); if (obj.exists()) { log.debug(L10NUtils.format("003003", ApplicationConstants.ARCHITECTURE_PROFILE_ROOT_ENV_KEY, obj.getURI())); this.rootResource = obj; setState(State.INITIALIZED); initailized = true; } } catch (Throwable e) { log.error(e); } } if (!initailized) { try { ServletContextResource resource = new ServletContextResource(servletContext, "/WEB-INF"); File file = resource.getFile(); if (file.exists()) { this.rootResource = new FileSystemResource(file); setState(State.INITIALIZED); initailized = true; } } catch (Throwable e) { log.error(e); } } }
From source file:com.gisgraphy.webapp.listener.StartupListener.java
@SuppressWarnings({ "unchecked" }) public void contextInitialized(ServletContextEvent event) { log.debug("initializing context..."); ServletContext context = event.getServletContext(); // Orion starts Servlets before Listeners, so check if the config // object already exists Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG); if (config == null) { config = new HashMap<String, Object>(); }/*from ww w . ja va 2 s .c o m*/ if (context.getInitParameter(Constants.CSS_THEME) != null) { config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME)); } ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); boolean encryptPassword = true; try { ProviderManager provider = (ProviderManager) ctx .getBean(ctx.getBeanNamesForType(ProviderManager.class)[0]); for (Object o : provider.getProviders()) { AuthenticationProvider p = (AuthenticationProvider) o; if (p instanceof RememberMeAuthenticationProvider) { config.put("rememberMeEnabled", Boolean.TRUE); } config.put(Constants.ENCRYPT_PASSWORD, Boolean.TRUE); config.put(Constants.ENC_ALGORITHM, "SHA"); } } catch (NoSuchBeanDefinitionException n) { log.debug("authenticationManager bean not found, assuming test and ignoring..."); // ignore, should only happen when testing } context.setAttribute(Constants.CONFIG, config); // output the retrieved values for the Init and Context Parameters if (log.isDebugEnabled()) { log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled")); log.debug("Encrypt Passwords? " + encryptPassword); if (encryptPassword) { log.debug("Encryption Algorithm: " + config.get(Constants.ENC_ALGORITHM)); } log.debug("Populating drop-downs..."); } setupContext(context); }
From source file:org.iplantc.phyloviewer.viewer.server.ParseTreeService.java
@Override public void init() throws ServletException { ServletContext servletContext = this.getServletContext(); IImportTreeData treeImporter = (IImportTreeData) servletContext .getAttribute(Constants.IMPORT_TREE_DATA_KEY); ImportTreeLayout layoutImporter = (ImportTreeLayout) servletContext .getAttribute(Constants.IMPORT_TREE_LAYOUT_KEY); String path = servletContext.getInitParameter("treefile.path"); path = servletContext.getRealPath(path); parseTree = new ParseTree(treeImporter, layoutImporter); parseTree.setTreeBackupDir(path);// ww w.j a v a2 s.c om Logger.getLogger("org.iplantc.phyloviewer").log(Level.INFO, "Setting parseTree file backup path to " + parseTree.getTreeBackupDir().getAbsolutePath()); }
From source file:au.org.paperminer.main.UserFilter.java
@Override public void init(FilterConfig config) throws ServletException { m_logger = Logger.getLogger(PaperMinerConstants.LOGGER); m_logger.info("AddUserFilter init"); ServletContext ctx = config.getServletContext(); m_serverName = ctx.getInitParameter("server-name"); m_logger.debug("Server=" + m_serverName); }
From source file:com.jaspersoft.jasperserver.war.xmla.XmlaServletImpl.java
public void init(ServletConfig config) throws ServletException { ServletContext servletContext = config.getServletContext(); // TODO it is meaningless to generate URLs here, but the XMLServlet requires it // Looks like XML/A clients ignore the URL try {//from w w w.ja v a 2 s .c o m InetAddress local = InetAddress.getLocalHost(); // We can override the default protocol and port with servlet init parameters String defaultProtocol = servletContext.getInitParameter("defaultProtocol"); if (defaultProtocol == null || defaultProtocol.trim().length() == 0) { defaultProtocol = "http"; } String defaultPort = servletContext.getInitParameter("defaultPort"); if (defaultPort == null || defaultPort.trim().length() == 0) { defaultPort = "-1"; } int port = Integer.parseInt(defaultPort); URL root = servletContext.getResource("/"); // Looks like the path will be /localhost/webapp int pastHost = root.getPath().indexOf("/", 1); String path = root.getPath().substring(pastHost, root.getPath().length()); SERVER_URL = (new URL(defaultProtocol, local.getCanonicalHostName(), port, path)).toString() + "xmla"; } catch (Exception e) { throw new RuntimeException(e); } super.init(config); }
From source file:gov.nih.nci.caarray.web.action.registration.RegistrationAction.java
/** * {@inheritDoc}/*from w w w . j av a2 s. c o 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:ejportal.webapp.listener.StartupListener.java
/** * {@inheritDoc}/*from www .j a v a2 s . co m*/ */ @SuppressWarnings("unchecked") public void contextInitialized(final ServletContextEvent event) { StartupListener.log.debug("Initializing context..."); final ServletContext context = event.getServletContext(); // Orion starts Servlets before Listeners, so check if the config // object already exists Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG); if (config == null) { config = new HashMap<String, Object>(); } if (context.getInitParameter(Constants.CSS_THEME) != null) { config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME)); } final ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); /* * String[] beans = ctx.getBeanDefinitionNames(); for (String bean : * beans) { log.debug(bean); } */ PasswordEncoder passwordEncoder = null; try { final ProviderManager provider = (ProviderManager) ctx.getBean("_authenticationManager"); for (final Object o : provider.getProviders()) { final AuthenticationProvider p = (AuthenticationProvider) o; if (p instanceof RememberMeAuthenticationProvider) { config.put("rememberMeEnabled", Boolean.TRUE); } else if (ctx.getBean("passwordEncoder") != null) { passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder"); } } } catch (final NoSuchBeanDefinitionException n) { StartupListener.log.debug("authenticationManager bean not found, assuming test and ignoring..."); // ignore, should only happen when testing } context.setAttribute(Constants.CONFIG, config); // output the retrieved values for the Init and Context Parameters if (StartupListener.log.isDebugEnabled()) { StartupListener.log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled")); if (passwordEncoder != null) { StartupListener.log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName()); } StartupListener.log.debug("Populating drop-downs..."); } StartupListener.setupContext(context); }