public void testParseCompany() { String xmlBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\r\n" + "<Document>\r\n" + " <name>ericsson.kml</name>\r\n" + " <StyleMap id=\"m_ylw-pushpin1\">\r\n" + " <Pair>\r\n" + " <key>normal</key>\r\n" + " <styleUrl>#s_ylw-pushpin00</styleUrl>\r\n" + " </Pair>\r\n" + " <Pair>\r\n" + " <key>highlight</key>\r\n" + " <styleUrl>#s_ylw-pushpin_hl0</styleUrl>\r\n" + " </Pair>\r\n" + " </StyleMap>\r\n" + " <Style id=\"sn_ylw-pushpin\">\r\n" + " <IconStyle>\r\n" + " <scale>1.1</scale>\r\n" + " <Icon>\r\n" + " <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>\r\n" + " </Icon>\r\n" + " <hotSpot x=\"20\" y=\"2\" xunits=\"pixels\" yunits=\"pixels\"/>\r\n" + " </IconStyle>\r\n" + " <PolyStyle>\r\n" + " <color>e37f00ff</color>\r\n" + " </PolyStyle>\r\n" + " </Style>\r\n" + " <Folder>\r\n" + " <name>Ericsson</name>\r\n" + " <open>1</open>\r\n" + " <Folder>\r\n" + " <name>Mjardevi</name>\r\n" + " <open>1</open>\r\n" + " <Folder>\r\n" + " <name>Parkering</name>\r\n" + " <open>1</open>\r\n" + " <Style>\r\n" + " <ListStyle>\r\n" + " <listItemType>check</listItemType>\r\n" + " <bgColor>00ffffff</bgColor>\r\n" + " <maxSnippetLines>2</maxSnippetLines>\r\n" + " </ListStyle>\r\n" + " </Style>\r\n" + " <Placemark>\r\n" + " <name>Parking</name>\r\n" + " <description>Parking for employees</description>\r\n" + " <styleUrl>#m_ylw-pushpin01</styleUrl>\r\n" + " <Polygon>\r\n" + " <tessellate>1</tessellate>\r\n" + " <outerBoundaryIs>\r\n" + " <LinearRing>\r\n" + " <coordinates>\r\n" + " 15.55907486318708,58.39770553685341,0 15.55873061159417,58.39759161098356,0 15.55965179836237,58.3969299945208,0 15.55997543061963,58.39705193711266,0 15.55907486318708,58.39770553685341,0 \r\n" + " </coordinates>\r\n" + " </LinearRing>\r\n" + " </outerBoundaryIs>\r\n" + " </Polygon>\r\n" + " </Placemark>\r\n" + " <Placemark>\r\n" + " <name>Parking</name>\r\n" + " <description>Parking for employees</description>\r\n" + " <styleUrl>#m_ylw-pushpin01</styleUrl>\r\n" + " <Polygon>\r\n" + " <tessellate>1</tessellate>\r\n" + " <outerBoundaryIs>\r\n" + " <LinearRing>\r\n" + " <coordinates>\r\n" + " 15.55440546390407,58.3986574712261,0 15.55447317550318,58.39851378860297,0 15.5549053856946,58.3985742159012,0 15.55484182192279,58.39871652764229,0 15.55440546390407,58.3986574712261,0 \r\n" + " </coordinates>\r\n" + " </LinearRing>\r\n" + " </outerBoundaryIs>\r\n" + " </Polygon>\r\n" + " </Placemark>\r\n" + " </Folder>\r\n" + " <Folder>\r\n" + " <name>Reception</name>\r\n" + " <open>1</open>\r\n" + " <Placemark>\r\n" + " <name>Reception 1</name>\r\n" + " <styleUrl>#msn_ylw-pushpin</styleUrl>\r\n" + " <Polygon>\r\n" + " <tessellate>1</tessellate>\r\n" + " <outerBoundaryIs>\r\n" + " <LinearRing>\r\n" + " <coordinates>\r\n" + " 15.55580674354399,58.39702770164073,0 15.55605831057186,58.39686290566417,0 15.55622568005853,58.3969220218273,0 15.55599962275058,58.39708869161678,0 15.55580674354399,58.39702770164073,0 \r\n" + " </coordinates>\r\n" + " </LinearRing>\r\n" + " </outerBoundaryIs>\r\n" + " </Polygon>\r\n" + " </Placemark>\r\n" + " </Folder>\r\n" + " </Folder>\r\n" + " <Folder>\r\n" + " <name>Kista</name>\r\n" + " <open>1</open>\r\n" + " <Folder>\r\n" + " <name>Parkering</name>\r\n" + " <open>1</open>\r\n" + " <Placemark>\r\n" + " <name>Parking for employees</name>\r\n" + " <styleUrl>#m_ylw-pushpin0</styleUrl>\r\n" + " <Polygon>\r\n" + " <tessellate>1</tessellate>\r\n" + " <outerBoundaryIs>\r\n" + " <LinearRing>\r\n" + " <coordinates>\r\n" + " 17.95652237297804,59.4034859346524,0 17.95734879911315,59.40278073205812,0 17.95603699657349,59.40233075744884,0 17.95668843982264,59.40189566245388,0 17.95904003622361,59.40278343624011,0 17.95761272428177,59.40388537542285,0 17.95652237297804,59.4034859346524,0 \r\n" + " </coordinates>\r\n" + " </LinearRing>\r\n" + " </outerBoundaryIs>\r\n" + " </Polygon>\r\n" + " </Placemark>\r\n" + " </Folder>\r\n" + " <Folder>\r\n" + " <name>Houses</name>\r\n" + " <open>1</open>\r\n" + " <Placemark>\r\n" + " <name>House 5</name>\r\n" + " <styleUrl>#m_ylw-pushpin0</styleUrl>\r\n" + " <Polygon>\r\n" + " <tessellate>1</tessellate>\r\n" + " <outerBoundaryIs>\r\n" + " <LinearRing>\r\n" + " <coordinates>\r\n" + " 17.95132364356021,59.40393745619702,0 17.95044751544161,59.4036551695751,0 17.9508780281932,59.40331676438417,0 17.95178689000125,59.4035903622625,0 17.95132364356021,59.40393745619702,0 \r\n" + " </coordinates>\r\n" + " </LinearRing>\r\n" + " </outerBoundaryIs>\r\n" + " </Polygon>\r\n" + " </Placemark>\r\n" + " </Folder>\r\n" + " </Folder>\r\n" + " </Folder>\r\n" + "</Document>\r\n" + "</kml>\r\n" + ""; KMLparser kmlParser = new KMLparser(true); try { parser.setInput(new StringReader(xmlBody)); Vector<Company> cas = kmlParser.parseKML(parser); assertNotNull(cas); assertEquals(1, cas.size()); Company c = cas.get(0); assertNotNull(c); assertTrue("Ericsson".equals(c.getName())); Iterator<CompanyArea> e = c.getCompanyAreas(); assertTrue(e.hasNext()); CompanyArea ca = e.next(); assertNotNull(ca); assertTrue("Mjardevi".equals(ca.getName())); assertTrue(e.hasNext()); ca = e.next(); assertNotNull(ca); assertTrue("Kista".equals(ca.getName())); } catch (Exception e) { fail(); } }
public void testParseCompanyArea() { String xmlBody = "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\r\n" + "<Folder>\r\n" + " <name>Mjardevi</name>\r\n" + " <open>1</open>\r\n" + " <Folder>\r\n" + " <name>Parkering</name>\r\n" + " <open>1</open>\r\n" + " <Style>\r\n" + " <ListStyle>\r\n" + " <listItemType>check</listItemType>\r\n" + " <bgColor>00ffffff</bgColor>\r\n" + " <maxSnippetLines>2</maxSnippetLines>\r\n" + " </ListStyle>\r\n" + " </Style>\r\n" + " <Placemark>\r\n" + " <name>Gästparkering</name>\r\n" + " <description>Enkel gästparkering</description>\r\n" + " <styleUrl>#m_ylw-pushpin00</styleUrl>\r\n" + " <Polygon>\r\n" + " <tessellate>1</tessellate>\r\n" + " <outerBoundaryIs>\r\n" + " <LinearRing>\r\n" + " <coordinates>\r\n" + " 15.55596143314125,58.39746581469188,0 15.5553913538694,58.39856164094756,0 15.55530072203812,58.39855030647441,0 15.5558711203315,58.39744114210799,0 15.55596143314125,58.39746581469188,0 \r\n" + " </coordinates>\r\n" + " </LinearRing>\r\n" + " </outerBoundaryIs>\r\n" + " </Polygon>\r\n" + " </Placemark>\r\n" + " </Folder>\r\n" + " <Folder>\r\n" + " <name>Houses</name>\r\n" + " <Placemark>\r\n" + " <name>KB</name>\r\n" + " <styleUrl>#m_ylw-pushpin1</styleUrl>\r\n" + " <Polygon>\r\n" + " <tessellate>1</tessellate>\r\n" + " <outerBoundaryIs>\r\n" + " <LinearRing>\r\n" + " <coordinates>\r\n" + " 15.55668214920198,58.39768692967193,0 15.556795061081,58.39761666339918,0 15.55671470722432,58.39758486460966,0 15.55679305101447,58.39754262601683,0 15.5566952877097,58.39752021347346,0 15.55685979988558,58.39739865154839,0 15.55692186407407,58.39740744522897,0 15.55717430140551,58.39727134236146,0 15.55736187612139,58.39734862387047,0 15.55682494482019,58.39774140457978,0 15.55668214920198,58.39768692967193,0 \r\n" + " </coordinates>\r\n" + " </LinearRing>\r\n" + " </outerBoundaryIs>\r\n" + " </Polygon>\r\n" + " </Placemark>\r\n" + " </Folder>\r\n" + " </Folder>\r\n" + "" + ""; KMLparser kmlParser = new KMLparser(true); try { parser.setInput(new StringReader(xmlBody)); int eventType = parser.getEventType(); while (eventType != XmlPullParser.START_TAG) { eventType = parser.next(); } assertTrue("kml".equalsIgnoreCase(parser.getName())); eventType = parser.next(); while (eventType != XmlPullParser.START_TAG) { eventType = parser.next(); } assertTrue("getName() = " + parser.getName(), "Folder".equalsIgnoreCase(parser.getName())); eventType = parser.next(); CompanyArea ca = kmlParser.parseCompanyArea(parser); assertNotNull(ca); assertTrue("Mjardevi".equals(ca.getName())); Iterator<PlacemarkerType> e = ca.getPlacemarkerTypes(); assertTrue(e.hasNext()); PlacemarkerType pmt = e.next(); assertNotNull(pmt); assertTrue("Parkering".equals(pmt.getName())); assertTrue(e.hasNext()); pmt = e.next(); assertNotNull(pmt); assertTrue("Houses".equals(pmt.getName())); assertFalse(e.hasNext()); } catch (Exception e) { fail(); } }