1717package org .springframework .web .servlet .view .script ;
1818
1919import java .nio .charset .Charset ;
20-
2120import javax .script .ScriptEngine ;
2221
2322/**
4039 * }
4140 * </pre>
4241 *
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}.
4645 *
4746 * @author Sebastien Deleuze
4847 * @since 4.2
@@ -54,6 +53,8 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig {
5453
5554 private String engineName ;
5655
56+ private Boolean sharedEngine ;
57+
5758 private String [] scripts ;
5859
5960 private String renderObject ;
@@ -64,17 +65,14 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig {
6465
6566 private String resourceLoaderPath ;
6667
67- private Boolean sharedEngine ;
6868
6969 /**
7070 * Set the {@link ScriptEngine} to use by the view.
7171 * The script engine must implement {@code Invocable}.
7272 * You must define {@code engine} or {@code engineName}, not both.
73- *
7473 * <p>When the {@code sharedEngine} flag is set to {@code false}, you should not specify
7574 * 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).
7876 * @see #setEngineName(String)
7977 */
8078 public void setEngine (ScriptEngine engine ) {
@@ -101,17 +99,35 @@ public String getEngineName() {
10199 return this .engineName ;
102100 }
103101
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+
104122 /**
105123 * Set the scripts to be loaded by the script engine (library or user provided).
106124 * Since {@code resourceLoaderPath} default value is "classpath:", you can load easily
107125 * 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
110127 * and a custom "render.js" file, you should call
111128 * {@code configurer.setScripts("/META-INF/resources/webjars/library/version/library.js",
112129 * "com/myproject/script/render.js");}.
113- *
114- * @see #setResourceLoaderPath(String)
130+ * @see #setResourceLoaderPath
115131 * @see <a href="http://www.webjars.org">WebJars</a>
116132 */
117133 public void setScripts (String ... scriptNames ) {
@@ -124,7 +140,7 @@ public String[] getScripts() {
124140 }
125141
126142 /**
127- * Set the object where belongs the render function (optional).
143+ * Set the object where the render function belongs (optional).
128144 * For example, in order to call {@code Mustache.render()}, {@code renderObject}
129145 * should be set to {@code "Mustache"} and {@code renderFunction} to {@code "render"}.
130146 */
@@ -138,11 +154,11 @@ public String getRenderObject() {
138154 }
139155
140156 /**
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:
143159 * <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>
146162 * </ol>
147163 */
148164 public void setRenderFunction (String renderFunction ) {
@@ -173,7 +189,7 @@ public Charset getCharset() {
173189 * Standard URLs like "file:" and "classpath:" and pseudo URLs are supported
174190 * as understood by Spring's {@link org.springframework.core.io.ResourceLoader}.
175191 * Relative paths are allowed when running in an ApplicationContext.
176- * Default is "classpath:".
192+ * <p> Default is "classpath:".
177193 */
178194 public void setResourceLoaderPath (String resourceLoaderPath ) {
179195 this .resourceLoaderPath = resourceLoaderPath ;
@@ -184,25 +200,4 @@ public String getResourceLoaderPath() {
184200 return this .resourceLoaderPath ;
185201 }
186202
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-
208203}
0 commit comments