Changeset 17534 in josm
- Timestamp:
- 2021-02-23T11:59:08+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r16505 r17534 17 17 import java.util.Collection; 18 18 import java.util.Collections; 19 import java.util.EnumSet; 19 20 import java.util.HashSet; 20 21 import java.util.LinkedHashSet; 21 22 import java.util.LinkedList; 22 23 import java.util.List; 24 import java.util.Objects; 23 25 import java.util.Set; 24 26 import java.util.concurrent.Future; 25 27 import java.util.regex.Matcher; 26 28 import java.util.regex.Pattern; 29 import java.util.stream.Stream; 27 30 28 31 import javax.swing.JOptionPane; … … 38 41 import org.openstreetmap.josm.gui.io.importexport.AllFormatsImporter; 39 42 import org.openstreetmap.josm.gui.io.importexport.FileImporter; 43 import org.openstreetmap.josm.gui.io.importexport.Options; 40 44 import org.openstreetmap.josm.gui.util.GuiHelper; 41 45 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; … … 96 100 */ 97 101 public static Future<?> openFiles(List<File> fileList) { 98 return openFiles(fileList, false);102 return openFiles(fileList, (Options[]) null); 99 103 } 100 104 … … 105 109 * @return the future task 106 110 * @since 11986 (return task) 107 */ 111 * @deprecated Since 17534, use {@link OpenFileAction#openFiles(List, Options...)} with {@link Options#RECORD_HISTORY} instead. 112 */ 113 @Deprecated 108 114 public static Future<?> openFiles(List<File> fileList, boolean recordHistory) { 115 Options[] options = recordHistory ? new Options[] {Options.RECORD_HISTORY} : null; 116 return openFiles(fileList, options); 117 } 118 119 /** 120 * Open a list of files. The complete list will be passed to batch importers. 121 * @param fileList A list of files 122 * @param options The options to use 123 * @return the future task 124 * @since 17534 ({@link Options}) 125 */ 126 public static Future<?> openFiles(List<File> fileList, Options... options) { 109 127 OpenFileTask task = new OpenFileTask(fileList, null); 110 task.set RecordHistory(recordHistory);128 task.setOptions(options); 111 129 return MainApplication.worker.submit(task); 112 130 } … … 122 140 private final FileFilter fileFilter; 123 141 private boolean canceled; 124 private boolean recordHistory;142 private final EnumSet<Options> options = EnumSet.noneOf(Options.class); 125 143 126 144 /** … … 168 186 * Sets whether to save filename in history (for list of recently opened files). 169 187 * @param recordHistory {@code true} to save filename in history (default: false) 170 */ 188 * @deprecated since 17534 (use {@link #setOptions} instead). 189 */ 190 @Deprecated 171 191 public void setRecordHistory(boolean recordHistory) { 172 this.recordHistory = recordHistory; 192 if (recordHistory) { 193 this.options.add(Options.RECORD_HISTORY); 194 } else { 195 this.options.remove(Options.RECORD_HISTORY); 196 } 197 } 198 199 /** 200 * Set the options for the task. 201 * @param options The options to set 202 * @see Options 203 * @since 17534 204 */ 205 public void setOptions(Options[] options) { 206 this.options.clear(); 207 if (options != null) { 208 Stream.of(options).filter(Objects::nonNull).forEach(this.options::add); 209 } 173 210 } 174 211 … … 178 215 */ 179 216 public boolean isRecordHistory() { 180 return recordHistory; 217 return this.options.contains(Options.RECORD_HISTORY); 218 } 219 220 /** 221 * Get the options for this task 222 * @return A set of options 223 * @since 17534 224 */ 225 public Set<Options> getOptions() { 226 return Collections.unmodifiableSet(this.options); 181 227 } 182 228 … … 340 386 } 341 387 342 if ( recordHistory) {388 if (this.options.contains(Options.RECORD_HISTORY)) { 343 389 Collection<String> oldFileHistory = Config.getPref().getList("file-open.history"); 344 390 fileHistory.addAll(oldFileHistory); … … 356 402 */ 357 403 public void importData(FileImporter importer, List<File> files) { 404 importer.setOptions(this.options.toArray(new Options[0])); 358 405 if (importer.isBatchImporter()) { 359 406 if (canceled) return; … … 373 420 } 374 421 } 375 if ( recordHistory&& !importer.isBatchImporter()) {422 if (this.options.contains(Options.RECORD_HISTORY) && !importer.isBatchImporter()) { 376 423 for (File f : files) { 377 424 try { -
trunk/src/org/openstreetmap/josm/gui/io/importexport/FileImporter.java
r16553 r17534 6 6 import java.io.File; 7 7 import java.io.IOException; 8 import java.util.EnumSet; 8 9 import java.util.List; 10 import java.util.Objects; 11 import java.util.stream.Stream; 9 12 10 13 import javax.swing.JOptionPane; … … 36 39 37 40 private boolean enabled; 41 42 protected final EnumSet<Options> options = EnumSet.noneOf(Options.class); 38 43 39 44 /** … … 191 196 this.enabled = enabled; 192 197 } 198 199 /** 200 * Set the options for the {@code FileImporter}. 201 * @param options The options to set 202 * @since 17534 203 */ 204 public final void setOptions(Options[] options) { 205 this.options.clear(); 206 if (options != null) { 207 Stream.of(options).filter(Objects::nonNull).forEach(this.options::add); 208 } 209 } 193 210 } -
trunk/src/org/openstreetmap/josm/gui/io/importexport/JpgImporter.java
r16970 r17534 8 8 import java.util.ArrayList; 9 9 import java.util.Arrays; 10 import java.util.EnumSet; 10 11 import java.util.HashSet; 11 12 import java.util.List; 12 13 import java.util.Set; 14 import java.util.regex.Matcher; 15 import java.util.regex.Pattern; 13 16 14 17 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 16 19 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 17 20 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 import org.openstreetmap.josm.io.CachedFile; 18 22 import org.openstreetmap.josm.io.IllegalDataException; 19 23 … … 23 27 */ 24 28 public class JpgImporter extends FileImporter { 29 /** Check if the filename starts with a borked path ({@link java.io.File#File} drops consecutive {@code /} characters). */ 30 private static final Pattern URL_START_BAD = Pattern.compile("^(https?:/)([^/].*)$"); 31 /** Check for the beginning of a "good" url */ 32 private static final Pattern URL_START_GOOD = Pattern.compile("^https?://.*$"); 33 25 34 private GpxLayer gpx; 26 35 … … 74 83 List<File> files = new ArrayList<>(); 75 84 Set<String> visitedDirs = new HashSet<>(); 76 addRecursiveFiles( files, visitedDirs, sel, progressMonitor.createSubTaskMonitor(1, true));85 addRecursiveFiles(this.options, files, visitedDirs, sel, progressMonitor.createSubTaskMonitor(1, true)); 77 86 78 87 if (progressMonitor.isCanceled()) … … 90 99 static void addRecursiveFiles(List<File> files, Set<String> visitedDirs, List<File> sel, ProgressMonitor progressMonitor) 91 100 throws IOException { 101 addRecursiveFiles(EnumSet.noneOf(Options.class), files, visitedDirs, sel, progressMonitor); 102 } 103 104 static void addRecursiveFiles(Set<Options> options, List<File> files, Set<String> visitedDirs, List<File> sel, 105 ProgressMonitor progressMonitor) throws IOException { 92 106 93 107 if (progressMonitor.isCanceled()) … … 101 115 File[] dirFiles = f.listFiles(); // Can be null for some strange directories (like lost+found) 102 116 if (dirFiles != null) { 103 addRecursiveFiles(files, visitedDirs, Arrays.asList(dirFiles), progressMonitor.createSubTaskMonitor(1, true)); 117 addRecursiveFiles(options, files, visitedDirs, Arrays.asList(dirFiles), 118 progressMonitor.createSubTaskMonitor(1, true)); 104 119 } 105 120 } else { … … 107 122 } 108 123 } else { 109 if (FILE_FILTER.accept(f)) { 124 /* Check if the path is a web path, and if so, ensure that it is "correct" */ 125 final String path = f.getPath(); 126 Matcher matcherBad = URL_START_BAD.matcher(path); 127 final String realPath; 128 if (matcherBad.matches()) { 129 realPath = matcherBad.replaceFirst(matcherBad.group(1) + "/" + matcherBad.group(2)); 130 } else { 131 realPath = path; 132 } 133 if (URL_START_GOOD.matcher(realPath).matches() && FILE_FILTER.accept(f) 134 && options.contains(Options.ALLOW_WEB_RESOURCES)) { 135 try (CachedFile cachedFile = new CachedFile(realPath)) { 136 files.add(cachedFile.getFile()); 137 } 138 } else if (FILE_FILTER.accept(f)) { 110 139 files.add(f); 111 140 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/PermissionPrefWithDefault.java
r16190 r17534 30 30 public static final PermissionPrefWithDefault OPEN_FILES = 31 31 new PermissionPrefWithDefault("remotecontrol.permission.open-files", false, tr("Open local files")); 32 /** Open web files */ 33 public static final PermissionPrefWithDefault ALLOW_WEB_RESOURCES = 34 new PermissionPrefWithDefault("remotecontrol.permission.open-remote-files", false, tr("Open remote files")); 32 35 /** Load imagery layers */ 33 36 public static final PermissionPrefWithDefault LOAD_IMAGERY = … … 45 48 public static final PermissionPrefWithDefault READ_PROTOCOL_VERSION = 46 49 new PermissionPrefWithDefault("remotecontrol.permission.read-protocolversion", true, tr("Read protocol version")); 50 47 51 /** 48 52 * name of the preference setting to permit the remote operation -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
r17330 r17534 163 163 addRequestHandlerClass(ImportHandler.command, ImportHandler.class, true); 164 164 addRequestHandlerClass(OpenFileHandler.command, OpenFileHandler.class, true); 165 PermissionPrefWithDefault.addPermissionPref(PermissionPrefWithDefault.ALLOW_WEB_RESOURCES); 165 166 addRequestHandlerClass(ImageryHandler.command, ImageryHandler.class, true); 166 167 PermissionPrefWithDefault.addPermissionPref(PermissionPrefWithDefault.CHANGE_SELECTION); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/OpenFileHandler.java
r10615 r17534 6 6 import java.io.File; 7 7 import java.util.Arrays; 8 import java.util.EnumSet; 8 9 9 10 import org.openstreetmap.josm.actions.OpenFileAction; 11 import org.openstreetmap.josm.gui.io.importexport.Options; 10 12 import org.openstreetmap.josm.gui.util.GuiHelper; 11 13 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; … … 43 45 @Override 44 46 protected void handleRequest() throws RequestHandlerErrorException, RequestHandlerBadRequestException { 45 GuiHelper.runInEDTAndWait(() -> OpenFileAction.openFiles(Arrays.asList(new File(args.get("filename"))))); 47 EnumSet<Options> options = EnumSet.noneOf(Options.class); 48 if (PermissionPrefWithDefault.ALLOW_WEB_RESOURCES.isAllowed()) { 49 options.add(Options.ALLOW_WEB_RESOURCES); 50 } 51 GuiHelper.runInEDTAndWait(() -> 52 OpenFileAction.openFiles(Arrays.asList(new File(args.get("filename"))), options.toArray(new Options[0]))); 46 53 } 47 54
Note:
See TracChangeset
for help on using the changeset viewer.