Search in sources :

Example 1 with InternalContextAdapterImpl

use of org.apache.velocity.context.InternalContextAdapterImpl in project gerrit by GerritCodeReview.

the class OutgoingEmail method velocify.

protected String velocify(String template) throws EmailException {
    try {
        RuntimeInstance runtime = args.velocityRuntime;
        String templateName = "OutgoingEmail";
        SimpleNode tree = runtime.parse(new StringReader(template), templateName);
        InternalContextAdapterImpl ica = new InternalContextAdapterImpl(velocityContext);
        ica.pushCurrentTemplateName(templateName);
        try {
            tree.init(ica, runtime);
            StringWriter w = new StringWriter();
            tree.render(ica, w);
            return w.toString();
        } finally {
            ica.popCurrentTemplateName();
        }
    } catch (Exception e) {
        throw new EmailException("Cannot format velocity template: " + template, e);
    }
}
Also used : InternalContextAdapterImpl(org.apache.velocity.context.InternalContextAdapterImpl) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) EmailException(com.google.gerrit.common.errors.EmailException) RuntimeInstance(org.apache.velocity.runtime.RuntimeInstance) OrmException(com.google.gwtorm.server.OrmException) ValidationException(com.google.gerrit.server.validators.ValidationException) MalformedURLException(java.net.MalformedURLException) EmailException(com.google.gerrit.common.errors.EmailException) SimpleNode(org.apache.velocity.runtime.parser.node.SimpleNode)

Aggregations

EmailException (com.google.gerrit.common.errors.EmailException)1 ValidationException (com.google.gerrit.server.validators.ValidationException)1 OrmException (com.google.gwtorm.server.OrmException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 MalformedURLException (java.net.MalformedURLException)1 InternalContextAdapterImpl (org.apache.velocity.context.InternalContextAdapterImpl)1 RuntimeInstance (org.apache.velocity.runtime.RuntimeInstance)1 SimpleNode (org.apache.velocity.runtime.parser.node.SimpleNode)1