留言板

Files from Document Library in Journal Template

Thorben V,修改在15 年前。

Files from Document Library in Journal Template

New Member 帖子: 8 加入日期: 08-3-5 最近的帖子
Hello!

I hope someone can help me with the following. I'm trying to build a Journal-Template where the user can add a document from the Document-Library. This file is should be displayed at the bottom of the Journal-Article. I don't want to add it in the Content Area as a Link. In the best case I have the name of the file and an icon of the filetype on the left of it. The icon should look like those ones, Liferay generates when you browse the document-library. That means I have an pdf-icon for pdfs, jpg-icon etc.
I added a Document-Library Element in the Structure named library. The template is an Velocity Macro (VM). How can I get to diplay the name of the file I've chosen? I've added the following line:

#if ($library.getData() != "")
<p>library.getdata()</p>
#end

This displays the path to the document. I understand that the xml-element contains the document path, but how can I generate the Filename and Icon of it? Is it possible to get the filetype or name or something like from the document-library elemet? Has someone some kind of code which is similar to what I search?

The Journal-Article should finally look like in the attached file.

Thx for any help.

- Thorben
thumbnail
Matthäus Janiczek,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 13 加入日期: 09-10-6 最近的帖子
Hi Thorben,

I've exactly the same problem. Did you've found any solution?

best regards,

Matthäus
thumbnail
Lisa Simpson,修改在14 年前。

RE: Files from Document Library in Journal Template

Liferay Legend 帖子: 2034 加入日期: 09-3-5 最近的帖子
I think that maybe this should be in the suggestions since it's probably not something Liferay seems to be able to do "out of the box".

However, it seems counter-intuitive to me that you cannot link to various assets from the link dialog
thumbnail
Matthäus Janiczek,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 13 加入日期: 09-10-6 最近的帖子
I seems that Liferay _could_ do something like this 'out of the Box'.
But it's simply not implemented.
When you go directly to the document library and then edit a file you will see that besides "Download" the file has a link (same link that is in the file name) that ends with the file extensions.
Based on that it would be possible to display an matching icon through a simple Velocity Script. But for that the generated URL would have to look similiar to the link that I've mentioned before.
Igor Stipanov,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 15 加入日期: 09-9-26 最近的帖子
It is counter intuitive to users that they need to go to a rich-text field and use the "add link" option to upload an attachment. People instinctively look for the "add attachment" option. And the consequence here is that you must have a rich-text field in your content structure if you want content contributors to be able to upload attachments referred to in content.
I really think this should be added to Liferay, as it is a common functionality in most web content management systems.
Even this form for forum messages has an "Add attachment" button ;)
S. R.,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 7 加入日期: 09-11-16 最近的帖子
The main problem ist that you aren't allowed to use the serviceLocator in the default configuration.

So it's impossible (like I know until now) to get the meta data of the file like name, filesize and type. You are able to get the uuid and groupid from the document library entry, but nothing more. With that identifier you can get that stuff with the help of com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService on the velocity layer. But if serviceLocator is not disabled in journal.template.velocity.restricted.variables you are doomed (like me right now).

Or does anybody got a tip for me?
Igor Stipanov,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 15 加入日期: 09-9-26 最近的帖子
I'm not sure I understand exactly what you meant but I'll try to help emoticon
You can use DLFileEntryLocalServiceUtil.getFileEntryByUuidAndGroupId() to get file metadata by UUID and GroupId:
DLFileEntryLocalServiceUtil.getFileEntryByUuidAndGroupId() javadoc

If this service is not available in velocity Journal templates, you can configure Liferay to make it available. I don't remember exactly where, but it's probably in portal-ext.properties , property journal.template.velocity.restricted.variables .

I hope this helps.

Btw, "Attach files" functionality in the Forum portlet (MessageBoard) is exactly what we want, so we decided to implement it in Journal portlet. It would be nice if the Liferay team implemented it in the next release. It should not be a problem, since it's already implemented in one place. We'll be glad to contribute our implementation...
S. R.,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 7 加入日期: 09-11-16 最近的帖子
Yes, that's the way I got it working.
Sadly I can't load the TextFormatter and had to convert the filesize directly in velocity with good old if else.

Is there any way to get the mime type?
Normally there has to be more meta information about the file, or?
S. R.,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 7 加入日期: 09-11-16 最近的帖子
I tried it with getExtraSettings() and getExtraSettingsProperties(), but both delivered me an empty result.
What are normally the result of the both functions?
Igor Stipanov,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 15 加入日期: 09-9-26 最近的帖子
I've never used them, so I wouldn't know.
I'm not sure if I understood what you're trying to do, but maybe this will help - here's how we placed file type icons and file sizes next to links to attached files:
  • file size: DLServiceUtil.getFileSize(companyId, CompanyConstants.SYSTEM, folderAndfileName);
  • file type: DLUtil.getFileExtension(fileName);

I suggest you have a look at source code of the DocumentLibrary and see how they extract file meta-data - you can see file meta-data when you browse through document library in the DocumentLibrary portlet so this is a good place to start.
thumbnail
Matthäus Janiczek,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 13 加入日期: 09-10-6 最近的帖子
Hi Igor,

sorry, but could you provide us a sample code how you have implemented
DLUtil.getFileExtension(fileName);
?
I have to admit that i don't really get it and i would like to know where i've made the mistake in the implementation.
Igor Stipanov,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 15 加入日期: 09-9-26 最近的帖子
@Matthäus...

Method DLUtil.getFileExtension(fileName) just parses the file name, for example "someFile.doc", and returns its extension ( "doc" in this exapmple).

Here's the sample code how this could be implemented:
public static String getFileExtension(String fileName) {
               return fileName.substring( fileName.lastIndexOf('.') + 1 );
}

public String getFileImage(String fileName) {
               StringBuilder sb = new StringBuilder();

               sb.append("<img align="\&quot;left\&quot;" border="\&quot;0\&quot;" src="\&quot;&quot;);" sb.append(" html themes my-liferay-theme images document_library "); sb.append(DLUtil.getFileExtension(fileName)); sb.append(".png\">");

               return sb.toString();
}


Of course, you need to have appropriate icons on the generated URL (in this exaple, the URL of the icon would be "/html/themes/my-liferay-theme/images/document_library/doc.png").
thumbnail
Matthäus Janiczek,修改在14 年前。

RE: Files from Document Library in Journal Template

New Member 帖子: 13 加入日期: 09-10-6 最近的帖子
Hi Ivan.
Thank you for the code.
thumbnail
Charu Babbar,修改在11 年前。

RE: Files from Document Library in Journal Template

Regular Member 帖子: 167 加入日期: 11-9-13 最近的帖子
Plz tell how can I apply above code in template of journal content.
thumbnail
Achmed Tyrannus Albab,修改在11 年前。

RE: Files from Document Library in Journal Template

Regular Member 帖子: 158 加入日期: 10-3-5 最近的帖子
Charu Babbar:
Plz tell how can I apply above code in template of journal content.


Agreed where to apply this?