3

I have a ftl template file stored in alfresco repository. The path of this file is: /app:company_home/app:dictionary/cm:StarXpert_x0020_Workflow/cm:templates/cm:contentModelTemplate.ftl

I want to use this FTL file to create an XML file. In my java backed webscript controller, i want to get the FTL file, i used many method to achieve this, but nothing works. I tried this code:

Template template=cfg.getTemplate("PATH:\"/app:company_home/app:dictionary/cm:StarXpert_x0020_Workflow/cm:templates/cm:contentModelTemplate.ftl\""); 

But i still getting this error:

java.io.FileNotFoundException: Template "contentModelTemplate.ftl" not found

I also tried to get the template by passing its nodeRef as reference to the getTemplate() method, but also it's not works.

Is there anybody who did this before ? Thanks for any hlep.

2
  • Where do you find this cfg service ? I guess this is a script root service ? Commented Aug 24, 2017 at 11:40
  • No it's not an alfresco service, i used freemaker API to manage my template but i can't load the template file. I guess that getTemplate do not understand Alfresco paths, so i already get the error Commented Aug 24, 2017 at 12:52

2 Answers 2

4

If the goal is to have your web script respond with the transformed XML file, then why not leverage the web script itself to do this transformation?

To do this, move the Freemarker template from its current home in the Data Dictionary to be part of your web script (I don't know if you are using repository deployed web scripts or classpath deployed web scripts--it doesn't make a functional difference).

Then, your Java-backed web script will grab data and put it in to the model.

The Freemarker template will automatically be used to render an XML response using the data in the model.

Sign up to request clarification or add additional context in comments.

2 Comments

My webscript will not respond with the transformed XML. I want to load the ftl, create the XML and store it into a specific Alfresco repository. My problem is that i don't found how to load the FTL, I tried to put the FTL in my linux repository, and i'm able to load it through its path cfg.setDirectoryForTemplateLoading(new File("/home/nmalloul/workspace/workflows/stage-workflow/templates"));. But when i use Alfresco path i still getting the error that the tempalte is not find.
An Alfresco path can only be resolved by Alfresco. A Freemarker class with a method that takes a path argument is going to have no idea what that path means. You can either (1) use the Alfresco API to find the FTL, then write it to a temp file in a known path and use that path or (2) mount the Alfresco repo as a CIFS/SMB share and use that path, because then it will look like a plain file system path to Freemarker.
0

You need to use serachService to retrieve the file which resides inside alfresco repository. Below link will help you in using the searchService.

Alfresco Solr SearchService.query() error parsing Xpath

2 Comments

The problem is that getTemplate() method accept only the name of the template as a parameter, so i can't use a Path as parameter to this method
You do not need to use cfg.getTemplate.Further more Please take a look on answer which is given by Jeff as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.