1616
1717package org .springframework .web .servlet .view .script ;
1818
19- import java .io .FileNotFoundException ;
2019import java .io .IOException ;
2120import java .io .InputStreamReader ;
2221import java .nio .charset .Charset ;
@@ -194,19 +193,6 @@ public void setResourceLoaderPath(String resourceLoaderPath) {
194193 }
195194 }
196195
197- @ Override
198- public boolean checkResource (Locale locale ) throws Exception {
199- try {
200- getTemplate (getUrl ());
201- return true ;
202- }
203- catch (IllegalStateException exc ) {
204- if (logger .isDebugEnabled ()) {
205- logger .debug ("No ScriptTemplate view found for URL: " + getUrl ());
206- }
207- return false ;
208- }
209- }
210196
211197 @ Override
212198 protected void initApplicationContext (ApplicationContext context ) {
@@ -265,7 +251,6 @@ else if (this.engine != null) {
265251 Assert .isTrue (this .renderFunction != null , "The 'renderFunction' property must be defined." );
266252 }
267253
268-
269254 protected ScriptEngine getEngine () {
270255 if (Boolean .FALSE .equals (this .sharedEngine )) {
271256 Map <Object , ScriptEngine > engines = enginesHolder .get ();
@@ -300,14 +285,17 @@ protected ScriptEngine createEngineFromName() {
300285
301286 protected void loadScripts (ScriptEngine engine ) {
302287 if (!ObjectUtils .isEmpty (this .scripts )) {
303- try {
304- for (String script : this .scripts ) {
305- Resource resource = getResource (script );
288+ for (String script : this .scripts ) {
289+ Resource resource = getResource (script );
290+ if (resource == null ) {
291+ throw new IllegalStateException ("Script resource [" + script + "] not found" );
292+ }
293+ try {
306294 engine .eval (new InputStreamReader (resource .getInputStream ()));
307295 }
308- }
309- catch ( Exception ex ) {
310- throw new IllegalStateException ( "Failed to load script" , ex );
296+ catch ( Throwable ex ) {
297+ throw new IllegalStateException ( "Failed to evaluate script [" + script + "]" , ex );
298+ }
311299 }
312300 }
313301 }
@@ -319,7 +307,7 @@ protected Resource getResource(String location) {
319307 return resource ;
320308 }
321309 }
322- throw new IllegalStateException ( "Resource [" + location + "] not found" ) ;
310+ return null ;
323311 }
324312
325313 protected ScriptTemplateConfig autodetectViewConfig () throws BeansException {
@@ -334,6 +322,12 @@ protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
334322 }
335323 }
336324
325+
326+ @ Override
327+ public boolean checkResource (Locale locale ) throws Exception {
328+ return (getResource (getUrl ()) != null );
329+ }
330+
337331 @ Override
338332 protected void prepareResponse (HttpServletRequest request , HttpServletResponse response ) {
339333 super .prepareResponse (request , response );
@@ -370,6 +364,9 @@ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletReq
370364
371365 protected String getTemplate (String path ) throws IOException {
372366 Resource resource = getResource (path );
367+ if (resource == null ) {
368+ throw new IllegalStateException ("Template resource [" + path + "] not found" );
369+ }
373370 InputStreamReader reader = new InputStreamReader (resource .getInputStream (), this .charset );
374371 return FileCopyUtils .copyToString (reader );
375372 }
0 commit comments