Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:27:44+00:00 2026-06-13T23:27:44+00:00

I have an application where in I am trying to create a velocity template

  • 0

I have an application where in I am trying to create a velocity template repository which will help me centralise all my email templates and will allow me to create a communication hub. All templates will be called at runtime and populates with data via services.

My problem is that I need to provide users with optional and compulsory params list when they define the template inputs for the velocity template.

Is there a way to read the tokens/tags from the velocity template file and extract them??

Like I want a list of tokens $name.address.streetName to be available to me from .vm file.

I do not want to go for Regex .

I do not have to cache or reuse them , its just going to be a one time read and store the default,compulsory & optional params in the database.

I am following these patterns : http://kickjava.com/src/org/apache/velocity/test/view/TemplateNodeView.java.htm

How to use String as Velocity Template?

Please advice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:27:46+00:00Added an answer on June 13, 2026 at 11:27 pm

    I got it working like this

                RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();            
            StringReader reader = new StringReader(String velocityTemplateBodu);
            SimpleNode node = runtimeServices.parse(reader, "dummyOne.vm");
    
    
            for(int i=0; i<node.jjtGetNumChildren();i++){
                if(node.jjtGetChild(i) instanceof org.apache.velocity.runtime.parser.node.ASTReference ){
                    System.out.println("Node -----------------"+i +"---"+node.jjtGetChild(i).literal());
                }
            }
    

    Using SimpleNode class you get all the nodes on the .vm file.

    The Nodes are read using javaCC as ASTReference and ASTText (both extend SimpleNode). To get the tokens you need to get the ASTReference and to get HTML text use the ASTText.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my own email server. I am trying to create an application for
I have an application in which i am trying to create autocompletion of jTextField
I have been trying to create a simple application that will let the user
I am trying to create an application that will have a tray icon only,
I have a winforms application and I am trying to create a method that
im trying to create a database for a feedback application in ASP.net i have
I'm trying to create an Hello World JSF application. I have a bean with
I'm trying to create Ruby on Rails 3 application and have a question. I
I am using Apache Velocity template engine for my web application html email utility.
I am trying to create a small server type application and have a question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.