Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
98642c7e
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,发现更多精彩内容 >>
提交
98642c7e
编写于
6月 26, 2017
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent ScriptTemplateView locale resolution via request
Issue: SPR-15064
上级
41eaf03b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
24 addition
and
59 deletion
+24
-59
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/RenderingContext.java
...ork/web/reactive/result/view/script/RenderingContext.java
+5
-4
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java
...k/web/reactive/result/view/script/ScriptTemplateView.java
+4
-11
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateViewResolver.java
...active/result/view/script/ScriptTemplateViewResolver.java
+1
-13
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script/KotlinScriptTemplateTests.java
...eactive/result/view/script/KotlinScriptTemplateTests.java
+1
-2
spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/RenderingContext.java
...ngframework/web/servlet/view/script/RenderingContext.java
+5
-4
spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java
...framework/web/servlet/view/script/ScriptTemplateView.java
+6
-12
spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateViewResolver.java
...k/web/servlet/view/script/ScriptTemplateViewResolver.java
+1
-12
spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/KotlinScriptTemplateTests.java
...rk/web/servlet/view/script/KotlinScriptTemplateTests.java
+1
-1
未找到文件。
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/RenderingContext.java
浏览文件 @
98642c7e
...
...
@@ -40,6 +40,7 @@ public class RenderingContext {
public
RenderingContext
(
ApplicationContext
applicationContext
,
Locale
locale
,
Function
<
String
,
String
>
templateLoader
,
String
url
)
{
this
.
applicationContext
=
applicationContext
;
this
.
locale
=
locale
;
this
.
templateLoader
=
templateLoader
;
...
...
@@ -48,19 +49,19 @@ public class RenderingContext {
public
ApplicationContext
getApplicationContext
()
{
return
applicationContext
;
return
this
.
applicationContext
;
}
public
Locale
getLocale
()
{
return
locale
;
return
this
.
locale
;
}
public
Function
<
String
,
String
>
getTemplateLoader
()
{
return
templateLoader
;
return
t
his
.
t
emplateLoader
;
}
public
String
getUrl
()
{
return
url
;
return
this
.
url
;
}
}
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java
浏览文件 @
98642c7e
...
...
@@ -35,6 +35,7 @@ import org.springframework.beans.factory.BeanFactoryUtils;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextException
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.core.io.buffer.DataBuffer
;
...
...
@@ -58,7 +59,7 @@ import org.springframework.web.server.ServerWebExchange;
* {@link ScriptTemplateConfig} bean in the web application context and using
* it to obtain the configured properties.
*
* <p>
Nashorn Javascript engine requires Java 8+,
and may require setting the
* <p>
The Nashorn JavaScript engine requires Java 8+
and may require setting the
* {@code sharedEngine} property to {@code false} in order to run properly. See
* {@link ScriptTemplateConfigurer#setSharedEngine(Boolean)} for more details.
*
...
...
@@ -77,8 +78,6 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
private
String
engineName
;
private
Locale
locale
;
private
Boolean
sharedEngine
;
private
String
[]
scripts
;
...
...
@@ -123,13 +122,6 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
this
.
engineName
=
engineName
;
}
/**
* Set the {@link Locale} to pass to the render function.
*/
public
void
setLocale
(
Locale
locale
)
{
this
.
locale
=
locale
;
}
/**
* See {@link ScriptTemplateConfigurer#setSharedEngine(Boolean)} documentation.
*/
...
...
@@ -312,8 +304,9 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
}
};
Locale
locale
=
LocaleContextHolder
.
getLocale
(
exchange
.
getLocaleContext
());
RenderingContext
context
=
new
RenderingContext
(
obtainApplicationContext
(),
this
.
locale
,
templateLoader
,
url
);
obtainApplicationContext
(),
locale
,
templateLoader
,
url
);
Object
html
;
if
(
this
.
renderFunction
==
null
)
{
...
...
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateViewResolver.java
浏览文件 @
98642c7e
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,12 +16,7 @@
package
org.springframework.web.reactive.result.view.script
;
import
java.util.Locale
;
import
reactor.core.publisher.Mono
;
import
org.springframework.web.reactive.result.view.UrlBasedViewResolver
;
import
org.springframework.web.reactive.result.view.View
;
/**
* Convenience subclass of {@link UrlBasedViewResolver} that supports
...
...
@@ -60,13 +55,6 @@ public class ScriptTemplateViewResolver extends UrlBasedViewResolver {
setSuffix
(
suffix
);
}
@Override
public
Mono
<
View
>
resolveViewName
(
String
viewName
,
Locale
locale
)
{
return
super
.
resolveViewName
(
viewName
,
locale
).
map
(
view
->
{
((
ScriptTemplateView
)
view
).
setLocale
(
locale
);
return
view
;
});
}
@Override
protected
Class
<?>
requiredViewClass
()
{
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script/KotlinScriptTemplateTests.java
浏览文件 @
98642c7e
...
...
@@ -78,8 +78,7 @@ public class KotlinScriptTemplateTests {
private
MockServerHttpResponse
renderViewWithModel
(
String
viewUrl
,
Map
<
String
,
Object
>
model
,
Locale
locale
,
Class
<?>
configuration
)
throws
Exception
{
ScriptTemplateView
view
=
createViewWithUrl
(
viewUrl
,
configuration
);
view
.
setLocale
(
locale
);
MockServerWebExchange
exchange
=
MockServerHttpRequest
.
get
(
"/"
).
toExchange
();
MockServerWebExchange
exchange
=
MockServerHttpRequest
.
get
(
"/"
).
acceptLanguageAsLocales
(
locale
).
toExchange
();
view
.
renderInternal
(
model
,
MediaType
.
TEXT_HTML
,
exchange
).
block
();
return
exchange
.
getResponse
();
}
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/RenderingContext.java
浏览文件 @
98642c7e
...
...
@@ -40,6 +40,7 @@ public class RenderingContext {
public
RenderingContext
(
ApplicationContext
applicationContext
,
Locale
locale
,
Function
<
String
,
String
>
templateLoader
,
String
url
)
{
this
.
applicationContext
=
applicationContext
;
this
.
locale
=
locale
;
this
.
templateLoader
=
templateLoader
;
...
...
@@ -48,19 +49,19 @@ public class RenderingContext {
public
ApplicationContext
getApplicationContext
()
{
return
applicationContext
;
return
this
.
applicationContext
;
}
public
Locale
getLocale
()
{
return
locale
;
return
this
.
locale
;
}
public
Function
<
String
,
String
>
getTemplateLoader
()
{
return
templateLoader
;
return
t
his
.
t
emplateLoader
;
}
public
String
getUrl
()
{
return
url
;
return
this
.
url
;
}
}
spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java
浏览文件 @
98642c7e
...
...
@@ -49,6 +49,7 @@ import org.springframework.util.Assert;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.servlet.support.RequestContextUtils
;
import
org.springframework.web.servlet.view.AbstractUrlBasedView
;
/**
...
...
@@ -59,7 +60,7 @@ import org.springframework.web.servlet.view.AbstractUrlBasedView;
* {@link ScriptTemplateConfig} bean in the web application context and using
* it to obtain the configured properties.
*
* <p>
Nashorn Javascript engine requires Java 8+,
and may require setting the
* <p>
The Nashorn JavaScript engine requires Java 8+
and may require setting the
* {@code sharedEngine} property to {@code false} in order to run properly. See
* {@link ScriptTemplateConfigurer#setSharedEngine(Boolean)} for more details.
*
...
...
@@ -86,8 +87,6 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
private
String
engineName
;
private
Locale
locale
;
private
Boolean
sharedEngine
;
private
String
[]
scripts
;
...
...
@@ -130,14 +129,6 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
this
.
engine
=
engine
;
}
/**
* Set the {@link Locale} to pass to the render function.
* @since 5.0
*/
public
void
setLocale
(
Locale
locale
)
{
this
.
locale
=
locale
;
}
/**
* See {@link ScriptTemplateConfigurer#setEngineName(String)} documentation.
*/
...
...
@@ -362,6 +353,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
String
url
=
getUrl
();
Assert
.
state
(
url
!=
null
,
"'url' not set"
);
String
template
=
getTemplate
(
url
);
Function
<
String
,
String
>
templateLoader
=
path
->
{
try
{
return
getTemplate
(
path
);
...
...
@@ -370,7 +362,9 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
throw
new
IllegalStateException
(
ex
);
}
};
RenderingContext
context
=
new
RenderingContext
(
obtainApplicationContext
(),
this
.
locale
,
templateLoader
,
url
);
Locale
locale
=
RequestContextUtils
.
getLocale
(
request
);
RenderingContext
context
=
new
RenderingContext
(
obtainApplicationContext
(),
locale
,
templateLoader
,
url
);
Object
html
;
if
(
this
.
renderFunction
==
null
)
{
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateViewResolver.java
浏览文件 @
98642c7e
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,9 +16,6 @@
package
org.springframework.web.servlet.view.script
;
import
java.util.Locale
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.view.UrlBasedViewResolver
;
/**
...
...
@@ -59,14 +56,6 @@ public class ScriptTemplateViewResolver extends UrlBasedViewResolver {
setSuffix
(
suffix
);
}
@Override
public
View
resolveViewName
(
String
viewName
,
Locale
locale
)
throws
Exception
{
ScriptTemplateView
view
=
(
ScriptTemplateView
)
super
.
resolveViewName
(
viewName
,
locale
);
if
(
view
!=
null
)
{
view
.
setLocale
(
locale
);
}
return
view
;
}
@Override
protected
Class
<?>
requiredViewClass
()
{
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/KotlinScriptTemplateTests.java
浏览文件 @
98642c7e
...
...
@@ -94,9 +94,9 @@ public class KotlinScriptTemplateTests {
private
MockHttpServletResponse
renderViewWithModel
(
String
viewUrl
,
Map
<
String
,
Object
>
model
,
Locale
locale
,
Class
<?>
configuration
)
throws
Exception
{
ScriptTemplateView
view
=
createViewWithUrl
(
viewUrl
,
configuration
);
view
.
setLocale
(
locale
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addPreferredLocale
(
locale
);
view
.
renderMergedOutputModel
(
model
,
request
,
response
);
return
response
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录