Home

In my past projects most of the times alfresco being used in backend to store contents and front end is built using portal or other web application now whenever this kind of architecture exist there is going to be requirement where we need to expose alfresco repository to front-end system. Most of the times when we pull alfresco contents from alfresco repository through webscript based on some business logic we get list of nodeRefs or nodes.

For extracting information from this list of nodes we have two options

1)    Iterate through nodes in javascript or java controller of webscript and pass it to output ftl file.

2)    Pass list of nodes directly to ftl file and iterate through those nodes in ftl

I normally prefer second approach reason is that in that approach we could produce multiple different output formats from that list like xml,csv,json etc… which is not possible in first approach as we have already prepared that output content in javascript itself so we need to create new webscript if we want to have different output format.

Now whenever we are having list of noderef we need to extract set of properties from those nodes, Most of the times we have to deal with out-of-box properties as well as custom properties.

Here is a piece of code which you can use to iterate through all those properties in ftl file.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<table>
    <#-- Get a list of all the property names for the document -->
    <#assign props = document.properties?keys>
    <#list props as t>
       <#-- If the property exists -->
       <#if document.properties[t]?exists>
          <#-- If it is a date, format it accordingly -->
          <#if document.properties[t]?is_date>
             <tr><td>${t} = ${document.properties[t]?datetime}</td></tr>
          
          <#-- If it is a boolean, format it accordingly -->
          <#elseif document.properties[t]?is_boolean>
             <tr><td>${t} = ${document.properties[t]?string("yes", "no")}</td></tr>
          
          <#-- If it is a collection, enumerate it -->
          <#elseif document.properties[t]?is_enumerable>
             <tr><td>${t} = <#list document.properties[t] as i>${i} </#list></td></tr>
          
          <#-- Otherwise treat it as a string -->
          <#else>
             <tr><td>${t} = ${document.properties[t]}</td></tr>
          </#if>
       </#if>
    </#list>
 </table>

Summary: Above piece you can inject in your ftl files and it is generic enough to be reusable across different output formats.

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Publicités

Laisser un commentaire

Choisissez une méthode de connexion pour poster votre commentaire:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s