List of usage examples for org.springframework.web.servlet FrameworkServlet SERVLET_CONTEXT_PREFIX
String SERVLET_CONTEXT_PREFIX
To view the source code for org.springframework.web.servlet FrameworkServlet SERVLET_CONTEXT_PREFIX.
Click Source Link
From source file:org.shredzone.commons.taglib.proxy.AbstractTagProxy.java
/** * Gets the {@link BeanFactory} from the given {@link JspContext}. The default * implementation automagically finds a {@link BeanFactory} that was previously set by * a {@link FrameworkServlet}. The result is cached. * * @param jspContext// w w w .ja va 2 s.c o m * {@link JspContext} to be used * @return {@link BeanFactory} found */ @SuppressWarnings("unchecked") protected BeanFactory getBeanFactory(JspContext jspContext) { Object bfCache = jspContext.getAttribute(TAGPROXY_BEANFACTORY_CACHE, PageContext.APPLICATION_SCOPE); if (bfCache != null && bfCache instanceof BeanFactory) { return (BeanFactory) bfCache; } Enumeration<String> en = jspContext.getAttributeNamesInScope(PageContext.APPLICATION_SCOPE); while (en.hasMoreElements()) { String attribute = en.nextElement(); if (attribute.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) { Object bf = jspContext.getAttribute(attribute, PageContext.APPLICATION_SCOPE); if (bf != null && bf instanceof BeanFactory) { BeanFactory bfBean = (BeanFactory) bf; jspContext.setAttribute(TAGPROXY_BEANFACTORY_CACHE, bfBean, PageContext.APPLICATION_SCOPE); return bfBean; } } } throw new IllegalStateException( "Could not find a BeanFactory. Use a FrameworkServlet or @BeanFactoryReference."); }
From source file:com.mtgi.analytics.servlet.BehaviorTrackingListener.java
private synchronized void checkInit(ServletRequestEvent event) { if (!initialized) { ServletContext context = event.getServletContext(); boolean hasFilter = BehaviorTrackingFilter.isFiltered(context); ArrayList<ServletRequestBehaviorTrackingAdapter> beans = new ArrayList<ServletRequestBehaviorTrackingAdapter>(); //find registered request adapters in all mvc servlet contexts. for (Enumeration<?> atts = context.getAttributeNames(); atts.hasMoreElements();) { String name = (String) atts.nextElement(); if (name.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) { Object value = context.getAttribute(name); if (value instanceof ListableBeanFactory) addRequestAdapters(beans, (ListableBeanFactory) value, hasFilter); }/*from w w w . j a v a2 s . c o m*/ } //look for shared application context, loaded by ContextLoaderListener. ListableBeanFactory parent = WebApplicationContextUtils.getWebApplicationContext(context); if (parent != null) addRequestAdapters(beans, parent, hasFilter); if (!beans.isEmpty()) { adapters = beans.toArray(new ServletRequestBehaviorTrackingAdapter[beans.size()]); log.info("BehaviorTracking for HTTP servlet requests started"); } initialized = true; } }
From source file:org.hdiv.config.multipart.SpringMVCMultipartConfig.java
/** * Obtain MultipartResolver instance for this application. * /* w w w . j ava2 s.co m*/ * @param servletContext * app ServletContext * @return MultipartResolver instance */ @SuppressWarnings("rawtypes") protected MultipartResolver lookupMultipartResolver(ServletContext servletContext) { MultipartResolver resolver = null; if (this.webApplicationContext == null) { this.webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); } try { resolver = this.webApplicationContext.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class); if (resolver != null) { return resolver; } } catch (NoSuchBeanDefinitionException ex) { // No MultipartResolver in this context. } if (resolver == null) { Enumeration e = servletContext.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); if (name.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) { this.webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext, name); break; } } } if (this.webApplicationContext != null) { try { resolver = this.webApplicationContext.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class); } catch (NoSuchBeanDefinitionException ex) { // No MultipartResolver in this context. } } if (log.isDebugEnabled() && resolver == null) { log.debug("Cant find MultipartResolver on any context."); } return resolver; }