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