本文整理匯總了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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
}
}
示例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");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}