/** * Creates and configures the velocity engine. * * @param devMode * @return */ private VelocityEngine configureVelocityEngine(final boolean devMode) { VelocityEngine engine = new VelocityEngine(); engine.setProperty("resource.loader", "classpath, jar"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.setProperty("classpath.resource.loader.cache", !devMode); engine.setProperty("classpath.resource.loader.modificationCheckInterval", 5L); engine.setProperty("jar.resource.loader.class", JarResourceLoader.class.getName()); engine.setProperty("jar.resource.loader.cache", !devMode); engine.setProperty("resource.manager.logwhenfound", false); engine.setProperty("input.encoding", "UTF-8"); engine.setProperty("output.encoding", "UTF-8"); engine.setProperty("directive.set.null.allowed", true); engine.setProperty("resource.manager.logwhenfound", false); engine.setProperty("velocimacro.permissions.allow.inline", true); engine.setProperty("velocimacro.library.autoreload", devMode); engine.setProperty("velocimacro.library", "/azkaban/webapp/servlet/velocity/macros.vm"); engine.setProperty("velocimacro.permissions.allow.inline.to.replace.global", true); engine.setProperty("velocimacro.arguments.strict", true); engine.setProperty("runtime.log.invalid.references", devMode); engine.setProperty("runtime.log.logsystem.class", Log4JLogChute.class); engine.setProperty("runtime.log.logsystem.log4j.logger", Logger.getLogger("org.apache.velocity.Logger")); engine.setProperty("parser.pool.size", 3); return engine; }
@Override protected void postProcessVelocityEngine(VelocityEngine velocityEngine) { super.postProcessVelocityEngine(velocityEngine); velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp,file,class,url,jar,spring,springMacro"); velocityEngine.setProperty("webapp.resource.loader.class", WebappResourceLoader.class.getName()); velocityEngine.setProperty("file.resource.loader.class", FileResourceLoader.class.getName()); velocityEngine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); velocityEngine.setProperty("url.resource.loader.class", URLResourceLoader.class.getName()); velocityEngine.setProperty("jar.resource.loader.class", JarResourceLoader.class.getName()); velocityEngine.setProperty("resource.manager.cache.class", ResourceCacheImpl.class.getName()); velocityEngine.setProperty("resource.manager.cache.size", 2048); velocityEngine.setProperty("resource.manager.class", ResourceManagerImpl.class.getName()); velocityEngine.setProperty(RuntimeConstants.COUNTER_INITIAL_VALUE, 1); velocityEngine.setProperty(RuntimeConstants.INPUT_ENCODING, inputEncoding); velocityEngine.setProperty(RuntimeConstants.OUTPUT_ENCODING, outputEncoding); velocityEngine.setProperty("contentType", contentType); // org.apache.velocity.runtime.log.AvalonLogChute // org.apache.velocity.runtime.log.Log4JLogChute // org.apache.velocity.runtime.log.CommonsLogLogChute // org.apache.velocity.runtime.log.ServletLogChute // org.apache.velocity.runtime.log.JdkLogChute velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new Log4JLogChute()); velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); }
private static VelocityEngine getInitialisedVelocityEngine() { try { VelocityEngine velocityEngine=new VelocityEngine(); velocityEngine.setProperty(VelocityEngine.PARSER_POOL_SIZE, 10); velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName()); velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", logger.getName()); velocityEngine.init(); return(velocityEngine); } catch (Exception e) { logger.error("Error", e); return(null); } }
public VelocityEngine(String baseTemplateDir) { this.baseTemplateDir = Utils.notNull(baseTemplateDir); this.engine = new org.apache.velocity.app.VelocityEngine(); engine.setProperty("resource.loader", "classpath"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.setProperty("classpath.resource.loader.cache", false); engine.setProperty("file.resource.loader.modificationCheckInterval", 0); engine.setProperty("input.encoding", "UTF-8"); engine.setProperty("velocimacro.permissions.allow.inline", true); engine.setProperty("velocimacro.library.autoreload", true); engine.setProperty("runtime.log.logsystem.class", Log4JLogChute.class); engine.setProperty("runtime.log.logsystem.log4j.logger", Logger.getLogger("org.apache.velocity.Logger")); engine.setProperty("parser.pool.size", 3); }
/** * Creates and configures the velocity engine. * * @param devMode * @return */ private VelocityEngine configureVelocityEngine(final boolean devMode) { VelocityEngine engine = new VelocityEngine(); engine.setProperty("resource.loader", "classpath, jar"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.setProperty("classpath.resource.loader.cache", !devMode); engine.setProperty("classpath.resource.loader.modificationCheckInterval", 5L); engine.setProperty("jar.resource.loader.class", JarResourceLoader.class.getName()); engine.setProperty("jar.resource.loader.cache", !devMode); engine.setProperty("resource.manager.logwhenfound", false); engine.setProperty("input.encoding", "UTF-8"); engine.setProperty("output.encoding", "UTF-8"); engine.setProperty("directive.set.null.allowed", true); engine.setProperty("resource.manager.logwhenfound", false); engine.setProperty("velocimacro.permissions.allow.inline", true); engine.setProperty("velocimacro.library.autoreload", devMode); engine.setProperty("velocimacro.library", "/azkaban/webapp/servlet/velocity/macros.vm"); engine.setProperty( "velocimacro.permissions.allow.inline.to.replace.global", true); engine.setProperty("velocimacro.arguments.strict", true); engine.setProperty("runtime.log.invalid.references", devMode); engine.setProperty("runtime.log.logsystem.class", Log4JLogChute.class); engine.setProperty("runtime.log.logsystem.log4j.logger", Logger.getLogger("org.apache.velocity.Logger")); engine.setProperty("parser.pool.size", 3); return engine; }
public void generate() throws JsonParseException, JsonMappingException, IOException { // INIT VELOCITY ENGINE VelocityEngine engine; Properties velocityProperties = new Properties(); velocityProperties.setProperty(RuntimeConstants.RESOURCE_LOADER, "cloader"); velocityProperties.setProperty("cloader.resource.loader.class", ClasspathResourceLoader.class.getName()); velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName()); velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM + ".log4j.logger", LOG.getName()); engine = new VelocityEngine(velocityProperties); engine.init(); Template endpointTemplate = engine.getTemplate("endpoint.vm"); Template consumerTemplate = engine.getTemplate("consumer.vm"); Template consumerCallbackImplTemplate = engine.getTemplate("consumer_callback_impl.vm"); Template producerTemplate = engine.getTemplate("producer.vm"); Template cameldocTemplate = engine.getTemplate("cameldoc.vm"); createClassBundle("org.atomspace.camel.component.tinkerforge", new File("src/test/resources/config/binding/brick_red_config.json"), endpointTemplate, consumerTemplate, producerTemplate, consumerCallbackImplTemplate, cameldocTemplate) ; /*File[] configFiles = new File("src/test/resources/config/binding").listFiles(); for (File file : configFiles) { if(file.toString().endsWith("brick_silent_stepper_config.json") || file.toString().endsWith("bricklet_ac_current_config.json") || file.toString().endsWith("bricklet_can_config.json") || file.toString().endsWith("bricklet_gas_detector_config.json") || file.toString().endsWith("bricklet_heart_rate_config.json") || file.toString().endsWith("bricklet_motorized_poti_config.json") || file.toString().endsWith("bricklet_ozone_config.json") || file.toString().endsWith("bricklet_pressure_config.json") ){ }else if(file.toString().endsWith("json")){ createClassBundle("org.atomspace.camel.component.tinkerforge", file, endpointTemplate, consumerTemplate, producerTemplate, consumerCallbackImplTemplate, cameldocTemplate) ; System.out.println("GENERATE SOURCES for "+file.getAbsolutePath()); } }*/ }
private static void initVelocity() { try { // Use log4j Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getCanonicalName()); Velocity.setProperty("runtime.log.logsystem.log4j.logger", "org.apache.velocity"); // Use UTF-8 Velocity.setProperty("input.encoding", "UTF-8"); Velocity.setProperty("output.encoding", "UTF-8"); Velocity.init(); } catch (Exception e) { System.err.println("Couldn't start up velocity."); System.exit(1); } }
private VelocityTemplates() { commonProps = new Properties(); commonProps.put(RuntimeConstants.INPUT_ENCODING, "UTF-8"); commonProps.put(RuntimeConstants.OUTPUT_ENCODING, "UTF-8"); commonProps.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName()); commonProps.put("runtime.log.logsystem.log4j.logger", "org.apache.velocity"); }
/** * Initialize Velocity engine. Support the template files in either jar file or file system directory. */ public VelocityTemplatingEngine() { final URL templateDirUrl = getClass().getClassLoader().getResource(VELOCITY_TEMPLATE_DIR); if (templateDirUrl == null) { throw new Rest4JInternalException("Unable to find the Velocity template resources"); } StringBuilder configName; if ("jar".equals(templateDirUrl.getProtocol())) { _velocity = new VelocityEngine(); // config Velocity to use the jar resource loader // more detail in Velocity user manual _velocity.setProperty(VelocityEngine.RESOURCE_LOADER, "jar"); configName = new StringBuilder("jar.").append(VelocityEngine.RESOURCE_LOADER).append(".class"); _velocity.setProperty(configName.toString(), JarResourceLoader.class.getName()); configName = new StringBuilder("jar.").append(VelocityEngine.RESOURCE_LOADER).append(".path"); // fix for Velocity 1.5: jar URL needs to be ended with "!/" final String normalizedUrl = templateDirUrl.toString().substring(0, templateDirUrl.toString().length() - VELOCITY_TEMPLATE_DIR.length()); _velocity.setProperty(configName.toString(), normalizedUrl); } else if ("file".equals(templateDirUrl.getProtocol())) { _velocity = new VelocityEngine(); final String resourceDirPath = new File(templateDirUrl.getPath()).getParent(); configName = new StringBuilder("file.").append(VelocityEngine.RESOURCE_LOADER).append(".path"); _velocity.setProperty(configName.toString(), resourceDirPath); } else { throw new IllegalArgumentException("Unsupported template path scheme"); } _velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName()); _velocity.setProperty(Log4JLogChute.RUNTIME_LOG_LOG4J_LOGGER, getClass().getName()); try { _velocity.init(); } catch (Exception e) { throw new Rest4JInternalException(e); } }