public static VelocityContext prepareContext(long userId, Event event, Position position) { User user = Context.getPermissionsManager().getUser(userId); Device device = Context.getIdentityManager().getById(event.getDeviceId()); VelocityContext velocityContext = new VelocityContext(); velocityContext.put("user", user); velocityContext.put("device", device); velocityContext.put("event", event); if (position != null) { velocityContext.put("position", position); velocityContext.put("speedUnit", ReportUtils.getSpeedUnit(userId)); velocityContext.put("distanceUnit", ReportUtils.getDistanceUnit(userId)); velocityContext.put("volumeUnit", ReportUtils.getVolumeUnit(userId)); } if (event.getGeofenceId() != 0) { velocityContext.put("geofence", Context.getGeofenceManager().getById(event.getGeofenceId())); } if (event.getMaintenanceId() != 0) { velocityContext.put("maintenance", Context.getMaintenancesManager().getById(event.getMaintenanceId())); } String driverUniqueId = event.getString(Position.KEY_DRIVER_UNIQUE_ID); if (driverUniqueId != null) { velocityContext.put("driver", Context.getDriversManager().getDriverByUniqueId(driverUniqueId)); } velocityContext.put("webUrl", Context.getVelocityEngine().getProperty("web.url")); velocityContext.put("dateTool", new DateTool()); velocityContext.put("numberTool", new NumberTool()); velocityContext.put("timezone", ReportUtils.getTimezone(userId)); velocityContext.put("locale", Locale.getDefault()); return velocityContext; }
public static org.jxls.common.Context initializeContext(long userId) { org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); jxlsContext.putVar("distanceUnit", getDistanceUnit(userId)); jxlsContext.putVar("speedUnit", getSpeedUnit(userId)); jxlsContext.putVar("volumeUnit", getVolumeUnit(userId)); jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url")); jxlsContext.putVar("dateTool", new DateTool()); jxlsContext.putVar("numberTool", new NumberTool()); jxlsContext.putVar("timezone", getTimezone(userId)); jxlsContext.putVar("locale", Locale.getDefault()); jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]"); return jxlsContext; }
VelocityContext ctx = new VelocityContext(); ctx.put("dateTool", new DateTool());
/** * Make a new Velocity context and populate it from a {@code UserFeedback} instance. * * @param report * . * @return . */ private static VelocityContext makeVelocityContext(UserFeedback report) { VelocityContext context = new VelocityContext(); context.put("date", new DateTool()); context.put("feedback", report); return context; }
private void sendMail(final Object backingObject) { MimeMessagePreparator preparator = new MimeMessagePreparator() { public void prepare(MimeMessage mimeMessage) throws Exception { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true); // Set subject, from, to, .... // Set model, which then will be used in velocity's mail template Map<String, Object> model = new HashMap<String, Object>(); model.put("backingObject", backingObject); // Add this line in order to initialize DateTool model.put("date", new DateTool()); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "mail_template.vm", model); message.setText(text, true); } }; this.javaMailSender.send(preparator); }
private VelocityContext createVelocityContext(List<TemplateContextObject> templateContexts, Locale locale, RenderingMedia renderingMedia) { VelocityContext context = new VelocityContext(); templateContexts.stream() .forEach(templateContext -> context.put(templateContext.getKey(), templateContext.getValue())); DateTool dateTool = new DateTool(); Map<String, Object> dateToolConfig = new HashMap<>(); dateToolConfig.put("locale", locale); dateTool.configure(dateToolConfig); context.put("date", dateTool); TemplateResourcesTool templateResourcesTool = new TemplateResourcesTool(renderingMedia, referencedResourceProvider); context.put(RESOURCE_TOOL_CONTEXT_KEY, templateResourcesTool); return context; }
public String getHtml(HttpServletRequest request, String pluginId, Locale locale) { SecurityContextHolder.getContext(); ResourceBundle resourceBundle = ResourceBundle.getBundle("org.jtalks.jcommune.plugin.kaptcha.messages", locale); VelocityEngine engine = new VelocityEngine(getProperties()); engine.init(); Map<String, Object> model = new HashMap<>(); model.put(CAPTCHA_LABEL, resourceBundle.getObject("label.tip.captcha")); model.put(ALT_CAPTCHA, resourceBundle.getObject("alt.captcha.image")); model.put(ALT_REFRESH_CAPTCHA, resourceBundle.getObject("alt.captcha.update")); model.put(CAPTCHA_PLUGIN_ID, pluginId); model.put(FORM_ELEMENT_ID, getFormElementId(pluginId)); model.put(BASE_URL, getDeploymentRootUrl(request)); model.put(DATE, new DateTool()); return VelocityEngineUtils.mergeTemplateIntoString( engine, "org/jtalks/jcommune/plugin/kaptcha/template/captcha.vm", "UTF-8", model); }
vc.put("date", new DateTool()); vc.put("escape", new EscapeTool()); vc.put("math", new MathTool());
/** * Helper method to create a string from a Velocity template. * * @param templateFile The name of the template file to use. * @param parameters The values to merge into the template. * @return The result of the merge. * @throws SystemException if template handling fails. */ public static String createStringFromVelocityTemplate(String templateFile, Map<String, Object> parameters) throws SystemException { try { Velocity.init(); ResourceLoader source = (ResourceLoader) RootContext.getInstance().getBean("emailTemplateResourceLoader"); Resource resource = source.getResource(templateFile); parameters.put("dateFormatter", new DateTool()); Configuration config = Aksess.getConfiguration(); String encoding = config.getString("mail.templates.encoding", "ISO-8859-1"); try(InputStream is = resource.getInputStream()) { String templateText = IOUtils.toString(is, encoding); VelocityContext context = new VelocityContext(parameters); StringWriter textWriter = new StringWriter(); Velocity.evaluate(context, textWriter, "body", templateText); return textWriter.toString(); } } catch (Exception e) { throw new SystemException("Feil ved generering av mailtekst basert på Velocity. TemplateFile: " + templateFile, e); } }
Resource resource = source.getResource(templateFile); if(!properties.containsKey("dateFormatter")){ properties.put("dateFormatter", new DateTool());
/** * Initializes Velocity engine */ private void init() { velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class"); velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); setLogFile(); DateTool dateTool = new DateTool(); dateTool.configure(this.configMap); MathTool mathTool = new MathTool(); NumberTool numberTool = new NumberTool(); numberTool.configure(this.configMap); SortTool sortTool = new SortTool(); defaultContext = new VelocityContext(); defaultContext.put("dateTool", dateTool); defaultContext.put("dateComparisonTool", new ComparisonDateTool()); defaultContext.put("mathTool", mathTool); defaultContext.put("numberTool", numberTool); defaultContext.put("sortTool", sortTool); // Following tools need VelocityTools version 2.0+ //defaultContext.put("displayTool", new DisplayTool()); //defaultContext.put("xmlTool", new XmlTool()); try { velocityEngine.init(); } catch (Exception e) { throw new VelocityException(e); } }
/** * Initializes Velocity engine */ private void init() { velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class"); velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); setLogFile(); DateTool dateTool = new DateTool(); dateTool.configure(this.configMap); MathTool mathTool = new MathTool(); NumberTool numberTool = new NumberTool(); numberTool.configure(this.configMap); SortTool sortTool = new SortTool(); defaultContext = new VelocityContext(); defaultContext.put("dateTool", dateTool); defaultContext.put("dateComparisonTool", new ComparisonDateTool()); defaultContext.put("mathTool", mathTool); defaultContext.put("numberTool", numberTool); defaultContext.put("sortTool", sortTool); // Following tools need VelocityTools version 2.0+ //defaultContext.put("displayTool", new DisplayTool()); //defaultContext.put("xmlTool", new XmlTool()); try { velocityEngine.init(); } catch (Exception e) { throw new VelocityException(e); } }
/** * Initializes Velocity engine */ private void init() { velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class"); velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); setLogFile(); DateTool dateTool = new DateTool(); dateTool.configure(this.configMap); MathTool mathTool = new MathTool(); NumberTool numberTool = new NumberTool(); numberTool.configure(this.configMap); SortTool sortTool = new SortTool(); defaultContext = new VelocityContext(); defaultContext.put("dateTool", dateTool); defaultContext.put("dateComparisonTool", new ComparisonDateTool()); defaultContext.put("mathTool", mathTool); defaultContext.put("numberTool", numberTool); defaultContext.put("sortTool", sortTool); // Following tools need VelocityTools version 2.0+ //defaultContext.put("displayTool", new DisplayTool()); //defaultContext.put("xmlTool", new XmlTool()); try { velocityEngine.init(); } catch (Exception e) { throw new VelocityException(e); } }
ctx.put(Constants.TEMPLATE_ACTION_ID, actionId); ctx.put(Constants.TEMPLATE_RULE_NAME, ruleName); ctx.put(VELOCITY_VAR_DATE, new DateTool()); StringWriter writer = new StringWriter(1000); template.getVelocityBodyTemplate().merge(ctx, writer);
ctx.put(entry.getKey(), entry.getValue()); ctx.put(VELOCITY_VAR_DATE, new DateTool()); StringWriter writer = new StringWriter(1000); template.getVelocityBodyTemplate().merge(ctx, writer);
velocityContext.put("dateTool", new DateTool()); velocityContext.put("resourcePath", bootstrapManager.getWebAppContextPath() + "/download/resources/confluence.repository.client:repository/resources"); velocityContext.put("helper", new VelocityHelper(subRenderer, renderContext, repoDS, buildNum));