You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by David Sperling <ve...@hakodateit.com> on 2006/02/20 00:48:55 UTC

getting the getVelocityEngine() method from within a Struts Action

Hi-

I'm trying to send mail from a Struts Action with velocity 1.5 and
velocity-tools-1.2.

The faq:
http://wiki.apache.org/jakarta-velocity/VelocityFAQ
Says:
>>You can get this instance for other uses of velocity by calling
getVelocityEngine
>>from a subclass

Another recommendation from this list was to:
>>To  get the VelocityEngine from getVelocityEngine(),


So my question is how do you get the VelocityEngine from the
getVelocityEngine()?

I've spent hours on google trying to find some code that calls the
getVelocityEngine()
but the only thing I could come up with was a VelocityManager class from
opensymphony.
And the VelocityManager.java class from opensymphony is quite complex
and has
many dependencies.


Cheers,




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: getting the getVelocityEngine() method from within a Struts Action

Posted by Bill Rishel <il...@gmail.com>.
I have extended VelocityViewServlet
and in that class I have:

        VelocityEngine ve = getVelocityEngine();
        Writer writer = getResponseWriter(response);

       // stringWriter has my preprocessed template
        ve.evaluate(ctx,(Writer) writer, "footer", stringWriter.toString());

        writer.flush();

Which works.




Bill



On 2/19/06, David Sperling <ve...@hakodateit.com> wrote:
>
> I got some hints from the Spring project source code, MessageTool
> source code and this 3 year old message by Mr. Bubna
> "Re: Using Velocity tools in an application?" and finally got
> this working.
>
> I wanted to figure out how to access the MessageTool
> from within a Velocity context and send the contents via mail.
> Hopefully this will help out others having similar trouble.
>
> So to test this out I added entries to my config files:
>
> ********************************************************************
> This was in my main Strut-Config.xml file:
> <message-resources parameter="resources.application"/>
> ********************************************************************
>
> ********************************************************************
> This was in a test-config.xml file
> <message-resources key="nonStandardResources"
>                   parameter="resources.nonStandardResources.application"/>
> ********************************************************************
>
> ********************************************************************
> next the template file: at mywebapp/mailTemplates/testTemplate.vm
>
> $title : $text.get("test.mail.name", ["jon","doe"])
> $title with no args: $text.get("test.mail.name")
> $title with args and bundle: $text.get("test.mail.name",
>                                   "nagisateiHotelResources", ["jon",
> "doe"] )
> ********************************************************************
>
> ********************************************************************
> Struts Action mapping in the Struts module:
> <action path="/test/testSendingVelocityMail"
>               type = "mydomain.myapp.action.TestSendingMailAction"
>               scope="request" >
>     <forward name ="success" path="/test/sendMail.vm" />
> </action>
> ********************************************************************
>
> ********************************************************************
> The web page: /test/sendMail.vm
>
> <html>
>   <head>
>     <title>Velocity Mail Test Page</title>
>     <meta http-equiv=Content-Type content="text/html; charset=utf-8">
>   </head>
>   <body>
>   <p>
>     <a href="$link.setAction("/test/testSendingVelocityMail.do")" >Send
> a test email</a>
>   </p>
>   </body>
> </html>
> ********************************************************************
>
> ********************************************************************
>
> The Action Class
>
> /*
> * Created on Feb 17, 2006
> *
> *
> */
>
> import java.io.StringWriter;
> import java.io.UnsupportedEncodingException;
> import java.util.Date;
> import java.util.Properties;
>
> import javax.mail.Message;
> import javax.mail.MessagingException;
> import javax.mail.Session;
> import javax.mail.Transport;
> import javax.mail.internet.InternetAddress;
> import javax.mail.internet.MimeMessage;
> import javax.mail.internet.MimeUtility;
> import javax.servlet.ServletContext;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> import org.apache.log4j.Logger;
> import org.apache.struts.action.Action;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionForward;
> import org.apache.struts.action.ActionMapping;
> import org.apache.velocity.Template;
> import org.apache.velocity.VelocityContext;
> import org.apache.velocity.app.VelocityEngine;
> import org.apache.velocity.exception.MethodInvocationException;
> import org.apache.velocity.exception.ParseErrorException;
> import org.apache.velocity.exception.ResourceNotFoundException;
> import org.apache.velocity.runtime.RuntimeConstants;
> import org.apache.velocity.tools.struts.MessageTool;
> import org.apache.velocity.tools.view.context.ChainedContext;
> import org.apache.velocity.tools.view.servlet.WebappLoader;
>
> public class TestSendingMailAction extends Action
> {
>     static Logger logger = Logger.getLogger(TestSendingMailAction.class);
>     public static final String TEST_TEMPLATE =
> "mailTemplates/testTemplate.vm";
>
>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>             HttpServletRequest request, HttpServletResponse response)
>             throws Exception
>     {
>
>         MessageTool messageTool = new MessageTool();
>         ServletContext servletContex =
> this.getServlet().getServletContext();
>         // Init the VelocityEngine Instance
>         VelocityEngine engine = new VelocityEngine();
>         this.initializeEngine(engine);
>
>         ChainedContext chainedContext = new ChainedContext(engine,
> request,
>                 response, servletContex);
>         messageTool.init(chainedContext);
>
>         VelocityContext context = new VelocityContext();
>         context.put("title", "MessageTool test mail");
>         context.put("text", messageTool);
>
>         String bodyText = createBodyText(engine, context);
>
>         this.sendMail(bodyText);
>
>         return (mapping.findForward("success"));
>
>     }
>
>     /**
>      * @param engine
>      * @param context
>      */
>     private String createBodyText(VelocityEngine engine, VelocityContext
> context)
>     {
>         StringWriter sw = new StringWriter();
>         Template temp;
>         try
>         {
>             temp = engine.getTemplate(TEST_TEMPLATE);
>             temp.merge(context, sw);
>             String body = sw.toString();
>         }
>         catch (ResourceNotFoundException e)
>         {
>             logger.error("resource no Found: " + e);
>         }
>         catch (ParseErrorException e)
>         {
>             logger.error("Parse Error Exception: " + e);
>         }
>         catch (MethodInvocationException e)
>         {
>             logger.error("MethodInvocationException, applying template:
> " + e);
>         }
>         catch (Exception e)
>         {
>             logger.error("General Exception, applying template: " + e);
>         }
>
>         return sw.toString();
>
>     }
>
>     private void sendMail(String bodyText)
>     {
>
>         String subject = "test mail";
>         String fromName = "Jon Doe";
>         String fromEmail = "jon@doe.com";
>         String toRecipient = "Mr. Recipient";
>         String toEmail = "velocity@test.com";
>         Properties mailProps = new Properties();
>         mailProps.put("mail.host", "localhost");
>         mailProps.put("debug", "true");
>
>         Session session = Session.getDefaultInstance(mailProps, null);
>         MimeMessage msg = new MimeMessage(session);
>
>         InternetAddress toAddress;
>         try
>         {
>             toAddress = new InternetAddress(toEmail,
> MimeUtility.encodeText(
>                     toRecipient, "UTF-8", null));
>             if (fromName != null && fromEmail != null)
>             {
>                 msg.setFrom(new InternetAddress(fromEmail, MimeUtility
>                         .encodeText(fromName, "UTF-8", null)));
>             }
>             msg.setRecipient(Message.RecipientType.TO, toAddress);
>             msg.setSubject(MimeUtility.encodeText(subject, "UTF-8",
> null));
>             msg.setHeader("X-Mailer", "Mailer");
>             msg.setSentDate(new Date());
>             msg.setText(bodyText, "UTF-8");
>
>             Transport.send(msg);
>
>         }
>         catch (UnsupportedEncodingException e)
>         {
>             logger.error("Problem encoding mail: " + e);
>         }
>         catch (MessagingException e)
>         {
>             logger.error("Problem sending mail: " + e);
>         }
>
>     }
>
>     /**
>      * @param engine
>      */
>     private void initializeEngine(VelocityEngine engine)
>     {
>
>         engine.setApplicationAttribute("javax.servlet.ServletContext",
> this
>                 .getServlet().getServletContext());
>
>         Properties p = new Properties();
>         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
>         p.setProperty("webapp.resource.loader.class", WebappLoader.class
>                 .getName());
>
>         p.setProperty("resource.manager.logwhenfound", "true");
>         p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
>                 "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
>         p.setProperty("runtime.log.logsystem.log4j.category",
>                 "VelocityMailManager");
>         try
>         {
>             engine.init(p);
>         }
>         catch (Exception e)
>         {
>             logger.error("failed to init the velocity engine: " + e);
>         }
>
>     }
>
> }
>
>
> Cheers,
>
> David
>
> ********************************************************************
>
>
> David Sperling wrote:
>
> >Hi-
> >
> >I'm trying to send mail from a Struts Action with velocity 1.5 and
> >velocity-tools-1.2.
> >
> >The faq:
> >http://wiki.apache.org/jakarta-velocity/VelocityFAQ
> >Says:
> >
> >
> >>>You can get this instance for other uses of velocity by calling
> >>>
> >>>
> >getVelocityEngine
> >
> >
> >>>from a subclass
> >>
> >>
> >
> >Another recommendation from this list was to:
> >
> >
> >>>To  get the VelocityEngine from getVelocityEngine(),
> >>>
> >>>
> >
> >
> >So my question is how do you get the VelocityEngine from the
> >getVelocityEngine()?
> >
> >I've spent hours on google trying to find some code that calls the
> >getVelocityEngine()
> >but the only thing I could come up with was a VelocityManager class from
> >opensymphony.
> >And the VelocityManager.java class from opensymphony is quite complex
> >and has
> >many dependencies.
> >
> >
> >Cheers,
> >
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

Re: getting the getVelocityEngine() method from within a Struts Action

Posted by David Sperling <ve...@hakodateit.com>.
Thank you both for the examples.  I reworked my code to
use a subclass of VelocityViewServlet as suggested.  It's
messy code, but it works with MessageTool from within a
Struts Action.


Cheers,

David


Subclass of VelocityViewServlet with overidden createContext
***********************************************************************

import java.io.StringWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.tools.view.context.ChainedContext;
import org.apache.velocity.tools.view.servlet.VelocityViewServlet;

/**
 * @author david
 *
 * Created Feb 21, 2006, for the xxxx project
 */
public class MyVVS extends VelocityViewServlet
{
    static Logger logger = Logger.getLogger(MyVVS.class);

    private VelocityEngine engine;
    private Context context;
    private HttpServletRequest request;
    private HttpServletResponse response;

    public void init(ServletConfig config, HttpServletRequest request,
            HttpServletResponse response) throws ServletException
    {
        super.init(config);
        // get already configured engine
        engine = getVelocityEngine();
        config.getServletContext().setAttribute("velocityEngine", engine);
        this.response = response;
        this.response = response;
        this.context = createContext(request, response);
    }

    /**
     * @return Returns the engine.
     */
    public VelocityEngine getEngine()
    {
        return engine;
    }

    /**
     * @return Returns the context.
     */
    public Context getContext()
    {
        return this.context;
    }

    protected Context createContext(HttpServletRequest request,
            HttpServletResponse response)
    {
        ChainedContext ctx = new ChainedContext(engine, request, response,
                getServletContext());

        /* if we have a toolbox manager, get a toolbox from it */
        if (toolboxManager != null)
        {
            ctx.setToolbox(toolboxManager.getToolbox(ctx));
        }
        return ctx;
    }

    public String generateText(String templatePath)

    {

        StringWriter sw = new StringWriter();
        Template template;

        try
        {
            template = engine.getTemplate(templatePath);
            template.merge(context, sw);
        }
        catch (ResourceNotFoundException e)
        {
            logger.error("resource no Found: " + e);
        }
        catch (ParseErrorException e)
        {
            logger.error("Parse Error Exception: " + e);
        }
        catch (MethodInvocationException e)
        {
            logger.error("MethodInvocationException, applying template:
" + e);
        }
        catch (Exception e)
        {
            logger.error("General Exception, applying template: " + e);
        }

        return sw.toString();

    }

    /**
     * @return Returns the request.
     */
    public HttpServletRequest getRequest()
    {
        return request;
    }

    /**
     * @param request
     *            The request to set.
     */
    public void setRequest(HttpServletRequest request)
    {
        this.request = request;
    }

    /**
     * @return Returns the response.
     */
    public HttpServletResponse getRespones()
    {
        return response;
    }

    /**
     * @param response
     *            The response to set.
     */
    public void setResponse(HttpServletResponse response)
    {
        this.response = response;
    }
}
*************************************************************************

Struts Action to send email with Velocity Template and MessageTool
*************************************************************************

import mydomain.myproject.util.MyVVS;

import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.tools.struts.MessageTool;

public class TestSendingMailAction extends Action
{
    static Logger logger = Logger.getLogger(TestSendingMailAction.class);
    public static final String TEST_TEMPLATE =
"WEB-INF/templates/mail/testTemplate.vm";

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception
    {

        MessageTool messageTool = new MessageTool();

        MyVVS myvvs = new MyVVS();
        myvvs.init(this.getServlet().getServletConfig(), request,
response);       

        VelocityContext context =
(VelocityContext)myvvs.getContext();            
        messageTool.init(context);  

        context.put("title", "MessageTool test mail");
        context.put("text", messageTool);

        String bodyText = myvvs.generateText(TEST_TEMPLATE);

        this.sendMail(bodyText);

        return (mapping.findForward("success"));

    }


    private void sendMail(String bodyText)
    {

        String subject = "test mail";
        String fromName = "Jon Doe";
        String fromEmail = "jon@doe.com";
        String toRecipient = "Mr. Recipient";
        String toEmail = "velocity@test.com";
       
        Properties mailProps = new Properties();
        mailProps.put("mail.host", "localhost");
        mailProps.put("debug", "true");

        Session session = Session.getDefaultInstance(mailProps, null);
        MimeMessage msg = new MimeMessage(session);

        InternetAddress toAddress;
        try
        {
            toAddress = new InternetAddress(toEmail, MimeUtility.encodeText(
                    toRecipient, "UTF-8", null));
            if (fromName != null && fromEmail != null)
            {
                msg.setFrom(new InternetAddress(fromEmail, MimeUtility
                        .encodeText(fromName, "UTF-8", null)));
            }
            msg.setRecipient(Message.RecipientType.TO, toAddress);
            msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", null));
            msg.setHeader("X-Mailer", "Mailer");
            msg.setSentDate(new Date());
            msg.setText(bodyText, "UTF-8");

            Transport.send(msg);

        }
        catch (UnsupportedEncodingException e)
        {
            logger.error("Problem encoding mail: " + e);
        }
        catch (MessagingException e)
        {
            logger.error("Problem sending mail: " + e);
        }

    }

}
***********************************************************************


David Sperling wrote:

>I got some hints from the Spring project source code, MessageTool
>source code and this 3 year old message by Mr. Bubna
>"Re: Using Velocity tools in an application?" and finally got
>this working.
>
>I wanted to figure out how to access the MessageTool
>from within a Velocity context and send the contents via mail.
>Hopefully this will help out others having similar trouble. 
>
>So to test this out I added entries to my config files:
>
>********************************************************************
>This was in my main Strut-Config.xml file: 
><message-resources parameter="resources.application"/>
>********************************************************************
>
>********************************************************************
>This was in a test-config.xml file
><message-resources key="nonStandardResources"
>                  parameter="resources.nonStandardResources.application"/>
>********************************************************************
>
>********************************************************************
>next the template file: at mywebapp/mailTemplates/testTemplate.vm
>
>$title : $text.get("test.mail.name", ["jon","doe"])
>$title with no args: $text.get("test.mail.name")
>$title with args and bundle: $text.get("test.mail.name",
>                                  "nagisateiHotelResources", ["jon",
>"doe"] )
>********************************************************************
>
>********************************************************************
>Struts Action mapping in the Struts module:
><action path="/test/testSendingVelocityMail"
>              type = "mydomain.myapp.action.TestSendingMailAction"
>              scope="request" >
>    <forward name ="success" path="/test/sendMail.vm" />
></action>
>********************************************************************
>
>********************************************************************
>The web page: /test/sendMail.vm
>
><html>
>  <head>
>    <title>Velocity Mail Test Page</title>
>    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
>  </head>
>  <body>
>  <p>
>    <a href="$link.setAction("/test/testSendingVelocityMail.do")" >Send
>a test email</a>
>  </p>
>  </body>
></html>
>********************************************************************
>
>********************************************************************
>
>The Action Class
>
>/*
> * Created on Feb 17, 2006
> *
> * 
> */
>
>import java.io.StringWriter;
>import java.io.UnsupportedEncodingException;
>import java.util.Date;
>import java.util.Properties;
>
>import javax.mail.Message;
>import javax.mail.MessagingException;
>import javax.mail.Session;
>import javax.mail.Transport;
>import javax.mail.internet.InternetAddress;
>import javax.mail.internet.MimeMessage;
>import javax.mail.internet.MimeUtility;
>import javax.servlet.ServletContext;
>import javax.servlet.http.HttpServletRequest;
>import javax.servlet.http.HttpServletResponse;
>
>import org.apache.log4j.Logger;
>import org.apache.struts.action.Action;
>import org.apache.struts.action.ActionForm;
>import org.apache.struts.action.ActionForward;
>import org.apache.struts.action.ActionMapping;
>import org.apache.velocity.Template;
>import org.apache.velocity.VelocityContext;
>import org.apache.velocity.app.VelocityEngine;
>import org.apache.velocity.exception.MethodInvocationException;
>import org.apache.velocity.exception.ParseErrorException;
>import org.apache.velocity.exception.ResourceNotFoundException;
>import org.apache.velocity.runtime.RuntimeConstants;
>import org.apache.velocity.tools.struts.MessageTool;
>import org.apache.velocity.tools.view.context.ChainedContext;
>import org.apache.velocity.tools.view.servlet.WebappLoader;
>
>public class TestSendingMailAction extends Action
>{
>    static Logger logger = Logger.getLogger(TestSendingMailAction.class);
>    public static final String TEST_TEMPLATE =
>"mailTemplates/testTemplate.vm";
>
>    public ActionForward execute(ActionMapping mapping, ActionForm form,
>            HttpServletRequest request, HttpServletResponse response)
>            throws Exception
>    {
>
>        MessageTool messageTool = new MessageTool();
>        ServletContext servletContex =
>this.getServlet().getServletContext();
>        // Init the VelocityEngine Instance
>        VelocityEngine engine = new VelocityEngine();
>        this.initializeEngine(engine);
>
>        ChainedContext chainedContext = new ChainedContext(engine, request,
>                response, servletContex);
>        messageTool.init(chainedContext);
>
>        VelocityContext context = new VelocityContext();
>        context.put("title", "MessageTool test mail");
>        context.put("text", messageTool);
>
>        String bodyText = createBodyText(engine, context);
>
>        this.sendMail(bodyText);
>
>        return (mapping.findForward("success"));
>
>    }
>
>    /**
>     * @param engine
>     * @param context
>     */
>    private String createBodyText(VelocityEngine engine, VelocityContext
>context)
>    {
>        StringWriter sw = new StringWriter();
>        Template temp;
>        try
>        {
>            temp = engine.getTemplate(TEST_TEMPLATE);
>            temp.merge(context, sw);
>            String body = sw.toString();
>        }
>        catch (ResourceNotFoundException e)
>        {
>            logger.error("resource no Found: " + e);
>        }
>        catch (ParseErrorException e)
>        {
>            logger.error("Parse Error Exception: " + e);
>        }
>        catch (MethodInvocationException e)
>        {
>            logger.error("MethodInvocationException, applying template:
>" + e);
>        }
>        catch (Exception e)
>        {
>            logger.error("General Exception, applying template: " + e);
>        }
>
>        return sw.toString();
>
>    }
>
>    private void sendMail(String bodyText)
>    {
>
>        String subject = "test mail";
>        String fromName = "Jon Doe";
>        String fromEmail = "jon@doe.com";
>        String toRecipient = "Mr. Recipient";
>        String toEmail = "velocity@test.com";
>        Properties mailProps = new Properties();
>        mailProps.put("mail.host", "localhost");
>        mailProps.put("debug", "true");
>
>        Session session = Session.getDefaultInstance(mailProps, null);
>        MimeMessage msg = new MimeMessage(session);
>
>        InternetAddress toAddress;
>        try
>        {
>            toAddress = new InternetAddress(toEmail, MimeUtility.encodeText(
>                    toRecipient, "UTF-8", null));
>            if (fromName != null && fromEmail != null)
>            {
>                msg.setFrom(new InternetAddress(fromEmail, MimeUtility
>                        .encodeText(fromName, "UTF-8", null)));
>            }
>            msg.setRecipient(Message.RecipientType.TO, toAddress);
>            msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", null));
>            msg.setHeader("X-Mailer", "Mailer");
>            msg.setSentDate(new Date());
>            msg.setText(bodyText, "UTF-8");
>
>            Transport.send(msg);
>
>        }
>        catch (UnsupportedEncodingException e)
>        {
>            logger.error("Problem encoding mail: " + e);
>        }
>        catch (MessagingException e)
>        {
>            logger.error("Problem sending mail: " + e);
>        }
>
>    }
>
>    /**
>     * @param engine
>     */
>    private void initializeEngine(VelocityEngine engine)
>    {
>
>        engine.setApplicationAttribute("javax.servlet.ServletContext", this
>                .getServlet().getServletContext());
>
>        Properties p = new Properties();
>        p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
>        p.setProperty("webapp.resource.loader.class", WebappLoader.class
>                .getName());
>
>        p.setProperty("resource.manager.logwhenfound", "true");
>        p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
>                "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
>        p.setProperty("runtime.log.logsystem.log4j.category",
>                "VelocityMailManager");
>        try
>        {
>            engine.init(p);
>        }
>        catch (Exception e)
>        {
>            logger.error("failed to init the velocity engine: " + e);
>        }
>
>    }
>
>}
>
>
>Cheers,
>
>David
>
>********************************************************************
>
>
>David Sperling wrote:
>
>  
>
>>Hi-
>>
>>I'm trying to send mail from a Struts Action with velocity 1.5 and
>>velocity-tools-1.2.
>>
>>The faq:
>>http://wiki.apache.org/jakarta-velocity/VelocityFAQ
>>Says:
>> 
>>
>>    
>>
>>>>You can get this instance for other uses of velocity by calling
>>>>     
>>>>
>>>>        
>>>>
>>getVelocityEngine
>> 
>>
>>    
>>
>>>>from a subclass
>>>   
>>>
>>>      
>>>
>>Another recommendation from this list was to:
>> 
>>
>>    
>>
>>>>To  get the VelocityEngine from getVelocityEngine(),
>>>>     
>>>>
>>>>        
>>>>
>>So my question is how do you get the VelocityEngine from the
>>getVelocityEngine()?
>>
>>I've spent hours on google trying to find some code that calls the
>>getVelocityEngine()
>>but the only thing I could come up with was a VelocityManager class from
>>opensymphony.
>>And the VelocityManager.java class from opensymphony is quite complex
>>and has
>>many dependencies.
>>
>>
>>Cheers,
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>> 
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: getting the getVelocityEngine() method from within a Struts Action

Posted by Nathan Bubna <nb...@gmail.com>.
This all looks pretty good!  Thanks for sharing it with the list.

i do have few tips inline that might simplify things a wee bit...

On 2/19/06, David Sperling <ve...@hakodateit.com> wrote:
> I got some hints from the Spring project source code, MessageTool
> source code and this 3 year old message by Mr. Bubna
> "Re: Using Velocity tools in an application?" and finally got
> this working.
>
> I wanted to figure out how to access the MessageTool
> from within a Velocity context and send the contents via mail.
> Hopefully this will help out others having similar trouble.
>
> So to test this out I added entries to my config files:
>
> ********************************************************************
> This was in my main Strut-Config.xml file:
> <message-resources parameter="resources.application"/>
> ********************************************************************
>
> ********************************************************************
> This was in a test-config.xml file
> <message-resources key="nonStandardResources"
>                   parameter="resources.nonStandardResources.application"/>
> ********************************************************************
>
> ********************************************************************
> next the template file: at mywebapp/mailTemplates/testTemplate.vm
>
> $title : $text.get("test.mail.name", ["jon","doe"])
> $title with no args: $text.get("test.mail.name")
> $title with args and bundle: $text.get("test.mail.name",
>                                   "nagisateiHotelResources", ["jon",
> "doe"] )
> ********************************************************************
>
> ********************************************************************
> Struts Action mapping in the Struts module:
> <action path="/test/testSendingVelocityMail"
>               type = "mydomain.myapp.action.TestSendingMailAction"
>               scope="request" >
>     <forward name ="success" path="/test/sendMail.vm" />
> </action>
> ********************************************************************
>
> ********************************************************************
> The web page: /test/sendMail.vm
>
> <html>
>   <head>
>     <title>Velocity Mail Test Page</title>
>     <meta http-equiv=Content-Type content="text/html; charset=utf-8">
>   </head>
>   <body>
>   <p>
>     <a href="$link.setAction("/test/testSendingVelocityMail.do")" >Send
> a test email</a>
>   </p>
>   </body>
> </html>
> ********************************************************************
>
> ********************************************************************
>
> The Action Class
>
> /*
>  * Created on Feb 17, 2006
>  *
>  *
>  */
>
> import java.io.StringWriter;
> import java.io.UnsupportedEncodingException;
> import java.util.Date;
> import java.util.Properties;
>
> import javax.mail.Message;
> import javax.mail.MessagingException;
> import javax.mail.Session;
> import javax.mail.Transport;
> import javax.mail.internet.InternetAddress;
> import javax.mail.internet.MimeMessage;
> import javax.mail.internet.MimeUtility;
> import javax.servlet.ServletContext;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> import org.apache.log4j.Logger;
> import org.apache.struts.action.Action;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionForward;
> import org.apache.struts.action.ActionMapping;
> import org.apache.velocity.Template;
> import org.apache.velocity.VelocityContext;
> import org.apache.velocity.app.VelocityEngine;
> import org.apache.velocity.exception.MethodInvocationException;
> import org.apache.velocity.exception.ParseErrorException;
> import org.apache.velocity.exception.ResourceNotFoundException;
> import org.apache.velocity.runtime.RuntimeConstants;
> import org.apache.velocity.tools.struts.MessageTool;
> import org.apache.velocity.tools.view.context.ChainedContext;
> import org.apache.velocity.tools.view.servlet.WebappLoader;
>
> public class TestSendingMailAction extends Action
> {
>     static Logger logger = Logger.getLogger(TestSendingMailAction.class);
>     public static final String TEST_TEMPLATE =
> "mailTemplates/testTemplate.vm";
>
>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>             HttpServletRequest request, HttpServletResponse response)
>             throws Exception
>     {
>
>         MessageTool messageTool = new MessageTool();
>         ServletContext servletContex =
> this.getServlet().getServletContext();
>         // Init the VelocityEngine Instance
>         VelocityEngine engine = new VelocityEngine();
>         this.initializeEngine(engine);

if you are also using the VelocityViewServlet and don't mind using the
same VelocityEngine, then you could do what i suggested in response to
your previous email in this thread.

>         ChainedContext chainedContext = new ChainedContext(engine, request,
>                 response, servletContex);
>         messageTool.init(chainedContext);

perfect. :)

>         VelocityContext context = new VelocityContext();
>         context.put("title", "MessageTool test mail");
>         context.put("text", messageTool);

actually, the ChainedContext is already a VelocityContext, so you can
feel free to directly put your title and text right into it and not
create an additional VelocityContext.

>         String bodyText = createBodyText(engine, context);
>
>         this.sendMail(bodyText);
>
>         return (mapping.findForward("success"));
>
>     }
>
>     /**
>      * @param engine
>      * @param context
>      */
>     private String createBodyText(VelocityEngine engine, VelocityContext
> context)
>     {
>         StringWriter sw = new StringWriter();
>         Template temp;
>         try
>         {
>             temp = engine.getTemplate(TEST_TEMPLATE);
>             temp.merge(context, sw);
>             String body = sw.toString();
>         }
>         catch (ResourceNotFoundException e)
>         {
>             logger.error("resource no Found: " + e);
>         }
>         catch (ParseErrorException e)
>         {
>             logger.error("Parse Error Exception: " + e);
>         }
>         catch (MethodInvocationException e)
>         {
>             logger.error("MethodInvocationException, applying template:
> " + e);
>         }
>         catch (Exception e)
>         {
>             logger.error("General Exception, applying template: " + e);
>         }
>
>         return sw.toString();
>
>     }
>
>     private void sendMail(String bodyText)
>     {
>
>         String subject = "test mail";
>         String fromName = "Jon Doe";
>         String fromEmail = "jon@doe.com";
>         String toRecipient = "Mr. Recipient";
>         String toEmail = "velocity@test.com";
>         Properties mailProps = new Properties();
>         mailProps.put("mail.host", "localhost");
>         mailProps.put("debug", "true");
>
>         Session session = Session.getDefaultInstance(mailProps, null);
>         MimeMessage msg = new MimeMessage(session);
>
>         InternetAddress toAddress;
>         try
>         {
>             toAddress = new InternetAddress(toEmail, MimeUtility.encodeText(
>                     toRecipient, "UTF-8", null));
>             if (fromName != null && fromEmail != null)
>             {
>                 msg.setFrom(new InternetAddress(fromEmail, MimeUtility
>                         .encodeText(fromName, "UTF-8", null)));
>             }
>             msg.setRecipient(Message.RecipientType.TO, toAddress);
>             msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", null));
>             msg.setHeader("X-Mailer", "Mailer");
>             msg.setSentDate(new Date());
>             msg.setText(bodyText, "UTF-8");
>
>             Transport.send(msg);
>
>         }
>         catch (UnsupportedEncodingException e)
>         {
>             logger.error("Problem encoding mail: " + e);
>         }
>         catch (MessagingException e)
>         {
>             logger.error("Problem sending mail: " + e);
>         }
>
>     }
>
>     /**
>      * @param engine
>      */
>     private void initializeEngine(VelocityEngine engine)
>     {
>
>         engine.setApplicationAttribute("javax.servlet.ServletContext", this
>                 .getServlet().getServletContext());
>
>         Properties p = new Properties();
>         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
>         p.setProperty("webapp.resource.loader.class", WebappLoader.class
>                 .getName());
>
>         p.setProperty("resource.manager.logwhenfound", "true");
>         p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
>                 "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
>         p.setProperty("runtime.log.logsystem.log4j.category",
>                 "VelocityMailManager");
>         try
>         {
>             engine.init(p);
>         }
>         catch (Exception e)
>         {
>             logger.error("failed to init the velocity engine: " + e);
>         }
>
>     }
>
> }
>
>
> Cheers,
>
> David
>
> ********************************************************************
>
>
> David Sperling wrote:
>
> >Hi-
> >
> >I'm trying to send mail from a Struts Action with velocity 1.5 and
> >velocity-tools-1.2.
> >
> >The faq:
> >http://wiki.apache.org/jakarta-velocity/VelocityFAQ
> >Says:
> >
> >
> >>>You can get this instance for other uses of velocity by calling
> >>>
> >>>
> >getVelocityEngine
> >
> >
> >>>from a subclass
> >>
> >>
> >
> >Another recommendation from this list was to:
> >
> >
> >>>To  get the VelocityEngine from getVelocityEngine(),
> >>>
> >>>
> >
> >
> >So my question is how do you get the VelocityEngine from the
> >getVelocityEngine()?
> >
> >I've spent hours on google trying to find some code that calls the
> >getVelocityEngine()
> >but the only thing I could come up with was a VelocityManager class from
> >opensymphony.
> >And the VelocityManager.java class from opensymphony is quite complex
> >and has
> >many dependencies.
> >
> >
> >Cheers,
> >
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: getting the getVelocityEngine() method from within a Struts Action

Posted by David Sperling <ve...@hakodateit.com>.
I got some hints from the Spring project source code, MessageTool
source code and this 3 year old message by Mr. Bubna
"Re: Using Velocity tools in an application?" and finally got
this working.

I wanted to figure out how to access the MessageTool
from within a Velocity context and send the contents via mail.
Hopefully this will help out others having similar trouble. 

So to test this out I added entries to my config files:

********************************************************************
This was in my main Strut-Config.xml file: 
<message-resources parameter="resources.application"/>
********************************************************************

********************************************************************
This was in a test-config.xml file
<message-resources key="nonStandardResources"
                  parameter="resources.nonStandardResources.application"/>
********************************************************************

********************************************************************
next the template file: at mywebapp/mailTemplates/testTemplate.vm

$title : $text.get("test.mail.name", ["jon","doe"])
$title with no args: $text.get("test.mail.name")
$title with args and bundle: $text.get("test.mail.name",
                                  "nagisateiHotelResources", ["jon",
"doe"] )
********************************************************************

********************************************************************
Struts Action mapping in the Struts module:
<action path="/test/testSendingVelocityMail"
              type = "mydomain.myapp.action.TestSendingMailAction"
              scope="request" >
    <forward name ="success" path="/test/sendMail.vm" />
</action>
********************************************************************

********************************************************************
The web page: /test/sendMail.vm

<html>
  <head>
    <title>Velocity Mail Test Page</title>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
  </head>
  <body>
  <p>
    <a href="$link.setAction("/test/testSendingVelocityMail.do")" >Send
a test email</a>
  </p>
  </body>
</html>
********************************************************************

********************************************************************

The Action Class

/*
 * Created on Feb 17, 2006
 *
 * 
 */

import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.tools.struts.MessageTool;
import org.apache.velocity.tools.view.context.ChainedContext;
import org.apache.velocity.tools.view.servlet.WebappLoader;

public class TestSendingMailAction extends Action
{
    static Logger logger = Logger.getLogger(TestSendingMailAction.class);
    public static final String TEST_TEMPLATE =
"mailTemplates/testTemplate.vm";

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception
    {

        MessageTool messageTool = new MessageTool();
        ServletContext servletContex =
this.getServlet().getServletContext();
        // Init the VelocityEngine Instance
        VelocityEngine engine = new VelocityEngine();
        this.initializeEngine(engine);

        ChainedContext chainedContext = new ChainedContext(engine, request,
                response, servletContex);
        messageTool.init(chainedContext);

        VelocityContext context = new VelocityContext();
        context.put("title", "MessageTool test mail");
        context.put("text", messageTool);

        String bodyText = createBodyText(engine, context);

        this.sendMail(bodyText);

        return (mapping.findForward("success"));

    }

    /**
     * @param engine
     * @param context
     */
    private String createBodyText(VelocityEngine engine, VelocityContext
context)
    {
        StringWriter sw = new StringWriter();
        Template temp;
        try
        {
            temp = engine.getTemplate(TEST_TEMPLATE);
            temp.merge(context, sw);
            String body = sw.toString();
        }
        catch (ResourceNotFoundException e)
        {
            logger.error("resource no Found: " + e);
        }
        catch (ParseErrorException e)
        {
            logger.error("Parse Error Exception: " + e);
        }
        catch (MethodInvocationException e)
        {
            logger.error("MethodInvocationException, applying template:
" + e);
        }
        catch (Exception e)
        {
            logger.error("General Exception, applying template: " + e);
        }

        return sw.toString();

    }

    private void sendMail(String bodyText)
    {

        String subject = "test mail";
        String fromName = "Jon Doe";
        String fromEmail = "jon@doe.com";
        String toRecipient = "Mr. Recipient";
        String toEmail = "velocity@test.com";
        Properties mailProps = new Properties();
        mailProps.put("mail.host", "localhost");
        mailProps.put("debug", "true");

        Session session = Session.getDefaultInstance(mailProps, null);
        MimeMessage msg = new MimeMessage(session);

        InternetAddress toAddress;
        try
        {
            toAddress = new InternetAddress(toEmail, MimeUtility.encodeText(
                    toRecipient, "UTF-8", null));
            if (fromName != null && fromEmail != null)
            {
                msg.setFrom(new InternetAddress(fromEmail, MimeUtility
                        .encodeText(fromName, "UTF-8", null)));
            }
            msg.setRecipient(Message.RecipientType.TO, toAddress);
            msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", null));
            msg.setHeader("X-Mailer", "Mailer");
            msg.setSentDate(new Date());
            msg.setText(bodyText, "UTF-8");

            Transport.send(msg);

        }
        catch (UnsupportedEncodingException e)
        {
            logger.error("Problem encoding mail: " + e);
        }
        catch (MessagingException e)
        {
            logger.error("Problem sending mail: " + e);
        }

    }

    /**
     * @param engine
     */
    private void initializeEngine(VelocityEngine engine)
    {

        engine.setApplicationAttribute("javax.servlet.ServletContext", this
                .getServlet().getServletContext());

        Properties p = new Properties();
        p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
        p.setProperty("webapp.resource.loader.class", WebappLoader.class
                .getName());

        p.setProperty("resource.manager.logwhenfound", "true");
        p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
        p.setProperty("runtime.log.logsystem.log4j.category",
                "VelocityMailManager");
        try
        {
            engine.init(p);
        }
        catch (Exception e)
        {
            logger.error("failed to init the velocity engine: " + e);
        }

    }

}


Cheers,

David

********************************************************************


David Sperling wrote:

>Hi-
>
>I'm trying to send mail from a Struts Action with velocity 1.5 and
>velocity-tools-1.2.
>
>The faq:
>http://wiki.apache.org/jakarta-velocity/VelocityFAQ
>Says:
>  
>
>>>You can get this instance for other uses of velocity by calling
>>>      
>>>
>getVelocityEngine
>  
>
>>>from a subclass
>>    
>>
>
>Another recommendation from this list was to:
>  
>
>>>To  get the VelocityEngine from getVelocityEngine(),
>>>      
>>>
>
>
>So my question is how do you get the VelocityEngine from the
>getVelocityEngine()?
>
>I've spent hours on google trying to find some code that calls the
>getVelocityEngine()
>but the only thing I could come up with was a VelocityManager class from
>opensymphony.
>And the VelocityManager.java class from opensymphony is quite complex
>and has
>many dependencies.
>
>
>Cheers,
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: getting the getVelocityEngine() method from within a Struts Action

Posted by Nathan Bubna <nb...@gmail.com>.
On 2/19/06, David Sperling <ve...@hakodateit.com> wrote:
> Hi-
>
> I'm trying to send mail from a Struts Action with velocity 1.5 and
> velocity-tools-1.2.
>
> The faq:
> http://wiki.apache.org/jakarta-velocity/VelocityFAQ
> Says:
> >>You can get this instance for other uses of velocity by calling
> getVelocityEngine
> >>from a subclass
>
> Another recommendation from this list was to:
> >>To  get the VelocityEngine from getVelocityEngine(),
>
>
> So my question is how do you get the VelocityEngine from the
> getVelocityEngine()?
>
> I've spent hours on google trying to find some code that calls the
> getVelocityEngine()
> but the only thing I could come up with was a VelocityManager class from
> opensymphony.
> And the VelocityManager.java class from opensymphony is quite complex
> and has
> many dependencies.

i'm not surprised you didn't find much on Google.  most
VelocityViewServlet subclasses are  probably in proprietart
subclasses.  still, it would be pretty easy to make the VelocityEngine
accessible to your Struts Actions.  since your actions have access to
the servlet context, you can do a simple subclass of the
VelocityViewServlet that puts the already configured VelocityEngine
into the ServletContext attributes.  something like:

public MyVVS extends VelocityViewServlet {

    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        VelocityEngine engine = getVelocityEngine();
        config.getServletContext().setAttribute("velocityEngine", engine);
    }

}

then you just pull the engine out of the servlet context in your
Struts Action. :)

> Cheers,
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: PANIC : Velocity cannot find any of the specified or default logging ...

Posted by Will Glass-Husain <wg...@forio.com>.
Hi Pascual,

I've never seen that error message in connection with Velocity.  Did you say
you were writing a plugin?  It's probably an Eclipse classpath problem.  Or 
are you running under some type of restrictive security policy?

You might consider using the VelocityEngine instead of Velocity.
Velocity.init() sets up a singleton - all other uses of Velocity in the same
classloader will share all the properties.  If you create a VelocityEngine
you can have different instances with different properties.

WILL


----- Original Message ----- 
From: "Pascual Queralt" <pq...@yahoo.es>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Tuesday, February 21, 2006 11:01 AM
Subject: Re: PANIC : Velocity cannot find any of the specified or default
logging ...


> Hi Will,
>
> I mean the instruction
>   Velocity.init();
>
> the velocitygen is only a constructor that binds values to the velocity
> properties.
>
>
>
> ----- Original Message ----- 
> From: "Will Glass-Husain" <wg...@forio.com>
> To: "Velocity Users List" <ve...@jakarta.apache.org>
> Sent: Tuesday, February 21, 2006 7:51 PM
> Subject: Re: PANIC : Velocity cannot find any of the specified or default
> logging ...
>
>
>> What's a VelocityGen?  That's not in the Velocity distribution.  Do the
>> error messages list what class was causing the problem?
>>
>> ----- Original Message ----- 
>> From: "Pascual Queralt" <pq...@yahoo.es>
>> To: "Velocity Users List" <ve...@jakarta.apache.org>
>> Sent: Tuesday, February 21, 2006 10:47 AM
>> Subject: PANIC : Velocity cannot find any of the specified or default
>> logging ...
>>
>>
>> Hi,
>> I need a little of help.
>> My plugin in Eclipse that use Velocity was working fine, but suddenly
>> I've got this velocity message.
>>
>> systems in the classpath, or the classpath doesn't contain the necessary
>> classes to support them. Please consult the documentation regarding
>> logging. Exception : java.lang.NoClassDefFound
>>
>> It happens just when I execute this instruction.
>>
>>   VGenerator = new VelocityGen();
>>
>> Any ideas will be helpfull.
>>
>> Many thanks.
>>
>>    Pascual
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>
>
>
> ______________________________________________ LLama Gratis a cualquier PC
> del Mundo. Llamadas a fijos y mviles desde 1 cntimo por minuto.
> http://es.voice.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: PANIC : Velocity cannot find any of the specified or default logging ...

Posted by Pascual Queralt <pq...@yahoo.es>.
Hi Will,

I mean the instruction
   Velocity.init();

the velocitygen is only a constructor that binds values to the velocity 
properties.



----- Original Message ----- 
From: "Will Glass-Husain" <wg...@forio.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Tuesday, February 21, 2006 7:51 PM
Subject: Re: PANIC : Velocity cannot find any of the specified or default 
logging ...


> What's a VelocityGen?  That's not in the Velocity distribution.  Do the 
> error messages list what class was causing the problem?
>
> ----- Original Message ----- 
> From: "Pascual Queralt" <pq...@yahoo.es>
> To: "Velocity Users List" <ve...@jakarta.apache.org>
> Sent: Tuesday, February 21, 2006 10:47 AM
> Subject: PANIC : Velocity cannot find any of the specified or default 
> logging ...
>
>
> Hi,
> I need a little of help.
> My plugin in Eclipse that use Velocity was working fine, but suddenly I've 
> got this velocity message.
>
> systems in the classpath, or the classpath doesn't contain the necessary 
> classes to support them. Please consult the documentation regarding 
> logging. Exception : java.lang.NoClassDefFound
>
> It happens just when I execute this instruction.
>
>   VGenerator = new VelocityGen();
>
> Any ideas will be helpfull.
>
> Many thanks.
>
>    Pascual
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


		
______________________________________________ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y m�viles desde 1 c�ntimo por minuto. 
http://es.voice.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: PANIC : Velocity cannot find any of the specified or default logging ...

Posted by Will Glass-Husain <wg...@forio.com>.
What's a VelocityGen?  That's not in the Velocity distribution.  Do the 
error messages list what class was causing the problem?

----- Original Message ----- 
From: "Pascual Queralt" <pq...@yahoo.es>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Tuesday, February 21, 2006 10:47 AM
Subject: PANIC : Velocity cannot find any of the specified or default 
logging ...


Hi,
I need a little of help.
My plugin in Eclipse that use Velocity was working fine, but suddenly I've 
got this velocity message.

systems in the classpath, or the classpath doesn't contain the necessary 
classes to support them. Please consult the documentation regarding logging. 
Exception : java.lang.NoClassDefFound

It happens just when I execute this instruction.

   VGenerator = new VelocityGen();

Any ideas will be helpfull.

Many thanks.

    Pascual


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: PANIC : Velocity cannot find any of the specified or default logging ...

Posted by Will Glass-Husain <wg...@forio.com>.
Of course!

Forgot about the basics...

----- Original Message ----- 
From: "Nathan Bubna" <nb...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Tuesday, February 21, 2006 11:20 AM
Subject: Re: PANIC : Velocity cannot find any of the specified or default 
logging ...


Sounds like you are using the vanilla velocity.jar without the
necessary dependencies.  You either need to use the velocity-dep.jar
included in your distribution, or else make sure that either logkit or
log4j are in the classpath.

On 2/21/06, Pascual Queralt <pq...@yahoo.es> wrote:
> Hi,
> I need a little of help.
> My plugin in Eclipse that use Velocity was working fine, but suddenly I've 
> got this velocity message.
>
> systems in the classpath, or the classpath doesn't contain the necessary 
> classes to support them. Please consult the documentation regarding 
> logging. Exception : java.lang.NoClassDefFound
>
> It happens just when I execute this instruction.
>
>    VGenerator = new VelocityGen();
>
> Any ideas will be helpfull.
>
> Many thanks.
>
>     Pascual
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: PANIC : Velocity cannot find any of the specified or default logging ...

Posted by Pascual Queralt <pq...@yahoo.es>.
Many thanks.

Although I can't understand why before it was working , It was that, I needed the library velocity-dep.jar. 






----- Original Message ----- 
From: "Nathan Bubna" <nb...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Tuesday, February 21, 2006 8:20 PM
Subject: Re: PANIC : Velocity cannot find any of the specified or default logging ...


Sounds like you are using the vanilla velocity.jar without the
necessary dependencies.  You either need to use the velocity-dep.jar
included in your distribution, or else make sure that either logkit or
log4j are in the classpath.

On 2/21/06, Pascual Queralt <pq...@yahoo.es> wrote:
> Hi,
> I need a little of help.
> My plugin in Eclipse that use Velocity was working fine, but suddenly I've got this velocity message.
>
> systems in the classpath, or the classpath doesn't contain the necessary classes to support them. Please consult the documentation regarding logging. Exception : java.lang.NoClassDefFound
>
> It happens just when I execute this instruction.
>
>    VGenerator = new VelocityGen();
>
> Any ideas will be helpfull.
>
> Many thanks.
>
>     Pascual
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org

Re: PANIC : Velocity cannot find any of the specified or default logging ...

Posted by Nathan Bubna <nb...@gmail.com>.
Sounds like you are using the vanilla velocity.jar without the
necessary dependencies.  You either need to use the velocity-dep.jar
included in your distribution, or else make sure that either logkit or
log4j are in the classpath.

On 2/21/06, Pascual Queralt <pq...@yahoo.es> wrote:
> Hi,
> I need a little of help.
> My plugin in Eclipse that use Velocity was working fine, but suddenly I've got this velocity message.
>
> systems in the classpath, or the classpath doesn't contain the necessary classes to support them. Please consult the documentation regarding logging. Exception : java.lang.NoClassDefFound
>
> It happens just when I execute this instruction.
>
>    VGenerator = new VelocityGen();
>
> Any ideas will be helpfull.
>
> Many thanks.
>
>     Pascual
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


PANIC : Velocity cannot find any of the specified or default logging ...

Posted by Pascual Queralt <pq...@yahoo.es>.
Hi, 
I need a little of help. 
My plugin in Eclipse that use Velocity was working fine, but suddenly I've got this velocity message.

systems in the classpath, or the classpath doesn't contain the necessary classes to support them. Please consult the documentation regarding logging. Exception : java.lang.NoClassDefFound

It happens just when I execute this instruction.

   VGenerator = new VelocityGen();

Any ideas will be helpfull.

Many thanks.

    Pascual