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


Java RequestContextUtils.getTimeZone方法代码示例

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


在下文中一共展示了RequestContextUtils.getTimeZone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTimeZone

import org.springframework.web.servlet.support.RequestContextUtils; //导入方法依赖的package包/类
@Override
public TimeZone getTimeZone() {
	TimeZone timeZone = RequestContextUtils.getTimeZone(this.request);
	return (timeZone != null ? timeZone : super.getTimeZone());
}
 
开发者ID:ghimisradu,项目名称:spring-velocity-adapter,代码行数:6,代码来源:VelocityView.java

示例2: resolveZoneId

import org.springframework.web.servlet.support.RequestContextUtils; //导入方法依赖的package包/类
private ZoneId resolveZoneId(HttpServletRequest request) {
    TimeZone timeZone = RequestContextUtils.getTimeZone(request);
    return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault());
}
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:5,代码来源:ArticleRestController.java

示例3: resolveArgument

import org.springframework.web.servlet.support.RequestContextUtils; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	Class<?> paramType = parameter.getParameterType();
	if (WebRequest.class.isAssignableFrom(paramType)) {
		return webRequest;
	}

	HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
	if (ServletRequest.class.isAssignableFrom(paramType) || MultipartRequest.class.isAssignableFrom(paramType)) {
		Object nativeRequest = webRequest.getNativeRequest(paramType);
		if (nativeRequest == null) {
			throw new IllegalStateException(
					"Current request is not of type [" + paramType.getName() + "]: " + request);
		}
		return nativeRequest;
	}
	else if (HttpSession.class.isAssignableFrom(paramType)) {
		return request.getSession();
	}
	else if (HttpMethod.class == paramType) {
		return ((ServletWebRequest) webRequest).getHttpMethod();
	}
	else if (Principal.class.isAssignableFrom(paramType)) {
		return request.getUserPrincipal();
	}
	else if (Locale.class == paramType) {
		return RequestContextUtils.getLocale(request);
	}
	else if (TimeZone.class == paramType) {
		TimeZone timeZone = RequestContextUtils.getTimeZone(request);
		return (timeZone != null ? timeZone : TimeZone.getDefault());
	}
	else if ("java.time.ZoneId".equals(paramType.getName())) {
		return ZoneIdResolver.resolveZoneId(request);
	}
	else if (InputStream.class.isAssignableFrom(paramType)) {
		return request.getInputStream();
	}
	else if (Reader.class.isAssignableFrom(paramType)) {
		return request.getReader();
	}
	else {
		// should never happen...
		throw new UnsupportedOperationException(
				"Unknown parameter type: " + paramType + " in method: " + parameter.getMethod());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:50,代码来源:ServletRequestMethodArgumentResolver.java

示例4: resolveZoneId

import org.springframework.web.servlet.support.RequestContextUtils; //导入方法依赖的package包/类
public static Object resolveZoneId(HttpServletRequest request) {
	TimeZone timeZone = RequestContextUtils.getTimeZone(request);
	return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:ServletRequestMethodArgumentResolver.java

示例5: doSomething

import org.springframework.web.servlet.support.RequestContextUtils; //导入方法依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException {
	WebApplicationContext wac = RequestContextUtils.getWebApplicationContext(request);
	if (!(wac instanceof ComplexWebApplicationContext)) {
		throw new ServletException("Incorrect WebApplicationContext");
	}
	if (WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class) == null) {
		throw new ServletException("Not in a MultipartHttpServletRequest");
	}
	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");
	}
	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.getTimeZone(request) != null) {
		throw new ServletException("Incorrect TimeZone");
	}
	if (!TimeZone.getDefault().equals(LocaleContextHolder.getTimeZone())) {
		throw new ServletException("Incorrect TimeZone");
	}
	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");
	}
	RequestContext rc = new RequestContext(request);
	rc.changeLocale(Locale.US, TimeZone.getTimeZone("GMT+1"));
	rc.changeTheme("theme2");
	if (!Locale.US.equals(RequestContextUtils.getLocale(request))) {
		throw new ServletException("Incorrect Locale");
	}
	if (!Locale.US.equals(LocaleContextHolder.getLocale())) {
		throw new ServletException("Incorrect Locale");
	}
	if (!TimeZone.getTimeZone("GMT+1").equals(RequestContextUtils.getTimeZone(request))) {
		throw new ServletException("Incorrect TimeZone");
	}
	if (!TimeZone.getTimeZone("GMT+1").equals(LocaleContextHolder.getTimeZone())) {
		throw new ServletException("Incorrect TimeZone");
	}
	if (!"theme2".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
		throw new ServletException("Incorrect theme name");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:63,代码来源:ComplexWebApplicationContext.java


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