XMLRoadUtil { public static void readRoadNetwork(Element xmlNode, RoadNetwork primitive, PathBuilder pathBuilder, XMLResources resources) throws IOException { final ContainerWrapper w = new ContainerWrapper(primitive); readGISElementContainer(xmlNode, w, NODE_ROAD, pathBuilder, resources); URL u; u = w.getElementGeometrySourceURL(); if (u != null) { primitive.setAttribute(MapElementLayer.ATTR_ELEMENT_GEOMETRY_URL, u); } else { primitive.removeAttribute(MapElementLayer.ATTR_ELEMENT_GEOMETRY_URL); } u = w.getElementAttributeSourceURL(); if (u != null) { primitive.setAttribute(MapElementLayer.ATTR_ELEMENT_ATTRIBUTES_URL, u); } else { primitive.removeAttribute(MapElementLayer.ATTR_ELEMENT_ATTRIBUTES_URL); } final MapMetricProjection projection = w.getElementGeometrySourceProjection(); if (projection != null) { primitive.setAttribute(MapElementLayer.ATTR_ELEMENT_GEOMETRY_PROJECTION, projection); } else { primitive.removeAttribute(MapElementLayer.ATTR_ELEMENT_GEOMETRY_PROJECTION); } } private  XMLRoadUtil(); static Element writeRoadPolyline(RoadPolyline primitive, XMLBuilder builder,
			XMLResources resources); static RoadPolyline readRoadPolyline(Element element, PathBuilder pathBuilder,
			XMLResources resources); static Element writeRoadSegment(RoadSegment primitive, XMLBuilder builder, XMLResources resources); static RoadSegment readRoadSegment(Element element, PathBuilder pathBuilder,
			XMLResources resources); static void writeRoadNetwork(Element xmlNode, RoadNetwork primitive, URL geometryURL,
			MapMetricProjection mapProjection, URL attributeURL, XMLBuilder builder,
			PathBuilder pathBuilder, XMLResources resources); static void readRoadNetwork(Element xmlNode, RoadNetwork primitive, PathBuilder pathBuilder,
			XMLResources resources); static StandardRoadNetwork readRoadNetwork(Element xmlNode, PathBuilder pathBuilder,
			XMLResources resources); static final String NODE_ROAD; static final String ATTR_HEIGHT; }
@Test public void readRoadNetworkElementPathBuilderXMLResources() throws Exception { URL xmlFile = Resources.getResource(XMLRoadUtilTest.class, "network.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc; try (InputStream is = xmlFile.openStream()) { doc = builder.parse(is); } PathBuilder pathBuilder = new SimplePathBuilder(); XMLResources res = new XMLResources(pathBuilder); Point2d p; RoadSegment polyline; StandardRoadNetwork network = XMLRoadUtil.readRoadNetwork(doc.getDocumentElement(), pathBuilder, res); Collection<? extends RoadSegment> list = network.getRoadSegments(); assertEquals(2, list.size()); Iterator<? extends RoadSegment> segmentIterator = list.iterator(); polyline = segmentIterator.next(); Iterator<Point2d> pts = polyline.pointIterator(); p = pts.next(); assertEpsilonEquals(1., p.getX()); assertEpsilonEquals(2., p.getY()); p = pts.next(); assertEpsilonEquals(-3., p.getX()); assertEpsilonEquals(4., p.getY()); p = pts.next(); assertEpsilonEquals(5., p.getX()); assertEpsilonEquals(-6., p.getY()); assertFalse(pts.hasNext()); assertEquals("name1", polyline.getName()); assertEquals(ColorNames.getColorFromName("orange").intValue(), polyline.getAttribute("color", 0xFFFFFF)); assertEquals("Text", polyline.getAttribute("attr1", (String) null)); polyline = segmentIterator.next(); pts = polyline.pointIterator(); p = pts.next(); assertEpsilonEquals(1., p.getX()); assertEpsilonEquals(2., p.getY()); p = pts.next(); assertEpsilonEquals(-1., p.getX()); assertEpsilonEquals(-2., p.getY()); p = pts.next(); assertEpsilonEquals(1., p.getX()); assertEpsilonEquals(-2., p.getY()); assertFalse(pts.hasNext()); assertEquals("name2", polyline.getName()); assertEquals(ColorNames.getColorFromName("red").intValue(), polyline.getAttribute("color", 0xFFFFFF)); assertEquals("Text2", polyline.getAttribute("attr2", (String) null)); }
@Test public void readRoadNetworkElementRoadNetworkPathBuilderXMLResources() throws Exception { URL xmlFile = Resources.getResource(XMLRoadUtilTest.class, "network.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc; try (InputStream is = xmlFile.openStream()) { doc = builder.parse(is); } PathBuilder pathBuilder = new SimplePathBuilder(); XMLResources res = new XMLResources(pathBuilder); Point2d p; RoadSegment polyline; StandardRoadNetwork network = new StandardRoadNetwork(new Rectangle2d(-3, -6, 8, 10)); XMLRoadUtil.readRoadNetwork(doc.getDocumentElement(), network, pathBuilder, res); Collection<? extends RoadSegment> list = network.getRoadSegments(); assertEquals(2, list.size()); Iterator<? extends RoadSegment> segmentIterator = list.iterator(); polyline = segmentIterator.next(); Iterator<Point2d> pts = polyline.pointIterator(); p = pts.next(); assertEpsilonEquals(1., p.getX()); assertEpsilonEquals(2., p.getY()); p = pts.next(); assertEpsilonEquals(-3., p.getX()); assertEpsilonEquals(4., p.getY()); p = pts.next(); assertEpsilonEquals(5., p.getX()); assertEpsilonEquals(-6., p.getY()); assertFalse(pts.hasNext()); assertEquals("name1", polyline.getName()); assertEquals(ColorNames.getColorFromName("orange").intValue(), polyline.getAttribute("color", 0xFFFFFF)); assertEquals("Text", polyline.getAttribute("attr1", (String) null)); polyline = segmentIterator.next(); pts = polyline.pointIterator(); p = pts.next(); assertEpsilonEquals(1., p.getX()); assertEpsilonEquals(2., p.getY()); p = pts.next(); assertEpsilonEquals(-1., p.getX()); assertEpsilonEquals(-2., p.getY()); p = pts.next(); assertEpsilonEquals(1., p.getX()); assertEpsilonEquals(-2., p.getY()); assertFalse(pts.hasNext()); assertEquals("name2", polyline.getName()); assertEquals(ColorNames.getColorFromName("red").intValue(), polyline.getAttribute("color", 0xFFFFFF)); assertEquals("Text2", polyline.getAttribute("attr2", (String) null)); }