XMLGISElementUtil { public static void writeGISElementContainer(Element xmlNode, GISElementContainer<?> primitive, XMLBuilder builder, PathBuilder pathBuilder, XMLResources resources) throws IOException { writeGISElementContainer(xmlNode, primitive, null, builder, pathBuilder, resources); } private  XMLGISElementUtil(); static Element writeMapElement(MapElement primitive, XMLBuilder builder, XMLResources resources); @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"}) static Element writeMapElement(MapElement primitive, String primitiveNodeName,
			XMLBuilder builder, XMLResources resources); static MapElement readMapElement(Element element, String elementNodeName,
			PathBuilder pathBuilder, XMLResources resources); @SuppressWarnings({"unchecked", "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"}) static T readMapElement(Element element, String elementNodeName,
			Class<T> type, PathBuilder pathBuilder, XMLResources resources); static String getDefaultMapElementNodeName(Class<? extends MapElement> type); static void writeGISElementContainer(Element xmlNode, GISElementContainer<?> primitive,
			XMLBuilder builder, PathBuilder pathBuilder, XMLResources resources); static void writeGISElementContainer(Element xmlNode, GISElementContainer<?> primitive,
			String elementNodeName, XMLBuilder builder, PathBuilder pathBuilder, XMLResources resources); static void readGISElementContainer(Element xmlNode,
			GISElementContainer<T> primitive, PathBuilder pathBuilder, XMLResources resources); @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:nestedifdepth", "resource"}) static void readGISElementContainer(Element xmlNode,
			GISElementContainer<T> primitive, String elementNodeName, PathBuilder pathBuilder,
			XMLResources resources); static void writeGISElementAttributes(Element element, GISElement primitive, XMLBuilder builder,
			XMLResources resources); static void readGISElementAttributes(Element element, GISElement primitive, PathBuilder pathBuilder,
			XMLResources resources); static final String NODE_CIRCLE; static final String NODE_ELEMENTS; static final String NODE_GROUP; static final String NODE_GROUPS; static final String NODE_MULTIPOINT; static final String NODE_POINT; static final String NODE_POINTS; static final String NODE_POLYGON; static final String NODE_POLYLINE; static final String ATTR_DOUBLEFRAME; static final String ATTR_FIRSTPOINTINDEX; static final String ATTR_LASTPOINTINDEX; static final String ATTR_RADIUS; static final String ATTR_SIZE; static final String ATTR_WIDE; static final String ATTR_WIDTH; static final String ATTR_X; static final String ATTR_Y; }
@Test public void writeGISElementContainerElementGISElementContainerXMLBuilderPathBuilderXMLResources() throws Exception { PathBuilder pathBuilder = new SimplePathBuilder(); XMLResources res = new XMLResources(pathBuilder); ArrayMapElementLayer<MapPoint> container = new ArrayMapElementLayer(MapPoint.class); MapPoint pts1 = new MapPoint(3, 4); pts1.setName("name1"); container.addMapElement(pts1); MapPoint pts2 = new MapPoint(34, 55); pts2.setName("name2"); container.addMapElement(pts2); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); XMLBuilder xmlBuilder = new XMLBuilder() { @Override public Document getDocument() throws DOMException { return doc; } }; Element element = xmlBuilder.createElement("doc"); doc.appendChild(element); XMLGISElementUtil.writeGISElementContainer(element, container, xmlBuilder, pathBuilder, res); String actual; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { XMLUtil.writeXML(doc, baos); baos.flush(); actual = new String(baos.toByteArray()); } final String id1 = pts1.getUUID().toString(); final String id2 = pts2.getUUID().toString(); final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<doc elementGeometryProjection=\"FRANCE_LAMBERT_2_EXTENDED\"><elements>" + "<point doubleFrame=\"false\" geoId=\"39e072ec9ca6460ee679103fd10d53dc#3;4;3;4\" id=\"" + id1 + "\" name=\"name1\" size=\"0.3\" x=\"3.0\" y=\"4.0\"/>" + "<point doubleFrame=\"false\" geoId=\"68a29c8943226086e04c05f595e8e580#34;55;34;55\" id=\"" + id2 + "\" name=\"name2\" size=\"0.3\" x=\"34.0\" y=\"55.0\"/></elements></doc>"; assertEquals(expected, actual); }
@Test public void writeGISElementContainerElementGISElementContainerStringXMLBuilderPathBuilderXMLResources() throws Exception { PathBuilder pathBuilder = new SimplePathBuilder(); XMLResources res = new XMLResources(pathBuilder); ArrayMapElementLayer<MapPoint> container = new ArrayMapElementLayer(MapPoint.class); MapPoint pts1 = new MapPoint(3, 4); pts1.setName("name1"); container.addMapElement(pts1); MapPoint pts2 = new MapPoint(34, 55); pts2.setName("name2"); container.addMapElement(pts2); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); XMLBuilder xmlBuilder = new XMLBuilder() { @Override public Document getDocument() throws DOMException { return doc; } }; Element element = xmlBuilder.createElement("doc"); doc.appendChild(element); XMLGISElementUtil.writeGISElementContainer(element, container, "point", xmlBuilder, pathBuilder, res); String actual; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { XMLUtil.writeXML(doc, baos); baos.flush(); actual = new String(baos.toByteArray()); } final String id1 = pts1.getUUID().toString(); final String id2 = pts2.getUUID().toString(); final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<doc elementGeometryProjection=\"FRANCE_LAMBERT_2_EXTENDED\"><elements>" + "<point doubleFrame=\"false\" geoId=\"39e072ec9ca6460ee679103fd10d53dc#3;4;3;4\" id=\"" + id1 + "\" name=\"name1\" size=\"0.3\" x=\"3.0\" y=\"4.0\"/>" + "<point doubleFrame=\"false\" geoId=\"68a29c8943226086e04c05f595e8e580#34;55;34;55\" id=\"" + id2 + "\" name=\"name2\" size=\"0.3\" x=\"34.0\" y=\"55.0\"/></elements></doc>"; assertEquals(expected, actual); }
@Test public void writeGISElementContainerElementGISElementContainerXMLBuilderPathBuilderXMLResources_shp() throws Exception { PathBuilder pathBuilder = new SimplePathBuilder(); XMLResources res = new XMLResources(pathBuilder); ArrayMapElementLayer<MapPoint> container = new ArrayMapElementLayer(MapPoint.class); container.setElementGeometrySource(new URL("file:/path/to/file.shp"), MapMetricProjection.FRANCE_LAMBERT_2); MapPoint pts1 = new MapPoint(3, 4); pts1.setName("name1"); container.addMapElement(pts1); MapPoint pts2 = new MapPoint(34, 55); pts2.setName("name2"); container.addMapElement(pts2); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); XMLBuilder xmlBuilder = new XMLBuilder() { @Override public Document getDocument() throws DOMException { return doc; } }; Element element = xmlBuilder.createElement("doc"); doc.appendChild(element); XMLGISElementUtil.writeGISElementContainer(element, container, xmlBuilder, pathBuilder, res); String actual; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { XMLUtil.writeXML(doc, baos); baos.flush(); actual = new String(baos.toByteArray()); } final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<doc elementGeometryProjection=\"FRANCE_LAMBERT_2\" elementGeometryUrl=\"#resource0\"/>"; assertEquals(expected, actual); if (OperatingSystem.WIN.isCurrentOS()) { assertEquals("file:/" + FileSystem.getUserHomeDirectoryName().replaceAll("\\\\", "/") + " } else { assertEquals("file:/path/to/file.shp", res.getResourceURL(0).toExternalForm()); } }