0
votes

In Liferay's Document and Media, I created a folder called myfolder containing a folder called subfolder containing a file called file.txt.

I have the DLFileEntry of file.txt.

How to get the string /folder/subfolder/file.txt?

Notes:

  • Context: For display/reporting purposes, I need to get the full path of the file, a bit like how it would appear in a breadcrumb.
  • getTreePath() gives identifiers such as /32701/ instead of folder names
  • I greped the whole Liferay 7 DXP SP4 for getBreadcrumbs and no source code came, even though a method with this name seemed to exist in Liferay 5.
1

1 Answers

0
votes

Here is my implementation:

protected String fullPath(DLFileEntry file) throws PortalException {
    String fileName = file.getFileName();
    DLFolder folder = file.getFolder();

    if (folder == null) {
        return "/" + fileName;
    }
    else {
        return fullPath(folder) + "/" + fileName;
    }
}

protected String fullPath(DLFolder folder) throws PortalException {
    String folderName = folder.getName();
    DLFolder parent = folder.getParentFolder();

    if (parent == null) {
        return "/" + folderName;
    }
    else {
        return fullPath(parent) + folderName;
    }
}

All ideas to improve maintainability and performance are welcome!