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