Package org.openstreetmap.josm.data.validation

Examples of org.openstreetmap.josm.data.validation.TestError


            if (parent instanceof Relation && ((Relation)parent).isMultipolygon())
                return;
        }

        for (UnclosedWaysCheck c : checks) {
            TestError error = c.getTestError(w);
            if (error != null) {
                errors.add(error);
                return;
            }
        }
View Full Code Here


        public final TestError getTestError(Way w) {
            String value = w.get(key);
            if (isValueErroneous(value)) {
                String  type = engMessage.contains("{0}") ? tr(engMessage, tr(value)) : tr(engMessage);
                String etype = engMessage.contains("{0}") ? MessageFormat.format(engMessage, value) : engMessage;
                return new TestError(UnclosedWays.this, Severity.WARNING, tr("Unclosed way"),
                        type, etype, code, Arrays.asList(w),
                        // The important parts of an unclosed way are the first and
                        // the last node which should be connected, therefore we highlight them
                        Arrays.asList(w.firstNode(), w.lastNode()));
            }
View Full Code Here

    public void visit(Node n) {
        if (n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty()) {
            String errorMessage = tr("Unconnected nodes without physical tags");
            if (!n.hasKeys()) {
                String msg = marktr("No tags");
                errors.add(new TestError(this, Severity.WARNING, errorMessage, tr(msg), msg, UNTAGGED_NODE_BLANK, n));
                return;
            }
            for (Map.Entry<String, String> tag : n.getKeys().entrySet()) {
                String key = tag.getKey();
                if (contains(tag, "fixme") || contains(tag, "FIXME")) {
                    /* translation note: don't translate quoted words */
                    String msg = marktr("Has tag containing ''fixme'' or ''FIXME''");
                    errors.add(new TestError(this, Severity.WARNING, errorMessage, tr(msg), msg, UNTAGGED_NODE_FIXME, n));
                    return;
                }

                String msg = null;
                int code = 0;
                if (key.startsWith("note") || key.startsWith("comment") || key.startsWith("description")) {
                    /* translation note: don't translate quoted words */
                    msg = marktr("Has key ''note'' or ''comment'' or ''description''");
                    code = UNTAGGED_NODE_NOTE;
                } else if (key.startsWith("created_by") || key.startsWith("converted_by")) {
                    /* translation note: don't translate quoted words */
                    msg = marktr("Has key ''created_by'' or ''converted_by''");
                    code = UNTAGGED_NODE_CREATED_BY;
                } else if (key.startsWith("watch")) {
                    /* translation note: don't translate quoted words */
                    msg = marktr("Has key ''watch''");
                    code = UNTAGGED_NODE_WATCH;
                } else if (key.startsWith("source")) {
                    /* translation note: don't translate quoted words */
                    msg = marktr("Has key ''source''");
                    code = UNTAGGED_NODE_SOURCE;
                }
                if (msg != null) {
                    errors.add(new TestError(this, Severity.WARNING, errorMessage, tr(msg), msg, code, n));
                    return;
                }
            }
            // Does not happen, but just to be sure. Maybe definition of uninteresting tags changes in future.
            errors.add(new TestError(this, Severity.WARNING, errorMessage, tr("Other"), "Other", UNTAGGED_NODE_OTHER, n));
        }
    }
View Full Code Here

        });
    }

    private void testHighwayLink(final Way way) {
        if (!isHighwayLinkOkay(way)) {
            errors.add(new TestError(this, Severity.WARNING,
                    tr("Highway link is not linked to adequate highway/link"), SOURCE_WRONG_LINK, way));
        }
    }
View Full Code Here

                    // - service highways support is TBD (see #9141 comments)
                    // - roads should be determined first. Another warning is raised anyway
                    handleCarWay(n, w);
                }
                if ((leftByPedestrians || leftByCyclists) && leftByCars) {
                    errors.add(new TestError(this, Severity.OTHER, tr("Missing pedestrian crossing information"), MISSING_PEDESTRIAN_CROSSING, n));
                    return;
                }
            }
        }
    }
View Full Code Here

        if (value.matches("[A-Z]{2}:.+")) {
            int index = value.indexOf(':');
            // Check country
            String country = value.substring(0, index);
            if (!ISO_COUNTRIES.contains(country)) {
                errors.add(new TestError(this, Severity.WARNING, tr("Unknown country code: {0}", country), SOURCE_MAXSPEED_UNKNOWN_COUNTRY_CODE, p));
            }
            // Check context
            String context = value.substring(index+1);
            if (!KNOWN_SOURCE_MAXSPEED_CONTEXTS.contains(context)) {
                errors.add(new TestError(this, Severity.WARNING, tr("Unknown source:maxspeed context: {0}", context), SOURCE_MAXSPEED_UNKNOWN_CONTEXT, p));
            }
            // TODO: Check coherence of context against maxspeed
            // TODO: Check coherence of context against highway
        }
    }
View Full Code Here

        HashSet<Node> nodes = new HashSet<>();

        for (int i = 1; i < w.getNodesCount() - 1; i++) {
            Node n = w.getNode(i);
            if (nodes.contains(n)) {
                errors.add(new TestError(this,
                        Severity.WARNING, tr("Self-intersecting ways"), SELF_INTERSECT,
                        Arrays.asList(w), Arrays.asList(n)));
                break;
            } else {
                nodes.add(n);
View Full Code Here

            return;

    }

    private void reportError(Way w, String msg, int type) {
        errors.add(new TestError(this, Severity.WARNING, msg, type, Collections.singletonList(w)));
    }
View Full Code Here

        if (checkComplex) {
            Map<String, String> keys = p.getKeys();
            for (CheckerData d : checkerData) {
                if (d.match(p, keys)) {
                    errors.add( new TestError(this, d.getSeverity(), tr("Suspicious tag/value combinations"),
                            d.getDescription(), d.getDescriptionOrig(), d.getCode(), p) );
                    withErrors.put(p, "TC");
                }
            }
        }

        for (Entry<String, String> prop : p.getKeys().entrySet()) {
            String s = marktr("Key ''{0}'' invalid.");
            String key = prop.getKey();
            String value = prop.getValue();
            if (checkValues && (containsLow(value)) && !withErrors.contains(p, "ICV")) {
                errors.add( new TestError(this, Severity.WARNING, tr("Tag value contains character with code less than 0x20"),
                        tr(s, key), MessageFormat.format(s, key), LOW_CHAR_VALUE, p) );
                withErrors.put(p, "ICV");
            }
            if (checkKeys && (containsLow(key)) && !withErrors.contains(p, "ICK")) {
                errors.add( new TestError(this, Severity.WARNING, tr("Tag key contains character with code less than 0x20"),
                        tr(s, key), MessageFormat.format(s, key), LOW_CHAR_KEY, p) );
                withErrors.put(p, "ICK");
            }
            if (checkValues && (value!=null && value.length() > 255) && !withErrors.contains(p, "LV")) {
                errors.add( new TestError(this, Severity.ERROR, tr("Tag value longer than allowed"),
                        tr(s, key), MessageFormat.format(s, key), LONG_VALUE, p) );
                withErrors.put(p, "LV");
            }
            if (checkKeys && (key!=null && key.length() > 255) && !withErrors.contains(p, "LK")) {
                errors.add( new TestError(this, Severity.ERROR, tr("Tag key longer than allowed"),
                        tr(s, key), MessageFormat.format(s, key), LONG_KEY, p) );
                withErrors.put(p, "LK");
            }
            if (checkValues && (value==null || value.trim().length() == 0) && !withErrors.contains(p, "EV")) {
                errors.add( new TestError(this, Severity.WARNING, tr("Tags with empty values"),
                        tr(s, key), MessageFormat.format(s, key), EMPTY_VALUES, p) );
                withErrors.put(p, "EV");
            }
            if (checkKeys && spellCheckKeyData.containsKey(key) && !withErrors.contains(p, "IPK")) {
                errors.add( new TestError(this, Severity.WARNING, tr("Invalid property key"),
                        tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p) );
                withErrors.put(p, "IPK");
            }
            if (checkKeys && key.indexOf(' ') >= 0 && !withErrors.contains(p, "IPK")) {
                errors.add( new TestError(this, Severity.WARNING, tr("Invalid white space in property key"),
                        tr(s, key), MessageFormat.format(s, key), INVALID_KEY_SPACE, p) );
                withErrors.put(p, "IPK");
            }
            if (checkValues && value != null && (value.startsWith(" ") || value.endsWith(" ")) && !withErrors.contains(p, "SPACE")) {
                errors.add( new TestError(this, Severity.WARNING, tr("Property values start or end with white space"),
                        tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) );
                withErrors.put(p, "SPACE");
            }
            if (checkValues && value != null && !value.equals(entities.unescape(value)) && !withErrors.contains(p, "HTML")) {
                errors.add( new TestError(this, Severity.OTHER, tr("Property values contain HTML entity"),
                        tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) );
                withErrors.put(p, "HTML");
            }
            if (checkValues && value != null && value.length() > 0 && presetsValueData != null) {
                final Set<String> values = presetsValueData.get(key);
                final boolean keyInPresets = values != null;
                final boolean tagInPresets = values != null && (values.isEmpty() || values.contains(prop.getValue()));

                boolean ignore = false;
                for (String a : ignoreDataStartsWith) {
                    if (key.startsWith(a)) {
                        ignore = true;
                    }
                }
                for (String a : ignoreDataEquals) {
                    if(key.equals(a)) {
                        ignore = true;
                    }
                }
                for (String a : ignoreDataEndsWith) {
                    if(key.endsWith(a)) {
                        ignore = true;
                    }
                }

                if (!tagInPresets) {
                    for (IgnoreKeyPair a : ignoreDataKeyPair) {
                        if (key.equals(a.key) && value.equals(a.value)) {
                            ignore = true;
                        }
                    }
                }

                if (!ignore) {
                    if (!keyInPresets) {
                        String i = marktr("Key ''{0}'' not in presets.");
                        errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property key"),
                                tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p) );
                        withErrors.put(p, "UPK");
                    } else if (!tagInPresets) {
                        String i = marktr("Value ''{0}'' for key ''{1}'' not in presets.");
                        errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property value"),
                                tr(i, prop.getValue(), key), MessageFormat.format(i, prop.getValue(), key), INVALID_VALUE, p) );
                        withErrors.put(p, "UPV");
                    }
                }
            }
            if (checkFixmes && value != null && value.length() > 0) {
                if ((value.toLowerCase().contains("fixme")
                        || value.contains("check and delete")
                        || key.contains("todo") || key.toLowerCase().contains("fixme"))
                        && !withErrors.contains(p, "FIXME")) {
                    errors.add(new TestError(this, Severity.OTHER,
                            tr("FIXMES"), FIXME, p));
                    withErrors.put(p, "FIXME");
                }
            }
        }
View Full Code Here

    private BoundingXYVisitor getBoundingBox() {
        BoundingXYVisitor v = "problem".equals(mode) ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor();

        switch(mode) {
        case "problem":
            TestError error = Main.map.validatorDialog.getSelectedError();
            if (error == null) return null;
            ((ValidatorBoundingXYVisitor) v).visit(error);
            if (v.getBounds() == null) return null;
            v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002));
            break;
View Full Code Here

TOP

Related Classes of org.openstreetmap.josm.data.validation.TestError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.