Changeset 4691 in josm
- Timestamp:
- 2011-12-21T23:19:49+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java
r4482 r4691 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn; 5 6 6 7 import java.io.IOException; … … 13 14 import java.text.ParseException; 14 15 import java.text.SimpleDateFormat; 16 import java.util.Collection; 15 17 import java.util.Date; 16 18 import java.util.Locale; 19 import java.util.Set; 20 import java.util.TreeSet; 17 21 import java.util.regex.Matcher; 18 22 import java.util.regex.Pattern; … … 84 88 return msg; 85 89 } 90 91 /** 92 * Explains a precondition exception when a child node could not be deleted because 93 * it is still referred to by undeleted parent ways. 94 * 95 * @param e the exception 96 * @param childNode the child node 97 * @param parentWays the parent ways 98 * @return 99 */ 100 public static String explainDeletedNodeStillInUse(OsmApiException e, long childNode, Collection<Long> parentWays) { 101 String ids = parentWays.size() == 1 ? parentWays.iterator().next().toString() : parentWays.toString(); 102 String msg = trn( 103 "<html><strong>Failed</strong> to delete <strong>node {0}</strong>." 104 + " It is still referred to by way {1}.<br>" 105 + "Please load way {1}, remove the reference to node {0}, and upload again.</html>", 106 "<html><strong>Failed</strong> to delete <strong>node {0}</strong>." 107 + " It is still referred to by ways {1}.<br>" 108 + "Please load ways {1}, remove the reference to node {0}, and upload again.</html>", 109 parentWays.size(), childNode, ids 110 ); 111 return msg; 112 } 86 113 87 114 /** … … 94 121 String msg = e.getErrorHeader(); 95 122 if (msg != null) { 96 String pattern = "Precondition failed: The relation (\\d+) is used in relation (\\d+)\\."; 97 Pattern p = Pattern.compile(pattern); 98 Matcher m = p.matcher(msg); 123 Matcher m = Pattern.compile("Precondition failed: The relation (\\d+) is used in relation (\\d+)\\.").matcher(msg); 99 124 if (m.matches()) { 100 125 long childRelation = Long.parseLong(m.group(1)); 101 126 long parentRelation = Long.parseLong(m.group(2)); 102 127 return explainDeletedRelationStillInUse(e, childRelation, parentRelation); 128 } 129 m = Pattern.compile("Precondition failed: Node (\\d+) is still used by ways (\\d+(?:,\\d+)*)\\.").matcher(msg); 130 if (m.matches()) { 131 long childNode = Long.parseLong(m.group(1)); 132 Set<Long> parentWays = new TreeSet<Long>(); // Error message can contain several times the same way 133 for (String s : m.group(2).split(",")) { 134 parentWays.add(Long.parseLong(s)); 135 } 136 return explainDeletedNodeStillInUse(e, childNode, parentWays); 103 137 } 104 138 }
Note:
See TracChangeset
for help on using the changeset viewer.