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; }
/** * 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); } }
/** * Converts an object to an instance of {@link Number} using the * format returned by {@link #getFormat()} and the {@link Locale} * returned by {@link #getLocale()} if the object is not already * an instance of Number. * * @param obj the number to convert * @return the object as a {@link Number} or <code>null</code> if no * conversion is possible */ public Number toNumber(Object obj) { return toNumber(getFormat(), obj, getLocale()); }
/** * Converts the specified object to a number and formats it according to * the pattern or style returned by {@link #getFormat()}. * * @param obj the number object to be formatted * @return the specified number formatted as a string * @see #format(String format, Object obj, Locale locale) */ public String format(Object obj) { return format(getFormat(), obj); }
/** * Converts the specified object to a number and returns * a formatted string representing that number in the locale * returned by {@link #getLocale()}. * * @param format the formatting instructions * @param obj the number object to be formatted * @return a formatted string for this locale representing the specified * number or <code>null</code> if the parameters are invalid * @see #format(String format, Object obj, Locale locale) */ public String format(String format, Object obj) { return format(format, obj, getLocale()); }
/** * Converts an object to an instance of {@link Number} using the * specified format and the {@link Locale} returned by * {@link #getLocale()} if the object is not already an instance * of Number. * * @param format - the format the number is in * @param obj - the number to convert * @return the object as a {@link Number} or <code>null</code> if no * conversion is possible * @see #toNumber(String format, Object obj, Locale locale) */ public Number toNumber(String format, Object obj) { return toNumber(format, obj, getLocale()); }
/** * Converts the specified object to a number and returns * a formatted string representing that number in the specified * {@link Locale}. * * @param format the custom or standard pattern to be used * @param obj the number object to be formatted * @param locale the {@link Locale} to be used when formatting * @return a formatted string representing the specified number or * <code>null</code> if the parameters are invalid */ public String format(String format, Object obj, Locale locale) { Number number = toNumber(obj); NumberFormat nf = getNumberFormat(format, locale); if (number == null || nf == null) { return null; } return nf.format(number); }
/** * Convenience method equivalent to $number.format("integer", $foo). * @param obj the number object to be formatted * @return the specified number formatted as an integer * @since VelocityTools 1.3 */ public String integer(Object obj) { return format("integer", obj); }
/** * 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); } }
/** * Convenience method equivalent to $number.format("currency", $foo). * @param obj the number object to be formatted * @return the specified number formatted as a currency * @since VelocityTools 1.3 */ public String currency(Object obj) { return format("currency", obj); }
/** * 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); } }
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; }
/** * Convenience method equivalent to $number.format("percent", $foo). * @param obj the number object to be formatted * @return the specified number formatted as a percentage * @since VelocityTools 1.3 */ public String percent(Object obj) { return format("percent", obj); }
context.put("math", mathTool); NumberTool numberTool = new NumberTool(); numberTool.configure(toolConfig); context.put("number", numberTool);
context.put("number", new NumberTool()); context.put("list", new ListTool()); context.put("date", new ComparisonDateTool());
/** * Convenience method equivalent to $number.format("number", $foo). * @param obj the number object to be formatted * @return the specified number formatted as a number * @since VelocityTools 1.3 */ public String number(Object obj) { return format("number", obj); }