Foren

Files from Document Library in Journal Template

Thorben V, geändert vor 15 Jahren.

Files from Document Library in Journal Template

New Member Beiträge: 8 Beitrittsdatum: 05.03.08 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 13 Beitrittsdatum: 06.10.09 Neueste Beiträge
Hi Thorben,

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

best regards,

Matthäus
thumbnail
Lisa Simpson, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

Liferay Legend Beiträge: 2034 Beitrittsdatum: 05.03.09 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 13 Beitrittsdatum: 06.10.09 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 15 Beitrittsdatum: 26.09.09 Neueste Beiträge
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., geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 7 Beitrittsdatum: 16.11.09 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 15 Beitrittsdatum: 26.09.09 Neueste Beiträge
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., geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 7 Beitrittsdatum: 16.11.09 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 15 Beitrittsdatum: 26.09.09 Neueste Beiträge
S. R., geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 7 Beitrittsdatum: 16.11.09 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 15 Beitrittsdatum: 26.09.09 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 13 Beitrittsdatum: 06.10.09 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 15 Beitrittsdatum: 26.09.09 Neueste Beiträge
@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, geändert vor 14 Jahren.

RE: Files from Document Library in Journal Template

New Member Beiträge: 13 Beitrittsdatum: 06.10.09 Neueste Beiträge
Hi Ivan.
Thank you for the code.
thumbnail
Charu Babbar, geändert vor 11 Jahren.

RE: Files from Document Library in Journal Template

Regular Member Beiträge: 167 Beitrittsdatum: 13.09.11 Neueste Beiträge
Plz tell how can I apply above code in template of journal content.
thumbnail
Achmed Tyrannus Albab, geändert vor 11 Jahren.

RE: Files from Document Library in Journal Template

Regular Member Beiträge: 158 Beitrittsdatum: 05.03.10 Neueste Beiträge
Charu Babbar:
Plz tell how can I apply above code in template of journal content.


Agreed where to apply this?