user2413412
user2413412

Reputation: 53

How to get FileEntry object in liferay search hook

We use Liferay 6.1.3 community edition in our company.

I want to edit search results page which is displayed after searching keyword (main_search_result_form.jsp) to allow user to download latest document version. So user won't be redirected to document library page but only download a file.

I think solution is to create hook and change URL for document. I've found code which creates the URL:

downloadUrl = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK, false, true);

But I can't figure out how to obtain FileEntry object in jsp. I've found only Document object. I don't know how to create URL for downloading file. I hope it is the right way to solve my problem.

I am new to Liferay development so any help would be appreciated.

Thanks for replies.

Upvotes: 1

Views: 1703

Answers (1)

user2413412
user2413412

Reputation: 53

Solution was simple as always...

long dlFileEntryId = assetRenderer.getClassPK(); 
if (enableDirectDocumentOpenHook && assetRendererFactory.getType().equals("document")) {
  FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(dlFileEntryId);
  FileVersion fileVersion = (FileVersion) fileEntry.getLatestFileVersion();
  downloadUrl = DLUtil.getPreviewURL(fileEntry, fileVersion, themeDisplay, StringPool.BLANK, false, true); 
} else { ... } 

Upvotes: 1

Related Questions