17
17
package org .springframework .web .servlet .view .script ;
18
18
19
19
import java .nio .charset .Charset ;
20
-
21
20
import javax .script .ScriptEngine ;
22
21
23
22
/**
40
39
* }
41
40
* </pre>
42
41
*
43
- * <p>It is possible to use non thread-safe script engines and templating libraries, like
44
- * Handlebars or React running on Nashorn, by setting the
45
- * {@link #setSharedEngine(Boolean) sharedEngine} property to {@code false}.
42
+ * <p><b>NOTE:</b> It is possible to use non thread-safe script engines and
43
+ * templating libraries, like Handlebars or React running on Nashorn, by setting
44
+ * the {@link #setSharedEngine sharedEngine} property to {@code false}.
46
45
*
47
46
* @author Sebastien Deleuze
48
47
* @since 4.2
@@ -54,6 +53,8 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig {
54
53
55
54
private String engineName ;
56
55
56
+ private Boolean sharedEngine ;
57
+
57
58
private String [] scripts ;
58
59
59
60
private String renderObject ;
@@ -64,17 +65,14 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig {
64
65
65
66
private String resourceLoaderPath ;
66
67
67
- private Boolean sharedEngine ;
68
68
69
69
/**
70
70
* Set the {@link ScriptEngine} to use by the view.
71
71
* The script engine must implement {@code Invocable}.
72
72
* You must define {@code engine} or {@code engineName}, not both.
73
- *
74
73
* <p>When the {@code sharedEngine} flag is set to {@code false}, you should not specify
75
74
* the script engine with this setter, but with the {@link #setEngineName(String)}
76
- * one (since it implies multiple lazy instanciations of the script engine).
77
- *
75
+ * one (since it implies multiple lazy instantiations of the script engine).
78
76
* @see #setEngineName(String)
79
77
*/
80
78
public void setEngine (ScriptEngine engine ) {
@@ -101,17 +99,35 @@ public String getEngineName() {
101
99
return this .engineName ;
102
100
}
103
101
102
+ /**
103
+ * When set to {@code false}, use thread-local {@link ScriptEngine} instances instead
104
+ * of one single shared instance. This flag should be set to {@code false} for those
105
+ * using non thread-safe script engines and templating libraries, like Handlebars or
106
+ * React running on Nashorn for example.
107
+ * <p>When this flag is set to {@code false}, the script engine must be specified using
108
+ * {@link #setEngineName(String)}. Using {@link #setEngine(ScriptEngine)} is not
109
+ * possible because multiple instances of the script engine need to be created lazily
110
+ * (one per thread).
111
+ * @see <a href="http://docs.oracle.com/javase/8/docs/api/javax/script/ScriptEngineFactory.html#getParameter-java.lang.String-">THREADING ScriptEngine parameter<a/>
112
+ */
113
+ public void setSharedEngine (Boolean sharedEngine ) {
114
+ this .sharedEngine = sharedEngine ;
115
+ }
116
+
117
+ @ Override
118
+ public Boolean isSharedEngine () {
119
+ return this .sharedEngine ;
120
+ }
121
+
104
122
/**
105
123
* Set the scripts to be loaded by the script engine (library or user provided).
106
124
* Since {@code resourceLoaderPath} default value is "classpath:", you can load easily
107
125
* any script available on the classpath.
108
- *
109
- * For example, in order to use a Javascript library available as a WebJars dependency
126
+ * <p>For example, in order to use a JavaScript library available as a WebJars dependency
110
127
* and a custom "render.js" file, you should call
111
128
* {@code configurer.setScripts("/META-INF/resources/webjars/library/version/library.js",
112
129
* "com/myproject/script/render.js");}.
113
- *
114
- * @see #setResourceLoaderPath(String)
130
+ * @see #setResourceLoaderPath
115
131
* @see <a href="http://www.webjars.org">WebJars</a>
116
132
*/
117
133
public void setScripts (String ... scriptNames ) {
@@ -124,7 +140,7 @@ public String[] getScripts() {
124
140
}
125
141
126
142
/**
127
- * Set the object where belongs the render function (optional).
143
+ * Set the object where the render function belongs (optional).
128
144
* For example, in order to call {@code Mustache.render()}, {@code renderObject}
129
145
* should be set to {@code "Mustache"} and {@code renderFunction} to {@code "render"}.
130
146
*/
@@ -138,11 +154,11 @@ public String getRenderObject() {
138
154
}
139
155
140
156
/**
141
- * Set the render function name (mandatory). This function will be called with the
142
- * following parameters:
157
+ * Set the render function name (mandatory).
158
+ * This function will be called with the following parameters:
143
159
* <ol>
144
- * <li>{@code template}: the view template content (String)</li>
145
- * <li>{@code model}: the view model (Map)</li>
160
+ * <li>{@code template}: the view template content (String)</li>
161
+ * <li>{@code model}: the view model (Map)</li>
146
162
* </ol>
147
163
*/
148
164
public void setRenderFunction (String renderFunction ) {
@@ -173,7 +189,7 @@ public Charset getCharset() {
173
189
* Standard URLs like "file:" and "classpath:" and pseudo URLs are supported
174
190
* as understood by Spring's {@link org.springframework.core.io.ResourceLoader}.
175
191
* Relative paths are allowed when running in an ApplicationContext.
176
- * Default is "classpath:".
192
+ * <p> Default is "classpath:".
177
193
*/
178
194
public void setResourceLoaderPath (String resourceLoaderPath ) {
179
195
this .resourceLoaderPath = resourceLoaderPath ;
@@ -184,25 +200,4 @@ public String getResourceLoaderPath() {
184
200
return this .resourceLoaderPath ;
185
201
}
186
202
187
- /**
188
- * When set to {@code false}, use thread-local {@link ScriptEngine} instances instead
189
- * of one single shared instance. This flag should be set to {@code false} for those
190
- * using non thread-safe script engines and templating libraries, like Handlebars or
191
- * React running on Nashorn for example.
192
- *
193
- * <p>When this flag is set to {@code false}, the script engine must be specified using
194
- * {@link #setEngineName(String)}. Using {@link #setEngine(ScriptEngine)} is not
195
- * possible because multiple instances of the script engine need to be created lazily
196
- * (one per thread).
197
- * @see <a href="http://docs.oracle.com/javase/8/docs/api/javax/script/ScriptEngineFactory.html#getParameter-java.lang.String-">THREADING ScriptEngine parameter<a/>
198
- */
199
- public void setSharedEngine (Boolean sharedEngine ) {
200
- this .sharedEngine = sharedEngine ;
201
- }
202
-
203
- @ Override
204
- public Boolean isShareEngine () {
205
- return this .sharedEngine ;
206
- }
207
-
208
203
}
0 commit comments