掲示板

[Velocity] Journal/WCD file properties from document library structure fiel

thumbnail
13年前 に Diego Pietralunga によって更新されました。

[Velocity] Journal/WCD file properties from document library structure fiel

New Member 投稿: 17 参加年月日: 09/08/04 最新の投稿
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[false]]></entry>
<entry name="required"><![CDATA[false]]></entry>
<entry name="instructions"><![CDATA[]]></entry>
<entry name="label"><![CDATA[content]]></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[true]]></entry>
<entry name="required"><![CDATA[false]]></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
thumbnail
13年前 に Diego Pietralunga によって更新されました。

RE: [Velocity] Journal/WCD file properties from document library structure

New Member 投稿: 17 参加年月日: 09/08/04 最新の投稿
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?
thumbnail
12年前 に Francesco Marangi によって更新されました。

RE: [Velocity] Journal/WCD file properties from document library structure

New Member 投稿: 9 参加年月日: 09/02/06 最新の投稿
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:
journal.template.velocity.restricted.variables=


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

## Get the group ID of the document library you are referring to
#set ($gid = $getterUtil.getLong($doc.getData().split("/").get(2)))

## Get the folder ID of the DL
#set ($fid = $getterUtil.getLong($doc.getData().split("/").get(3)))

## Get the file title
#set ($fileTitle = $doc.getData().split("/").get(4))

## Since the file title is URL encoded, we need to decode it first
## (I assume you are using UTF-8 as charset)
#set ($tmp = {})
#set ($decoder = $tmp.class.forName("java.net.URLDecoder").newInstance())
#set ($fileTitle = $decoder.decode($fileTitle, "UTF-8"))

## Now we can retrieve the FileEntry from the DL
#set ($dlService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
#set ($fileEntry = $dlService.getFileEntryByTitle($gid, $fid, $fileTitle))


That's it, hope this helps other developers!
11年前 に Jody Braaten によって更新されました。

RE: [Velocity] Journal/WCD file properties from document library structure

New Member 投稿: 5 参加年月日: 08/11/13 最新の投稿
Thanks for posting your solution to the 'ancient' thread - it saved me tons of time!! emoticon
10年前 に Nicolas Lafaury によって更新されました。

RE: [Velocity] Journal/WCD file properties from document library structure

New Member 投稿: 3 参加年月日: 12/09/25 最新の投稿
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
thumbnail
9年前 に Enrique Valdes Lacasa によって更新されました。

RE: [Velocity] Journal/WCD file properties from document library structure

Junior Member 投稿: 92 参加年月日: 14/07/29 最新の投稿
Thanks for the code Francesco. One important thing: in Liferay 6.2 the portal property to enable the $serviceLocator was changed! instead of
journal.template.velocity.restricted.variables=
it is now:
velocity.engine.restricted.variables=
. These property changes are scary sometimes, but they are supposed to be for the better. Check out the answer by James Falkner in this thread to know more about this:

6.2 serviceLocator variable

Best regards
8年前 に juan meza によって更新されました。

RE: [Velocity] Journal/WCD file properties from document library structure

Regular Member 投稿: 228 参加年月日: 14/01/06 最新の投稿
in the new version of liferay (6.2 GA4)

#set ($fileEntry = $dlService.getFileEntryByTitle($gid, $fid, $fileTitle))


changed to this:

#set ($fileEntry = $dlService.getFileEntry($gid, $fid, $fileTitle))