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:ch.qos.logback.ext.spring.web.WebLogbackConfigurer.java
/** * Return whether to expose the web app root system property, * checking the corresponding ServletContext init parameter. * * @param servletContext the servlet context * @return {@code true} if the webapp's root should be exposed; otherwise, {@code false} * @see #EXPOSE_WEB_APP_ROOT_PARAM//from w ww . jav a2s. com */ @SuppressWarnings({ "BooleanMethodNameMustStartWithQuestion" }) private static boolean exposeWebAppRoot(ServletContext servletContext) { String exposeWebAppRootParam = servletContext.getInitParameter(EXPOSE_WEB_APP_ROOT_PARAM); return (exposeWebAppRootParam == null || Boolean.valueOf(exposeWebAppRootParam)); }
From source file:com.orange.wro.taglib.config.WroConfig.java
private static WroConfigOptions getOptionsFromInitParams(ServletContext servletContext) { WroConfigOptions configOptions = new WroConfigOptions(); configOptions.setWroBaseUrl(servletContext.getInitParameter(WRO_BASE_URL_ATTRIBUTE)); configOptions.setLessJsPath(servletContext.getInitParameter(LESS_SCRIPT_ATTRIBUTE)); configOptions.setPretty(Boolean.parseBoolean(servletContext.getInitParameter(PRETTY_ATTRIBUTE))); configOptions.setMinimize(Boolean.parseBoolean(servletContext.getInitParameter(MINIMIZE_ATTRIBUTE))); configOptions.setExploded(Boolean.parseBoolean(servletContext.getInitParameter(EXPLODED_ATTRIBUTE))); configOptions.setDebug(Boolean.parseBoolean(servletContext.getInitParameter(DEBUG_ATTRIBUTE))); return configOptions; }
From source file:com.tacitknowledge.util.migration.jdbc.util.ConfigurationUtil.java
/** * Returns the value of the specified servlet context initialization parameter. * * @param param the parameter to return * @param sce the <code>ServletContextEvent</code> being handled * @param caller calling object, used for printing information if there is a problem * @param throwException if <code>true</code> then the method will throw an exception; if * <code>false</code> is supplied then it will return <code>null</code> * @return the value of the specified servlet context initialization parameter if found; * <code>null</code> otherwise * @throws IllegalArgumentException if the parameter does not exist *///from w ww .j a v a 2 s . c om private static String getServletContextParam(String param, ServletContextEvent sce, Object caller, boolean throwException) throws IllegalArgumentException { ServletContext context = sce.getServletContext(); String value = context.getInitParameter(param); if (value == null && throwException) { throw new IllegalArgumentException( "'" + param + "' is a required " + "servlet context initialization parameter for the \"" + caller.getClass().getName() + "\" class. Aborting."); } return value; }
From source file:com.qualogy.qafe.web.ContextLoader.java
private static void create(ServletContext servletContext) throws MalformedURLException, URISyntaxException { String configLocation = servletContext.getInitParameter(CONFIG_FILE_PARAM); String contextPath = getContextPath(servletContext); QafeConfigurationManager contextInitialiser = new QafeConfigurationManager(contextPath); ApplicationContext springContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); contextInitialiser.setSpringContext(springContext); qafeContext.putInstance(QafeConfigurationManager.class.getName(), contextInitialiser); StopWatch watch = new StopWatch(); watch.start();/*from w ww . j av a 2s.com*/ ApplicationContextLoader.unload(); // The default way: works on JBoss/Tomcat/Jetty String configFileLocation = servletContext.getRealPath("/WEB-INF/"); if (configFileLocation != null) { configFileLocation += File.separator + configLocation; logger.log(Level.INFO, "URL to config file on disk :" + configFileLocation + ")"); ApplicationContextLoader.load(configFileLocation, true); } else { // This is how a weblogic explicitly wants the fetching of resources. URL url = servletContext.getResource("/WEB-INF/" + configLocation); logger.log(Level.INFO, "Fallback scenario" + url.toString()); if (url != null) { logger.log(Level.INFO, "URL to config file " + url.toString()); ApplicationContextLoader.load(url.toURI(), true); } else { throw new RuntimeException( "Strange Error: /WEB-INF/ cannot be found. Check the appserver or installation directory."); } } watch.stop(); logger.log(Level.INFO, "Root WebApplicationContext: initialization completed in " + watch.getTime() + " ms"); }
From source file:org.codehaus.groovy.grails.web.context.GrailsConfigUtils.java
public static GrailsRuntimeConfigurator determineGrailsRuntimeConfiguratorFromServletContext( GrailsApplication application, ServletContext servletContext, ApplicationContext parent) { GrailsRuntimeConfigurator configurator = null; if (servletContext.getInitParameter(GrailsRuntimeConfigurator.BEAN_ID + "Class") != null) { // try to load configurator class as specified in servlet context String configuratorClassName = servletContext .getInitParameter(GrailsRuntimeConfigurator.BEAN_ID + "Class").toString(); Class<?> configuratorClass = null; try {// w ww . ja va 2 s .com configuratorClass = ClassUtils.forName(configuratorClassName, application.getClassLoader()); } catch (Exception e) { String msg = "failed to create Grails runtime configurator as specified in web.xml: " + configuratorClassName; LOG.error("[GrailsContextLoader] " + msg, e); throw new IllegalArgumentException(msg); } if (!GrailsRuntimeConfigurator.class.isAssignableFrom(configuratorClass)) { throw new IllegalArgumentException("class " + configuratorClassName + " is not assignable to " + GrailsRuntimeConfigurator.class.getName()); } Constructor<?> constr = ClassUtils.getConstructorIfAvailable(configuratorClass, GrailsApplication.class, ApplicationContext.class); configurator = (GrailsRuntimeConfigurator) BeanUtils.instantiateClass(constr, application, parent); } return configurator; }
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); }//from w w w . ja v a2s .c o m }); }
From source file:at.gv.egiz.bku.online.webapp.MoccaParameterBean.java
public static String getInitParameter(String name, ServletConfig config, ServletContext context) { String initVal = config.getInitParameter(name); String contextVal = context.getInitParameter(config.getServletName() + "." + name); log.debug("Reading init param " + name + ": " + initVal + " - context param " + (config.getServletName() + "." + name) + ": " + contextVal); if (contextVal != null) return contextVal; return initVal; }
From source file:de.itsvs.cwtrpc.core.CwtRpcUtils.java
public static void preloadContextClasses(ServletContext servletContext) throws ApplicationContextException { final Log log = LogFactory.getLog(CwtRpcUtils.class); final String preloadedClasses; preloadedClasses = servletContext.getInitParameter(PRELOADED_CLASSES_INIT_PARAM_NAME); if (preloadedClasses != null) { final String[] classNames = preloadedClasses.split("\\s"); for (String className : classNames) { if (className.length() > 0) { if (log.isDebugEnabled()) { log.debug("Preloading class: " + className); }//from www. j a va 2 s .com try { CwtRpcUtils.class.getClassLoader().loadClass(className); } catch (ClassNotFoundException e) { throw new ApplicationContextException("Could not load class '" + className + "'", e); } } } } }
From source file:org.apache.myfaces.shared_impl.config.MyfacesConfig.java
/** * ExtensionFilter needs access to AddResourceClass init param without having * an ExternalContext at hand./* w w w.j a va2 s . c o m*/ */ public static String getAddResourceClassFromServletContext(ServletContext servletContext) { String addResourceClass = servletContext.getInitParameter(INIT_PARAM_ADD_RESOURCE_CLASS); if (addResourceClass == null) { return INIT_PARAM_ADD_RESOURCE_CLASS_DEFAULT; } else { return addResourceClass; } }
From source file:com.scf.web.context.spring.ProjectLog4jWebConfigurer.java
public static void initLogging(ServletContext servletContext, String location) { if (location != null) { try {//www . j ava 2 s.c om // Write log message to server log. servletContext.log("Initializing log4j from [" + location + "]"); // Check whether refresh interval was specified. String intervalString = servletContext.getInitParameter(REFRESH_INTERVAL_PARAM); if (StringUtils.hasText(intervalString)) { // Initialize with refresh interval, i.e. with log4j's watchdog thread, // checking the file in the background. try { long refreshInterval = Long.parseLong(intervalString); Log4jConfigurer.initLogging(location, refreshInterval); } catch (NumberFormatException ex) { throw new IllegalArgumentException( "Invalid 'log4jRefreshInterval' parameter: " + ex.getMessage()); } } else { // Initialize without refresh check, i.e. without log4j's watchdog thread. Log4jConfigurer.initLogging(location); } } catch (FileNotFoundException ex) { throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); } } }