16
16
17
17
package org .springframework .web .servlet .view .script ;
18
18
19
- import java .io .FileNotFoundException ;
20
19
import java .io .IOException ;
21
20
import java .io .InputStreamReader ;
22
21
import java .nio .charset .Charset ;
@@ -193,19 +192,6 @@ public void setResourceLoaderPath(String resourceLoaderPath) {
193
192
}
194
193
}
195
194
196
- @ Override
197
- public boolean checkResource (Locale locale ) throws Exception {
198
- try {
199
- getTemplate (getUrl ());
200
- return true ;
201
- }
202
- catch (IllegalStateException exc ) {
203
- if (logger .isDebugEnabled ()) {
204
- logger .debug ("No ScriptTemplate view found for URL: " + getUrl ());
205
- }
206
- return false ;
207
- }
208
- }
209
195
210
196
@ Override
211
197
protected void initApplicationContext (ApplicationContext context ) {
@@ -264,7 +250,6 @@ else if (this.engine != null) {
264
250
Assert .isTrue (this .renderFunction != null , "The 'renderFunction' property must be defined." );
265
251
}
266
252
267
-
268
253
protected ScriptEngine getEngine () {
269
254
if (Boolean .FALSE .equals (this .sharedEngine )) {
270
255
Map <Object , ScriptEngine > engines = enginesHolder .get ();
@@ -299,14 +284,17 @@ protected ScriptEngine createEngineFromName() {
299
284
300
285
protected void loadScripts (ScriptEngine engine ) {
301
286
if (!ObjectUtils .isEmpty (this .scripts )) {
302
- try {
303
- for (String script : this .scripts ) {
304
- Resource resource = getResource (script );
287
+ for (String script : this .scripts ) {
288
+ Resource resource = getResource (script );
289
+ if (resource == null ) {
290
+ throw new IllegalStateException ("Script resource [" + script + "] not found" );
291
+ }
292
+ try {
305
293
engine .eval (new InputStreamReader (resource .getInputStream ()));
306
294
}
307
- }
308
- catch ( Exception ex ) {
309
- throw new IllegalStateException ( "Failed to load script" , ex );
295
+ catch ( Throwable ex ) {
296
+ throw new IllegalStateException ( "Failed to evaluate script [" + script + "]" , ex );
297
+ }
310
298
}
311
299
}
312
300
}
@@ -318,7 +306,7 @@ protected Resource getResource(String location) {
318
306
return resource ;
319
307
}
320
308
}
321
- throw new IllegalStateException ( "Resource [" + location + "] not found" ) ;
309
+ return null ;
322
310
}
323
311
324
312
protected ScriptTemplateConfig autodetectViewConfig () throws BeansException {
@@ -333,6 +321,12 @@ protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
333
321
}
334
322
}
335
323
324
+
325
+ @ Override
326
+ public boolean checkResource (Locale locale ) throws Exception {
327
+ return (getResource (getUrl ()) != null );
328
+ }
329
+
336
330
@ Override
337
331
protected void prepareResponse (HttpServletRequest request , HttpServletResponse response ) {
338
332
super .prepareResponse (request , response );
@@ -369,6 +363,9 @@ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletReq
369
363
370
364
protected String getTemplate (String path ) throws IOException {
371
365
Resource resource = getResource (path );
366
+ if (resource == null ) {
367
+ throw new IllegalStateException ("Template resource [" + path + "] not found" );
368
+ }
372
369
InputStreamReader reader = new InputStreamReader (resource .getInputStream (), this .charset );
373
370
return FileCopyUtils .copyToString (reader );
374
371
}
0 commit comments