@Inject public VelocityDefaultConfigurationFactory(@Optional final ServletContext servletContext) { String loader = "class"; Velocity.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true"); if (servletContext != null) { Velocity.setProperty("webapp.resource.loader.class", WebappResourceLoader.class.getName()); Velocity.setProperty("webapp.resource.loader.path", "/"); Velocity.setApplicationAttribute("javax.servlet.ServletContext", servletContext); loader += ",webapp"; } Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, loader); configuration = new Configuration(); }
@Lazy @Bean(name = "shibboleth.VelocityEngine") public VelocityEngineFactoryBean velocityEngineFactoryBean() { final VelocityEngineFactoryBean bean = new VelocityEngineFactoryBean(); final Properties properties = new Properties(); properties.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SLF4JLogChute.class.getName()); properties.put(RuntimeConstants.INPUT_ENCODING, StandardCharsets.UTF_8.name()); properties.put(RuntimeConstants.OUTPUT_ENCODING, StandardCharsets.UTF_8.name()); properties.put(RuntimeConstants.ENCODING_DEFAULT, StandardCharsets.UTF_8.name()); properties.put(RuntimeConstants.RESOURCE_LOADER, "file, classpath, string"); properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, FileUtils.getTempDirectory().getAbsolutePath()); properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, Boolean.FALSE); properties.put("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); properties.put("string.resource.loader.class", StringResourceLoader.class.getName()); properties.put("file.resource.loader.class", FileResourceLoader.class.getName()); bean.setOverrideLogging(false); bean.setVelocityProperties(properties); return bean; }
@Override public String createTable(Grammar grammar) { Velocity.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8"); Velocity.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8"); Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); Velocity.init(); VelocityContext context = new VelocityContext(); context.put("grammar", grammar); context.put("nonterminalSymbols", grammar.getLhsSymbols()); Template template = Velocity.getTemplate("/grammartools/PredictiveParsingTable.velo"); StringWriter stringWriter = new StringWriter(); template.merge(context, stringWriter); return stringWriter.toString().replaceAll("\n", ""); }
/** * Compile takes an absolute path of the app and returns an absolute path * of the resulting Vertabrae. * * @param abs_path_from the absolute path where the resources of an application * lives. * @param abs_path_to the absolute path to where the application should be * built to and served from. * @return the absolute path to serve the application from */ public static String compile(Path abs_path_from, Path abs_path_to) { System.out.println("[SPINE] Template path: " + abs_path_from); velocity_engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, abs_path_from.resolve("templates").toString()); velocity_engine.init(); System.out.println("[SPINE] From path: " + abs_path_from); System.out.println("[SPINE] To path: " + abs_path_to); try { Path dir = abs_path_from.resolve("content"); Map<String, Vertabrae> file_names = extract_files(dir); generate_markup(abs_path_from, abs_path_to, file_names); static_files_copy(abs_path_from, abs_path_to); } catch (IOException e) { e.printStackTrace(); } return abs_path_to.toAbsolutePath().toString(); }
@Before public void setUp() throws TikaException, IOException, SAXException { VelocityEngine engine = new VelocityEngine(); engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.init(); Templater templater = new Templater(); templater.setEngine(engine); exporter = new HtmlExporter(); exporter.setTemplater(templater); TikaProvider provider = new TikaProvider(); Tika tika = provider.tika(); transformer = new TikaTransformer(); transformer.setTika(tika); }
@Before public void setUp() throws TikaException, IOException, SAXException { VelocityEngine engine = new VelocityEngine(); engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.init(); Templater templater = new Templater(); templater.setEngine(engine); exporter = new PdfExporter(); exporter.setTemplater(templater); TikaProvider provider = new TikaProvider(); Tika tika = provider.tika(); transformer = new TikaTransformer(); transformer.setTika(tika); }
public static VelocityEngine getEngine() { try { final Properties props = new Properties(); props.putAll(net.shibboleth.utilities.java.support.velocity.VelocityEngine.getDefaultProperties()); props.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8"); props.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8"); props.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); props.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SLF4JLogChute.class.getName()); final VelocityEngine velocityEngine = net.shibboleth.utilities.java.support.velocity.VelocityEngine .newVelocityEngine(props); return velocityEngine; } catch (final Exception e) { throw new TechnicalException("Error configuring velocity", e); } }
private static VelocityEngine setUpVelocity(final MavenProject project) { final String templateRoot = getTemplateRoot(project); final Properties config = new Properties(); config.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath,file"); config.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateRoot); config.setProperty(RuntimeConstants.VM_LIBRARY, "macros.vm"); config.setProperty(RuntimeConstants.ENCODING_DEFAULT, UTF_8); config.setProperty(RuntimeConstants.INPUT_ENCODING, UTF_8); config.setProperty(RuntimeConstants.OUTPUT_ENCODING, UTF_8); final String resourceLoader = ClasspathResourceLoader.class.getName(); config.setProperty("classpath.resource.loader.class", resourceLoader); final String includeHandler = OptionalIncludeEventHandler.class.getName(); config.setProperty(RuntimeConstants.EVENTHANDLER_INCLUDE, includeHandler); VelocityEngine velocityEngine = new VelocityEngine(); velocityEngine.init(config); return velocityEngine; }
public VelocityGenerator(String packageName ) { this.packageName = packageName; this.javaClassGenerator = new JavaClassGenerator(); velocityEngine = new VelocityEngine(); velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); try { velocityEngine.init(); } catch (Exception e) { e.printStackTrace(); System.out.println("VelocityEngine can not initialize."); System.exit(0); } }
public SQLGenerator(String type) { this.type = type; this.javaClassGenerator = new JavaClassGenerator(); velocityEngine = new VelocityEngine(); velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); try { velocityEngine.init(); } catch (Exception e) { e.printStackTrace(); System.out.println("VelocityEngine can not initialize."); System.exit(0); } }
/** * Return the String representation of the template rendered using Velocity. * * @param context context use to render the template * @param templateFileName file name of the template in the classpath * @throws TemplateRenderException if there is an error with the template */ public static String renderTemplate(String templateFileName, VelocityContext context) throws TemplateRenderException { VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); StringWriter sw = new StringWriter(); try { ve.mergeTemplate(templateFileName, "UTF-8", context, sw); } catch (ResourceNotFoundException | ParseErrorException | MethodInvocationException e) { throw new TemplateRenderException("Error rendering template file: " + templateFileName, e); } return sw.toString(); }
/** * Create a template. * * @param language * programming language name of the generated source code. * @param templatePath * template path. * @param defaultTemplate * default template path. */ protected Template createTemplate(String language, String templatePath, String defaultTemplate) { String defaultResourcePath = "resources/" + this.language + "/" + defaultTemplate; if (templatePath == null || templatePath.isEmpty()) { templatePath = defaultResourcePath; } VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file, classpath"); ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, ""); ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); ve.init(); try { return ve.getTemplate(templatePath); } catch (ResourceNotFoundException ex) { if (templatePath != defaultResourcePath) { return ve.getTemplate(defaultResourcePath); } else { throw ex; } } }
/** * Render it. * @param folder Template folder * @param template Page template * @param params Params for velocity * @return Page body * @throws IOException If fails */ private static InputStream render(final String folder, final InputStream template, final Map<CharSequence, Object> params) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Writer writer = new Utf8OutputStreamWriter(baos); final VelocityEngine engine = new VelocityEngine(); engine.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new NullLogChute() ); engine.setProperty( "file.resource.loader.path", folder ); engine.evaluate( new VelocityContext(params), writer, "", new Utf8InputStreamReader(template) ); writer.close(); return new ByteArrayInputStream(baos.toByteArray()); }
@SuppressWarnings("deprecation") public synchronized void checkVelocity() { if (velocityInitialized) { return; } velocityInitialized = true; ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "string"); ve.setProperty("resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader"); ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute"); ve.setProperty("runtime.log.logsystem.log4j.logger", "net.sf.taverna.t2.activities.interaction.velocity.InteractionVelocity"); ve.init(); ve.loadDirective(RequireDirective.class.getName()); ve.loadDirective(ProduceDirective.class.getName()); ve.loadDirective(NotifyDirective.class.getName()); loadTemplates(); interactionTemplate = ve.getTemplate(INTERACTION_TEMPLATE_NAME); if (interactionTemplate == null) { logger.error("Could not open interaction template " + INTERACTION_TEMPLATE_NAME); } }
/** * @return produz uma instancia do velocity template para uso no sistema */ @Produces VelocityEngine produceEngine() { final VelocityEngine engine = new VelocityEngine(); // manda carregar os recursos dos resources engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "class"); engine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); final Properties properties = new Properties(); // joga os logs do velocity no log do server properties.put("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem"); properties.put("runtime.log.logsystem.log4j.category", "velocity"); properties.put("runtime.log.logsystem.log4j.logger", "velocity"); engine.init(properties); return engine; }
@Override public boolean process( Set<? extends TypeElement> annotations, RoundEnvironment roundEnv ) { ModelCollector collector = new ModelCollector( processingEnv.getMessager() ); processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Start processing JNI Proxies" ); JNIElementVisitor elementVisitor = new JNIElementVisitor( processingEnv.getMessager() ); for ( TypeElement annotation : annotations ) { for ( Element element : roundEnv.getElementsAnnotatedWith( annotation ) ) { element.accept( elementVisitor, collector ); } } VelocityEngine engine = new VelocityEngine(); engine.setProperty( RuntimeConstants.RESOURCE_LOADER, "classpath" ); engine.setProperty( "classpath.resource.loader.class", ClasspathResourceLoader.class.getName() ); engine.init(); GeneralGenerator generalGenerator = new GeneralGenerator( processingEnv, engine ); for ( JNIProxyClass proxyClass : collector.getClasses() ) { proxyClass.accept( generalGenerator ); } return true; }
private static void createReportFromValidationResult(ValidationResult result, Path outputPath) { Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); Velocity.init(); try { Template template = Velocity.getTemplate("reporting/ValidationResult.vm"); VelocityContext context = new VelocityContext(); context.put("validationResult", result); context.put("resourcesWithWarnings", getResourcesWithWarnings(result)); StringWriter sw = new StringWriter(); template.merge(context, sw); try (FileWriter fw = new FileWriter(outputPath.toFile())) { fw.write(sw.toString()); fw.flush(); } catch (IOException ioe) { LOGGER.error("Creation of HTML Report file {} failed.", outputPath.toString(), ioe); } } catch (VelocityException e) { LOGGER.error("Creation of HTML report failed due to a Velocity Exception", e); } }
/** * Intializes the Apache Velocity template engine. * * @throws ConfigurationException thrown if there is a problem initializing Velocity */ protected static void initializeVelocity() throws ConfigurationException { try { log.debug("Initializing Velocity template engine"); Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogChute"); Velocity.setProperty(RuntimeConstants.ENCODING_DEFAULT, "UTF-8"); Velocity.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8"); Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); Velocity.setProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); Velocity.init(); } catch (Exception e) { throw new ConfigurationException("Unable to initialize Velocity template engine", e); } }
/** Constructor. * @throws Exception */ public SAML2HTTPPostSimpleSignSecurityPolicyRuleTest() throws Exception { signingCert = SecurityTestHelper.buildJavaX509Cert(signingCertBase64); signingPrivateKey = SecurityTestHelper.buildJavaRSAPrivateKey(signingPrivateKeyBase64); signingX509Cred = new BasicX509Credential(); signingX509Cred.setEntityCertificate(signingCert); signingX509Cred.setPrivateKey(signingPrivateKey); signingX509Cred.setEntityId(issuer); otherCert1 = SecurityTestHelper.buildJavaX509Cert(otherCert1Base64); otherCred1 = new BasicX509Credential(); otherCred1.setEntityCertificate(otherCert1); otherCred1.setEntityId("other-1"); velocityEngine = new VelocityEngine(); velocityEngine = new VelocityEngine(); velocityEngine.setProperty(RuntimeConstants.ENCODING_DEFAULT, "UTF-8"); velocityEngine.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8"); velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); velocityEngine.setProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); velocityEngine.init(); }
private MailerWithTemplate(MailPackageStaticDependenciesWrapper webappAndMailHelper) { this.webappAndMailHelper = webappAndMailHelper; // init velocity engine Properties p = null; try { velocityEngine = new VelocityEngine(); p = new Properties(); p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.SimpleLog4JLogSystem"); p.setProperty("runtime.log.logsystem.log4j.category", "syslog"); // p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, // "org.apache.velocity.runtime.log.SimpleLog4JLogSystem"); // p.setProperty(RuntimeConstants.RUNTIME_LOG, // OLATContext.getUserdataRoot() + "logs/velocity-email.log.txt"); // p.setProperty("runtime.log.logsystem.log4j.category", "syslog"); // p.setProperty(RuntimeConstants.RUNTIME_LOG_ERROR_STACKTRACE, "false"); // p.setProperty(RuntimeConstants.RUNTIME_LOG_INFO_STACKTRACE, "false"); velocityEngine.init(p); } catch (Exception e) { throw new RuntimeException("config error " + p.toString()); } }
private String getAccordianHeadingHTML(LinkObject link, List<LinkObject> links) { VelocityEngine engine = new VelocityEngine(); engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); StringWriter writer = new StringWriter(); try { engine.init(); VelocityContext context = new VelocityContext(); context.put("link", link); context.put("links", links); engine.mergeTemplate("/templates/leftnav-accordian.vm", context, writer); return writer.toString(); } catch (Exception e1) { getLog().error(e1); } return null; }
public String render(String template, HashMap<String,Object> parameters) throws Exception { /* first, get and initialize an engine */ VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); ve.init(); /* next, get the Template */ Template t = ve.getTemplate( template ); /* create a context and add data */ VelocityContext context = new VelocityContext(); for (Map.Entry<String,Object> entry : parameters.entrySet()) { context.put(entry.getKey(),entry.getValue()); } /* now render the template into a StringWriter */ StringWriter writer = new StringWriter(); t.merge( context, writer ); /* show the World */ return writer.toString(); }
/** * Generate a script from the specified template * using the given object map. * * @param template * @param objMap * * @return script * * @throws IOException */ public String generateScript(PraatScriptContext ctx) throws IOException { final Properties p = new Properties(); p.setProperty(RuntimeConstants.RESOURCE_LOADER, "string"); p.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader"); final VelocityEngine ve = new VelocityEngine(); ve.init(p); if(scriptTemplate == null || scriptTemplate.length() == 0) { // install string and set template name scriptTemplate = UUID.randomUUID().toString(); StringResourceRepository repository = StringResourceLoader.getRepository(); repository.putStringResource(scriptTemplate, scriptText); } // load template final Template t = ve.getTemplate(getScriptTemplate()); final StringWriter sw = new StringWriter(); t.merge(ctx.velocityContext(), sw); return sw.toString(); }
@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); }
/** * @see HttpServlet#HttpServlet() */ public WmsServlet() { super(); advertisedPalettes.add(ColourPalette.DEFAULT_PALETTE_NAME); /* * Initialise the velocity templating engine ready for use in * GetFeatureInfo and GetCapabilities */ Properties props = new Properties(); props.put("resource.loader", "class"); props.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); velocityEngine = new VelocityEngine(); velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute"); velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", "velocity"); velocityEngine.init(props); }
/** * @param args */ public static void main(String[] args) { Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); Velocity.setProperty(RuntimeConstants.RUNTIME_LOG, "velocity.log"); Velocity.init(); StringWriter writer = new StringWriter(); VelocityContext context = new VelocityContext(); context.put("a", 1); context.put("b", 2); context.put("c", 3); context.put("sysTime", new Date()); context.put("dateUtil", new DateUtil()); String template = "" + "#set($timeString = $dateUtil.format($sysTime, 'yyyy-MM-dd HH:mm:ss') + 'ssss')\r\n" + "#set($value = ($a + $b) * $c)\r\n" + "$value\r\n" + "${($a + $b) * $c}\r\n" + "$dateUtil.format($sysTime, 'yyyy-MM-dd HH:mm:ss')\r\n" + "$timeString\r\n"; Velocity.evaluate(context, writer, "mergeTemplate", template); System.out.println(writer.toString()); }
/** * Create and initialize Velocity engine. * @return The engine to use */ private static VelocityEngine init() { final VelocityEngine engine = new VelocityEngine(); engine.setProperty("resource.loader", "cp"); engine.setProperty( "cp.resource.loader.class", ClasspathResourceLoader.class.getName() ); engine.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute" ); engine.setProperty( "runtime.log.logsystem.log4j.logger", "org.apache.velocity" ); engine.init(); return engine; }
/** * Initializes the code adf engine */ private void init() throws Exception { if (!inited) { // Init velocity engine Properties properties = new Properties(); properties.setProperty("resource.loader", "class"); properties.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader"); properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); //TODO REVIEW THIS properties.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.JdkLogChute"); // init velocity engine velocityEngine.init(properties); inited = true; } }
/***********************************************************************/ public static Writer parse(String template, Properties props, ContextAware process[], Writer out) { try { props.put("directive.foreach.counter.initial.value", "0"); props.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogSystem.class.getName()); VelocityEngine engine = initializeEngine(props); VelocityContext context = new VelocityContext(); Template velocityTemplate = engine.getTemplate(template); for (int i = 0; i < process.length; i++) { if(process[i] != null) process[i].setupContext(context); } velocityTemplate.merge(context, out); return out; } catch (Exception e) { throw ObjectUtils.throwAsError(e); } }
private static synchronized VelocityEngine getEngine() { if (instance == null) { try { Properties extendedProperties = new Properties(); extendedProperties.setProperty(RuntimeConstants.RESOURCE_LOADER, "file"); extendedProperties.setProperty(RuntimeConstants.PARSER_POOL_SIZE, "1"); extendedProperties.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); extendedProperties.setProperty("file.resource.loader.path", "resources"); VelocityEngine engine = new VelocityEngine(extendedProperties); engine.init(); instance = engine; } catch (Exception ignored) { } } return instance; }
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, "html/pages, html/snippets"); ve.init(); VelocityContext context = new VelocityContext(); Pair<Entity, UserCookie> infoAndCookie = init(context, req); UserCookie userCookie = infoAndCookie.y; boolean loggedIn = (boolean) context.get("loggedIn"); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); if (loggedIn && !userCookie.isAdmin()) { context.put("updated", req.getParameter("updated")); context.put("passError", req.getParameter("passError")); context.put("confPassError", req.getParameter("confPassError")); close(context, ve.getTemplate("changePassword.html"), resp); } else { resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "User account required for that operation"); } }
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, "html/pages, html/snippets"); ve.init(); VelocityContext context = new VelocityContext(); init(context, req); Pair<Entity, UserCookie> infoAndCookie = init(context, req); Yaml yaml = new Yaml(); HashMap<String, String> directions = (HashMap<String, String>) yaml.load(((Text) infoAndCookie.x.getProperty("directions")).getValue()); context.put("directions", directions); context.put("school", infoAndCookie.x.getProperty("school")); context.put("location", infoAndCookie.x.getProperty("location")); context.put("address", infoAndCookie.x.getProperty("address")); context.put("esc", new EscapeTool()); close(context, ve.getTemplate("directions.html"), resp); }
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, "html/pages, html/snippets"); ve.init(); VelocityContext context = new VelocityContext(); Pair<Entity, UserCookie> infoAndCookie = init(context, req); Yaml yaml = new Yaml(); HashMap<String, String> schedule = (HashMap<String, String>) yaml.load(((Text) infoAndCookie.x.getProperty("schedule")).getValue()); context.put("schedule", schedule); context.put("aboutText", ((Text) infoAndCookie.x.getProperty("aboutText")).getValue()); context.put("qualifyingCriteria", Retrieve.qualifyingCriteria(infoAndCookie.x)); context.put("Test", Test.class); context.put("Level", Level.class); context.put("Subject", Subject.class); close(context, ve.getTemplate("about.html"), resp); }
/** * Initializes the code generation engine */ private void init() throws Exception { if (!inited) { // Init velocity engine Properties properties = new Properties(); properties.setProperty("resource.loader", "class"); properties.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader"); properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); //TODO REVIEW THIS properties.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.JdkLogChute"); // init velocity engine velocityEngine.init(properties); inited = true; } }
@PostConstruct public void init() { // create velocity engine velocityEngine = new VelocityEngine(); velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); velocityEngine.init(); }
@Before public void setUp() { VelocityEngine engine = new VelocityEngine(); engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.init(); templater = new Templater(); templater.setEngine(engine); }
@Before public void setUp() throws IOException, TikaException, SAXException { MockitoAnnotations.initMocks(this); createDirectories(Paths.get("fileTestFiles")); docxExporter = new DocxExporter(); xlsxExporter = new XlsxExporter(); VelocityEngine engine = new VelocityEngine(); engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.init(); templater = new Templater(); templater.setEngine(engine); pdfExporter = new PdfExporter(); pdfExporter.setTemplater(templater); ObjectMapperProducer objectMapperProducer = new ObjectMapperProducer(); mapper = objectMapperProducer.objectMapper(false, false); TikaProvider provider = new TikaProvider(); Tika tika = provider.tika(); transformer = new TikaTransformer(); transformer.setTika(tika); }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext=applicationContext; ve = new VelocityEngine(); ve.setProperty(Velocity.RESOURCE_LOADER, "class"); ve.setProperty("class.resource.loader.class","org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,new NullLogChute()); ve.init(); }
/** * Prepare the VelocityEngine instance and return it. * @return the VelocityEngine instance * @throws IOException if the config file wasn't found * @throws VelocityException on Velocity initialization failure */ public VelocityEngine createVelocityEngine() throws IOException, VelocityException { VelocityEngine velocityEngine = newVelocityEngine(); Map<String, Object> props = new HashMap<String, Object>(); // Load config file if set. if (this.configLocation != null) { if (logger.isInfoEnabled()) { logger.info("Loading Velocity config from [" + this.configLocation + "]"); } CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), props); } // Merge local properties if set. if (!this.velocityProperties.isEmpty()) { props.putAll(this.velocityProperties); } // Set a resource loader path, if required. if (this.resourceLoaderPath != null) { initVelocityResourceLoader(velocityEngine, this.resourceLoaderPath); } // Log via Commons Logging? if (this.overrideLogging) { velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute()); } // Apply properties to VelocityEngine. for (Map.Entry<String, Object> entry : props.entrySet()) { velocityEngine.setProperty(entry.getKey(), entry.getValue()); } postProcessVelocityEngine(velocityEngine); // Perform actual initialization. velocityEngine.init(); return velocityEngine; }