当前位置: 首页>>代码示例>>Java>>正文


Java RequestContextUtils类代码示例

本文整理汇总了Java中org.springframework.web.servlet.support.RequestContextUtils的典型用法代码示例。如果您正苦于以下问题:Java RequestContextUtils类的具体用法?Java RequestContextUtils怎么用?Java RequestContextUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RequestContextUtils类属于org.springframework.web.servlet.support包,在下文中一共展示了RequestContextUtils类的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: preHandle

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
	if (request.getUserPrincipal() != null) {
		String codiIdioma = request.getParameter(this.paramName);
		
		if (codiIdioma != null) {
			personaService.savePrefIdioma(codiIdioma);
			LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
			if (localeResolver == null)
				throw new IllegalStateException  ("No LocaleResolver found: not in a DispatcherServlet request?");
			LocaleEditor localeEditor = new LocaleEditor();
			localeEditor.setAsText(codiIdioma);
			localeResolver.setLocale(request, response, (Locale)localeEditor.getValue());
		}
	}
	return true;
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:17,代码来源:IdiomaInterceptor.java

示例4: renderMergedOutputModel

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
/**
 * Convert model to request parameters and redirect to the given URL.
 * @see #appendQueryProperties
 * @see #sendRedirect
 */
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws IOException {

	String targetUrl = createTargetUrl(model, request);
	targetUrl = updateTargetUrl(targetUrl, model, request, response);

	FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
	if (!CollectionUtils.isEmpty(flashMap)) {
		UriComponents uriComponents = UriComponentsBuilder.fromUriString(targetUrl).build();
		flashMap.setTargetRequestPath(uriComponents.getPath());
		flashMap.addTargetRequestParams(uriComponents.getQueryParams());
		FlashMapManager flashMapManager = RequestContextUtils.getFlashMapManager(request);
		if (flashMapManager == null) {
			throw new IllegalStateException("FlashMapManager not found despite output FlashMap having been set");
		}
		flashMapManager.saveOutputFlashMap(flashMap, request, response);
	}

	sendRedirect(request, response, targetUrl, this.http10Compatible);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:RedirectView.java

示例5: updateTargetUrl

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
/**
 * Find the registered {@link RequestDataValueProcessor}, if any, and allow
 * it to update the redirect target URL.
 * @param targetUrl the given redirect URL
 * @return the updated URL or the same as URL as the one passed in
 */
protected String updateTargetUrl(String targetUrl, Map<String, Object> model,
		HttpServletRequest request, HttpServletResponse response) {

	WebApplicationContext wac = getWebApplicationContext();
	if (wac == null) {
		wac = RequestContextUtils.findWebApplicationContext(request, getServletContext());
	}

	if (wac != null && wac.containsBean(RequestContextUtils.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) {
		RequestDataValueProcessor processor = wac.getBean(
				RequestContextUtils.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class);
		return processor.processUrl(request, targetUrl);
	}

	return targetUrl;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:RedirectView.java

示例6: getModelAndView

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
private ModelAndView getModelAndView(ModelAndViewContainer mavContainer,
		ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception {

	modelFactory.updateModel(webRequest, mavContainer);
	if (mavContainer.isRequestHandled()) {
		return null;
	}
	ModelMap model = mavContainer.getModel();
	ModelAndView mav = new ModelAndView(mavContainer.getViewName(), model);
	if (!mavContainer.isViewReference()) {
		mav.setView((View) mavContainer.getView());
	}
	if (model instanceof RedirectAttributes) {
		Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
		HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
		RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes);
	}
	return mav;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:RequestMappingHandlerAdapter.java

示例7: handle

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
/**
 * Print {@link MvcResult} details.
 */
@Override
public final void handle(MvcResult result) throws Exception {
	this.printer.printHeading("MockHttpServletRequest");
	printRequest(result.getRequest());

	this.printer.printHeading("Handler");
	printHandler(result.getHandler(), result.getInterceptors());

	this.printer.printHeading("Async");
	printAsyncResult(result);

	this.printer.printHeading("Resolved Exception");
	printResolvedException(result.getResolvedException());

	this.printer.printHeading("ModelAndView");
	printModelAndView(result.getModelAndView());

	this.printer.printHeading("FlashMap");
	printFlashMap(RequestContextUtils.getOutputFlashMap(result.getRequest()));

	this.printer.printHeading("MockHttpServletResponse");
	printResponse(result.getResponse());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:PrintingResultHandler.java

示例8: preHandle

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

    LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
    if (localeResolver == null) {
        return true;
    }

    try {
        Cookie[] cookies = request.getCookies();
        if (cookies != null){
            for (Cookie cookie : cookies){
                if (Objects.equal("lang", cookie.getName())){
                    LocaleContextHolder.setLocale(new Locale(cookie.getValue()));
                }
            }
        }
    } catch (Exception e) {
        Logs.error("occur errors when resolve locale: {}", Throwables.getStackTraceAsString(e));
    }

    return true;
}
 
开发者ID:ihaolin,项目名称:diablo,代码行数:24,代码来源:LocaleInterceptor.java

示例9: handleAllExceptions

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
@ExceptionHandler({Exception.class, RuntimeException.class})
public ModelAndView handleAllExceptions(Exception ex,
                                        HttpServletRequest request) {
    log.error(String.format("An unhandled error occurred on page %s.", request.getRequestURL()) ,ex);

    if (config.isDevOn()) {
        FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
        flashMap.put("exceptionName", ex.getClass().getSimpleName());
        flashMap.put("exception", ex.getMessage());

        StringWriter errors = new StringWriter();
        ex.printStackTrace(new PrintWriter(errors));
        flashMap.put("stackTrace", errors.toString());
    }
    return new ModelAndView("redirect:/error");
}
 
开发者ID:mattpwest,项目名称:entelect-spring-webapp-template,代码行数:17,代码来源:GlobalExceptionControllerAdvice.java

示例10: preHandle

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
    String newLocale = request.getParameter(getParamName());
    if(newLocale != null) {
        LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
        if(localeResolver == null) {
            throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
        }

        Locale locale = StringUtils.parseLocaleString(newLocale);
        localeResolver.setLocale(request, response, locale);
        localeHolder.setLocale(locale);
    }

    return true;
}
 
开发者ID:Javakit,项目名称:Javakit,代码行数:17,代码来源:LocaleChangeInterceptorWrapper.java

示例11: preHandle

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request,
		HttpServletResponse response, Object handler)
		throws ServletException {
	LocaleResolver localeResolver = RequestContextUtils
			.getLocaleResolver(request);
	if (localeResolver == null) {
		throw new IllegalStateException(
				"No LocaleResolver found: not in a DispatcherServlet request?");
	}
//	CmsSite site = CmsUtils.getSite(request);
	CmsSite site=CmsThreadVariable.getSite();
	String newLocale = site.getLocaleAdmin();
	LocaleEditor localeEditor = new LocaleEditor();
	localeEditor.setAsText(newLocale);
	localeResolver.setLocale(request, response, (Locale) localeEditor
			.getValue());
	// Proceed in any case.
	return true;
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:21,代码来源:AdminLocaleInterceptor.java

示例12: preHandle

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request,
		HttpServletResponse response, Object handler)
		throws ServletException {
	LocaleResolver localeResolver = RequestContextUtils
			.getLocaleResolver(request);
	if (localeResolver == null) {
		throw new IllegalStateException(
				"No LocaleResolver found: not in a DispatcherServlet request?");
	}
	CmsSite site = CmsUtils.getSite(request);
	String newLocale = site.getLocaleFront();
	LocaleEditor localeEditor = new LocaleEditor();
	localeEditor.setAsText(newLocale);
	localeResolver.setLocale(request, response, (Locale) localeEditor
			.getValue());
	// Proceed in any case.
	return true;
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:20,代码来源:FrontLocaleInterceptor.java

示例13: 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

示例14: preHandle

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {
	LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);

	// Check if it's our case
	if (localeResolver == null) {
		throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
	}
	if (!(localeResolver instanceof CookieLocaleResolver)) {
		return true;
	}

	// Check if locale not in cookie.
	// If so, then force it to store in cookie
	CookieLocaleResolver cookieLocaleResolver = (CookieLocaleResolver) localeResolver;
	Cookie cookie = WebUtils.getCookie(request, cookieLocaleResolver.getCookieName());
	if (cookie == null) {
		cookieLocaleResolver.setLocale(request, response, localeResolver.resolveLocale(request));
	}

	return true;
}
 
开发者ID:skarpushin,项目名称:summerb,代码行数:24,代码来源:ForceLocaleToCoockieInterceptor.java

示例15: preHandle

import org.springframework.web.servlet.support.RequestContextUtils; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {
	LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);

	// Check if it's our case
	if (localeResolver == null) {
		throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
	}
	if (!(localeResolver instanceof LocaleResolverUserBasedImpl)) {
		return true;
	}

	// Check if locale not in cookie.
	// If so, then force it to store in cookie
	LocaleResolverUserBasedImpl cookieLocaleResolver = (LocaleResolverUserBasedImpl) localeResolver;
	Locale localeFromCookie = cookieLocaleResolver.resolveLocaleFromCookie(request);
	Locale localeFromUser = cookieLocaleResolver.resolveLocale(request);
	if (localeFromUser != null && !localeFromUser.equals(localeFromCookie)) {
		cookieLocaleResolver.setLocale(request, response, localeFromUser);
	}

	return true;
}
 
开发者ID:skarpushin,项目名称:summerb,代码行数:25,代码来源:ForceLocaleToCoockieUserAwareInterceptor.java


注:本文中的org.springframework.web.servlet.support.RequestContextUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。