Changeset 3612 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-10-16T22:08:17+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r2990 r3612 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.io.InputStreamReader; 8 9 import java.util.Collection; 9 10 import java.util.Collections; … … 16 17 import org.openstreetmap.josm.io.MirroredInputStream; 17 18 import org.openstreetmap.josm.tools.ImageProvider; 18 import org. xml.sax.InputSource;19 import org.openstreetmap.josm.tools.XmlObjectParser; 19 20 import org.xml.sax.SAXException; 20 import org.xml.sax.XMLReader; 21 import org.xml.sax.helpers.XMLReaderFactory; 21 import org.xml.sax.SAXParseException; 22 22 23 23 public class MapPaintStyles { … … 86 86 a = new String[] { null, file }; 87 87 } 88 XMLReader xmlReader = XMLReaderFactory.createXMLReader(); 89 ElemStyleHandler handler = new ElemStyleHandler(a[0]); 90 xmlReader.setContentHandler(handler); 91 xmlReader.setErrorHandler(handler); 88 XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler(a[0])); 92 89 MirroredInputStream in = new MirroredInputStream(a[1]); 93 90 InputStream zip = in.getZipEntry("xml","style"); 91 InputStreamReader ins; 94 92 if(zip != null) 95 93 { 96 94 zipIcons = in.getFile(); 97 xmlReader.parse(new InputSource(zip));95 ins = new InputStreamReader(zip); 98 96 } else { 99 xmlReader.parse(new InputSource(in)); 97 ins = new InputStreamReader(in); 98 } 99 parser.startWithValidation(ins, "http://josm.openstreetmap.de/mappaint-styöe-1.0", 100 "resource://data/mappaint-style.xsd"); 101 while(parser.hasNext()) { 100 102 } 101 103 } catch(IOException e) { 102 104 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", a[1], e.toString())); 103 105 e.printStackTrace(); 106 } catch(SAXParseException e) { 107 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", a[1], e.getLineNumber(), e.getColumnNumber(), e.getMessage())); 108 e.printStackTrace(); 104 109 } catch(SAXException e) { 105 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. E xception was: {1}", a[1], e.toString()));110 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", a[1], e.getMessage())); 106 111 e.printStackTrace(); 107 112 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r3582 r3612 40 40 import javax.swing.JTextField; 41 41 import javax.swing.SwingUtilities; 42 import javax.xml.transform.stream.StreamSource;43 42 44 43 import org.openstreetmap.josm.Main; … … 749 748 750 749 if (validate) { 751 parser.startWithValidation(in, "http://josm.openstreetmap.de/tagging-preset-1.0", new StreamSource(TaggingPreset.class.getResourceAsStream("/data/tagging-preset.xsd")));750 parser.startWithValidation(in, "http://josm.openstreetmap.de/tagging-preset-1.0", "resource://data/tagging-preset.xsd"); 752 751 } else { 753 752 parser.start(in); -
trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java
r3385 r3612 5 5 6 6 import java.io.Reader; 7 import java.io.IOException; 7 8 import java.lang.reflect.Field; 8 9 import java.lang.reflect.Method; … … 19 20 import javax.xml.parsers.SAXParserFactory; 20 21 import javax.xml.transform.Source; 22 import javax.xml.transform.stream.StreamSource; 21 23 import javax.xml.validation.Schema; 22 24 import javax.xml.validation.SchemaFactory; 23 25 import javax.xml.validation.ValidatorHandler; 26 27 import org.openstreetmap.josm.io.MirroredInputStream; 24 28 25 29 import org.xml.sax.Attributes; … … 276 280 277 281 private Map<String, Entry> mapping = new HashMap<String, Entry>(); 278 private Parser parser;282 private DefaultHandler parser; 279 283 280 284 /** … … 297 301 public XmlObjectParser() { 298 302 parser = new Parser(); 303 } 304 305 public XmlObjectParser(DefaultHandler handler) { 306 parser = handler; 299 307 } 300 308 … … 328 336 } 329 337 330 public Iterable<Object> startWithValidation(final Reader in, String namespace, Source schemaSource) throws SAXException { 331 SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); 332 Schema schema = factory.newSchema(schemaSource); 333 ValidatorHandler validator = schema.newValidatorHandler(); 334 validator.setContentHandler(parser); 335 validator.setErrorHandler(parser); 336 337 AddNamespaceFilter filter = new AddNamespaceFilter(namespace); 338 filter.setContentHandler(validator); 339 340 return start(in, filter); 338 public Iterable<Object> startWithValidation(final Reader in, String namespace, String schemaSource) throws SAXException { 339 try { 340 SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); 341 Schema schema = factory.newSchema(new StreamSource(new MirroredInputStream(schemaSource))); 342 ValidatorHandler validator = schema.newValidatorHandler(); 343 validator.setContentHandler(parser); 344 validator.setErrorHandler(parser); 345 346 AddNamespaceFilter filter = new AddNamespaceFilter(namespace); 347 filter.setContentHandler(validator); 348 return start(in, filter); 349 } catch(IOException e) { 350 throw new SAXException(tr("Failed to load XML schema."), e); 351 } 341 352 } 342 353
Note:
See TracChangeset
for help on using the changeset viewer.