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; }
public static Logger getLog(VelocityEngine engine, String childNamespace) { /* first check config for a logger instance, then for a base logger name this is mostly what RuntimeServices.getLog(String) does, but we don't have access to RuntimeServices here */ Logger logger = (Logger)engine.getProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE); if (logger == null) { String basename = (String)engine.getProperty(RuntimeConstants.RUNTIME_LOG_NAME); if (basename == null) { basename = RuntimeConstants.DEFAULT_RUNTIME_LOG_NAME; } logger = LoggerFactory.getLogger(basename + "." + childNamespace); } return logger; }
/***********************************************************************/ private static boolean isDifferentForProperties(Properties props, VelocityEngine velo, String[] keys) { for (int i = 0; i < keys.length; i++) { String key = keys[i]; if (!ObjectUtils.isEqual(props.get(key), velo.getProperty(key))) { return true; } } return false; } /***********************************************************************/
/** * Returns a reference to the default static repository. * * @param engine Velocity engine to obtain repository for * * @return the applicable repository * @throw VelocityException if the repository cannot be obtained */ public static StringResourceRepository getRepository(VelocityEngine engine) { String implClass = engine.getProperty("string.resource.loader.class").toString(); if (implClass == null) { throw new VelocityException("Velocity engine did not contain a string.resource.loader.class property"); } try { Method m = Class.forName(implClass).getMethod("getRepository", (Class[]) null); return (StringResourceRepository) m.invoke(null, (Object[]) null); } catch (Exception e) { e.printStackTrace(); throw new VelocityException("Exception obtaining StringResourceRepository", e); } }
/** * Returns a reference to the repository stored statically under the specified name. * * @param engine Velocity engine to obtain repository for * @param name name of repository to access * * @return the applicable repository * @throw VelocityException if the repository cannot be obtained */ public static StringResourceRepository getRepository(VelocityEngine engine, String name) { String implClass = engine.getProperty("string.resource.loader.class").toString(); if (implClass == null) { throw new VelocityException("Velocity engine did not contain a string.resource.loader.class property"); } try { Method m = Class.forName(implClass).getMethod("getRepository", String.class); return (StringResourceRepository) m.invoke(null, name); } catch (Exception e) { e.printStackTrace(); throw new VelocityException("Exception obtaining StringResourceRepository", e); } } }
String path = (String) velocityEngine.getProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH);
log.debug("current velocity path is '{}'", ve.getProperty( VELOCITY_FILE_RESOURCE_LOADER_PATH )); throw e;
String encoding = (String) ve.getProperty( RuntimeConstants.OUTPUT_ENCODING ); if (encoding == null || encoding.length() == 0 || encoding.equals("8859-1") || encoding.equals("8859_1"))
String encoding = (String) ve.getProperty( RuntimeConstants.OUTPUT_ENCODING ); if (encoding == null || encoding.length() == 0 || encoding.equals("8859-1") || encoding.equals("8859_1"))
String encoding = (String) ve.getProperty( RuntimeConstants.OUTPUT_ENCODING ); if (encoding == null || encoding.length() == 0 || encoding.equals("8859-1") || encoding.equals("8859_1"))
/** * Puts the specified VelocityEngine in the tool properties, * as well as the Log for that engine. Last, if the specified * engine has a MethodExceptionEventHandler configured, then * this will automatically set {@link #CATCH_EXCEPTIONS_KEY} * to false in the tool properties. * @param engine VelocityEngine instance */ public void putVelocityEngine(VelocityEngine engine) { // add the engine and log as common tool properties putToolProperty(ENGINE_KEY, engine); putToolProperty(LOG_KEY, ConfigurationUtils.getLog(engine, "tools")); // tell interested tools not to catch exceptions whenever there's a // method exception event handler configured for the engine Object ehme = engine.getProperty(VelocityEngine.EVENTHANDLER_METHODEXCEPTION); if (ehme != null) { putToolProperty(CATCH_EXCEPTIONS_KEY, Boolean.FALSE); } }