@Override public ResponseDefinition transform(final Request request, final ResponseDefinition responseDefinition, final FileSource files, final Parameters parameters) { if (responseDefinition.specifiesBodyFile() && templateDeclared(responseDefinition)) { this.fileSource = files; final VelocityEngine velocityEngine = new VelocityEngine(); velocityEngine.init(); final ToolManager toolManager = new ToolManager(); toolManager.setVelocityEngine(velocityEngine); context = toolManager.createContext(); addBodyToContext(request.getBodyAsString()); addHeadersToContext(request.getHeaders()); context.put("requestAbsoluteUrl", request.getAbsoluteUrl()); context.put("requestUrl", request.getUrl()); context.put("requestMethod", request.getMethod()); final String body = getRenderedBody(responseDefinition); return ResponseDefinitionBuilder.like(responseDefinition).but() .withBody(body) .build(); } else { return responseDefinition; } }
private Context createContextForLocale(Locale locale) { EasyFactoryConfiguration config = new EasyFactoryConfiguration(); config.toolbox(Scope.APPLICATION) .tool(MSG, ResourceTool.class) .property(BUNDLES, MESSAGES) .property(LOCALE, locale); ToolManager manager = new ToolManager(false, false); manager.configure(config); return manager.createContext(); }
/** * initialize required components */ @PostConstruct public void init() { toolManager = new ToolManager(false, false); toolManager.setVelocityEngine(velocityEngine); toolManager.configure("com/communote/server/core/note/template/velocity-toolbox.xml"); propertyManagement.addObjectPropertyFilter(PropertyType.NoteProperty, PropertyManagement.KEY_GROUP, NOTE_PROPERTY_KEY_TEMPLATE_ID); propertyManagement.addObjectPropertyFilter(PropertyType.NoteProperty, PropertyManagement.KEY_GROUP, NOTE_PROPERTY_KEY_TEMPLATE_PROPERTIES); }
/** * The constructor. * * @param templatePath the classpath location where to look for velocity templates. */ public VelocityServicesGenerator( String templatePath ) { super(); this.engine = new VelocityEngine(); this.engine.setProperty( RuntimeConstants.RESOURCE_LOADER, "classpath" ); this.engine.setProperty( "classpath.resource.loader.class", ClasspathResourceLoader.class.getName() ); this.engine.init(); ToolManager manager = new ToolManager(); this.context = manager.createContext(); this.templatePath = templatePath; this.template = this.engine.getTemplate( templatePath, ENCODING ); }
public static VelocityContext getContext() { if (toolManager == null) { ToolManager newToolManager = new ToolManager(); newToolManager.configure("WEB-INF/velocity-tools.xml"); toolManager = newToolManager; } return new VelocityContext(toolManager.createContext()); }