當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestContextUtils.getWebApplicationContext方法代碼示例

本文整理匯總了Java中org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestContextUtils.getWebApplicationContext方法的具體用法?Java RequestContextUtils.getWebApplicationContext怎麽用?Java RequestContextUtils.getWebApplicationContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.servlet.support.RequestContextUtils的用法示例。


在下文中一共展示了RequestContextUtils.getWebApplicationContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBeanFactory

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * @return A found BeanFactory configuration
 */
private BeanFactory getBeanFactory()
{
    // If someone has set a resource name then we need to load that.
    if (configLocation != null && configLocation.length > 0)
    {
        log.info("Spring BeanFactory via ClassPathXmlApplicationContext using " + configLocation.length + "configLocations.");
        return new ClassPathXmlApplicationContext(configLocation);
    }

    ServletContext srvCtx = WebContextFactory.get().getServletContext();
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();

    if (request != null)
    {
        return RequestContextUtils.getWebApplicationContext(request, srvCtx);
    }
    else
    {
        return WebApplicationContextUtils.getWebApplicationContext(srvCtx);
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:25,代碼來源:SpringCreator.java

示例2: getBeanFactory

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * @return A found BeanFactory configuration
 */
private BeanFactory getBeanFactory()
{
    // If someone has set a resource name then we need to load that.
    if (configLocation != null && configLocation.length > 0)
    {
        log.info("Spring BeanFactory via ClassPathXmlApplicationContext using " + configLocation.length + "configLocations.");
        return new ClassPathXmlApplicationContext(configLocation);
    }

    ServletContext srvCtx = ServerContextFactory.get().getServletContext();

    HttpServletRequest request = null;
    try
    {
        request = WebContextFactory.get().getHttpServletRequest();
    }
    catch (Exception ex)
    {
        // Probably on boot time
    }
    return request != null ? RequestContextUtils.getWebApplicationContext(request, srvCtx) : WebApplicationContextUtils.getWebApplicationContext(srvCtx);
}
 
開發者ID:directwebremoting,項目名稱:dwr,代碼行數:26,代碼來源:SpringCreator.java

示例3: getMessage

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * 獲得國際化信息
 * 
 * @param request
 *            HttpServletRequest
 * @param code
 *            國際化代碼
 * @param args
 *            替換參數
 * @return
 * @see org.springframework.context.MessageSource#getMessage(String,
 *      Object[], Locale)
 */
public static String getMessage(HttpServletRequest request, String code,
		Object... args) {
	WebApplicationContext messageSource = RequestContextUtils.getWebApplicationContext(request);
	if (messageSource == null) {
		throw new IllegalStateException("WebApplicationContext not found!");
	}
	LocaleResolver localeResolver = RequestContextUtils
			.getLocaleResolver(request);
	Locale locale;
	if (localeResolver != null) {
		locale = localeResolver.resolveLocale(request);
	} else {
		locale = request.getLocale();
	}
	return messageSource.getMessage(code, args, locale);
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:30,代碼來源:MessageResolver.java

示例4: handleRequest

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@Override
@SuppressWarnings("deprecation")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	if (!(RequestContextUtils.getWebApplicationContext(request) instanceof SimpleWebApplicationContext)) {
		throw new ServletException("Incorrect WebApplicationContext");
	}
	if (!(RequestContextUtils.getLocaleResolver(request) instanceof AcceptHeaderLocaleResolver)) {
		throw new ServletException("Incorrect LocaleResolver");
	}
	if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) {
		throw new ServletException("Incorrect Locale");
	}
	return null;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:SimpleWebApplicationContext.java

示例5: getMockRequestDataValueProcessor

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
protected RequestDataValueProcessor getMockRequestDataValueProcessor() {
	RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
	ServletRequest request = getPageContext().getRequest();
	StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.getWebApplicationContext(request);
	wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
	return mockProcessor;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:9,代碼來源:AbstractHtmlElementTagTests.java

示例6: nullMessageSource

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@Test
@SuppressWarnings("deprecation")
public void nullMessageSource() throws JspException {
	PageContext pc = createPageContext();
	ConfigurableWebApplicationContext ctx = (ConfigurableWebApplicationContext)
			RequestContextUtils.getWebApplicationContext(pc.getRequest(), pc.getServletContext());
	ctx.close();

	MessageTag tag = new MessageTag();
	tag.setPageContext(pc);
	tag.setCode("test");
	tag.setVar("testvar2");
	tag.doStartTag();
	assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:MessageTagTests.java

示例7: getResourceKey

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * 獲取資源key
 * @param request
 * @param key
 * @param args 附帶參數
 * @return
 */
public static String getResourceKey(HttpServletRequest request,String key,Object[] args){
    WebApplicationContext ac =RequestContextUtils.getWebApplicationContext(request);
    if(StringUtil.isNotNull(key)){
        return ac.getMessage(key,args, RequestContextUtils.getLocale(request));
    }
    return null;
}
 
開發者ID:haizicq,項目名稱:osframe,代碼行數:15,代碼來源:ResourceUtil.java

示例8: WebErrors

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * 通過HttpServletRequest創建WebErrors
 * 
 * @param request
 *            從request中獲得MessageSource和Locale,如果存在的話。
 */
public WebErrors(HttpServletRequest request) {
	WebApplicationContext webApplicationContext = RequestContextUtils
			.getWebApplicationContext(request);
	if (webApplicationContext != null) {
		LocaleResolver localeResolver = RequestContextUtils
				.getLocaleResolver(request);
		Locale locale;
		if (localeResolver != null) {
			locale = localeResolver.resolveLocale(request);
			this.messageSource = webApplicationContext;
			this.locale = locale;
		}
	}
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:21,代碼來源:WebErrors.java

示例9: doSomething

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@Override
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException {
	WebApplicationContext wac = RequestContextUtils.getWebApplicationContext(request);
	if (!(wac instanceof ComplexWebApplicationContext)) {
		throw new ServletException("Incorrect WebApplicationContext");
	}
	if (!(request instanceof MultipartHttpServletRequest)) {
		throw new ServletException("Not in a MultipartHttpServletRequest");
	}
	if (!(RequestContextUtils.getLocaleResolver(request) instanceof SessionLocaleResolver)) {
		throw new ServletException("Incorrect LocaleResolver");
	}
	if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) {
		throw new ServletException("Incorrect Locale");
	}
	if (!Locale.CANADA.equals(LocaleContextHolder.getLocale())) {
		throw new ServletException("Incorrect Locale");
	}
	if (!(RequestContextUtils.getThemeResolver(request) instanceof SessionThemeResolver)) {
		throw new ServletException("Incorrect ThemeResolver");
	}
	if (!"theme".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
		throw new ServletException("Incorrect theme name");
	}
	if (request.getParameter("fail") != null) {
		throw new ModelAndViewDefiningException(new ModelAndView("failed1"));
	}
	if (request.getParameter("access") != null) {
		throw new IllegalAccessException("illegal access");
	}
	if (request.getParameter("servlet") != null) {
		throw new ServletRequestBindingException("servlet");
	}
	if (request.getParameter("exception") != null) {
		throw new RuntimeException("servlet");
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:38,代碼來源:ComplexWebApplicationContext.java

示例10: handleRequest

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	if (!(RequestContextUtils.getWebApplicationContext(request) instanceof SimpleWebApplicationContext)) {
		throw new ServletException("Incorrect WebApplicationContext");
	}
	if (!(RequestContextUtils.getLocaleResolver(request) instanceof AcceptHeaderLocaleResolver)) {
		throw new ServletException("Incorrect LocaleResolver");
	}
	if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) {
		throw new ServletException("Incorrect Locale");
	}
	return null;
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:15,代碼來源:SimpleWebApplicationContext.java

示例11: createAndPopulatePageContext

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
protected MockPageContext createAndPopulatePageContext() throws JspException {
	MockPageContext pageContext = createPageContext();
	MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest();
	StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.getWebApplicationContext(request);
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	extendRequest(request);
	extendPageContext(pageContext);
	RequestContext requestContext = new JspAwareRequestContext(pageContext);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
	return pageContext;
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:12,代碼來源:AbstractHtmlElementTagTests.java

示例12: getMockRequestDataValueProcessor

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
protected RequestDataValueProcessor getMockRequestDataValueProcessor() {
	RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
	ServletRequest request = getPageContext().getRequest();
	StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.getWebApplicationContext(request);
	wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
	return mockProcessor;
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:8,代碼來源:AbstractHtmlElementTagTests.java

示例13: testNullMessageSource

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
public void testNullMessageSource() throws JspException {
	PageContext pc = createPageContext();
	ConfigurableWebApplicationContext ctx = (ConfigurableWebApplicationContext)
			RequestContextUtils.getWebApplicationContext(pc.getRequest(), pc.getServletContext());
	ctx.close();

	MessageTag tag = new MessageTag();
	tag.setPageContext(pc);
	tag.setCode("test");
	tag.setVar("testvar2");
	tag.doStartTag();
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:13,代碼來源:MessageTagTests.java

示例14: execute

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * This implementation delegates to {@code doPerform},
 * lazy-initializing the application context reference if necessary.
 * <p>This is the preferred execution method in Struts 1.2.
 * When running with Struts 1.1, it will be called by {@code perform}.
 * @see #perform
 * @see #doPerform
 */
@Override
public final void execute(
		ComponentContext componentContext, HttpServletRequest request,
		HttpServletResponse response, ServletContext servletContext)
	throws Exception {

	synchronized (this) {
		if (this.webApplicationContext == null) {
			this.webApplicationContext = RequestContextUtils.getWebApplicationContext(request, servletContext);
			this.messageSourceAccessor = new MessageSourceAccessor(this.webApplicationContext);
		}
	}
	doPerform(componentContext, request, response);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:23,代碼來源:ComponentControllerSupport.java

示例15: getResource

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * @see I18nResourceProvider#getResource(String, String, Tag, PageContext)
 */
@Override
public String getResource(String resourceKey, String defaultValue, Tag tag, PageContext pageContext)
{
    MessageSource messageSource = RequestContextUtils.getWebApplicationContext(pageContext.getRequest(), pageContext.getServletContext());
    if (messageSource == null)
    {
        log.warn("messageSource not found");
        return null;
    }

    // if resourceKey isn't defined either, use defaultValue
    String key = (resourceKey != null) ? resourceKey : defaultValue;

    String message = null;

    message = messageSource.getMessage(key, null, null, RequestContextUtils
        .getLocale((HttpServletRequest) pageContext.getRequest()));

    // if user explicitely added a titleKey we guess this is an error
    if (message == null && resourceKey != null)
    {
        log.debug(Messages.getString("Localization.missingkey", resourceKey)); //$NON-NLS-1$
        message = UNDEFINED_KEY + resourceKey + UNDEFINED_KEY;
    }

    return message;

}
 
開發者ID:webbfontaine,項目名稱:displaytag,代碼行數:32,代碼來源:I18nSpringAdapter.java


注:本文中的org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。