本文整理汇总了Java中org.springframework.context.i18n.LocaleContextHolder.resetLocaleContext方法的典型用法代码示例。如果您正苦于以下问题:Java LocaleContextHolder.resetLocaleContext方法的具体用法?Java LocaleContextHolder.resetLocaleContext怎么用?Java LocaleContextHolder.resetLocaleContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.i18n.LocaleContextHolder
的用法示例。
在下文中一共展示了LocaleContextHolder.resetLocaleContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestDestroyed
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Override
public void requestDestroyed(ServletRequestEvent requestEvent) {
ServletRequestAttributes attributes = null;
Object reqAttr = requestEvent.getServletRequest().getAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE);
if (reqAttr instanceof ServletRequestAttributes) {
attributes = (ServletRequestAttributes) reqAttr;
}
RequestAttributes threadAttributes = RequestContextHolder.getRequestAttributes();
if (threadAttributes != null) {
// We're assumably within the original request thread...
LocaleContextHolder.resetLocaleContext();
RequestContextHolder.resetRequestAttributes();
if (attributes == null && threadAttributes instanceof ServletRequestAttributes) {
attributes = (ServletRequestAttributes) threadAttributes;
}
}
if (attributes != null) {
attributes.requestCompleted();
}
}
示例2: service
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
LocaleContextHolder.setLocale(request.getLocale());
try {
this.target.handleRequest(request, response);
}
catch (HttpRequestMethodNotSupportedException ex) {
String[] supportedMethods = ex.getSupportedMethods();
if (supportedMethods != null) {
response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
}
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, ex.getMessage());
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例3: testBindingErrorWithFormatter
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testBindingErrorWithFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1x2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(0.0), tb.getMyFloat());
assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例4: testBindingWithFormatterAgainstList
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testBindingWithFormatterAgainstList() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("integerList[0]", "1");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Integer(1), tb.getIntegerList().get(0));
assertEquals("1", binder.getBindingResult().getFieldValue("integerList[0]"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例5: testBindingErrorWithFormatterAgainstList
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testBindingErrorWithFormatterAgainstList() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("integerList[0]", "1x2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertTrue(tb.getIntegerList().isEmpty());
assertEquals("1x2", binder.getBindingResult().getFieldValue("integerList[0]"));
assertTrue(binder.getBindingResult().hasFieldErrors("integerList[0]"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例6: testBindingErrorWithFormatterAgainstFields
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testBindingErrorWithFormatterAgainstFields() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.initDirectFieldAccess();
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1x2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(0.0), tb.getMyFloat());
assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例7: testBindingErrorWithCustomFormatter
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testBindingErrorWithCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.addCustomFormatter(new NumberStyleFormatter());
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1x2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(0.0), tb.getMyFloat());
assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例8: testDefaultFormattersOn
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testDefaultFormattersOn() throws Exception {
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
factory.afterPropertiesSet();
FormattingConversionService fcs = factory.getObject();
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
Object value = fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
assertEquals(15.0, value);
value = fcs.convert(15.0, descriptor, TypeDescriptor.valueOf(String.class));
assertEquals("15", value);
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:FormattingConversionServiceFactoryBeanTests.java
示例9: statusCodeAndReasonMessage
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void statusCodeAndReasonMessage() {
Locale locale = Locale.CHINESE;
LocaleContextHolder.setLocale(locale);
try {
StaticMessageSource messageSource = new StaticMessageSource();
messageSource.addMessage("gone.reason", locale, "Gone reason message");
exceptionResolver.setMessageSource(messageSource);
StatusCodeAndReasonMessageException ex = new StatusCodeAndReasonMessageException();
exceptionResolver.resolveException(request, response, null, ex);
assertEquals("Invalid status reason", "Gone reason message", response.getErrorMessage());
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例10: service
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
LocaleContextHolder.setLocale(request.getLocale());
try {
this.target.service(request, response);
} catch (HttpRequestMethodNotSupportedException ex) {
String[] supportedMethods = ex.getSupportedMethods();
if (supportedMethods != null) {
response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
}
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, ex.getMessage());
} finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例11: testBindingWithFormatter
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testBindingWithFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(1.2), tb.getMyFloat());
assertEquals("1,2", binder.getBindingResult().getFieldValue("myFloat"));
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertNotNull(editor);
editor.setValue(new Float(1.4));
assertEquals("1,4", editor.getAsText());
editor = binder.getBindingResult().findEditor("myFloat", null);
assertNotNull(editor);
editor.setAsText("1,6");
assertEquals(new Float(1.6), editor.getValue());
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例12: testBindingWithFormatterAgainstFields
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testBindingWithFormatterAgainstFields() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
binder.initDirectFieldAccess();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(1.2), tb.getMyFloat());
assertEquals("1,2", binder.getBindingResult().getFieldValue("myFloat"));
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertNotNull(editor);
editor.setValue(new Float(1.4));
assertEquals("1,4", editor.getAsText());
editor = binder.getBindingResult().findEditor("myFloat", null);
assertNotNull(editor);
editor.setAsText("1,6");
assertEquals(new Float(1.6), editor.getValue());
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例13: testBindingWithCustomFormatter
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
public void testBindingWithCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.addCustomFormatter(new NumberStyleFormatter(), Float.class);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(1.2), tb.getMyFloat());
assertEquals("1,2", binder.getBindingResult().getFieldValue("myFloat"));
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertNotNull(editor);
editor.setValue(new Float(1.4));
assertEquals("1,4", editor.getAsText());
editor = binder.getBindingResult().findEditor("myFloat", null);
assertNotNull(editor);
editor.setAsText("1,6");
assertTrue(((Number) editor.getValue()).floatValue() == 1.6f);
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例14: handlerExceptionResolver
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void handlerExceptionResolver() throws Exception {
ApplicationContext context = initContext(WebConfig.class);
HandlerExceptionResolverComposite compositeResolver =
context.getBean("handlerExceptionResolver", HandlerExceptionResolverComposite.class);
assertEquals(0, compositeResolver.getOrder());
List<HandlerExceptionResolver> expectedResolvers = compositeResolver.getExceptionResolvers();
assertEquals(ExceptionHandlerExceptionResolver.class, expectedResolvers.get(0).getClass());
assertEquals(ResponseStatusExceptionResolver.class, expectedResolvers.get(1).getClass());
assertEquals(DefaultHandlerExceptionResolver.class, expectedResolvers.get(2).getClass());
ExceptionHandlerExceptionResolver eher = (ExceptionHandlerExceptionResolver) expectedResolvers.get(0);
assertNotNull(eher.getApplicationContext());
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(eher);
List<Object> interceptors = (List<Object>) fieldAccessor.getPropertyValue("responseBodyAdvice");
assertEquals(1, interceptors.size());
assertEquals(JsonViewResponseBodyAdvice.class, interceptors.get(0).getClass());
LocaleContextHolder.setLocale(Locale.ENGLISH);
try {
ResponseStatusExceptionResolver rser = (ResponseStatusExceptionResolver) expectedResolvers.get(1);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
rser.resolveException(request, response, context.getBean(TestController.class), new UserAlreadyExistsException());
assertEquals("User already exists!", response.getErrorMessage());
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例15: close
import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
@After
public void close() {
LocaleContextHolder.resetLocaleContext();
if (this.context != null) {
this.context.close();
}
}