Changeset 32130 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-03-27T23:17:02+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/opendata
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmlReader.java
r32127 r32130 9 9 import java.util.List; 10 10 import java.util.Map; 11 import java.util.regex.Pattern; 11 12 12 13 import javax.xml.stream.FactoryConfigurationError; … … 32 33 33 34 public static final String KML_PLACEMARK = "Placemark"; 34 public static final String KML_NAME 35 public static final String KML_NAME = "name"; 35 36 public static final String KML_COLOR = "color"; 36 37 public static final String KML_SIMPLE_DATA = "SimpleData"; … … 43 44 public static final String KML_COORDINATES = "coordinates"; 44 45 46 public static Pattern COLOR_PATTERN = Pattern.compile("\\p{XDigit}{8}"); 45 47 46 48 private XMLStreamReader parser; … … 54 56 InputStreamReader ir = UTFInputStreamReader.create(in); 55 57 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir); 56 //XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in, UTF8);57 58 return new KmlReader(parser).parseDoc(); 58 59 } … … 92 93 if (parser.getLocalName().equals(KML_COLOR)) { 93 94 String s = parser.getElementText(); 94 // KML color format is aabbggrr, convert it to OSM (web) format: #rrggbb 95 String rgbColor = '#'+s.substring(6,8)+s.substring(4,6)+s.substring(2,4); 96 tags.put(KML_COLOR, rgbColor); 95 if (COLOR_PATTERN.matcher(s).matches()) { 96 // KML color format is aabbggrr, convert it to OSM (web) format: #rrggbb 97 tags.put(KML_COLOR, '#'+s.substring(6,8)+s.substring(4,6)+s.substring(2,4)); 98 } 97 99 } else if (parser.getLocalName().equals(KML_NAME)) { 98 100 tags.put(KML_NAME, parser.getElementText()); -
applications/editors/josm/plugins/opendata/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmlReaderTest.java
r31990 r32130 2 2 package org.openstreetmap.josm.plugins.opendata.core.io.geographic; 3 3 4 import java.io.File; 5 import java.io.FileInputStream; 4 import static org.junit.Assert.assertFalse; 5 import static org.junit.Assert.assertTrue; 6 6 7 import java.io.IOException; 7 8 import java.io.InputStream; … … 28 29 JOSMFixture.createUnitTestFixture().init(); 29 30 } 31 32 /** 33 * Unit test of {@link KmlReader#COLOR_PATTERN} 34 */ 35 @Test 36 public void testColorPattern() { 37 assertTrue(KmlReader.COLOR_PATTERN.matcher("00112233").matches()); 38 assertTrue(KmlReader.COLOR_PATTERN.matcher("44556677").matches()); 39 assertTrue(KmlReader.COLOR_PATTERN.matcher("8899aabb").matches()); 40 assertTrue(KmlReader.COLOR_PATTERN.matcher("CCDDEEFF").matches()); 41 assertFalse(KmlReader.COLOR_PATTERN.matcher("0011223").matches()); 42 assertFalse(KmlReader.COLOR_PATTERN.matcher("001122330").matches()); 43 assertFalse(KmlReader.COLOR_PATTERN.matcher("gg112233").matches()); 44 assertFalse(KmlReader.COLOR_PATTERN.matcher("red").matches()); 45 assertFalse(KmlReader.COLOR_PATTERN.matcher("yellow").matches()); 46 } 30 47 48 /** 49 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/12694">#12694</a> 50 * @throws IOException if an error occurs during reading 51 */ 52 @Test 53 public void testTicket12694() throws IOException, XMLStreamException, FactoryConfigurationError { 54 try (InputStream is = TestUtils.getRegressionDataStream(12694, "Alvinรณpolis_314946.kml")) { 55 NonRegFunctionalTests.testGeneric("#12694", KmlReader.parseDataSet(is, null)); 56 } 57 } 58 31 59 /** 32 60 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/10214">#10214</a> … … 39 67 } 40 68 } 41 69 42 70 /** 43 71 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/7714">#7714</a>
Note:
See TracChangeset
for help on using the changeset viewer.