Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Diego Pietralunga
[Velocity] Journal/WCD file properties from document library structure fiel
26 de Outubro de 2010 11:17
Resposta

Diego Pietralunga

Ranking: New Member

Mensagens: 17

Data de entrada: 4 de Agosto de 2009

Mensagens recentes

Hello everybody.

I'm stuck with this seemingly simple task:

Get file names (or size or owner or ID or else) from a WCD/Journal portlet using a document_library (repeatable) field.

I tried search around quite a lot but couldn't find a suitable and ready-to-go solution.

Here's my WCD structure:

<root>
<dynamic-element name='content' type='text_area' index-type='' repeatable='false'>
<meta-data>
<entry name="displayAsTooltip"><![CDATA]></entry>
<entry name="required"><![CDATA]></entry>
<entry name="instructions"><![CDATA[]]></entry>
<entry name="label"><![CDATA]></entry>
<entry name="predefinedValue"><![CDATA[]]></entry>
</meta-data>
</dynamic-element>
<dynamic-element name='files' type='document_library' index-type='' repeatable='true'>
<meta-data>
<entry name="displayAsTooltip"><![CDATA]></entry>
<entry name="required"><![CDATA]></entry>
<entry name="instructions"><![CDATA[]]></entry>
<entry name="label"><![CDATA[DocumentLibraryField]]></entry>
<entry name="predefinedValue"><![CDATA[]]></entry>
</meta-data>
</dynamic-element>
</root>

and the sample template trying to list link and file names:

Content is:<br/>
$content.getData()
<br/>
Files are:
<br/>
<ul>
#foreach ($ListItem in $files.getSiblings())

<li><a href='$ListItem.getData()'> ??</a> </li>

#end
</ul>


Content data is showing up and I can get the "files" fields contents (which are document library links without the host name, as per selection fron WCD editor)
I get something like this:

Content is:
Yocontent


Files are:
?? (<-- Note: link IS working here with url: http://myLiferayHost.here/documents/16292/18041/myUploadedFilename.here.pdf
??

I guess I need some service here, somehing like (velocity):

#set($dlFileEntryUtil = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
#set ($longGroupId = $getterUtil.getLong($groupId))
#set($fileEntry = $dlFileEntryUtil.getFileEntryByUuidAndGroupId($uuid,$longGroupId))
(from here )

but the question is:

What is the correct way to create a FileEntryXXX velocity object with the correct parameters if I (apparently) have only the (web) file path (such as /documents/16292/18041/myUploadedFilename.here.pdf) ?

Do I need some URL parsing? Or there's a dedicated Liferay way ?
What class and method(s) to use?

Config:

Liferay 6.0.10 from Trunk (30 sept 2010 build)
Java 6
Linux CentOS

P.S= I put an empty property journal.template.velocity.restricted.variables=
in portal-ext.properties


Thanks in advance!

Diego
Diego Pietralunga
RE: [Velocity] Journal/WCD file properties from document library structure
28 de Outubro de 2010 10:40
Resposta

Diego Pietralunga

Ranking: New Member

Mensagens: 17

Data de entrada: 4 de Agosto de 2009

Mensagens recentes

Nobody has a little hint? ... I guess it's a common task... :-(((((


While searching meanwhile, I made up my mind that you need to parse the journal document library fields' URLs according to the FriendlyUrlMapping naming strategy. Then there's a possibility to che a FileEntry handle (still wondering if there's a "standard" LR way...)

Supposing I am right, can somebody please post a quick and tested LR/Velocity code snippet to parse a document library URL?
Francesco Marangi
RE: [Velocity] Journal/WCD file properties from document library structure
3 de Novembro de 2011 10:47
Resposta

Francesco Marangi

Ranking: New Member

Mensagens: 9

Data de entrada: 6 de Fevereiro de 2009

Mensagens recentes

Even if this thread is quite "ancient", I'd love to contribute the solution I used for it.

First off, make sure you have the serviceLocator enabled in your portal-ext.properties:
1journal.template.velocity.restricted.variables=


Suppose the document library link is stored in a field called 'doc'.

 1## Get the group ID of the document library you are referring to
 2#set ($gid = $getterUtil.getLong($doc.getData().split("/").get(2)))
 3
 4## Get the folder ID of the DL
 5#set ($fid = $getterUtil.getLong($doc.getData().split("/").get(3)))
 6
 7## Get the file title
 8#set ($fileTitle = $doc.getData().split("/").get(4))
 9
10## Since the file title is URL encoded, we need to decode it first
11## (I assume you are using UTF-8 as charset)
12#set ($tmp = {})
13#set ($decoder = $tmp.class.forName("java.net.URLDecoder").newInstance())
14#set ($fileTitle = $decoder.decode($fileTitle, "UTF-8"))
15
16## Now we can retrieve the FileEntry from the DL
17#set ($dlService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
18#set ($fileEntry = $dlService.getFileEntryByTitle($gid, $fid, $fileTitle))


That's it, hope this helps other developers!
Jody Braaten
RE: [Velocity] Journal/WCD file properties from document library structure
26 de Fevereiro de 2013 10:37
Resposta

Jody Braaten

Ranking: New Member

Mensagens: 5

Data de entrada: 13 de Novembro de 2008

Mensagens recentes

Thanks for posting your solution to the 'ancient' thread - it saved me tons of time!! emoticon
Nicolas Lafaury
RE: [Velocity] Journal/WCD file properties from document library structure
23 de Julho de 2013 01:57
Resposta

Nicolas Lafaury

Ranking: New Member

Mensagens: 3

Data de entrada: 25 de Setembro de 2012

Mensagens recentes

Hello

Thanks for your solution. Is there any other option that split the URL?

BTW, code was not working for me, set ($fileEntry = $dlService.getFileEntryByTitle($gid, $fid, $fileTitle)) was always null

I had to change

## Get the file uid
#set ($fileUid = $fichier.getData().split("/").get(5))

#set ($fileEntry = $dlService.getFileEntryByUuidAndGroupId($fileUid, $gid))


Many thanks

Nicolas