This short post brings together the little pieces critical to crafting an ADT in velocity to provide direct download links to documents in your Documents and Media repository. You will find parts of this solution strewn across forums and blogs.
In essence, you'll have to do two things:
1. Add the following property to your portal-ext.properties if you have not done so yet. If you've been using the serviceLocator to pull in various Liferay service APIs in your ADTs, then you've likely done this already.
velocity.engine.restricted.variables=
That just says no variables are restricted in your ADTs.
2. Craft the document's download URL. Your document download URL should looks like this:
/documents/<groupId>/<folderId>/<document-title>/<document-uuid>?version=<version>
For example:
/documents/10181/11405/College+Sample+Doc.docx/7a5680cf-8de5-4d65-b179-72ee5c9f5966?version=1.0
In the above code, you may have noticed the call:
$fileEntry.getLatestFileVersion(false)
That boolearn parameter is named
trusted, and basically, this is what the code looks like in the implementation (just in case you're curious).
public DLFileVersion getLatestFileVersion(boolean trusted) throws PortalException, SystemException {
if (trusted) {
return DLFileVersionLocalServiceUtil.getLatestFileVersion(getFileEntryId(),false);
}
else {
return DLFileVersionServiceUtil.getLatestFileVersion(getFileEntryId());
}
}
I think that means that if
trusted is true, then the working copy (Draft) is heeded as the latest version. Otherwise it is not. (Call me out on that if I'm off the mark.)
Hope this saves someone out there a little time.