Ignore:
Timestamp:
2008-08-15T13:47:07+02:00 (17 years ago)
Author:
stoecker
Message:

finished TagChecker

Location:
applications/editors/josm/plugins/validator
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java

    r9755 r9854  
    4242import org.openstreetmap.josm.data.osm.Node;
    4343import org.openstreetmap.josm.data.osm.OsmPrimitive;
     44import org.openstreetmap.josm.data.osm.OsmUtils;
     45import org.openstreetmap.josm.data.osm.Relation;
    4446import org.openstreetmap.josm.data.osm.Way;
    4547import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference;
     
    121123        protected static int INVALID_SPACE     = 1204;
    122124        protected static int INVALID_KEY_SPACE = 1205;
    123         protected static int TAG_CHECK         = 1206;
     125        /** 1250 and up is used by tagcheck */
    124126
    125127        /** List of sources for spellcheck data */
     
    276278                                if(d.match(p))
    277279                                {
    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) );
    280282                                        withErrors.add(p, "TC");
    281283                                        break;
     
    662664                private List<CheckerElement> data = new ArrayList<CheckerElement>();
    663665                private Integer type = 0;
     666                private Integer code;
     667                protected Severity severity;
    664668                protected static int NODE = 1;
    665669                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;
    667675
    668676                private class CheckerElement {
     
    672680                        public Boolean tagAll = false;
    673681                        public Boolean valueAll = false;
     682                        public Boolean valueBool = false;
    674683                        private Pattern getPattern(String str) throws IllegalStateException, PatternSyntaxException
    675684                        {
     
    694703                                if(n.equals("*"))
    695704                                        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                                }
    696715                                else
    697716                                        value = n.startsWith("/") ? getPattern(n) : n;
    698717                        }
    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;
    704729                        }
    705730                };
     
    719744                                description = null;
    720745                        }
    721                         String[] n = str.split(" *: *", 2);
     746                        String[] n = str.split(" *: *", 3);
    722747                        if(n[0].equals("way"))
    723748                                type = WAY;
    724749                        else if(n[0].equals("node"))
    725750                                type = NODE;
     751                        else if(n[0].equals("relation"))
     752                                type = RELATION;
    726753                        else if(n[0].equals("*"))
    727754                                type = ALL;
    728                         if(type == 0 || n.length != 2)
     755                        if(type == 0 || n.length != 3)
    729756                                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(" *&& *"))
    731775                        {
    732776                                try
     
    747791                public Boolean match(OsmPrimitive osm)
    748792                {
    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)))
    750795                                return false;
    751796                        for(CheckerElement ce : data)
    752797                        {
    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))
    760799                                        return false;
    761800                        }
     
    766805                        return tr(description);
    767806                }
     807                public Severity getSeverity()
     808                {
     809                        return severity;
     810                }
     811                public int getCode()
     812                {
     813                        return code + type;
     814                }
    768815        }
    769816}
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java

    r9684 r9854  
    77import org.openstreetmap.josm.data.osm.OsmPrimitive;
    88import org.openstreetmap.josm.data.osm.Way;
     9import org.openstreetmap.josm.data.osm.OsmUtils;
    910import org.openstreetmap.josm.data.coor.LatLon;
    1011import org.openstreetmap.josm.plugins.validator.Severity;
     
    110111                        mode = 1108;
    111112                }
    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)
    114115                {
    115116                        force = true;
     
    117118                        mode = 1120;
    118119                }
    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)
    121122                {
    122123                        force = true;
  • applications/editors/josm/plugins/validator/tagchecker.cfg

    r9745 r9854  
    33# format:
    44# each line specifies a certain error to be reported
    5 # <data type>: <key><expression><value>
     5# <data type> : messagetype : <key><expression><value>
    66#
    77# data type can be:
     
    1111#  *           - all data types
    1212#
     13# message type can be:
     14# E            - an error
     15# W            - a warning
     16# I            - an low priority informational warning
     17#
    1318# key and value are expressions describing certain keys and values of these keys
    1419# 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.
    1622#
    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:
    1828#  !=          - the key/value combination does not match
    1929#  ==          - the key/value combination does match
     
    2636# Empty lines and space signs are ignored
    2737
    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
     38node : W : oneway == *                                         # oneway tag on a node
     39node : W : bridge == BOOLEAN_TRUE                              # bridge tag on a node
     40node : W : highway == tertiary                                 # wrong highway tag on a node
     41node : W : highway == secondary                                # wrong highway tag on a node
     42node : W : highway == residential                              # wrong highway tag on a node
     43node : W : highway == unclassified                             # wrong highway tag on a node
     44node : W : highway == track                                    # wrong highway tag on a node
     45way  : I : highway == secondary && ref != *                    # highway without a reference
     46way  : 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.