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

Last change on this file since 12671 was 12620, checked in by Don-vip, 7 years ago

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Locale;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.tools.Logging;
10
11/**
12 * The chunk mode to use when uploading
13 */
14public enum UploadStrategy {
15 /**
16 * Uploads the objects individually, one request per object
17 */
18 INDIVIDUAL_OBJECTS_STRATEGY("individualobjects"),
19 /**
20 * Upload the objects in junks of n objects using m diff uploads
21 */
22 CHUNKED_DATASET_STRATEGY("chunked"),
23 /**
24 * Upload the objects in one request using 1 diff upload
25 */
26 SINGLE_REQUEST_STRATEGY("singlerequest");
27
28 private final String preferenceValue;
29
30 UploadStrategy(String preferenceValue) {
31 this.preferenceValue = preferenceValue;
32 }
33
34 /**
35 * Reads the value from preferences
36 * @param preferenceValue The preference value
37 * @return The {@link UploadStrategy} for that preference or <code>null</code> if unknown
38 */
39 public static UploadStrategy fromPreference(String preferenceValue) {
40 if (preferenceValue == null) return null;
41 preferenceValue = preferenceValue.trim().toLowerCase(Locale.ENGLISH);
42 for (UploadStrategy strategy: values()) {
43 if (strategy.getPreferenceValue().equals(preferenceValue))
44 return strategy;
45 }
46 return null;
47 }
48
49 /**
50 * Replies the value which is written to the preferences for a specific
51 * upload strategy
52 *
53 * @return the value which is written to the preferences for a specific
54 * upload strategy
55 */
56 public String getPreferenceValue() {
57 return preferenceValue;
58 }
59
60 /**
61 * the default upload strategy
62 */
63 public static final UploadStrategy DEFAULT_UPLOAD_STRATEGY = SINGLE_REQUEST_STRATEGY;
64
65 /**
66 * Replies the upload strategy currently configured in the preferences.
67 *
68 * First checks for the preference key <pre>osm-server.upload-strategy</pre>. If not
69 * present, checks for the legacy preference key <pre>osm-server.atomic-upload</pre>.
70 *
71 * If both are 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 = Main.pref.get("osm-server.upload-strategy", null);
78 if (v == null) {
79 // legacy support. Until 12/2009 we had osm-server.atomic-upload only.
80 // If we still find "osm-server.atomic-upload" we use it and remove it.
81 // When the preferences are saved the next time, "osm-server.upload-strategy"
82 // will be inserted.
83 v = Main.pref.get("osm-server.atomic-upload", null);
84 if (v != null) {
85 Main.pref.removeFromCollection("osm-server.atomic-upload", v);
86 } else {
87 v = "";
88 }
89 v = v.trim().toLowerCase(Locale.ENGLISH);
90 if ("true".equals(v))
91 return SINGLE_REQUEST_STRATEGY;
92 else if ("false".equals(v))
93 return INDIVIDUAL_OBJECTS_STRATEGY;
94 else
95 return DEFAULT_UPLOAD_STRATEGY;
96 }
97 UploadStrategy strategy = fromPreference(v);
98 if (strategy == null) {
99 Logging.warn(tr("Unexpected value for key ''{0}'' in preferences, got ''{1}''", "osm-server.upload-strategy", v));
100 return DEFAULT_UPLOAD_STRATEGY;
101 }
102 return strategy;
103 }
104
105 /**
106 * Saves the upload strategy <code>strategy</code> to the preferences.
107 *
108 * @param strategy the strategy to save
109 */
110 public static void saveToPreferences(UploadStrategy strategy) {
111 Main.pref.put("osm-server.upload-strategy", strategy.getPreferenceValue());
112 }
113}
Note: See TracBrowser for help on using the repository browser.