/** * Overridden to create a ChainedContext, which is part of the view package * of Velocity Tools, as special context. ChainedContext is needed for * initialization of ViewTool instances. * @see #initTool */ @Override protected Context createVelocityContext( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Create a ChainedContext instance. ChainedContext velocityContext = new ChainedContext( new VelocityContext(model), getVelocityEngine(), request, response, getServletContext()); // Load a Velocity Tools toolbox, if necessary. if (getToolboxConfigLocation() != null) { ToolboxManager toolboxManager = ServletToolboxManager.getInstance( getServletContext(), getToolboxConfigLocation()); Map<String,Object> toolboxContext = toolboxManager.getToolbox(velocityContext); velocityContext.setToolbox(toolboxContext); } return velocityContext; }
@Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { VelocityView view = (VelocityView) super.buildView(viewName); view.setDateToolAttribute(this.dateToolAttribute); view.setNumberToolAttribute(this.numberToolAttribute); if (this.toolboxConfigLocation != null) { ((VelocityToolboxView) view).setToolboxConfigLocation(this.toolboxConfigLocation); } return view; }
/** * Overrides {@code VelocityView.checkTemplate()} to additionally check * that both the layout template and the screen content template can be loaded. * Note that during rendering of the screen content, the layout template * can be changed which may invalidate any early checking done here. */ @Override public boolean checkResource(Locale locale) throws Exception { if (!super.checkResource(locale)) { return false; } try { // Check that we can get the template, even if we might subsequently get it again. getTemplate(this.layoutUrl); return true; } catch (ResourceNotFoundException ex) { throw new NestedIOException("Cannot find Velocity template for URL [" + this.layoutUrl + "]: Did you specify the correct resource loader path?", ex); } catch (Exception ex) { throw new NestedIOException( "Could not load Velocity template for URL [" + this.layoutUrl + "]", ex); } }
@Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { VelocityView view = (VelocityView) super.buildView(viewName); view.setDateToolAttribute(this.dateToolAttribute); view.setNumberToolAttribute(this.numberToolAttribute); if (this.toolboxConfigLocation != null) { ((VelocityToolboxView) view).setToolboxConfigLocation(this.toolboxConfigLocation); } return view; }
/** * Overrides {@code VelocityView.checkTemplate()} to additionally check * that both the layout template and the screen content template can be loaded. * Note that during rendering of the screen content, the layout template * can be changed which may invalidate any early checking done here. */ @Override public boolean checkResource(Locale locale) throws Exception { if (!super.checkResource(locale)) { return false; } try { // Check that we can get the template, even if we might subsequently get it again. getTemplate(this.layoutUrl); return true; } catch (ResourceNotFoundException ex) { throw new NestedIOException("Cannot find Velocity template for URL [" + this.layoutUrl + "]: Did you specify the correct resource loader path?", ex); } catch (Exception ex) { throw new NestedIOException( "Could not load Velocity template for URL [" + this.layoutUrl + "]", ex); } }
/** * Overridden to create a ChainedContext, which is part of the view package * of Velocity Tools, as special context. ChainedContext is needed for * initialization of ViewTool instances. * @see #initTool */ @Override protected Context createVelocityContext( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Create a ChainedContext instance. ChainedContext velocityContext = new ChainedContext( new VelocityContext(model), getVelocityEngine(), request, response, getServletContext()); // Load a Velocity Tools toolbox, if necessary. if (getToolboxConfigLocation() != null) { ToolboxManager toolboxManager = ServletToolboxManager.getInstance( getServletContext(), getToolboxConfigLocation()); Map<?, ?> toolboxContext = toolboxManager.getToolbox(velocityContext); velocityContext.setToolbox(toolboxContext); } return velocityContext; }
@Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { VelocityView view = (VelocityView) super.buildView(viewName); view.setDateToolAttribute(this.dateToolAttribute); view.setNumberToolAttribute(this.numberToolAttribute); if (this.toolboxConfigLocation != null) { ((VelocityToolboxView) view).setToolboxConfigLocation(this.toolboxConfigLocation); } return view; }
/** * Overrides {@code VelocityView.checkTemplate()} to additionally check * that both the layout template and the screen content template can be loaded. * Note that during rendering of the screen content, the layout template * can be changed which may invalidate any early checking done here. */ @Override public boolean checkResource(Locale locale) throws Exception { if (!super.checkResource(locale)) { return false; } try { // Check that we can get the template, even if we might subsequently get it again. getTemplate(this.layoutUrl); return true; } catch (ResourceNotFoundException ex) { throw new NestedIOException("Cannot find Velocity template for URL [" + this.layoutUrl + "]: Did you specify the correct resource loader path?", ex); } catch (Exception ex) { throw new NestedIOException( "Could not load Velocity template for URL [" + this.layoutUrl + "]", ex); } }
/** * Overridden to create a ChainedContext, which is part of the view package * of Velocity Tools, as special context. ChainedContext is needed for * initialization of ViewTool instances. * @see #initTool */ @Override protected Context createVelocityContext( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Create a ChainedContext instance. ChainedContext velocityContext = new ChainedContext( new VelocityContext(model), getVelocityEngine(), request, response, getServletContext()); // Load a Velocity Tools toolbox, if necessary. if (getToolboxConfigLocation() != null) { ToolboxManager toolboxManager = ServletToolboxManager.getInstance( getServletContext(), getToolboxConfigLocation()); Map<String, Object> toolboxContext = toolboxManager.getToolbox(velocityContext); velocityContext.setToolbox(toolboxContext); } return velocityContext; }