| 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 | |
| | 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 | } |