Check template availability in ScriptTemplateView
This commit overrides the `checkResource` implementation in
`ScriptTemplateView` in order to check if the template file resource is
available and if the resolver can then proceed with rendering the
template.
Issue: SPR-14729
Cherry-picked from: 66b370e10
This commit is contained in:
@@ -16,12 +16,14 @@
|
||||
|
||||
package org.springframework.web.servlet.view.script;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
@@ -192,6 +194,19 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkResource(Locale locale) throws Exception {
|
||||
try {
|
||||
getTemplate(getUrl());
|
||||
return true;
|
||||
}
|
||||
catch (IllegalStateException exc) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("No ScriptTemplate view found for URL: " + getUrl());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initApplicationContext(ApplicationContext context) {
|
||||
|
||||
Reference in New Issue
Block a user