Hi there,
In Servlet mode, you can directly use the WAR client connector like this:
getContext().getClientDispatcher().get("war:///WEB-INF/yourFile.ftl");
Then, just wrap the response entity with a FreeMarker TemplateRepresentation
as explained by Thierry.
Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ <http://www.restlet.org/>
http://www.restlet.org
Noelios Technologies ~ Co-founder ~ <http://www.noelios.com/>
http://www.noelios.com
_____
De : Gan123 [mailto:[EMAIL PROTECTED]
Envoye : mardi 18 novembre 2008 05:31
A : [email protected]
Objet : Re: refering a web app file with FileRepresentation
Hi,
what that result.tmpl file contains? is there a way to load ftl files
using CLAP, from web application context, like i am planning to store files
either in WEB-INF or classes folder.
Thanks for your help.
On Mon, Nov 17, 2008 at 8:53 PM, Thierry Boileau (via Nabble)
<[EMAIL PROTECTED]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=1512866&i=0> >
wrote:
Hello,
>File templateDir=new File("clap:///template");
I don't think a java.io.File can be instantiated with a CLAP URI (CLAP is a
pure Restlet concept). I just suggested you to create a FileRepresentation
from either a CLAP or a WAR URI in order to return a Representation of a
file.
If you want to build your HTML representations with Freemarker, you can
either:
- create a TemplateRepresentation with it's template name, which
requires you to set up the Freemarker configuration as you do but with a
standard directory => File templateDir = new File("c:/temp/template");
- or create a TemplateRepresentation from a Representation of the
template. For example:
result = new TemplateRepresentation(new
FileRepresentation("war:///items/result.tmpl",MediaType.TEXT_HTML),
configme(), getItem(), MediaType.TEXT_HTML );
I hope this will help you.
Best regards,
Thierry Boileau
--
Restlet ~ Core developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
> Hi Thierry,
>
> Thanks for your reply, i tried to get the files from classpath
> using CLAP.i have "template" directory in the classpath. but it is still
not
> able to read the files in that folder.actually i am trying to use
freemarker
> template files stored in my classpath to render output.
> code is ...
>
> public Representation getRepresentation(Variant variant) {
> Representation result = null;
> if (variant.getMediaType().equals(MediaType.TEXT_HTML)) {
> try {
> // page.buildFromBackend(getRequest());
> result = new TemplateRepresentation(getTemplateName(),
> configme(), getItem(),
> MediaType.TEXT_HTML);
> }
> ---
> }
> return result;
> }
>
> Configuration configme() throws IOException{
> Configuration config=null;
> config=new Configuration();
> File templateDir=new File("clap:///template");
> TemplateLoader fileTemplateLoader=new FileTemplateLoader(templateDir);
> config.setTemplateLoader(fileTemplateLoader);
> return config;
> }
>
> String getTemplateName() { return "oneitem.ftl"; }
>
> Stack Trace :
> java.io.FileNotFoundException: clap:\template does not exist.
> at freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:125)
> at java.security.AccessController.doPrivileged(Native Method)
> at freemarker.cache.FileTemplateLoader.<init>(FileTemplateLoader.java:122)
> ---
> ---
>
> please help me .. Thanks
>
>
> Thierry Boileau wrote:
>
>> Hello,
>>
>>
>> you can use the WAR protocol scheme (used for serving files from a war
>> application deployed inside a servlet container), or the CLAP one
>> (looks for "files" from the classpath).
>> For example, if your "items" directory is located just under the
>> "Web-Content" directory:
>>
>> FileRepresentation rep=new
>> FileRepresentation("war:///items/result.jsp",MediaType.TEXT_HTML);
>>
>> I would like to precise the FileRepresentation simply gets the content
>> of the targetted file.
>>
>>
>> Best regards,
>> Thierry Boileau
>> --
>> Restlet
>> ~ Core developer ~ http://www.restlet.org
>> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
>>
>>
>> I am trying to create a web application with restlet. how can i
call
>> a
>> file in the web application (using relative path).
>> I went through documentation of restlet, there creating html content in
>> the
>> Resource class was explained as shown here.
>>
>> getResponse().setStatus(Status.SUCCESS_CREATED);
>> String result="<h3>Item Created. </h3>";
>> result += " <p>use <br>
>> http://localhost:8080/itemRestlet/itemapp/items <br>in
>> a new browser instance to see the data.</p>";
>> Representation rep = new
StringRepresentation(result,MediaType.TEXT_HTML);
>>
>> The FileRepresentation class can take path of the file you want
to
>> invoke and content type, but here the problem is trying to locate
>> result.jsp
>> in the webserver installation directory rather than in webapp.
>>
>> FileRepresentation rep=new
>> FileRepresentation("items/result.jsp",MediaType.TEXT_HTML);
>>
>> Can any one please help me to invoke this result.jsp from a
>> resource?
>> I am trying to invoke a html/jsp page from web application from a
>> resource....help me please
_____
View this message in context: Re:
<http://n2.nabble.com/refering-a-web-app-file-with-FileRepresentation-tp1493
159p1512866.html> refering a web app file with FileRepresentation
Sent from the Restlet Discuss
<http://n2.nabble.com/Restlet-Discuss-f1400322.html> mailing list archive at
Nabble.com.