Package org.springframework.web.servlet.view.groovy

# Class GroovyMarkupView

java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.view.AbstractView
org.springframework.web.servlet.view.AbstractUrlBasedView
org.springframework.web.servlet.view.AbstractTemplateView
org.springframework.web.servlet.view.groovy.GroovyMarkupView

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanNameAware`, `org.springframework.beans.factory.InitializingBean`, `org.springframework.context.ApplicationContextAware`, `org.springframework.web.context.ServletContextAware`, `View`

public class GroovyMarkupView extends AbstractTemplateView
An `AbstractTemplateView` subclass based on Groovy XML/XHTML markup templates.

Spring's Groovy Markup Template support requires Groovy 2.3.1 and higher.

Since:
  4.1
Author:
  Brian Clozel, Rossen Stoyanchev
See Also:
  - `GroovyMarkupViewResolver`
  - `GroovyMarkupConfigurer`
  - Groovy Markup Template engine documentation

## Field Summary

### Fields inherited from class org.springframework.web.servlet.view.AbstractTemplateView

`SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE`

### Fields inherited from class org.springframework.web.servlet.view.AbstractView

`DEFAULT_CONTENT_TYPE`

### Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

`logger`

### Fields inherited from interface org.springframework.web.servlet.View

`PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE`

## Constructor Summary

Constructors
Constructor
Description
`GroovyMarkupView()`

## Method Summary

Modifier and Type
Method
Description
`protected groovy.text.markup.MarkupTemplateEngine`
`autodetectMarkupTemplateEngine()`
Autodetect a MarkupTemplateEngine via the ApplicationContext.
`boolean`
`checkResource(Locale locale)`
Check whether the underlying resource that the configured URL points to actually exists.
`protected groovy.text.Template`
`getTemplate(String viewUrl)`
Return a template compiled by the configured Groovy Markup template engine for the given view URL.
`protected void`
`initApplicationContext(org.springframework.context.ApplicationContext context)`
Invoked at startup.
`protected void`
`renderMergedTemplateModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response)`
Subclasses must implement this method to actually render the view.
`void`
`setTemplateEngine(groovy.text.markup.MarkupTemplateEngine engine)`
Set the MarkupTemplateEngine to use in this view.

### Methods inherited from class org.springframework.web.servlet.view.AbstractTemplateView

`applyContentType, renderMergedOutputModel, setAllowRequestOverride, setAllowSessionOverride, setExposeRequestAttributes, setExposeSessionAttributes, setExposeSpringMacroHelpers`

### Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView

`afterPropertiesSet, getUrl, isUrlRequired, setUrl, toString`

### Methods inherited from class org.springframework.web.servlet.view.AbstractView

`addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse`

### Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

`getServletContext, getTempDir, getWebApplicationContext, initServletContext, isContextRequired, setServletContext`

### Methods inherited from class org.springframework.context.support.ApplicationObjectSupport

`getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### GroovyMarkupView

public GroovyMarkupView()

## Method Details

### setTemplateEngine

public void setTemplateEngine(groovy.text.markup.MarkupTemplateEngine engine)
Set the MarkupTemplateEngine to use in this view.

If not set, the engine is auto-detected by looking up a single `GroovyMarkupConfig` bean in the web application context and using it to obtain the configured `MarkupTemplateEngine` instance.

See Also:
  - `GroovyMarkupConfig`

### initApplicationContext

protected void initApplicationContext(org.springframework.context.ApplicationContext context)
Invoked at startup. If no `templateEngine` has been manually set, this method looks up a `GroovyMarkupConfig` bean by type and uses it to obtain the Groovy Markup template engine.

Overrides:
  `initApplicationContext` in class `org.springframework.web.context.support.WebApplicationObjectSupport`
See Also:
  - `GroovyMarkupConfig`
  - `setTemplateEngine(groovy.text.markup.MarkupTemplateEngine)`

### autodetectMarkupTemplateEngine

protected groovy.text.markup.MarkupTemplateEngine autodetectMarkupTemplateEngine() throws org.springframework.beans.BeansException
Autodetect a MarkupTemplateEngine via the ApplicationContext. Called if a MarkupTemplateEngine has not been manually configured.

Throws:
  `org.springframework.beans.BeansException`

### checkResource

public boolean checkResource(Locale locale) throws Exception
Description copied from class: `AbstractUrlBasedView`
Check whether the underlying resource that the configured URL points to actually exists.

Overrides:
  `checkResource` in class `AbstractUrlBasedView`
Parameters:
  `locale` - the desired Locale that we're looking for
Returns:
  `true` if the resource exists (or is assumed to exist); `false` if we know that it does not exist
Throws:
  `Exception` - if the resource exists but is invalid (for example, could not be parsed)

### renderMergedTemplateModel

protected void renderMergedTemplateModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception
Description copied from class: `AbstractTemplateView`
Subclasses must implement this method to actually render the view.

Specified by:
  `renderMergedTemplateModel` in class `AbstractTemplateView`
Parameters:
  `model` - combined output Map, with request attributes and session attributes merged into it if required
  `request` - current HTTP request
  `response` - current HTTP response
Throws:
  `Exception` - if rendering failed

### getTemplate

protected groovy.text.Template getTemplate(String viewUrl) throws Exception
Return a template compiled by the configured Groovy Markup template engine for the given view URL.

Throws:
  `Exception`