Changeset 19443 in josm
- Timestamp:
- 2025-10-09T11:03:09+02:00 (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/upload/ApiPreconditionCheckerHook.java
r19437 r19443 14 14 import org.openstreetmap.josm.data.osm.Tagged; 15 15 import org.openstreetmap.josm.data.osm.Way; 16 import org.openstreetmap.josm.data.preferences.AbstractProperty; 17 import org.openstreetmap.josm.data.preferences.BooleanProperty; 16 18 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 17 19 import org.openstreetmap.josm.gui.MainApplication; … … 30 32 */ 31 33 public class ApiPreconditionCheckerHook implements UploadHook { 34 static AbstractProperty<Boolean> PREF_LENGTH_CHECK = new BooleanProperty("upload.check-maxlength-value", true).cached(); 32 35 33 36 @Override … … 62 65 private static boolean checkMaxNodes(Collection<OsmPrimitive> primitives, long maxNodes) { 63 66 for (OsmPrimitive osmPrimitive : primitives) { 64 for (Map.Entry<String, String> entry: osmPrimitive.getKeys().entrySet()) { 65 String key = entry.getKey(); 66 String value = entry.getValue(); 67 if (!Utils.checkCodePointCount(value, Tagged.MAX_TAG_LENGTH)) { 68 if (osmPrimitive.isDeleted()) { 69 // if OsmPrimitive is going to be deleted we automatically shorten the value 70 Logging.warn( 71 tr("Automatically truncating value of tag ''{0}'' on deleted object {1}", 72 key, 73 Long.toString(osmPrimitive.getId()) 74 ) 75 ); 76 osmPrimitive.put(key, Utils.shortenString(value, Tagged.MAX_TAG_LENGTH)); 77 continue; 78 } 79 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 80 tr("Length of value for tag ''{0}'' on object {1} exceeds the max. allowed length {2}. Values length is {3}.", 81 key, Long.toString(osmPrimitive.getId()), Tagged.MAX_TAG_LENGTH, Utils.getCodePointCount(value) 82 ), 83 tr("Precondition violation"), 84 JOptionPane.ERROR_MESSAGE 85 ); 86 MainApplication.getLayerManager().getEditDataSet().setSelected(Collections.singleton(osmPrimitive)); 87 return false; 88 } 67 if (Boolean.TRUE.equals(PREF_LENGTH_CHECK.get()) && !valueLengthCheck(osmPrimitive)) { 68 return false; 89 69 } 90 70 … … 107 87 return true; 108 88 } 89 90 /** 91 * Check that the tag values of a primitive are not too long. 92 * @param osmPrimitive the primitive to check 93 * @return false if any tag value of the primitive is too long, true else 94 */ 95 private static boolean valueLengthCheck(OsmPrimitive osmPrimitive) { 96 for (Map.Entry<String, String> entry: osmPrimitive.getKeys().entrySet()) { 97 String key = entry.getKey(); 98 String value = entry.getValue(); 99 if (!Utils.checkCodePointCount(value, Tagged.MAX_TAG_LENGTH)) { 100 if (osmPrimitive.isDeleted()) { 101 // if OsmPrimitive is going to be deleted we automatically shorten the value 102 Logging.warn( 103 tr("Automatically truncating value of tag ''{0}'' on deleted object {1}", 104 key, 105 Long.toString(osmPrimitive.getId()) 106 ) 107 ); 108 osmPrimitive.put(key, Utils.shortenString(value, Tagged.MAX_TAG_LENGTH)); 109 continue; 110 } 111 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 112 tr("Length of value for tag ''{0}'' on object {1} exceeds the max. allowed length {2}. Values length is {3}.", 113 key, Long.toString(osmPrimitive.getId()), Tagged.MAX_TAG_LENGTH, Utils.getCodePointCount(value) 114 ), 115 tr("Precondition violation"), 116 JOptionPane.ERROR_MESSAGE 117 ); 118 MainApplication.getLayerManager().getEditDataSet().setSelected(Collections.singleton(osmPrimitive)); 119 return false; 120 } 121 } 122 return true; 123 } 109 124 }
Note:
See TracChangeset
for help on using the changeset viewer.
