Changeset 9854 in osm for applications/editors/josm/plugins/validator
- Timestamp:
- 2008-08-15T13:47:07+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/validator
- Files:
-
- 3 edited
-
src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java (modified) (9 diffs)
-
src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java (modified) (3 diffs)
-
tagchecker.cfg (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java
r9755 r9854 42 42 import org.openstreetmap.josm.data.osm.Node; 43 43 import org.openstreetmap.josm.data.osm.OsmPrimitive; 44 import org.openstreetmap.josm.data.osm.OsmUtils; 45 import org.openstreetmap.josm.data.osm.Relation; 44 46 import org.openstreetmap.josm.data.osm.Way; 45 47 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; … … 121 123 protected static int INVALID_SPACE = 1204; 122 124 protected static int INVALID_KEY_SPACE = 1205; 123 protected static int TAG_CHECK = 1206;125 /** 1250 and up is used by tagcheck */ 124 126 125 127 /** List of sources for spellcheck data */ … … 276 278 if(d.match(p)) 277 279 { 278 errors.add( new TestError(this, Severity .WARNING, tr("Illegal tag/value combinations"),279 d.getDescription(), TAG_CHECK, p) );280 errors.add( new TestError(this, d.getSeverity(), tr("Illegal tag/value combinations"), 281 d.getDescription(), d.getCode(), p) ); 280 282 withErrors.add(p, "TC"); 281 283 break; … … 662 664 private List<CheckerElement> data = new ArrayList<CheckerElement>(); 663 665 private Integer type = 0; 666 private Integer code; 667 protected Severity severity; 664 668 protected static int NODE = 1; 665 669 protected static int WAY = 2; 666 protected static int ALL = 3; 670 protected static int RELATION = 3; 671 protected static int ALL = 4; 672 protected static int TAG_CHECK_ERROR = 1250; 673 protected static int TAG_CHECK_WARN = 1260; 674 protected static int TAG_CHECK_INFO = 1270; 667 675 668 676 private class CheckerElement { … … 672 680 public Boolean tagAll = false; 673 681 public Boolean valueAll = false; 682 public Boolean valueBool = false; 674 683 private Pattern getPattern(String str) throws IllegalStateException, PatternSyntaxException 675 684 { … … 694 703 if(n.equals("*")) 695 704 valueAll = true; 705 else if(n.equals("BOOLEAN_TRUE")) 706 { 707 valueBool = true; 708 value = OsmUtils.trueval; 709 } 710 else if(n.equals("BOOLEAN_FALSE")) 711 { 712 valueBool = true; 713 value = OsmUtils.falseval; 714 } 696 715 else 697 716 value = n.startsWith("/") ? getPattern(n) : n; 698 717 } 699 public Boolean match(String key, String val) 700 { 701 Boolean tagtrue = tagAll || (tag instanceof Pattern ? ((Pattern)tag).matcher(key).matches() : key.equals(tag)); 702 Boolean valtrue = valueAll || (value instanceof Pattern ? ((Pattern)value).matcher(val).matches() : val.equals(value)); 703 return tagtrue && (noMatch ? !valtrue : valtrue); 718 public Boolean match(OsmPrimitive osm) 719 { 720 for(Entry<String, String> prop: osm.keys.entrySet()) 721 { 722 String key = prop.getKey(); 723 String val = valueBool ? OsmUtils.getNamedOsmBoolean(prop.getValue()) : prop.getValue(); 724 if((tagAll || (tag instanceof Pattern ? ((Pattern)tag).matcher(key).matches() : key.equals(tag))) 725 && (valueAll || (value instanceof Pattern ? ((Pattern)value).matcher(val).matches() : val.equals(value)))) 726 return !noMatch; 727 } 728 return noMatch; 704 729 } 705 730 }; … … 719 744 description = null; 720 745 } 721 String[] n = str.split(" *: *", 2);746 String[] n = str.split(" *: *", 3); 722 747 if(n[0].equals("way")) 723 748 type = WAY; 724 749 else if(n[0].equals("node")) 725 750 type = NODE; 751 else if(n[0].equals("relation")) 752 type = RELATION; 726 753 else if(n[0].equals("*")) 727 754 type = ALL; 728 if(type == 0 || n.length != 2)755 if(type == 0 || n.length != 3) 729 756 return tr("Could not find element type"); 730 for(String exp: n[1].split(" *&& *")) 757 if(n[1].equals("W")) 758 { 759 severity = Severity.WARNING; 760 code = TAG_CHECK_WARN; 761 } 762 else if(n[1].equals("E")) 763 { 764 severity = Severity.ERROR; 765 code = TAG_CHECK_ERROR; 766 } 767 else if(n[1].equals("I")) 768 { 769 severity = Severity.OTHER; 770 code = TAG_CHECK_INFO; 771 } 772 else 773 return tr("Could not find warning level"); 774 for(String exp: n[2].split(" *&& *")) 731 775 { 732 776 try … … 747 791 public Boolean match(OsmPrimitive osm) 748 792 { 749 if(osm.keys == null) 793 if(osm.keys == null || (type == NODE && !(osm instanceof Node)) 794 || (type == RELATION && !(osm instanceof Relation)) || (type == WAY && !(osm instanceof Way))) 750 795 return false; 751 796 for(CheckerElement ce : data) 752 797 { 753 Boolean result = false; 754 for(Entry<String, String> prop: osm.keys.entrySet()) 755 { 756 if(result = ce.match(prop.getKey(), prop.getValue())) 757 break; 758 } 759 if(!result) 798 if(!ce.match(osm)) 760 799 return false; 761 800 } … … 766 805 return tr(description); 767 806 } 807 public Severity getSeverity() 808 { 809 return severity; 810 } 811 public int getCode() 812 { 813 return code + type; 814 } 768 815 } 769 816 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java
r9684 r9854 7 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 8 import org.openstreetmap.josm.data.osm.Way; 9 import org.openstreetmap.josm.data.osm.OsmUtils; 9 10 import org.openstreetmap.josm.data.coor.LatLon; 10 11 import org.openstreetmap.josm.plugins.validator.Severity; … … 110 111 mode = 1108; 111 112 } 112 test =w.get("building");113 if (test != null && ("true".equalsIgnoreCase(test) || "yes".equalsIgnoreCase(test) || "1".equals(test)))113 Boolean btest = OsmUtils.getOsmBoolean(w.get("building")); 114 if (btest != null && btest) 114 115 { 115 116 force = true; … … 117 118 mode = 1120; 118 119 } 119 test =w.get("area");120 if (test != null && ("true".equalsIgnoreCase(test) || "yes".equalsIgnoreCase(test) || "1".equals(test)))120 btest = OsmUtils.getOsmBoolean(w.get("area")); 121 if (btest != null && btest) 121 122 { 122 123 force = true; -
applications/editors/josm/plugins/validator/tagchecker.cfg
r9745 r9854 3 3 # format: 4 4 # each line specifies a certain error to be reported 5 # <data type>: <key><expression><value> 5 # <data type> : messagetype : <key><expression><value> 6 6 # 7 7 # data type can be: … … 11 11 # * - all data types 12 12 # 13 # message type can be: 14 # E - an error 15 # W - a warning 16 # I - an low priority informational warning 17 # 13 18 # key and value are expressions describing certain keys and values of these keys 14 19 # regulator expressions are supported. In this case the expressions starts and 15 # ends with // signs. The * sign indicates any string. 20 # ends with // signs. If an i is appended, the regular expression is 21 # case insensitive. 16 22 # 17 # expression can be: 23 # The * sign indicates any string. 24 # The texts BOOLEAN_TRUE and BOOLEAN_FALSE in the value part indicate a special 25 # handling for boolean values (yes, true, 0, false, no, ...). 26 # 27 # Expression can be: 18 28 # != - the key/value combination does not match 19 29 # == - the key/value combination does match … … 26 36 # Empty lines and space signs are ignored 27 37 28 node : oneway == * # oneway tag on a node 29 node : highway == tertiary # wrong highway tag on a node 30 node : highway == secondary # wrong highway tag on a node 31 way : highway == secondary && ref != * # highway without a reference 32 way : highway == tertiary && ref != * # highway without a reference 33 * : / *name */i == * && name != * # misspelled key 38 node : W : oneway == * # oneway tag on a node 39 node : W : bridge == BOOLEAN_TRUE # bridge tag on a node 40 node : W : highway == tertiary # wrong highway tag on a node 41 node : W : highway == secondary # wrong highway tag on a node 42 node : W : highway == residential # wrong highway tag on a node 43 node : W : highway == unclassified # wrong highway tag on a node 44 node : W : highway == track # wrong highway tag on a node 45 way : I : highway == secondary && ref != * # highway without a reference 46 way : I : highway == tertiary && ref != * # highway without a reference 47 * : W : / *name */i == * && name != * # misspelled key name
Note:
See TracChangeset
for help on using the changeset viewer.
