Top Description Fields Constructors Methods
org.springframework.web.reactive.result.view.script

public Class ScriptTemplateView

extends AbstractUrlBasedView
Class Inheritance
Imports
java.io.IOException, .InputStreamReader, java.nio.charset.StandardCharsets, java.util.Locale, .Map, java.util.function.Function, .Supplier, javax.script.Invocable, .ScriptEngine, .ScriptEngineManager, .ScriptException, .SimpleBindings, reactor.core.publisher.Mono, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactoryUtils, .NoSuchBeanDefinitionException, org.springframework.context.ApplicationContext, .ApplicationContextException, org.springframework.context.i18n.LocaleContextHolder, org.springframework.core.io.Resource, org.springframework.http.MediaType, org.springframework.lang.Nullable, org.springframework.scripting.support.StandardScriptEvalException, .StandardScriptUtils, org.springframework.util.Assert, .FileCopyUtils, .ObjectUtils, .StringUtils, org.springframework.web.reactive.result.view.AbstractUrlBasedView, org.springframework.web.server.ServerWebExchange

An AbstractUrlBasedView subclass designed to run any template library based on a JSR-223 script engine.

If not set, each property is auto-detected by looking up a single ScriptTemplateConfig bean in the web application context and using it to obtain the configured properties.

The Nashorn JavaScript engine requires Java 8+ and may require setting the sharedEngine property to false in order to run properly. See ScriptTemplateConfigurer#setSharedEngine(Boolean) for more details.

Authors
Sebastien Deleuze, Juergen Hoeller
Since
5.0
See Also
ScriptTemplateConfigurer, ScriptTemplateViewResolver

Field Summary

Modifier and TypeField and Description
private static final String
private ScriptEngine
private String
private Supplier<ScriptEngine>
private String
private String
private String[]
private volatile ScriptEngineManager
private String[]
private Boolean

Constructor Summary

AccessConstructor and Description
public
ScriptTemplateView()

Constructor for use as a bean.

public
ScriptTemplateView(String url)

Create a new ScriptTemplateView with the given URL.

Method Summary

Modifier and TypeMethod and Description
protected ScriptTemplateConfig
public boolean
checkResourceExists(Locale
the desired Locale that we're looking for
locale
)

Implements abstract org.springframework.web.reactive.result.view.AbstractUrlBasedView.checkResourceExists.

Check whether the resource for the configured URL actually exists.

protected ScriptEngine
private ScriptEngine
protected ScriptEngine
protected Resource
getResource(String location)

protected String
protected void
protected Mono<Void>
renderInternal(Map<String, Object>
combined output Map (never null), with dynamic values taking precedence over static attributes
model
,
MediaType
the content type selected to render with, which should match one of the supported media types
contentType
,
ServerWebExchange
current exchange
exchange
)

Implements abstract org.springframework.web.reactive.result.view.AbstractView.renderInternal.

Subclasses must implement this method to actually render the view.

public void
setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object
context
)

Overrides org.springframework.web.reactive.result.view.AbstractView.setApplicationContext.

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

public void
public void
public void
public void
public void
public void
public void
public void
Inherited from org.springframework.web.reactive.result.view.AbstractUrlBasedView:
afterPropertiesSetgetUrlresourceExistssetUrltoString

Field Detail

DEFAULT_RESOURCE_LOADER_PATHback to summary
private static final String DEFAULT_RESOURCE_LOADER_PATH
engineback to summary
private ScriptEngine engine
Annotations
@Nullable
engineNameback to summary
private String engineName
Annotations
@Nullable
engineSupplierback to summary
private Supplier<ScriptEngine> engineSupplier
Annotations
@Nullable
renderFunctionback to summary
private String renderFunction
Annotations
@Nullable
renderObjectback to summary
private String renderObject
Annotations
@Nullable
resourceLoaderPathsback to summary
private String[] resourceLoaderPaths
Annotations
@Nullable
scriptEngineManagerback to summary
private volatile ScriptEngineManager scriptEngineManager
Annotations
@Nullable
scriptsback to summary
private String[] scripts
Annotations
@Nullable
sharedEngineback to summary
private Boolean sharedEngine
Annotations
@Nullable

Constructor Detail

ScriptTemplateViewback to summary
public ScriptTemplateView()

Constructor for use as a bean.

See Also
setUrl
ScriptTemplateViewback to summary
public ScriptTemplateView(String url)

Create a new ScriptTemplateView with the given URL.

Method Detail

autodetectViewConfigback to summary
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException
checkResourceExistsback to summary
public boolean checkResourceExists(Locale locale) throws Exception

Implements abstract org.springframework.web.reactive.result.view.AbstractUrlBasedView.checkResourceExists.

Doc from org.springframework.web.reactive.result.view.AbstractUrlBasedView.checkResourceExists.

Check whether the resource for the configured URL actually exists.

Parameters
locale:Locale

the desired Locale that we're looking for

Returns:boolean

false if the resource exists false if we know that it does not exist

Annotations
@Override
Exceptions
Exception:
if the resource exists but is invalid (e.g. could not be parsed)
createEngineFromNameback to summary
protected ScriptEngine createEngineFromName(String engineName)
createEngineFromSupplierback to summary
private ScriptEngine createEngineFromSupplier()
getEngineback to summary
protected ScriptEngine getEngine()
getResourceback to summary
protected Resource getResource(String location)
Annotations
@Nullable
getTemplateback to summary
protected String getTemplate(String path) throws IOException
loadScriptsback to summary
protected void loadScripts(ScriptEngine engine)
renderInternalback to summary
protected Mono<Void> renderInternal(Map<String, Object> model, MediaType contentType, ServerWebExchange exchange)

Implements abstract org.springframework.web.reactive.result.view.AbstractView.renderInternal.

Doc from org.springframework.web.reactive.result.view.AbstractView.renderInternal.

Subclasses must implement this method to actually render the view.

Parameters
model:Map<String, Object>

combined output Map (never null), with dynamic values taking precedence over static attributes

contentType:MediaType

the content type selected to render with, which should match one of the supported media types

exchange:ServerWebExchange

current exchange

Returns:Mono<Void>

a Mono that represents when and if rendering succeeds

Annotations
@Override
setApplicationContextback to summary
public void setApplicationContext(ApplicationContext context)

Overrides org.springframework.web.reactive.result.view.AbstractView.setApplicationContext.

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Doc from org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback such as org.springframework.beans.factory.InitializingBean#afterPropertiesSet() or a custom init-method. Invoked after ResourceLoaderAware#setResourceLoader, ApplicationEventPublisherAware#setApplicationEventPublisher and MessageSourceAware, if applicable.

Parameters
context:ApplicationContext

the ApplicationContext object to be used by this object

Annotations
@Override
setEngineback to summary
public void setEngine(ScriptEngine engine)

See ScriptTemplateConfigurer#setEngine(ScriptEngine) documentation.

setEngineNameback to summary
public void setEngineName(String engineName)

See ScriptTemplateConfigurer#setEngineName(String) documentation.

setEngineSupplierback to summary
public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier)

See ScriptTemplateConfigurer#setEngineSupplier(Supplier) documentation.

Since
5.2
setRenderFunctionback to summary
public void setRenderFunction(String functionName)

See ScriptTemplateConfigurer#setRenderFunction(String) documentation.

setRenderObjectback to summary
public void setRenderObject(String renderObject)

See ScriptTemplateConfigurer#setRenderObject(String) documentation.

setResourceLoaderPathback to summary
public void setResourceLoaderPath(String resourceLoaderPath)

See ScriptTemplateConfigurer#setResourceLoaderPath(String) documentation.

setScriptsback to summary
public void setScripts(String... scripts)

See ScriptTemplateConfigurer#setScripts(String...) documentation.

setSharedEngineback to summary
public void setSharedEngine(Boolean sharedEngine)

See ScriptTemplateConfigurer#setSharedEngine(Boolean) documentation.