Foren
[Velocity] Journal/WCD file properties from document library structure fiel
Diego Pietralunga, geändert vor 13 Jahren.
[Velocity] Journal/WCD file properties from document library structure fiel
New Member Beiträge: 17 Beitrittsdatum: 04.08.09 Neueste Beiträge
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
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
Diego Pietralunga, geändert vor 13 Jahren.
RE: [Velocity] Journal/WCD file properties from document library structure
New Member Beiträge: 17 Beitrittsdatum: 04.08.09 Neueste Beiträge
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?
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, geändert vor 12 Jahren.
RE: [Velocity] Journal/WCD file properties from document library structure
New Member Beiträge: 9 Beitrittsdatum: 06.02.09 Neueste Beiträge
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:
Suppose the document library link is stored in a field called 'doc'.
That's it, hope this helps other developers!
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!
Jody Braaten, geändert vor 11 Jahren.
RE: [Velocity] Journal/WCD file properties from document library structure
New Member Beiträge: 5 Beitrittsdatum: 13.11.08 Neueste Beiträge
Thanks for posting your solution to the 'ancient' thread - it saved me tons of time!!
Nicolas Lafaury, geändert vor 10 Jahren.
RE: [Velocity] Journal/WCD file properties from document library structure
New Member Beiträge: 3 Beitrittsdatum: 25.09.12 Neueste Beiträge
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
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
Enrique Valdes Lacasa, geändert vor 9 Jahren.
RE: [Velocity] Journal/WCD file properties from document library structure
Junior Member Beiträge: 92 Beitrittsdatum: 29.07.14 Neueste Beiträge
Thanks for the code Francesco. One important thing: in Liferay 6.2 the portal property to enable the $serviceLocator was changed! instead of
6.2 serviceLocator variable
Best regards
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
juan meza, geändert vor 8 Jahren.
RE: [Velocity] Journal/WCD file properties from document library structure
Regular Member Beiträge: 228 Beitrittsdatum: 06.01.14 Neueste Beiträge
in the new version of liferay (6.2 GA4)
changed to this:
#set ($fileEntry = $dlService.getFileEntryByTitle($gid, $fid, $fileTitle))
changed to this:
#set ($fileEntry = $dlService.getFileEntry($gid, $fid, $fileTitle))