Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9ec337b7
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ec337b7
编写于
11月 04, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
joda time formatting tests
上级
79183278
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
160 addition
and
37 deletion
+160
-37
org.springframework.context/src/main/java/org/springframework/ui/format/jodatime/JodaTimeFormattingConfigurer.java
...work/ui/format/jodatime/JodaTimeFormattingConfigurer.java
+9
-20
org.springframework.context/src/test/java/org/springframework/ui/format/jodatime/JodaTimeFormattingTests.java
...framework/ui/format/jodatime/JodaTimeFormattingTests.java
+132
-0
org.springframework.core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java
...mework/core/convert/support/DefaultConversionService.java
+0
-17
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
...mework/core/convert/support/GenericConversionService.java
+19
-0
未找到文件。
org.springframework.context/src/main/java/org/springframework/ui/format/jodatime/JodaTimeFormattingConfigurer.java
浏览文件 @
9ec337b7
...
...
@@ -36,8 +36,6 @@ import org.springframework.ui.format.Printer;
*/
public
class
JodaTimeFormattingConfigurer
{
private
FormatterRegistry
formatterRegistry
;
private
String
dateStyle
;
private
String
timeStyle
;
...
...
@@ -46,15 +44,6 @@ public class JodaTimeFormattingConfigurer {
private
boolean
useISOFormat
;
/**
* Creates a new JodaTimeFormattingConfigurer that installs into the provided FormatterRegistry.
* Call {@link #registerJodaTimeFormatting()} to install.
* @param formatterRegistry the registry to register Joda Time formatters with
*/
public
JodaTimeFormattingConfigurer
(
FormatterRegistry
formatterRegistry
)
{
this
.
formatterRegistry
=
formatterRegistry
;
}
/**
* Set the default format style of Joda {@link LocalDate} objects.
* Default is {@link DateTimeFormat#shortDate()}.
...
...
@@ -95,25 +84,25 @@ public class JodaTimeFormattingConfigurer {
/**
* Install Joda Time formatters given the current configuration of this {@link JodaTimeFormattingConfigurer}.
*/
public
void
registerJodaTimeFormatting
(
)
{
JodaTimeConverters
.
registerConverters
(
this
.
formatterRegistry
.
getConverterRegistry
());
public
void
installJodaTimeFormatting
(
FormatterRegistry
formatterRegistry
)
{
JodaTimeConverters
.
registerConverters
(
formatterRegistry
.
getConverterRegistry
());
DateTimeFormatter
jodaDateFormatter
=
getJodaDateFormatter
();
this
.
formatterRegistry
.
addFormatterForFieldType
(
LocalDate
.
class
,
new
ReadablePartialPrinter
(
jodaDateFormatter
),
new
DateTimeParser
(
jodaDateFormatter
));
formatterRegistry
.
addFormatterForFieldType
(
LocalDate
.
class
,
new
ReadablePartialPrinter
(
jodaDateFormatter
),
new
DateTimeParser
(
jodaDateFormatter
));
DateTimeFormatter
jodaTimeFormatter
=
getJodaTimeFormatter
();
this
.
formatterRegistry
.
addFormatterForFieldType
(
LocalTime
.
class
,
new
ReadablePartialPrinter
(
jodaTimeFormatter
),
new
DateTimeParser
(
jodaTimeFormatter
));
formatterRegistry
.
addFormatterForFieldType
(
LocalTime
.
class
,
new
ReadablePartialPrinter
(
jodaTimeFormatter
),
new
DateTimeParser
(
jodaTimeFormatter
));
DateTimeFormatter
jodaDateTimeFormatter
=
getJodaDateTimeFormatter
();
Parser
<
DateTime
>
dateTimeParser
=
new
DateTimeParser
(
jodaDateTimeFormatter
);
this
.
formatterRegistry
.
addFormatterForFieldType
(
LocalDateTime
.
class
,
new
ReadablePartialPrinter
(
jodaDateTimeFormatter
),
dateTimeParser
);
formatterRegistry
.
addFormatterForFieldType
(
LocalDateTime
.
class
,
new
ReadablePartialPrinter
(
jodaDateTimeFormatter
),
dateTimeParser
);
Printer
<
ReadableInstant
>
readableInstantPrinter
=
new
ReadableInstantPrinter
(
jodaDateTimeFormatter
);
this
.
formatterRegistry
.
addFormatterForFieldType
(
ReadableInstant
.
class
,
readableInstantPrinter
,
dateTimeParser
);
this
.
formatterRegistry
.
addFormatterForFieldType
(
Calendar
.
class
,
readableInstantPrinter
,
dateTimeParser
);
this
.
formatterRegistry
.
addFormatterForFieldType
(
Date
.
class
,
new
MillisecondInstantPrinter
(
jodaDateTimeFormatter
),
dateTimeParser
);
formatterRegistry
.
addFormatterForFieldType
(
ReadableInstant
.
class
,
readableInstantPrinter
,
dateTimeParser
);
formatterRegistry
.
addFormatterForFieldType
(
Calendar
.
class
,
readableInstantPrinter
,
dateTimeParser
);
formatterRegistry
.
addFormatterForFieldType
(
Date
.
class
,
new
MillisecondInstantPrinter
(
jodaDateTimeFormatter
),
dateTimeParser
);
this
.
formatterRegistry
.
addFormatterForFieldAnnotation
(
new
DateTimeFormatAnnotationFormatterFactory
());
formatterRegistry
.
addFormatterForFieldAnnotation
(
new
DateTimeFormatAnnotationFormatterFactory
());
}
// internal helpers
...
...
org.springframework.context/src/test/java/org/springframework/ui/format/jodatime/JodaTimeFormattingTests.java
0 → 100644
浏览文件 @
9ec337b7
package
org.springframework.ui.format.jodatime
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Locale
;
import
org.joda.time.DateTime
;
import
org.joda.time.LocalDate
;
import
org.joda.time.LocalDateTime
;
import
org.joda.time.LocalTime
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.ui.format.support.FormattingConversionService
;
import
org.springframework.validation.DataBinder
;
public
class
JodaTimeFormattingTests
{
private
FormattingConversionService
conversionService
=
new
FormattingConversionService
();
private
DataBinder
binder
;
@Before
public
void
setUp
()
{
JodaTimeFormattingConfigurer
configurer
=
new
JodaTimeFormattingConfigurer
();
configurer
.
installJodaTimeFormatting
(
conversionService
);
binder
=
new
DataBinder
(
new
JodaTimeBean
());
binder
.
setConversionService
(
conversionService
);
LocaleContextHolder
.
setLocale
(
Locale
.
US
);
}
@After
public
void
tearDown
()
{
LocaleContextHolder
.
setLocale
(
null
);
}
@Test
public
void
testBindLocalDate
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
addPropertyValue
(
"localDate"
,
"10/31/09"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
}
@Test
public
void
testBindLocalDateArray
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
addPropertyValue
(
"localDate"
,
new
String
[]
{
"10/31/09"
});
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
}
private
static
class
JodaTimeBean
{
private
LocalDate
localDate
;
private
LocalTime
localTime
;
private
LocalDateTime
localDateTime
;
private
DateTime
dateTime
;
private
Date
date
;
private
Calendar
calendar
;
private
Long
millis
;
public
LocalDate
getLocalDate
()
{
return
localDate
;
}
public
void
setLocalDate
(
LocalDate
localDate
)
{
this
.
localDate
=
localDate
;
}
public
LocalTime
getLocalTime
()
{
return
localTime
;
}
public
void
setLocalTime
(
LocalTime
localTime
)
{
this
.
localTime
=
localTime
;
}
public
LocalDateTime
getLocalDateTime
()
{
return
localDateTime
;
}
public
void
setLocalDateTime
(
LocalDateTime
localDateTime
)
{
this
.
localDateTime
=
localDateTime
;
}
public
DateTime
getDateTime
()
{
return
dateTime
;
}
public
void
setDateTime
(
DateTime
dateTime
)
{
this
.
dateTime
=
dateTime
;
}
public
Date
getDate
()
{
return
date
;
}
public
void
setDate
(
Date
date
)
{
this
.
date
=
date
;
}
public
Calendar
getCalendar
()
{
return
calendar
;
}
public
void
setCalendar
(
Calendar
calendar
)
{
this
.
calendar
=
calendar
;
}
public
Long
getMillis
()
{
return
millis
;
}
public
void
setMillis
(
Long
millis
)
{
this
.
millis
=
millis
;
}
}
}
org.springframework.core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java
浏览文件 @
9ec337b7
...
...
@@ -16,9 +16,7 @@
package
org.springframework.core.convert.support
;
import
java.util.Collection
;
import
java.util.Locale
;
import
java.util.Map
;
/**
* Default implementation of a conversion service. Will automatically register <i>from string</i>
...
...
@@ -34,21 +32,6 @@ public class DefaultConversionService extends GenericConversionService {
* Create a new default conversion service, installing the default converters.
*/
public
DefaultConversionService
()
{
addGenericConverter
(
Object
[].
class
,
Object
[].
class
,
new
ArrayToArrayConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Collection
.
class
,
new
ArrayToCollectionConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Map
.
class
,
new
ArrayToMapConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Object
.
class
,
new
ArrayToObjectConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Collection
.
class
,
new
CollectionToCollectionConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Object
[].
class
,
new
CollectionToArrayConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Map
.
class
,
new
CollectionToMapConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Object
.
class
,
new
CollectionToObjectConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Map
.
class
,
new
MapToMapConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Object
[].
class
,
new
MapToArrayConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Collection
.
class
,
new
MapToCollectionConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Object
.
class
,
new
MapToObjectConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Object
[].
class
,
new
ObjectToArrayConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Collection
.
class
,
new
ObjectToCollectionConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Map
.
class
,
new
ObjectToMapConverter
(
this
));
addConverter
(
String
.
class
,
Boolean
.
class
,
new
StringToBooleanConverter
());
addConverter
(
String
.
class
,
Character
.
class
,
new
StringToCharacterConverter
());
addConverter
(
String
.
class
,
Locale
.
class
,
new
StringToLocaleConverter
());
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
浏览文件 @
9ec337b7
...
...
@@ -19,6 +19,7 @@ package org.springframework.core.convert.support;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
invokeConverter
;
import
java.lang.reflect.Array
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
...
...
@@ -61,6 +62,24 @@ public class GenericConversionService implements ConversionService, ConverterReg
}
};
public
GenericConversionService
()
{
addGenericConverter
(
Object
[].
class
,
Object
[].
class
,
new
ArrayToArrayConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Collection
.
class
,
new
ArrayToCollectionConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Map
.
class
,
new
ArrayToMapConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Object
.
class
,
new
ArrayToObjectConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Collection
.
class
,
new
CollectionToCollectionConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Object
[].
class
,
new
CollectionToArrayConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Map
.
class
,
new
CollectionToMapConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Object
.
class
,
new
CollectionToObjectConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Map
.
class
,
new
MapToMapConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Object
[].
class
,
new
MapToArrayConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Collection
.
class
,
new
MapToCollectionConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Object
.
class
,
new
MapToObjectConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Object
[].
class
,
new
ObjectToArrayConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Collection
.
class
,
new
ObjectToCollectionConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Map
.
class
,
new
ObjectToMapConverter
(
this
));
}
/**
* Registers the converters in the set provided.
* JavaBean-friendly alternative to calling {@link #addConverter(Converter)}.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录