Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Thorben V
Files from Document Library in Journal Template
December 9, 2008 5:23 AM
Answer

Thorben V

Rank: New Member

Posts: 8

Join Date: March 5, 2008

Recent Posts

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
Attachment

Attachments: bild.png (30.7k)
Matthäus Janiczek
RE: Files from Document Library in Journal Template
November 9, 2009 4:00 AM
Answer

Matthäus Janiczek

Rank: New Member

Posts: 12

Join Date: October 6, 2009

Recent Posts

Hi Thorben,

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

best regards,

Matthäus
Lisa Simpson
RE: Files from Document Library in Journal Template
November 10, 2009 7:54 AM
Answer

Lisa Simpson

Rank: Liferay Legend

Posts: 2034

Join Date: March 5, 2009

Recent Posts

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
Matthäus Janiczek
RE: Files from Document Library in Journal Template
November 10, 2009 8:11 AM
Answer

Matthäus Janiczek

Rank: New Member

Posts: 12

Join Date: October 6, 2009

Recent Posts

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
RE: Files from Document Library in Journal Template
November 26, 2009 1:03 PM
Answer

Igor Stipanov

Rank: New Member

Posts: 16

Join Date: September 26, 2009

Recent Posts

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.
RE: Files from Document Library in Journal Template
November 30, 2009 11:20 AM
Answer

S. R.

Rank: New Member

Posts: 7

Join Date: November 16, 2009

Recent Posts

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
RE: Files from Document Library in Journal Template
December 1, 2009 12:41 PM
Answer

Igor Stipanov

Rank: New Member

Posts: 16

Join Date: September 26, 2009

Recent Posts

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.
RE: Files from Document Library in Journal Template
January 13, 2010 11:48 AM
Answer

S. R.

Rank: New Member

Posts: 7

Join Date: November 16, 2009

Recent Posts

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?
Igor Stipanov
RE: Files from Document Library in Journal Template
January 14, 2010 1:37 AM
Answer

Igor Stipanov

Rank: New Member

Posts: 16

Join Date: September 26, 2009

Recent Posts

Try with
[url=http://docs.liferay.com/portal/5.1/javadocs/portal-service/com/liferay/portlet/documentlibrary/model/DLFileEntry.html#getExtraSettings()]DLFileEntry.getExtraSettings()
or
[url=http://docs.liferay.com/portal/5.1/javadocs/portal-service/com/liferay/portlet/documentlibrary/model/DLFileEntry.html#getExtraSettingsProperties()]DLFileEntry.getExtraSettingsProperties()
S. R.
RE: Files from Document Library in Journal Template
January 24, 2010 12:38 PM
Answer

S. R.

Rank: New Member

Posts: 7

Join Date: November 16, 2009

Recent Posts

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
RE: Files from Document Library in Journal Template
January 25, 2010 2:17 AM
Answer

Igor Stipanov

Rank: New Member

Posts: 16

Join Date: September 26, 2009

Recent Posts

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.
Matthäus Janiczek
RE: Files from Document Library in Journal Template
February 9, 2010 5:23 AM
Answer

Matthäus Janiczek

Rank: New Member

Posts: 12

Join Date: October 6, 2009

Recent Posts

Hi Igor,

sorry, but could you provide us a sample code how you have implemented
1DLUtil.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
RE: Files from Document Library in Journal Template
February 10, 2010 2:15 AM
Answer

Igor Stipanov

Rank: New Member

Posts: 16

Join Date: September 26, 2009

Recent Posts

@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:
 1public static String getFileExtension(String fileName) {
 2               return fileName.substring( fileName.lastIndexOf('.') + 1 );
 3}
 4
 5public String getFileImage(String fileName) {
 6               StringBuilder sb = new StringBuilder();
 7
 8               sb.append("<img align=\"left\" border=\"0\" src=\"");
 9               sb.append("/html/themes/my-liferay-theme/images/document_library/");
10               sb.append(DLUtil.getFileExtension(fileName));
11               sb.append(".png\">");
12
13               return sb.toString();
14}


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").
Matthäus Janiczek
RE: Files from Document Library in Journal Template
February 11, 2010 1:02 AM
Answer

Matthäus Janiczek

Rank: New Member

Posts: 12

Join Date: October 6, 2009

Recent Posts

Hi Ivan.
Thank you for the code.
Charu Babbar
RE: Files from Document Library in Journal Template
July 30, 2012 4:05 AM
Answer

Charu Babbar

Rank: Regular Member

Posts: 148

Join Date: September 13, 2011

Recent Posts

Plz tell how can I apply above code in template of journal content.
Achmed Tyrannus Albab
RE: Files from Document Library in Journal Template
July 31, 2012 10:45 PM
Answer

Achmed Tyrannus Albab

Rank: Junior Member

Posts: 58

Join Date: March 5, 2010

Recent Posts

Charu Babbar:
Plz tell how can I apply above code in template of journal content.


Agreed where to apply this?