Skip to content
Snippets Groups Projects
Commit 5fc77e3c authored by srosse's avatar srosse
Browse files

Merge with ff1d68f6390039d454583149552fc11591025447

parents 724531ae de9b9511
No related branches found
No related tags found
No related merge requests found
......@@ -265,7 +265,7 @@ public class FileChooseCreateEditController extends BasicController{
VFSContainer vfsRoot = new NamedContainerImpl(getTranslator().translate(NLS_FOLDER_DISPLAYNAME), rootContainer);
VFSItemFilter typeFilter = null;
if (!allFileSuffixesAllowed && allowedFileSuffixes != null) {
typeFilter = new VFSItemFileTypeFilter(allowedFileSuffixes);
typeFilter = new VFSItemFileTypeFilter(allowedFileSuffixes, false);
}
// Clanup old file chooser and open up new one
removeAsListenerAndDispose(fileChooserCtr);
......
......@@ -130,7 +130,7 @@ public class FileLinkChooserController extends BasicController {
VFSItemFilter customFilter = null;
VFSItemFilter dirFilter = new VFSItemExcludePrefixFilter(dirFilters);
if (suffixes != null) {
VFSItemFileTypeFilter typeFilter = new VFSItemFileTypeFilter(suffixes);
VFSItemFileTypeFilter typeFilter = new VFSItemFileTypeFilter(suffixes, uriValidation);
typeFilter.setCompositeFilter(dirFilter);
customFilter = typeFilter;
} else {
......
......@@ -20,7 +20,9 @@
package org.olat.core.util.vfs.filters;
import java.net.URI;
import java.util.Hashtable;
import java.util.Map;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem;
......@@ -33,14 +35,17 @@ import org.olat.core.util.vfs.VFSItem;
*
*/
public class VFSItemFileTypeFilter extends VFSItemCompositeFilter {
private Hashtable<String, String> fileTypes = new Hashtable<String, String>();
private final boolean uriValidation;
private Map<String, String> fileTypes = new Hashtable<String, String>();
/**
* Constrtuctor
*
* @param filetypes
*/
public VFSItemFileTypeFilter(String[] fileTypes) {
public VFSItemFileTypeFilter(String[] fileTypes, boolean uriValidation) {
this.uriValidation = uriValidation;
for (int i = 0; i < fileTypes.length; i++) {
addFileType(fileTypes[i]);
}
......@@ -51,24 +56,35 @@ public class VFSItemFileTypeFilter extends VFSItemCompositeFilter {
*/
public void addFileType(String fileType) {
fileType = fileType.toLowerCase();
this.fileTypes.put(fileType, fileType);
fileTypes.put(fileType, fileType);
}
/**
* @param fileType
*/
public void removeFileType(String fileType) {
this.fileTypes.remove(fileType.toLowerCase());
fileTypes.remove(fileType.toLowerCase());
}
/**
* @see org.olat.core.util.vfs.filters.VFSItemCompositeFilter#acceptFilter(VFSItem)
*/
@Override
public boolean acceptFilter(VFSItem vfsItem) {
if (vfsItem instanceof VFSContainer) {
return true;
}
String name = vfsItem.getName().toLowerCase();
}
String name = vfsItem.getName();
if(uriValidation) {
try {
new URI(name).getPath();
} catch(Exception e) {
return false;
}
}
name = name.toLowerCase();
int dotPos = name.lastIndexOf(".");
if (dotPos == -1) return false;
return fileTypes.containsKey(name.substring(dotPos + 1));
......
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