* path will start from this relativeBasePath
* @return
*/
public static String getSelectedRelativeItemPath(FileChoosenEvent event, VFSContainer rootContainer, String relativeBasePath) {
// 1) Create path absolute to the root container
VFSItem selectedItem = event.getSelectedItem();
if (selectedItem == null) return null;
String absPath = "";
VFSItem tmpItem = selectedItem;
// Check for merged containers to fix problems with named containers, see OLAT-3848
List<NamedContainerImpl> namedRootChilds = new ArrayList<NamedContainerImpl>();
for (VFSItem rootItem : rootContainer.getItems()) {
if (rootItem instanceof NamedContainerImpl) {
namedRootChilds.add((NamedContainerImpl) rootItem);
}
}
// Check if root container is the same as the item and vice versa. It is
// necessary to perform the check on both containers to catch all potential
// cases with MergedSource and NamedContainer where the check in one
// direction is not necessarily the same as the opposite check
while ( tmpItem != null && !rootContainer.isSame(tmpItem) && !tmpItem.isSame(rootContainer)) {
String itemFileName = tmpItem.getName();
// Special case: check if this is a named container, see OLAT-3848
for (NamedContainerImpl namedRootChild : namedRootChilds) {
if (namedRootChild.isSame(tmpItem)) {
itemFileName = namedRootChild.getName();
}
}
absPath = "/" + itemFileName + absPath;
tmpItem = tmpItem.getParentContainer();
}
if (relativeBasePath == null) {
return absPath;
}