/** * Constructor for use as a bean. * @see #setUrl */ public ScriptTemplateView() { setContentType(null); }
/** * A convenience constructor that allows for specifying {@link #setPrefix prefix} * and {@link #setSuffix suffix} as constructor arguments. * @param prefix the prefix that gets prepended to view names when building a URL * @param suffix the suffix that gets appended to view names when building a URL * @since 4.3 */ public ScriptTemplateViewResolver(String prefix, String suffix) { this(); setPrefix(prefix); setSuffix(suffix); }
/** * Sets the default {@link #setViewClass view class} to {@link #requiredViewClass}: * by default {@link ScriptTemplateView}. */ public ScriptTemplateViewResolver() { setViewClass(requiredViewClass()); }
@Bean public ScriptTemplateConfigurer kotlinScriptConfigurer() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setEngineName("kotlin"); configurer.setScripts("org/springframework/web/servlet/view/script/kotlin/render.kts"); configurer.setRenderFunction("render"); return configurer; }
@Override public boolean checkResource(Locale locale) throws Exception { String url = getUrl(); Assert.state(url != null, "'url' not set"); return (getResource(url) != null); }
private ScriptTemplateView createViewWithUrl(String viewUrl) throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ScriptTemplatingConfiguration.class); ctx.refresh(); ScriptTemplateView view = new ScriptTemplateView(); view.setApplicationContext(ctx); view.setUrl(viewUrl); view.afterPropertiesSet(); return view; }
public ScriptRegistration() { super(new ScriptTemplateViewResolver()); getViewResolver(); } }
@Before public void setup() { this.configurer = new ScriptTemplateConfigurer(); this.wac = new StaticWebApplicationContext(); this.wac.getBeanFactory().registerSingleton("scriptTemplateConfigurer", this.configurer); this.view = new ScriptTemplateView(); }
@Bean public ScriptTemplateConfigurer kotlinScriptConfigurer() { return new ScriptTemplateConfigurer("kotlin"); } }
private MockHttpServletResponse render(String viewUrl, Map<String, Object> model) throws Exception { ScriptTemplateView view = createViewWithUrl(viewUrl); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); view.renderMergedOutputModel(model, request, response); return response; }
private MockHttpServletResponse render(String viewUrl, Map<String, Object> model) throws Exception { ScriptTemplateView view = createViewWithUrl(viewUrl); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); view.renderMergedOutputModel(model, request, response); return response; }
private MockHttpServletResponse render(String viewUrl, Map<String, Object> model, Class<?> configuration) throws Exception { ScriptTemplateView view = createViewWithUrl(viewUrl, configuration); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); view.renderMergedOutputModel(model, request, response); return response; }
private MockHttpServletResponse render(String viewUrl, Map<String, Object> model, Locale locale, Class<?> configuration) throws Exception { ScriptTemplateView view = createViewWithUrl(viewUrl, configuration); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addPreferredLocale(locale); view.renderMergedOutputModel(model, request, response); return response; }
@Bean public ScriptTemplateConfigurer nashornConfigurer() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setEngineName("nashorn"); configurer.setScripts("org/springframework/web/servlet/view/script/nashorn/render.js"); configurer.setRenderFunction("renderWithUrl"); return configurer; } }
private ScriptTemplateView createViewWithUrl(String viewUrl) throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ScriptTemplatingConfiguration.class); ctx.refresh(); ScriptTemplateView view = new ScriptTemplateView(); view.setApplicationContext(ctx); view.setUrl(viewUrl); view.afterPropertiesSet(); return view; }
/** * Create a new ScriptTemplateView with the given URL. * @since 4.2.1 */ public ScriptTemplateView(String url) { super(url); setContentType(null); }
@Bean public ScriptTemplateConfigurer jythonConfigurer() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setScripts("org/springframework/web/servlet/view/script/jython/render.py"); configurer.setEngineName("jython"); configurer.setRenderFunction("render"); return configurer; } }
private ScriptTemplateView createViewWithUrl(String viewUrl, Class<?> configuration) throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(configuration); ctx.refresh(); ScriptTemplateView view = new ScriptTemplateView(); view.setApplicationContext(ctx); view.setUrl(viewUrl); view.afterPropertiesSet(); return view; }
@Bean public ScriptTemplateConfigurer jRubyConfigurer() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setScripts("org/springframework/web/servlet/view/script/jruby/render.rb"); configurer.setEngineName("jruby"); configurer.setRenderFunction("render"); return configurer; } }
@Bean public ScriptTemplateConfigurer nashornConfigurer() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setEngineName("nashorn"); configurer.setScripts("org/springframework/web/servlet/view/script/nashorn/render.js"); configurer.setRenderFunction("render"); return configurer; } }