source: josm/trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java@ 729

Last change on this file since 729 was 729, checked in by stoecker, 16 years ago

added automatic tag correction system by Robin Rattay

File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.corrector;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.regex.Matcher;
8import java.util.regex.Pattern;
9
10import org.openstreetmap.josm.data.osm.OsmUtils;
11import org.openstreetmap.josm.data.osm.Way;
12
13public class ReverseWayTagCorrector extends TagCorrector<Way> {
14
15 private static final Pattern leftRightStartRegex = Pattern.compile(
16 "^(left|right):.*", Pattern.CASE_INSENSITIVE);
17
18 private static final Pattern leftRightEndRegex = Pattern.compile(
19 ".*:(left|right)$", Pattern.CASE_INSENSITIVE);
20
21 @Override public boolean execute(Way way) {
22
23 ArrayList<TagCorrection> tagCorrections = new ArrayList<TagCorrection>();
24
25 for (String key : way.keySet()) {
26 String newKey = key;
27 String value = way.get(key);
28 String newValue = value;
29
30 if (key.equals("oneway")) {
31 if (value.equals("-1"))
32 newValue = OsmUtils.trueval;
33 else {
34 Boolean boolValue = OsmUtils.getOsmBoolean(value);
35 if (boolValue != null && boolValue.booleanValue()) {
36 newValue = "-1";
37 }
38 }
39 } else {
40 Matcher m = leftRightStartRegex.matcher(key);
41 if (!m.matches())
42 m = leftRightEndRegex.matcher(key);
43
44 if (m.matches()) {
45 String leftRight = m.group(1).toLowerCase();
46
47 newKey = key.substring(0, m.start(1)).concat(
48 leftRight.equals("left") ? "right" : "left")
49 .concat(key.substring(m.end(1)));
50 }
51 }
52
53 if (key != newKey || value != newValue)
54 tagCorrections.add(new TagCorrection(key, value, newKey,
55 newValue));
56 }
57
58 return applyCorrections(tagCorrections, way,
59 tr("When reverting this way, following changes to the "
60 + "properties are suggested in order to maintain "
61 + "data consistency."));
62 }
63}
Note: See TracBrowser for help on using the repository browser.