Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
a1916ca7
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
a1916ca7
编写于
11月 27, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polishing
上级
d6197b74
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
70 addition
and
46 deletion
+70
-46
org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java
...org/springframework/format/annotation/DateTimeFormat.java
+4
-2
org.springframework.context/src/main/java/org/springframework/format/annotation/NumberFormat.java
...a/org/springframework/format/annotation/NumberFormat.java
+4
-2
org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java
...tetime/joda/DateTimeFormatAnnotationFormatterFactory.java
+24
-10
org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormattingConfigurer.java
...rk/format/datetime/joda/JodaTimeFormattingConfigurer.java
+35
-24
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/UrlTag.java
...ain/java/org/springframework/web/servlet/tags/UrlTag.java
+3
-8
未找到文件。
org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java
浏览文件 @
a1916ca7
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.format.annotation
;
import
java.lang.annotation.ElementType
;
...
...
@@ -43,7 +44,7 @@ import java.lang.annotation.Target;
* @since 3.0
* @see org.joda.time.format.DateTimeFormat
*/
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
FIELD
,
ElementType
.
PARAMETER
})
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
FIELD
,
ElementType
.
PARAMETER
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DateTimeFormat
{
...
...
@@ -69,6 +70,7 @@ public @interface DateTimeFormat {
*/
String
pattern
()
default
""
;
/**
* Common ISO date time format patterns.
* @author Keith Donald
...
...
@@ -96,6 +98,6 @@ public @interface DateTimeFormat {
* Indicates that no ISO-based format pattern should be applied.
*/
NONE
}
}
org.springframework.context/src/main/java/org/springframework/format/annotation/NumberFormat.java
浏览文件 @
a1916ca7
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.format.annotation
;
import
java.lang.annotation.ElementType
;
...
...
@@ -36,7 +37,7 @@ import java.lang.annotation.Target;
* @since 3.0
* @see java.text.NumberFormat
*/
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
FIELD
,
ElementType
.
PARAMETER
})
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
FIELD
,
ElementType
.
PARAMETER
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
NumberFormat
{
...
...
@@ -54,6 +55,7 @@ public @interface NumberFormat {
*/
String
pattern
()
default
""
;
/**
* Common number format styles.
* @author Keith Donald
...
...
@@ -75,6 +77,6 @@ public @interface NumberFormat {
* The percent format for the current locale.
*/
PERCENT
}
}
org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java
浏览文件 @
a1916ca7
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.format.datetime.joda
;
import
java.util.Calendar
;
...
...
@@ -29,6 +30,7 @@ import org.joda.time.LocalTime;
import
org.joda.time.ReadableInstant
;
import
org.joda.time.ReadablePartial
;
import
org.joda.time.format.DateTimeFormatter
;
import
org.springframework.format.AnnotationFormatterFactory
;
import
org.springframework.format.Parser
;
import
org.springframework.format.Printer
;
...
...
@@ -37,7 +39,9 @@ import org.springframework.format.annotation.DateTimeFormat.ISO;
/**
* Formats fields annotated with the {@link DateTimeFormat} annotation.
*
* @author Keith Donald
* @author Juergen Hoeller
* @since 3.0
* @see DateTimeFormat
*/
...
...
@@ -45,6 +49,7 @@ public final class DateTimeFormatAnnotationFormatterFactory implements Annotatio
private
final
Set
<
Class
<?>>
fieldTypes
;
public
DateTimeFormatAnnotationFormatterFactory
()
{
this
.
fieldTypes
=
Collections
.
unmodifiableSet
(
createFieldTypes
());
}
...
...
@@ -53,16 +58,20 @@ public final class DateTimeFormatAnnotationFormatterFactory implements Annotatio
return
this
.
fieldTypes
;
}
public
Printer
<?>
getPrinter
(
DateTimeFormat
annotation
,
Class
<?>
fieldType
)
{
DateTimeFormatter
formatter
=
configureDateTimeFormatterFrom
(
annotation
);
if
(
ReadableInstant
.
class
.
isAssignableFrom
(
fieldType
))
{
return
new
ReadableInstantPrinter
(
formatter
);
}
else
if
(
ReadablePartial
.
class
.
isAssignableFrom
(
fieldType
))
{
}
else
if
(
ReadablePartial
.
class
.
isAssignableFrom
(
fieldType
))
{
return
new
ReadablePartialPrinter
(
formatter
);
}
else
if
(
Calendar
.
class
.
isAssignableFrom
(
fieldType
))
{
}
else
if
(
Calendar
.
class
.
isAssignableFrom
(
fieldType
))
{
// assumes Calendar->ReadableInstant converter is registered
return
new
ReadableInstantPrinter
(
formatter
);
}
else
{
}
else
{
// assumes Date->Long converter is registered
return
new
MillisecondInstantPrinter
(
formatter
);
}
...
...
@@ -72,6 +81,7 @@ public final class DateTimeFormatAnnotationFormatterFactory implements Annotatio
return
new
DateTimeParser
(
configureDateTimeFormatterFrom
(
annotation
));
}
// internal helpers
private
Set
<
Class
<?>>
createFieldTypes
()
{
...
...
@@ -90,9 +100,11 @@ public final class DateTimeFormatAnnotationFormatterFactory implements Annotatio
private
DateTimeFormatter
configureDateTimeFormatterFrom
(
DateTimeFormat
annotation
)
{
if
(!
annotation
.
pattern
().
isEmpty
())
{
return
forPattern
(
annotation
.
pattern
());
}
else
if
(
annotation
.
iso
()
!=
ISO
.
NONE
)
{
return
forISO
(
annotation
.
iso
());
}
else
{
}
else
if
(
annotation
.
iso
()
!=
ISO
.
NONE
)
{
return
forIso
(
annotation
.
iso
());
}
else
{
return
forStyle
(
annotation
.
style
());
}
}
...
...
@@ -101,12 +113,14 @@ public final class DateTimeFormatAnnotationFormatterFactory implements Annotatio
return
org
.
joda
.
time
.
format
.
DateTimeFormat
.
forPattern
(
pattern
);
}
private
DateTimeFormatter
forI
SO
(
ISO
iso
)
{
private
DateTimeFormatter
forI
so
(
ISO
iso
)
{
if
(
iso
==
ISO
.
DATE
)
{
return
org
.
joda
.
time
.
format
.
ISODateTimeFormat
.
date
();
}
else
if
(
iso
==
ISO
.
TIME
)
{
}
else
if
(
iso
==
ISO
.
TIME
)
{
return
org
.
joda
.
time
.
format
.
ISODateTimeFormat
.
time
();
}
else
{
}
else
{
return
org
.
joda
.
time
.
format
.
ISODateTimeFormat
.
dateTime
();
}
}
...
...
@@ -115,4 +129,4 @@ public final class DateTimeFormatAnnotationFormatterFactory implements Annotatio
return
org
.
joda
.
time
.
format
.
DateTimeFormat
.
forStyle
(
style
);
}
}
\ No newline at end of file
}
org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormattingConfigurer.java
浏览文件 @
a1916ca7
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.format.datetime.joda
;
import
java.util.Calendar
;
...
...
@@ -26,19 +27,22 @@ import org.joda.time.ReadableInstant;
import
org.joda.time.format.DateTimeFormat
;
import
org.joda.time.format.DateTimeFormatter
;
import
org.joda.time.format.ISODateTimeFormat
;
import
org.springframework.format.FormatterRegistry
;
import
org.springframework.format.Parser
;
import
org.springframework.format.Printer
;
/**
* Configures Joda Time's Formatting system for use with Spring.
*
* @author Keith Donald
* @author Juergen Hoeller
* @since 3.0
* @see #setDateStyle
(String)
* @see #setTimeStyle
(String)
* @see #setDateTimeStyle
(String)
* @see #setUseI
SOFormat(boolean)
* @see #installJodaTimeFormatting
(FormatterRegistry)
* @see #setDateStyle
* @see #setTimeStyle
* @see #setDateTimeStyle
* @see #setUseI
soFormat
* @see #installJodaTimeFormatting
*/
public
class
JodaTimeFormattingConfigurer
{
...
...
@@ -48,12 +52,12 @@ public class JodaTimeFormattingConfigurer {
private
String
dateTimeStyle
;
private
boolean
useISOFormat
;
private
boolean
useIsoFormat
;
/**
* Set the default format style of Joda {@link LocalDate} objects.
* Default is {@link DateTimeFormat#shortDate()}.
* @param dateStyle the date format style
*/
public
void
setDateStyle
(
String
dateStyle
)
{
this
.
dateStyle
=
dateStyle
;
...
...
@@ -62,16 +66,15 @@ public class JodaTimeFormattingConfigurer {
/**
* Set the default format style of Joda {@link LocalTime} objects.
* Default is {@link DateTimeFormat#shortTime()}.
* @param timeStyle the time format style
*/
public
void
setTimeStyle
(
String
timeStyle
)
{
this
.
timeStyle
=
timeStyle
;
}
/**
* Set the default format style of Joda {@link LocalDateTime} and {@link DateTime} objects, as well as JDK {@link Date} and {@link Calendar} objects.
* Set the default format style of Joda {@link LocalDateTime} and {@link DateTime} objects,
* as well as JDK {@link Date} and {@link Calendar} objects.
* Default is {@link DateTimeFormat#shortDateTime()}.
* @param dateTimeStyle the date time format style
*/
public
void
setDateTimeStyle
(
String
dateTimeStyle
)
{
this
.
dateTimeStyle
=
dateTimeStyle
;
...
...
@@ -81,27 +84,30 @@ public class JodaTimeFormattingConfigurer {
* Set whether standard ISO formatting should be applied to all Date/Time types.
* Default is false (no).
* If set to true, the dateStyle, timeStyle, and dateTimeStyle properties are ignored.
* @param useISOFormat true to enable ISO formatting
*/
public
void
setUseI
SOFormat
(
boolean
useISO
Format
)
{
this
.
useI
SOFormat
=
useISO
Format
;
public
void
setUseI
soFormat
(
boolean
useIso
Format
)
{
this
.
useI
soFormat
=
useIso
Format
;
}
/**
* Install Joda Time formatters given the current configuration of this {@link JodaTimeFormattingConfigurer}.
*/
public
void
installJodaTimeFormatting
(
FormatterRegistry
formatterRegistry
)
{
JodaTimeConverters
.
registerConverters
(
formatterRegistry
.
getConverterRegistry
()
);
JodaTimeConverters
.
registerConverters
(
formatterRegistry
);
DateTimeFormatter
jodaDateFormatter
=
getJodaDateFormatter
();
formatterRegistry
.
addFormatterForFieldType
(
LocalDate
.
class
,
new
ReadablePartialPrinter
(
jodaDateFormatter
),
new
DateTimeParser
(
jodaDateFormatter
));
formatterRegistry
.
addFormatterForFieldType
(
LocalDate
.
class
,
new
ReadablePartialPrinter
(
jodaDateFormatter
),
new
DateTimeParser
(
jodaDateFormatter
));
DateTimeFormatter
jodaTimeFormatter
=
getJodaTimeFormatter
();
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
);
formatterRegistry
.
addFormatterForFieldType
(
LocalDateTime
.
class
,
new
ReadablePartialPrinter
(
jodaDateTimeFormatter
),
dateTimeParser
);
formatterRegistry
.
addFormatterForFieldType
(
LocalDateTime
.
class
,
new
ReadablePartialPrinter
(
jodaDateTimeFormatter
),
dateTimeParser
);
Printer
<
ReadableInstant
>
readableInstantPrinter
=
new
ReadableInstantPrinter
(
jodaDateTimeFormatter
);
formatterRegistry
.
addFormatterForFieldType
(
ReadableInstant
.
class
,
readableInstantPrinter
,
dateTimeParser
);
...
...
@@ -111,37 +117,42 @@ public class JodaTimeFormattingConfigurer {
formatterRegistry
.
addFormatterForFieldAnnotation
(
new
DateTimeFormatAnnotationFormatterFactory
());
}
// internal helpers
private
DateTimeFormatter
getJodaDateFormatter
()
{
if
(
this
.
useI
SO
Format
)
{
if
(
this
.
useI
so
Format
)
{
return
ISODateTimeFormat
.
date
();
}
if
(
this
.
dateStyle
!=
null
)
{
return
DateTimeFormat
.
forStyle
(
this
.
dateStyle
+
"-"
);
}
else
{
}
else
{
return
DateTimeFormat
.
shortDate
();
}
}
private
DateTimeFormatter
getJodaTimeFormatter
()
{
if
(
this
.
useI
SO
Format
)
{
if
(
this
.
useI
so
Format
)
{
return
ISODateTimeFormat
.
time
();
}
if
(
this
.
timeStyle
!=
null
)
{
return
DateTimeFormat
.
forStyle
(
"-"
+
this
.
timeStyle
);
}
else
{
}
else
{
return
DateTimeFormat
.
shortTime
();
}
}
private
DateTimeFormatter
getJodaDateTimeFormatter
()
{
if
(
this
.
useI
SO
Format
)
{
if
(
this
.
useI
so
Format
)
{
return
ISODateTimeFormat
.
dateTime
();
}
if
(
this
.
dateTimeStyle
!=
null
)
{
return
DateTimeFormat
.
forStyle
(
this
.
dateTimeStyle
);
}
else
{
}
else
{
return
DateTimeFormat
.
shortDateTime
();
}
}
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/UrlTag.java
浏览文件 @
a1916ca7
...
...
@@ -18,23 +18,21 @@ package org.springframework.web.servlet.tags;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Set
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.jsp.JspException
;
import
javax.servlet.jsp.PageContext
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.util.ExpressionEvaluationUtils
;
import
org.springframework.web.util.HtmlUtils
;
import
org.springframework.web.util.JavaScriptUtils
;
import
org.springframework.web.util.TagUtils
;
import
org.springframework.web.util.UriUtils
;
import
org.springframework.util.StringUtils
;
/**
* JSP tag for creating URLs. Modeled after the JSTL c:url tag with backwards
...
...
@@ -44,7 +42,7 @@ import org.springframework.util.StringUtils;
* <ul>
* <li>URL encoded template URI variables</li>
* <li>HTML/XML escaping of URLs</li>
* <li>JavaScipt escaping of URLs</li>
* <li>JavaSc
r
ipt escaping of URLs</li>
* </ul>
*
* <p>Template URI variables are indicated in the {@link #setValue(String) 'value'}
...
...
@@ -235,13 +233,11 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
* @param includeQueryStringDelimiter true if the query string should start
* with a '?' instead of '&'
* @return the query string
* @throws JspException
*/
protected
String
createQueryString
(
List
<
Param
>
params
,
Set
<
String
>
usedParams
,
boolean
includeQueryStringDelimiter
)
throws
JspException
{
String
encoding
=
pageContext
.
getResponse
().
getCharacterEncoding
();
StringBuilder
qs
=
new
StringBuilder
();
for
(
Param
param
:
params
)
{
if
(!
usedParams
.
contains
(
param
.
getName
())
&&
StringUtils
.
hasLength
(
param
.
getName
()))
{
...
...
@@ -274,12 +270,11 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
* @param params parameters used to replace template markers
* @param usedParams set of template parameter names that have been replaced
* @return the URL with template parameters replaced
* @throws JspException
*/
protected
String
replaceUriTemplateParams
(
String
uri
,
List
<
Param
>
params
,
Set
<
String
>
usedParams
)
throws
JspException
{
String
encoding
=
pageContext
.
getResponse
().
getCharacterEncoding
();
String
encoding
=
pageContext
.
getResponse
().
getCharacterEncoding
();
for
(
Param
param
:
params
)
{
String
template
=
URL_TEMPLATE_DELIMITER_PREFIX
+
param
.
getName
()
+
URL_TEMPLATE_DELIMITER_SUFFIX
;
if
(
uri
.
contains
(
template
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录