Changeset 3038 in osm for applications/editors/josm
- Timestamp:
- 2007-05-27T20:32:30+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r2839 r3038 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.lang.reflect.InvocationTargetException; 5 6 import java.util.*; 6 7 import java.util.regex.Matcher; … … 11 12 import org.openstreetmap.josm.Main; 12 13 import org.openstreetmap.josm.actions.UploadAction; 14 import org.openstreetmap.josm.actions.UploadAction.UploadHook; 13 15 import org.openstreetmap.josm.gui.MapFrame; 14 16 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 43 45 DuplicateSegment.class, 44 46 SingleNodeSegment.class, 47 UntaggedNode.class, 45 48 TaggedSegment.class, 49 UntaggedWay.class, 46 50 UnorderedWay.class, 47 51 SpellCheck.class, 48 UntaggedNode.class,49 52 OrphanSegment.class, 53 ReusedSegment.class, 54 CrossingSegments.class, 50 55 }; 51 56 … … 73 78 newFrame.addToggleDialog(validationDialog); 74 79 Main.main.addLayer(new ErrorLayer(tr("Validation errors"))); 75 try 80 } 81 82 // Add/Remove the upload hook 83 try 84 { 85 LinkedList<UploadHook> hooks = ((UploadAction)Main.main.menu.upload).uploadHooks; 86 Iterator<UploadHook> hooksIt = hooks.iterator(); 87 while( hooksIt.hasNext() ) 76 88 { 77 ((UploadAction)Main.main.menu.upload).uploadHooks.add( 0, new ValidateUploadHook() ); 89 if( hooksIt.next() instanceof ValidateUploadHook ) 90 { 91 if( newFrame == null ) 92 hooksIt.remove(); 93 break; 94 } 78 95 } 79 catch(Throwable t) 80 { 81 // JOSM has no upload hooks in older versions 82 } 83 } 96 if( newFrame != null ) 97 hooks.add( 0, new ValidateUploadHook() ); 98 } 99 catch(Throwable t) 100 { 101 // JOSM has no upload hooks in older versions 102 } 84 103 } 85 104 … … 118 137 119 138 String simpleName = testClass.getSimpleName(); 120 test.testBeforeUpload = Main.pref.getBoolean( "tests." + simpleName + ".checkBeforeUpload" );139 test.testBeforeUpload = Main.pref.getBoolean( "tests." + simpleName + ".checkBeforeUpload", true); 121 140 enabledTests.put(simpleName, test); 122 141 } … … 165 184 } 166 185 } 167 catch(Exception e) 168 { 169 e.printStackTrace(); 170 JOptionPane.showMessageDialog(null, tr("Error initializing test {0}.", test.getClass().getSimpleName())); 171 } 186 catch(InvocationTargetException ite) 187 { 188 ite.getCause().printStackTrace(); 189 JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}", test.getClass().getSimpleName(), ite.getCause().getMessage())); 190 } 191 catch(Exception e) 192 { 193 e.printStackTrace(); 194 JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}", test.getClass().getSimpleName(), e)); 195 } 172 196 } 173 197 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/SpellCheck.java
r2790 r3038 46 46 /** Preference name for checking values */ 47 47 public static final String PREF_CHECK_KEYS = "tests." + SpellCheck.class.getSimpleName() + ".checkKeys"; 48 /** Preference name for checking FIXMES */ 49 public static final String PREF_CHECK_FIXMES = "tests." + SpellCheck.class.getSimpleName() + ".checkFixmes"; 48 50 /** Preference name for sources */ 49 51 public static final String PREF_SOURCES = "tests." + SpellCheck.class.getSimpleName() + ".sources"; … … 54 56 /** Preference name for values upload check */ 55 57 public static final String PREF_CHECK_VALUES_BEFORE_UPLOAD = "tests." + SpellCheck.class.getSimpleName() + ".checkValuesBeforeUpload"; 58 /** Preference name for fixmes upload check */ 59 public static final String PREF_CHECK_FIXMES_BEFORE_UPLOAD = "tests." + SpellCheck.class.getSimpleName() + ".checkFixmesBeforeUpload"; 56 60 57 61 /** Whether to check keys */ … … 59 63 /** Whether to check values */ 60 64 protected boolean checkValues = false; 65 /** Whether to check for fixmes in values */ 66 protected boolean checkFixmes = false; 61 67 62 68 /** Preferences checkbox for keys */ … … 64 70 /** Preferences checkbox for values */ 65 71 protected JCheckBox prefCheckValues; 72 /** Preferences checkbox for FIXMES */ 73 protected JCheckBox prefCheckFixmes; 66 74 /** The preferences checkbox for validation of keys on upload */ 67 75 protected JCheckBox prefCheckKeysBeforeUpload; 68 76 /** The preferences checkbox for validation of values on upload */ 69 77 protected JCheckBox prefCheckValuesBeforeUpload; 78 /** The preferences checkbox for validation of fixmes on upload */ 79 protected JCheckBox prefCheckFixmesBeforeUpload; 70 80 /** The add button */ 71 81 protected JButton addSrcButton; … … 79 89 /** Invalid key error */ 80 90 protected static int INVALID_KEY = 1; 81 /** Invalid value error */ 82 protected static int INVALID_VALUE = 2; 91 /** Invalid value error */ 92 protected static int INVALID_VALUE = 2; 93 /** fixme error */ 94 protected static int FIXME = 3; 83 95 84 96 /** List of sources for spellcheck data */ … … 89 101 /** Whether this test must check the values before upload. Used by peferences */ 90 102 protected boolean testValuesBeforeUpload; 103 /** Whether this test must check form fixmes in values before upload. Used by peferences */ 104 protected boolean testFixmesBeforeUpload; 91 105 92 106 /** … … 95 109 public SpellCheck() 96 110 { 97 super(tr("Properties spellchecker."),98 tr("This plugin checks misspelledproperty keys and values."));111 super(tr("Properties checker."), 112 tr("This plugin checks for errors in property keys and values.")); 99 113 } 100 114 … … 124 138 125 139 StringTokenizer st = new StringTokenizer(sources, ";"); 140 StringBuilder errorSources = new StringBuilder(); 126 141 while (st.hasMoreTokens()) 127 142 { 128 143 String source = st.nextToken(); 129 144 File sourceFile = Util.mirror(new URL(source), plugin.getPluginDir()); 145 if( sourceFile == null || !sourceFile.exists() ) 146 { 147 errorSources.append(source).append("\n"); 148 continue; 149 } 150 130 151 BufferedReader reader = new BufferedReader(new FileReader(sourceFile)); 131 152 … … 154 175 while( true ); 155 176 } 177 178 if( errorSources.length() > 0 ) 179 throw new IOException( tr("Could not download spellcheck data file:\n {0}", errorSources) ); 180 156 181 } 157 182 … … 223 248 withErrors.add(p, "IPK"); 224 249 } 225 if( checkValues && value != null && value.length() > 0 ) 226 { 227 List<String> values = spellCheckValueData.get(key); 228 if( values != null && !values.contains(prop.getValue()) && !withErrors.contains(p, "UPV")) 229 { 230 errors.add( new TestError(this, Severity.OTHER, tr("Unknown property values"), p, INVALID_VALUE) ); 231 withErrors.add(p, "UPV"); 232 } 233 } 250 if( checkValues && value != null && value.length() > 0 && spellCheckValueData != null) 251 { 252 List<String> values = spellCheckValueData.get(key); 253 if( values != null && !values.contains(prop.getValue()) && !withErrors.contains(p, "UPV")) 254 { 255 errors.add( new TestError(this, Severity.OTHER, tr("Unknown property values"), p, INVALID_VALUE) ); 256 withErrors.add(p, "UPV"); 257 } 258 } 259 if( checkFixmes && value != null && value.length() > 0 ) 260 { 261 if( value.contains("FIXME") && !withErrors.contains(p, "FIXME")) 262 { 263 errors.add( new TestError(this, Severity.OTHER, tr("FIXMES"), p, FIXME) ); 264 withErrors.add(p, "FIXME"); 265 } 266 } 234 267 } 235 268 } … … 312 345 checkKeys = Main.pref.getBoolean(PREF_CHECK_KEYS); 313 346 if( isBeforeUpload ) 314 checkKeys = checkKeys && Main.pref.getBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD );347 checkKeys = checkKeys && Main.pref.getBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD, true); 315 348 316 349 checkValues = Main.pref.getBoolean(PREF_CHECK_VALUES); 317 350 if( isBeforeUpload ) 318 checkValues = checkValues && Main.pref.getBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD); 351 checkValues = checkValues && Main.pref.getBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD, true); 352 353 checkFixmes = Main.pref.getBoolean(PREF_CHECK_FIXMES); 354 if( isBeforeUpload ) 355 checkFixmes = checkFixmes && Main.pref.getBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, true); 319 356 } 320 357 … … 331 368 testPanel.add( new JLabel(), GBC.eol()); 332 369 333 boolean checkKeys = Main.pref.getBoolean(PREF_CHECK_KEYS );370 boolean checkKeys = Main.pref.getBoolean(PREF_CHECK_KEYS, true); 334 371 prefCheckKeys = new JCheckBox(tr("Check property keys."), checkKeys); 335 372 prefCheckKeys .setToolTipText(tr("Validate that property keys are valid checking against list of words.")); … … 337 374 338 375 prefCheckKeysBeforeUpload = new JCheckBox(); 339 prefCheckKeysBeforeUpload.setSelected(Main.pref.getBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD ));376 prefCheckKeysBeforeUpload.setSelected(Main.pref.getBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD, true)); 340 377 testPanel.add(prefCheckKeysBeforeUpload, GBC.eop().insets(20,0,0,0)); 341 378 … … 411 448 buttonPanel.setEnabled( checkKeys ); 412 449 413 boolean checkValues = Main.pref.getBoolean(PREF_CHECK_VALUES );450 boolean checkValues = Main.pref.getBoolean(PREF_CHECK_VALUES, true); 414 451 prefCheckValues = new JCheckBox(tr("Check property values."), checkValues); 415 452 prefCheckValues .setToolTipText(tr("Validate that property values are valid checking against presets.")); … … 417 454 418 455 prefCheckValuesBeforeUpload = new JCheckBox(); 419 prefCheckValuesBeforeUpload.setSelected(Main.pref.getBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD ));456 prefCheckValuesBeforeUpload.setSelected(Main.pref.getBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD, true)); 420 457 testPanel.add(prefCheckValuesBeforeUpload, GBC.eop().insets(20,0,0,0)); 421 458 459 boolean checkFixmes = Main.pref.getBoolean(PREF_CHECK_FIXMES, true); 460 prefCheckFixmes = new JCheckBox(tr("Check for FIXMES."), checkFixmes); 461 prefCheckFixmes.setToolTipText(tr("Looks for nodes, segments or ways with FIXME in any property value.")); 462 testPanel.add(prefCheckFixmes, GBC.std().insets(40,0,0,0)); 463 464 prefCheckFixmesBeforeUpload = new JCheckBox(); 465 prefCheckFixmesBeforeUpload.setSelected(Main.pref.getBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, true)); 466 testPanel.add(prefCheckFixmesBeforeUpload, GBC.eop().insets(20,0,0,0)); 422 467 } 423 468 … … 432 477 prefCheckValues.setEnabled(enabled); 433 478 prefCheckValuesBeforeUpload.setEnabled(enabled); 479 prefCheckFixmes.setEnabled(enabled); 480 prefCheckFixmesBeforeUpload.setEnabled(enabled); 434 481 } 435 482 … … 439 486 Main.pref.put(PREF_CHECK_VALUES, prefCheckValues.isSelected()); 440 487 Main.pref.put(PREF_CHECK_KEYS, prefCheckKeys.isSelected()); 488 Main.pref.put(PREF_CHECK_FIXMES, prefCheckFixmes.isSelected()); 441 489 Main.pref.put(PREF_CHECK_VALUES_BEFORE_UPLOAD, prefCheckValuesBeforeUpload.isSelected()); 442 490 Main.pref.put(PREF_CHECK_KEYS_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected()); 443 Main.pref.put(PREF_CHECK_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected() || prefCheckValuesBeforeUpload.isSelected()); 491 Main.pref.put(PREF_CHECK_FIXMES_BEFORE_UPLOAD, prefCheckFixmesBeforeUpload.isSelected()); 492 Main.pref.put(PREF_CHECK_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected() || prefCheckValuesBeforeUpload.isSelected() || prefCheckFixmesBeforeUpload.isSelected()); 444 493 String sources = ""; 445 494 if( spellcheckSources.getModel().getSize() > 0 ) -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/Util.java
r2791 r3038 6 6 import java.io.*; 7 7 import java.net.URL; 8 import java.net.URLConnection; 8 9 import java.util.StringTokenizer; 9 10 import java.util.regex.Matcher; … … 172 173 * @param destDir The destionation dir of the mirrored file 173 174 * @return The local file 174 * @throws IOException If any error reading or writing the file 175 */ 176 public static File mirror(URL url, String destDir) throws IOException 175 */ 176 public static File mirror(URL url, String destDir) 177 177 { 178 178 if( url.getProtocol().equals("file") ) … … 199 199 try 200 200 { 201 bis = new BufferedInputStream(url.openStream()); 201 URLConnection conn = url.openConnection(); 202 conn.setConnectTimeout(5000); 203 bis = new BufferedInputStream(conn.getInputStream()); 202 204 bos = new BufferedOutputStream( new FileOutputStream(localPath) ); 203 205 byte[] buffer = new byte[4096]; … … 207 209 bos.write( buffer, 0, length ); 208 210 } 211 } 212 catch(IOException ioe) 213 { 214 if( oldFile != null ) 215 return oldFile; 216 else 217 return null; 209 218 } 210 219 finally
Note:
See TracChangeset
for help on using the changeset viewer.