source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java@ 4234

Last change on this file since 4234 was 4043, checked in by stoecker, 13 years ago

fix #6153 - spelling fixes

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.util.Collection;
8import java.util.Map;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.command.Command;
12import org.openstreetmap.josm.command.DeleteCommand;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.validation.Severity;
16import org.openstreetmap.josm.data.validation.Test;
17import org.openstreetmap.josm.data.validation.TestError;
18import org.openstreetmap.josm.gui.progress.ProgressMonitor;
19
20/**
21 * Checks for nodes with uninteresting tags that are in no way
22 *
23 * @author frsantos
24 */
25public class UntaggedNode extends Test {
26
27 protected static final int UNTAGGED_NODE_BLANK = 201;
28 protected static final int UNTAGGED_NODE_FIXME = 202;
29 protected static final int UNTAGGED_NODE_NOTE = 203;
30 protected static final int UNTAGGED_NODE_CREATED_BY = 204;
31 protected static final int UNTAGGED_NODE_WATCH = 205;
32 protected static final int UNTAGGED_NODE_SOURCE = 206;
33 protected static final int UNTAGGED_NODE_OTHER = 207;
34
35 /**
36 * Constructor
37 */
38 public UntaggedNode() {
39 super(tr("Untagged and unconnected nodes."),
40 tr("This test checks for untagged nodes that are not part of any way."));
41 }
42
43 @Override
44 public void startTest(ProgressMonitor monitor) {
45 super.startTest(monitor);
46 }
47
48 @Override
49 public void visit(Collection<OsmPrimitive> selection) {
50 for (OsmPrimitive p : selection) {
51 if (p.isUsable() && p instanceof Node) {
52 p.visit(this);
53 }
54 }
55 }
56
57 @Override
58 public void visit(Node n) {
59 if(n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty()) {
60 if (!n.hasKeys()) {
61 String msg = marktr("No tags");
62 errors.add(new TestError(this, Severity.WARNING, tr("Unconnected nodes without physical tags"), tr(msg), msg, UNTAGGED_NODE_BLANK, n));
63 return;
64 }
65 for (Map.Entry<String, String> tag : n.getKeys().entrySet()) {
66 String key = tag.getKey();
67 if (contains(tag, "fixme") || contains(tag, "FIXME")) {
68 /* translation note: don't translate quoted words */
69 String msg = marktr("Has tag containing ''fixme'' or ''FIXME''");
70 errors.add(new TestError(this, Severity.WARNING, tr("Unconnected nodes without physical tags"),
71 tr(msg), msg, UNTAGGED_NODE_FIXME, n));
72 return;
73 }
74
75 String msg = null;
76 int code = 0;
77 if (key.startsWith("note") || key.startsWith("comment") || key.startsWith("description")) {
78 /* translation note: don't translate quoted words */
79 msg = marktr("Has key ''note'' or ''comment'' or ''description''");
80 code = UNTAGGED_NODE_NOTE;
81 } else if (key.startsWith("created_by") || key.startsWith("converted_by")) {
82 /* translation note: don't translate quoted words */
83 msg = marktr("Has key ''created_by'' or ''converted_by''");
84 code = UNTAGGED_NODE_CREATED_BY;
85 } else if (key.startsWith("watch")) {
86 /* translation note: don't translate quoted words */
87 msg = marktr("Has key ''watch''");
88 code = UNTAGGED_NODE_WATCH;
89 } else if (key.startsWith("source")) {
90 /* translation note: don't translate quoted words */
91 msg = marktr("Has key ''source''");
92 code = UNTAGGED_NODE_SOURCE;
93 }
94 if (msg != null) {
95 errors.add(new TestError(this, Severity.WARNING, tr("Unconnected nodes without physical tags"),
96 tr(msg), msg, code, n));
97 return;
98 }
99 }
100 // Does not happen, but just to be sure. Maybe definition of uninteresting tags changes in future.
101 errors.add(new TestError(this, Severity.WARNING, tr("Unconnected nodes without physical tags"),
102 tr("Other"), "Other", UNTAGGED_NODE_OTHER, n));
103 }
104 }
105
106 private boolean contains(Map.Entry<String, String> tag, String s) {
107 return tag.getKey().indexOf(s) != -1 || tag.getValue().indexOf(s) != -1;
108 }
109
110 @Override
111 public Command fixError(TestError testError) {
112 return DeleteCommand.delete(Main.map.mapView.getEditLayer(), testError.getPrimitives());
113 }
114
115 @Override
116 public boolean isFixable(TestError testError) {
117 if (testError.getTester() instanceof UntaggedNode) {
118 int code = testError.getCode();
119 switch (code) {
120 case UNTAGGED_NODE_BLANK:
121 case UNTAGGED_NODE_CREATED_BY:
122 case UNTAGGED_NODE_WATCH:
123 case UNTAGGED_NODE_SOURCE:
124 return true;
125 }
126 }
127 return false;
128 }
129}
Note: See TracBrowser for help on using the repository browser.