Getting the preview URL of a File Entry
Posted on
by Charalampos Chrysikopoulos
If you are working in a custom portlet and with FileEntries, it is very likely that you will need the preview url of this file, to use it in your UI.
There is a class with the name DLUtil that provide you with a method for this.
But, is you don't have the themeDisplay (because, for example, you are writing the code of a scheduler job), you can't use this class. You have to do this alone:
public String getFileUrl(FileEntry fileEntry, boolean appendToken) throws Exception{ try { StringBundler sb = new StringBundler(); sb.append("/documents/"); sb.append(fileEntry.getRepositoryId()); sb.append(StringPool.SLASH); sb.append(fileEntry.getFolderId()); sb.append(StringPool.SLASH); sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(fileEntry.getTitle()), true)); sb.append("?version="); sb.append(fileEntry.getFileVersion().getVersion()); if (appendToken) { sb.append("&t="); Date modifiedDate = fileEntry.getFileVersion().getModifiedDate(); sb.append(modifiedDate.getTime()); } return sb.toString(); } catch (PortalException | SystemException e) { throw e } return null; }
This entry was posted in Liferay, Uncategorized and tagged liferay 6.2 by Charalampos Chrysikopoulos