source: josm/trunk/src/org/openstreetmap/josm/io/UploadStrategy.java@ 13608

Last change on this file since 13608 was 13064, checked in by Don-vip, 6 years ago

remove legacy properties (pluginmanager.warntime and osm-server.atomic-upload) kind-of-deprecated 8 years ago in r2569 and r2924

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Locale;
7
8import org.openstreetmap.josm.spi.preferences.Config;
9import org.openstreetmap.josm.tools.Logging;
10
11/**
12 * The chunk mode to use when uploading
13 * @since 12687 (moved from {@code gui.io} package)
14 */
15public enum UploadStrategy {
16 /**
17 * Uploads the objects individually, one request per object
18 */
19 INDIVIDUAL_OBJECTS_STRATEGY("individualobjects"),
20 /**
21 * Upload the objects in junks of n objects using m diff uploads
22 */
23 CHUNKED_DATASET_STRATEGY("chunked"),
24 /**
25 * Upload the objects in one request using 1 diff upload
26 */
27 SINGLE_REQUEST_STRATEGY("singlerequest");
28
29 private final String preferenceValue;
30
31 UploadStrategy(String preferenceValue) {
32 this.preferenceValue = preferenceValue;
33 }
34
35 /**
36 * Reads the value from preferences
37 * @param preferenceValue The preference value
38 * @return The {@link UploadStrategy} for that preference or <code>null</code> if unknown
39 */
40 public static UploadStrategy fromPreference(String preferenceValue) {
41 if (preferenceValue == null) return null;
42 preferenceValue = preferenceValue.trim().toLowerCase(Locale.ENGLISH);
43 for (UploadStrategy strategy: values()) {
44 if (strategy.getPreferenceValue().equals(preferenceValue))
45 return strategy;
46 }
47 return null;
48 }
49
50 /**
51 * Replies the value which is written to the preferences for a specific
52 * upload strategy
53 *
54 * @return the value which is written to the preferences for a specific
55 * upload strategy
56 */
57 public String getPreferenceValue() {
58 return preferenceValue;
59 }
60
61 /**
62 * the default upload strategy
63 */
64 public static final UploadStrategy DEFAULT_UPLOAD_STRATEGY = SINGLE_REQUEST_STRATEGY;
65
66 /**
67 * Replies the upload strategy currently configured in the preferences.
68 *
69 * Checks for the preference key <pre>osm-server.upload-strategy</pre>.
70 *
71 * If missing or if the preference value is illegal, {@link #DEFAULT_UPLOAD_STRATEGY}
72 * is replied.
73 *
74 * @return the upload strategy currently configured in the preferences.
75 */
76 public static UploadStrategy getFromPreferences() {
77 String v = Config.getPref().get("osm-server.upload-strategy", null);
78 if (v == null) {
79 return DEFAULT_UPLOAD_STRATEGY;
80 }
81 UploadStrategy strategy = fromPreference(v);
82 if (strategy == null) {
83 Logging.warn(tr("Unexpected value for key ''{0}'' in preferences, got ''{1}''", "osm-server.upload-strategy", v));
84 return DEFAULT_UPLOAD_STRATEGY;
85 }
86 return strategy;
87 }
88
89 /**
90 * Saves the upload strategy <code>strategy</code> to the preferences.
91 *
92 * @param strategy the strategy to save
93 */
94 public static void saveToPreferences(UploadStrategy strategy) {
95 Config.getPref().put("osm-server.upload-strategy", strategy.getPreferenceValue());
96 }
97}
Note: See TracBrowser for help on using the repository browser.