You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lidija Dolinar <li...@gmail.com> on 2014/05/26 15:03:53 UTC

FreeMarker configuration problems

Hi,

I'm trying to use freemarker templates according to the following
instructions:
http://chenillekit.codehaus.org/chenillekit-template/howto_freemarkerservice.html

My code in AppModule is the same as specified above.

In my Java code I'm trying to send mail with the use of a template file:

OutputStream emailBodyStream = new ByteArrayOutputStream();
templateService.mergeDataWithResource(new
URIResource("./templates/test.ftl"), emailBodyStream, parameterMap);
mailService.sendHtmlMail(mmh, emailBodyStream.toString());


The template file is not found - I get exceptions no matter how I set the
URIResource path to the template file:

- If the path is "./templates/test.ftl", there's a
"java.lang.IllegalArgumentException: URI is not absolute" exception in
URIResource.exists() method when calling uri.toURL().
Why does this error occur? (the instructions specify relative path to the
file as a parameter to the URIResource).

- If the path is an absolute filepath, i.e.
"file:/home/lidija/workspace/.../templates/test.ftl", there's a
"java.lang.RuntimeException: Template file:/home/lidija/workspace/... not
found". The file exists though and has read / write / execute permissions
on it.
(I'm just trying to understand, of course the path shouldn't be set like
this.)

- If the path is absolute filepath to the file, without the "file:" String,
the eror is again "java.lang.IllegalArgumentException: URI is not absolute"


My questions are:
- should I specifically set the path to the "templates" folder at
configuration time?
- how to specify the template filename parameter to URIResource?

Any suggestions welcome.

Kind regards,
Lidija

Re: FreeMarker configuration problems

Posted by Lidija Dolinar <li...@gmail.com>.
Hi Thilo,

thank you for your response.

I solved it like you said using ClasspathResource and it works :).

Kind regards,
Lidija




On Mon, May 26, 2014 at 3:30 PM, Thilo Tanner <th...@reprisk.com>wrote:

> Hi Lidija,
>
> I don't use Chenillekit for Freemarker, but I integrated Freemarker not
> too long ago, also to render emails, using the AssetSource service:
>
> First, I created a AssetTemplateLoader implements TemplateLoader which
> uses the AssetSource service behind the scenes to load the actual template
> from a regular Resource object.
>
> Then I created a Freemarker service with a render method. Something like
> this:
>
> public String render(Resource templateResource, Map dataModel)
>
> to render the text (or email) to a String. Now, you can inject your
> template as a Resource object into the service / page which is using the
> Freemarker service. Using the AssetSource also allow you to create
> localized template files, if necessary.
>
> Best,
> Thilo
>
> ________________________________________
> From: Lidija Dolinar <li...@gmail.com>
> Sent: Monday, May 26, 2014 15:03
> To: Tapestry users
> Subject: FreeMarker configuration problems
>
> Hi,
>
> I'm trying to use freemarker templates according to the following
> instructions:
>
> http://chenillekit.codehaus.org/chenillekit-template/howto_freemarkerservice.html
>
> My code in AppModule is the same as specified above.
>
> In my Java code I'm trying to send mail with the use of a template file:
>
> OutputStream emailBodyStream = new ByteArrayOutputStream();
> templateService.mergeDataWithResource(new
> URIResource("./templates/test.ftl"), emailBodyStream, parameterMap);
> mailService.sendHtmlMail(mmh, emailBodyStream.toString());
>
>
> The template file is not found - I get exceptions no matter how I set the
> URIResource path to the template file:
>
> - If the path is "./templates/test.ftl", there's a
> "java.lang.IllegalArgumentException: URI is not absolute" exception in
> URIResource.exists() method when calling uri.toURL().
> Why does this error occur? (the instructions specify relative path to the
> file as a parameter to the URIResource).
>
> - If the path is an absolute filepath, i.e.
> "file:/home/lidija/workspace/.../templates/test.ftl", there's a
> "java.lang.RuntimeException: Template file:/home/lidija/workspace/... not
> found". The file exists though and has read / write / execute permissions
> on it.
> (I'm just trying to understand, of course the path shouldn't be set like
> this.)
>
> - If the path is absolute filepath to the file, without the "file:" String,
> the eror is again "java.lang.IllegalArgumentException: URI is not absolute"
>
>
> My questions are:
> - should I specifically set the path to the "templates" folder at
> configuration time?
> - how to specify the template filename parameter to URIResource?
>
> Any suggestions welcome.
>
> Kind regards,
> Lidija
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

RE: FreeMarker configuration problems

Posted by Thilo Tanner <th...@reprisk.com>.
Hi Lidija,

I don't use Chenillekit for Freemarker, but I integrated Freemarker not too long ago, also to render emails, using the AssetSource service:

First, I created a AssetTemplateLoader implements TemplateLoader which uses the AssetSource service behind the scenes to load the actual template from a regular Resource object.

Then I created a Freemarker service with a render method. Something like this: 

public String render(Resource templateResource, Map dataModel)

to render the text (or email) to a String. Now, you can inject your template as a Resource object into the service / page which is using the Freemarker service. Using the AssetSource also allow you to create localized template files, if necessary.

Best,
Thilo

________________________________________
From: Lidija Dolinar <li...@gmail.com>
Sent: Monday, May 26, 2014 15:03
To: Tapestry users
Subject: FreeMarker configuration problems

Hi,

I'm trying to use freemarker templates according to the following
instructions:
http://chenillekit.codehaus.org/chenillekit-template/howto_freemarkerservice.html

My code in AppModule is the same as specified above.

In my Java code I'm trying to send mail with the use of a template file:

OutputStream emailBodyStream = new ByteArrayOutputStream();
templateService.mergeDataWithResource(new
URIResource("./templates/test.ftl"), emailBodyStream, parameterMap);
mailService.sendHtmlMail(mmh, emailBodyStream.toString());


The template file is not found - I get exceptions no matter how I set the
URIResource path to the template file:

- If the path is "./templates/test.ftl", there's a
"java.lang.IllegalArgumentException: URI is not absolute" exception in
URIResource.exists() method when calling uri.toURL().
Why does this error occur? (the instructions specify relative path to the
file as a parameter to the URIResource).

- If the path is an absolute filepath, i.e.
"file:/home/lidija/workspace/.../templates/test.ftl", there's a
"java.lang.RuntimeException: Template file:/home/lidija/workspace/... not
found". The file exists though and has read / write / execute permissions
on it.
(I'm just trying to understand, of course the path shouldn't be set like
this.)

- If the path is absolute filepath to the file, without the "file:" String,
the eror is again "java.lang.IllegalArgumentException: URI is not absolute"


My questions are:
- should I specifically set the path to the "templates" folder at
configuration time?
- how to specify the template filename parameter to URIResource?

Any suggestions welcome.

Kind regards,
Lidija
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org