Skip to content
Snippets Groups Projects
Commit 437164ea authored by srosse's avatar srosse
Browse files

OO-1407: fix the relative path of uploaded images

parent 23d4c580
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@
package org.olat.core.commons.controllers.filechooser;
import org.olat.core.commons.modules.bc.FolderEvent;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.util.vfs.VFSContainer;
......@@ -146,4 +147,26 @@ public class FileChooserUIFactory {
VFSItem selectedItem = event.getSelectedItem();
return VFSManager.getRelativeItemPath(selectedItem, rootContainer, relativeBasePath);
}
/**
* Get the path as string of the selected item relative to the root
* container and the relative base path
*
* @param event The folder event
* @param rootContainer
* The root container for which the relative path should be
* calculated
* @param relativeBasePath
* when NULL, the path will be calculated relative to the
* rootContainer; when NULL, the relativeBasePath must
* represent a relative path within the root container that
* serves as the base. In this case, the calculated relative item
* path will start from this relativeBasePath
* @return
*/
public static String getSelectedRelativeItemPath(FolderEvent event, VFSContainer rootContainer, String relativeBasePath) {
// 1) Create path absolute to the root container
VFSItem selectedItem = event.getItem();
return VFSManager.getRelativeItemPath(selectedItem, rootContainer, relativeBasePath);
}
}
......@@ -187,6 +187,7 @@ public class FileLinkChooserController extends BasicController {
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == uploadCtr) {
if (event instanceof FolderEvent) {
......@@ -194,13 +195,19 @@ public class FileLinkChooserController extends BasicController {
if (isFileSuffixOk(folderEvent.getFilename())) {
Size size = null;
VFSItem item = folderEvent.getItem();
String relPath;
if(item != null) {
size = getSize(item, item.getName());
relPath = FileChooserUIFactory
.getSelectedRelativeItemPath(folderEvent, rootDir, fileName);
} else {
relPath = folderEvent.getFilename();
}
if(size != null) {
fireEvent(ureq, new URLChoosenEvent(folderEvent.getFilename(), null, null, null, size.getWidth(), size.getHeight()));
fireEvent(ureq, new URLChoosenEvent(relPath, null, null, null, size.getWidth(), size.getHeight()));
} else {
fireEvent(ureq, new URLChoosenEvent(folderEvent.getFilename()));
fireEvent(ureq, new URLChoosenEvent(relPath));
}
} else {
setErrorMessage(folderEvent.getFilename());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment