Changeset 17558 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2021-03-10T20:33:44+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/importexport/ImageImporter.java
r17553 r17558 9 9 import java.util.Arrays; 10 10 import java.util.Collections; 11 import java.util.EnumSet; 11 12 import java.util.HashSet; 12 13 import java.util.List; 13 14 import java.util.Set; 15 import java.util.regex.Matcher; 16 import java.util.regex.Pattern; 14 17 import java.util.stream.Collectors; 15 18 … … 20 23 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 21 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 import org.openstreetmap.josm.io.CachedFile; 22 26 import org.openstreetmap.josm.io.IllegalDataException; 23 27 … … 27 31 */ 28 32 public class ImageImporter extends FileImporter { 33 34 /** Check if the filename starts with a borked path ({@link java.io.File#File} drops consecutive {@code /} characters). */ 35 private static final Pattern URL_START_BAD = Pattern.compile("^(https?:/)([^/].*)$"); 36 /** Check for the beginning of a "good" url */ 37 private static final Pattern URL_START_GOOD = Pattern.compile("^https?://.*$"); 38 29 39 private GpxLayer gpx; 30 40 … … 91 101 List<File> files = new ArrayList<>(); 92 102 Set<String> visitedDirs = new HashSet<>(); 93 addRecursiveFiles(files, visitedDirs, sel, progressMonitor.createSubTaskMonitor(1, true)); 103 addRecursiveFiles(this.options, files, visitedDirs, sel, progressMonitor.createSubTaskMonitor(1, true)); 94 104 95 105 if (progressMonitor.isCanceled()) … … 107 117 static void addRecursiveFiles(List<File> files, Set<String> visitedDirs, List<File> sel, ProgressMonitor progressMonitor) 108 118 throws IOException { 119 addRecursiveFiles(EnumSet.noneOf(Options.class), files, visitedDirs, sel, progressMonitor); 120 } 109 121 122 static void addRecursiveFiles(Set<Options> options, List<File> files, Set<String> visitedDirs, List<File> sel, 123 ProgressMonitor progressMonitor) throws IOException { 110 124 if (progressMonitor.isCanceled()) 111 125 return; … … 118 132 File[] dirFiles = f.listFiles(); // Can be null for some strange directories (like lost+found) 119 133 if (dirFiles != null) { 120 addRecursiveFiles(files, visitedDirs, Arrays.asList(dirFiles), progressMonitor.createSubTaskMonitor(1, true)); 134 addRecursiveFiles(options, files, visitedDirs, Arrays.asList(dirFiles), 135 progressMonitor.createSubTaskMonitor(1, true)); 121 136 } 122 137 } else { … … 124 139 } 125 140 } else { 126 if (FILE_FILTER.accept(f)) { 141 /* Check if the path is a web path, and if so, ensure that it is "correct" */ 142 final String path = f.getPath(); 143 Matcher matcherBad = URL_START_BAD.matcher(path); 144 final String realPath; 145 if (matcherBad.matches()) { 146 realPath = matcherBad.replaceFirst(matcherBad.group(1) + "/" + matcherBad.group(2)); 147 } else { 148 realPath = path; 149 } 150 if (URL_START_GOOD.matcher(realPath).matches() && FILE_FILTER.accept(f) 151 && options.contains(Options.ALLOW_WEB_RESOURCES)) { 152 try (CachedFile cachedFile = new CachedFile(realPath)) { 153 files.add(cachedFile.getFile()); 154 } 155 } else if (FILE_FILTER.accept(f)) { 127 156 files.add(f); 128 157 }
Note:
See TracChangeset
for help on using the changeset viewer.