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

Last change on this file since 12542 was 12370, checked in by michael2402, 7 years ago

Document upload dialog classes

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