/** * Retrieve the FreeMarker template for the given locale, * to be rendering by this view. * <p>By default, the template specified by the "url" bean property * will be retrieved. * @param locale the current locale * @return the FreeMarker template to render * @throws IOException if the template file could not be retrieved * @see #setUrl * @see #getTemplate(String, java.util.Locale) */ protected Template getTemplate(Locale locale) throws IOException { String url = getUrl(); Assert.state(url != null, "'url' not set"); return getTemplate(url, locale); }
/** * Retrieve the FreeMarker template for the given locale, * to be rendering by this view. * <p>By default, the template specified by the "url" bean property * will be retrieved. * @param locale the current locale * @return the FreeMarker template to render * @throws IOException if the template file could not be retrieved * @see #setUrl * @see #getTemplate(String, java.util.Locale) */ protected Template getTemplate(Locale locale) throws IOException { String url = getUrl(); Assert.state(url != null, "'url' not set"); return getTemplate(url, locale); }
/** * Check that the FreeMarker template used for this view exists and is valid. * <p>Can be overridden to customize the behavior, for example in case of * multiple templates to be rendered into a single view. */ @Override public boolean checkResource(Locale locale) throws Exception { String url = getUrl(); Assert.state(url != null, "'url' not set"); try { // Check that we can get the template, even if we might subsequently get it again. getTemplate(url, locale); return true; } catch (FileNotFoundException ex) { // Allow for ViewResolver chaining... return false; } catch (ParseException ex) { throw new ApplicationContextException("Failed to parse [" + url + "]", ex); } catch (IOException ex) { throw new ApplicationContextException("Failed to load [" + url + "]", ex); } }
/** * Check that the FreeMarker template used for this view exists and is valid. * <p>Can be overridden to customize the behavior, for example in case of * multiple templates to be rendered into a single view. */ @Override public boolean checkResource(Locale locale) throws Exception { String url = getUrl(); Assert.state(url != null, "'url' not set"); try { // Check that we can get the template, even if we might subsequently get it again. getTemplate(url, locale); return true; } catch (FileNotFoundException ex) { // Allow for ViewResolver chaining... return false; } catch (ParseException ex) { throw new ApplicationContextException("Failed to parse [" + url + "]", ex); } catch (IOException ex) { throw new ApplicationContextException("Failed to load [" + url + "]", ex); } }
processTemplate(getTemplate(locale), fmModel, response);
processTemplate(getTemplate(locale), fmModel, response);
@Override public Template getTemplate(Locale locale) throws IOException { return super.getTemplate(locale); }
/** * Retrieve the FreeMarker template specified by the given name, * using the encoding specified by the "encoding" bean property. * <p>Can be called by subclasses to retrieve a specific template, * for example to render multiple templates into a single view. * @param name the file name of the desired template * @param locale the current locale * @return the FreeMarker template * @throws IOException if the template file could not be retrieved */ protected Template getTemplate(String name, Locale locale) throws IOException { return (getEncoding() != null ? getConfiguration().getTemplate(name, locale, getEncoding()) : getConfiguration().getTemplate(name, locale)); }
@Override protected Template getTemplate(String name, Locale locale) throws IOException { if (logger.isDebugEnabled()) { logger.debug("locate template: " + name); } return super.getTemplate(name, locale); } }