Changeset 9755 in osm
- Timestamp:
- 2008-08-12T23:07:59+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorTreePanel.java
r9598 r9755 194 194 public void setErrors(List<TestError> newerrors) 195 195 { 196 if(errors == null) 197 return; 196 198 errors.clear(); 197 199 for(TestError error : newerrors) -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java
r9684 r9755 15 15 import java.io.IOException; 16 16 import java.io.UnsupportedEncodingException; 17 import java.lang.IllegalStateException; 17 18 import java.net.URL; 18 19 import java.util.ArrayList; … … 23 24 import java.util.Map; 24 25 import java.util.Map.Entry; 25 import java.util.StringTokenizer; 26 import java.util.regex.Matcher; 27 import java.util.regex.Pattern; 28 import java.util.regex.PatternSyntaxException; 26 29 27 30 import javax.swing.DefaultListModel; … … 140 143 /** 141 144 * Reads the spellcheck file into a HashMap. 142 * <p>143 145 * The data file is a list of words, beginning with +/-. If it starts with +, 144 146 * the word is valid, but if it starts with -, the word should be replaced … … 167 169 } 168 170 169 StringTokenizer st = new StringTokenizer(sources, ";"); 170 StringBuilder errorSources = new StringBuilder(); 171 while (st.hasMoreTokens()) 172 { 173 String source = st.nextToken(); 171 String errorSources = ""; 172 for(String source: sources.split(";")) 173 { 174 174 File sourceFile = Util.mirror(new URL(source), Util.getPluginDir(), -1); 175 175 if( sourceFile == null || !sourceFile.exists() ) 176 176 { 177 errorSources .append(source).append("\n");177 errorSources += source + "\n"; 178 178 continue; 179 179 } … … 203 203 checkerData.add(d); 204 204 else 205 System.err.println( "Invalid tagchecker line - "+err+":" + line);205 System.err.println(tr("Invalid tagchecker line - {0}: {1}", err, line)); 206 206 } 207 207 } … … 216 216 else 217 217 { 218 System.err.println( "Invalid spellcheck line:" + line);218 System.err.println(tr("Invalid spellcheck line: {0}", line)); 219 219 } 220 220 } … … 277 277 { 278 278 errors.add( new TestError(this, Severity.WARNING, tr("Illegal tag/value combinations"), 279 tr(d.description()), TAG_CHECK, p) );279 d.getDescription(), TAG_CHECK, p) ); 280 280 withErrors.add(p, "TC"); 281 281 break; … … 380 380 { 381 381 String allAnnotations = Main.pref.get("taggingpreset.sources"); 382 StringTokenizer st = new StringTokenizer(allAnnotations, ";"); 383 while (st.hasMoreTokens()) 382 for(String source : allAnnotations.split(";")) 384 383 { 385 384 InputStream in = null; 386 String source = st.nextToken();387 385 try 388 386 { … … 461 459 462 460 String sources = Main.pref.get( PREF_SOURCES ); 463 StringTokenizer st = new StringTokenizer(sources, ";"); 464 while (st.hasMoreTokens()) 465 ((DefaultListModel)Sources.getModel()).addElement(st.nextToken()); 461 for(String source : sources.split(";")) 462 ((DefaultListModel)Sources.getModel()).addElement(source); 466 463 467 464 addSrcButton = new JButton(tr("Add")); … … 598 595 if( Sources.getModel().getSize() > 0 ) 599 596 { 600 String Builder sb = new StringBuilder();597 String sb = ""; 601 598 for (int i = 0; i < Sources.getModel().getSize(); ++i) 602 sb .append(";"+Sources.getModel().getElementAt(i));599 sb += ";"+Sources.getModel().getElementAt(i); 603 600 sources = sb.substring(1); 604 601 } … … 662 659 663 660 private static class CheckerData { 664 public String getData(String data) 665 { 666 return "not implemented yet"; 661 private String description; 662 private List<CheckerElement> data = new ArrayList<CheckerElement>(); 663 private Integer type = 0; 664 protected static int NODE = 1; 665 protected static int WAY = 2; 666 protected static int ALL = 3; 667 668 private class CheckerElement { 669 public Object tag; 670 public Object value; 671 public Boolean noMatch; 672 public Boolean tagAll = false; 673 public Boolean valueAll = false; 674 private Pattern getPattern(String str) throws IllegalStateException, PatternSyntaxException 675 { 676 if(str.endsWith("/i")) 677 return Pattern.compile(str.substring(1,str.length()-2), Pattern.CASE_INSENSITIVE); 678 else if(str.endsWith("/")) 679 return Pattern.compile(str.substring(1,str.length()-1)); 680 throw new IllegalStateException(); 681 } 682 public CheckerElement(String exp) throws IllegalStateException, PatternSyntaxException 683 { 684 Matcher m = Pattern.compile("(.+)([!=]=)(.+)").matcher(exp); 685 m.matches(); 686 687 String n = m.group(1).trim(); 688 if(n.equals("*")) 689 tagAll = true; 690 else 691 tag = n.startsWith("/") ? getPattern(n) : n; 692 noMatch = m.group(2).equals("!="); 693 n = m.group(3).trim(); 694 if(n.equals("*")) 695 valueAll = true; 696 else 697 value = n.startsWith("/") ? getPattern(n) : n; 698 } 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); 704 } 705 }; 706 707 public String getData(String str) 708 { 709 Matcher m = Pattern.compile(" *# *([^#]+) *$").matcher(str); 710 str = m.replaceFirst("").trim(); 711 try 712 { 713 description = m.group(1); 714 if(description != null && description.length() == 0) 715 description = null; 716 } 717 catch (IllegalStateException e) 718 { 719 description = null; 720 } 721 String[] n = str.split(" *: *", 2); 722 if(n[0].equals("way")) 723 type = WAY; 724 else if(n[0].equals("node")) 725 type = NODE; 726 else if(n[0].equals("*")) 727 type = ALL; 728 if(type == 0 || n.length != 2) 729 return tr("Could not find element type"); 730 for(String exp: n[1].split(" *&& *")) 731 { 732 try 733 { 734 data.add(new CheckerElement(exp)); 735 } 736 catch(IllegalStateException e) 737 { 738 return tr("Illegal expression ''{0}''", exp); 739 } 740 catch(PatternSyntaxException e) 741 { 742 return tr("Illegal regular expression ''{0}''", exp); 743 } 744 } 745 return null; 667 746 } 668 747 public Boolean match(OsmPrimitive osm) 669 748 { 670 return false; 671 } 672 public String description() 673 { 674 return "not implemented yet"; 749 if(osm.keys == null) 750 return false; 751 for(CheckerElement ce : data) 752 { 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) 760 return false; 761 } 762 return true; 763 } 764 public String getDescription() 765 { 766 return tr(description); 675 767 } 676 768 }
Note:
See TracChangeset
for help on using the changeset viewer.