diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/library/ResourcesComponentLibrary.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/library/ResourcesComponentLibrary.java index 0ca7b425f..440ca2a90 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/library/ResourcesComponentLibrary.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/library/ResourcesComponentLibrary.java @@ -11,7 +11,12 @@ import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URL; @@ -66,14 +71,8 @@ private void loadLibrary(String directory, StringBuilder styleSheetBuilder) { String resourceName = directory + "/" + s.getFileName(); LOGGER.debug("Reading subComponent {}", resourceName); SVGOMDocument doc = svgLoadDoc.read(resourceName); - Map mapSubDoc; - if (!svgDocuments.containsKey(componentType)) { - mapSubDoc = new TreeMap<>(); - svgDocuments.put(componentType, mapSubDoc); - } else { - mapSubDoc = svgDocuments.get(componentType); - } - mapSubDoc.put(s.getName(), doc); + cleanEmptyTextNodes(doc, resourceName); + svgDocuments.computeIfAbsent(componentType, k -> new TreeMap<>()).put(s.getName(), doc); }); components.put(componentType, c); }); @@ -86,6 +85,22 @@ private void loadLibrary(String directory, StringBuilder styleSheetBuilder) { } } + private static void cleanEmptyTextNodes(Node parentNode, String resourceName) { + try { + // Find empty text nodes + NodeList nl = (NodeList) XPathFactory.newInstance().newXPath() + .evaluate("//text()[normalize-space(.)='']", parentNode, XPathConstants.NODESET); + + // Remove the found nodes + for (int i = 0; i < nl.getLength(); ++i) { + Node node = nl.item(i); + node.getParentNode().removeChild(node); + } + } catch (XPathExpressionException e) { + LOGGER.warn("Exception occurred while cleaning the subcomponent {} from empty text nodes", resourceName); + } + } + @Override public Map getSvgDocument(String type) { Objects.requireNonNull(type); diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java index a78025244..2c0304e1e 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java @@ -731,10 +731,8 @@ private void insertClonedSubcomponent(Element g, BiConsumer ele for (int i = 0; i < subComponentChildren.getLength(); i++) { org.w3c.dom.Node n = subComponentChildren.item(i).cloneNode(true); if (n instanceof Element) { - elementAttributesSetter.accept((Element) n, subComponentName); + setAttributesAndInsertElement(g, elementAttributesSetter, subComponentName, (Element) n); } - g.getOwnerDocument().adoptNode(n); - g.appendChild(n); } } diff --git a/single-line-diagram-core/src/test/resources/substation.svg b/single-line-diagram-core/src/test/resources/substation.svg index 320b5a824..f0ad0b63c 100644 --- a/single-line-diagram-core/src/test/resources/substation.svg +++ b/single-line-diagram-core/src/test/resources/substation.svg @@ -202,22 +202,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -229,22 +229,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -256,22 +256,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -280,102 +280,102 @@ - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - - -vl1_load1 + + + + vl1_load1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl1_trf1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl1_trf2 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl2_bbs1 @@ -384,22 +384,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -411,22 +411,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -438,22 +438,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -462,74 +462,74 @@ - - - -vl2_gen1 + + + + vl2_gen1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl2_trf1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl2_trf2 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl3_bbs1 @@ -538,22 +538,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -565,22 +565,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -589,65 +589,62 @@ - - - - -vl3_capa1 + + + + + vl3_capa1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl3_trf2 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - - - + + + - - - - - - + + + + diff --git a/single-line-diagram-core/src/test/resources/substation_no_feeder_values.svg b/single-line-diagram-core/src/test/resources/substation_no_feeder_values.svg index 8dad4d1a3..a7e75e86c 100644 --- a/single-line-diagram-core/src/test/resources/substation_no_feeder_values.svg +++ b/single-line-diagram-core/src/test/resources/substation_no_feeder_values.svg @@ -226,102 +226,102 @@ - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - - -vl1_load1 + + + + vl1_load1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl1_trf1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl1_trf2 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl2_bbs1 @@ -354,74 +354,74 @@ - - - -vl2_gen1 + + + + vl2_gen1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl2_trf1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl2_trf2 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl3_bbs1 @@ -445,65 +445,62 @@ - - - - -vl3_capa1 + + + + + vl3_capa1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl3_trf2 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - - - + + + - - - - - - + + + + diff --git a/single-line-diagram-core/src/test/resources/substation_optimized.svg b/single-line-diagram-core/src/test/resources/substation_optimized.svg index 2129c431c..9c91f7cfb 100644 --- a/single-line-diagram-core/src/test/resources/substation_optimized.svg +++ b/single-line-diagram-core/src/test/resources/substation_optimized.svg @@ -119,60 +119,57 @@ ]]> - - - - + + + + - - - - - - - + + + + + + + - - - - + + + + - - - - - - - - + + + + + + + + - - - - - + + + + + - - - - + + + - - - - - - + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl1.svg b/single-line-diagram-core/src/test/resources/vl1.svg index 6be0c4c1c..3f5aac2de 100644 --- a/single-line-diagram-core/src/test/resources/vl1.svg +++ b/single-line-diagram-core/src/test/resources/vl1.svg @@ -168,22 +168,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -195,22 +195,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -222,43 +222,43 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -270,83 +270,82 @@ - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - - -vl1_load1 + + + + vl1_load1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - - -vl1_trf1 + + + vl1_trf1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl1_trf2 @@ -354,30 +353,28 @@ vl1_trf2 - - - - - - + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl1_decorated.svg b/single-line-diagram-core/src/test/resources/vl1_decorated.svg index 722d6de20..45ac10df4 100644 --- a/single-line-diagram-core/src/test/resources/vl1_decorated.svg +++ b/single-line-diagram-core/src/test/resources/vl1_decorated.svg @@ -180,22 +180,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -207,22 +207,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -234,43 +234,43 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -282,97 +282,89 @@ - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - -vl1_load1 + + + + vl1_load1 - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - -vl1_trf1 + + + vl1_trf1 - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + vl1_trf2 @@ -380,34 +372,30 @@ vl1_trf2 - - - - - - + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl1_decorated_opt.svg b/single-line-diagram-core/src/test/resources/vl1_decorated_opt.svg index 16ded5c18..754e93bf4 100644 --- a/single-line-diagram-core/src/test/resources/vl1_decorated_opt.svg +++ b/single-line-diagram-core/src/test/resources/vl1_decorated_opt.svg @@ -131,55 +131,52 @@ ]]> - - - - - - - + + + + + + + - - - - + + + + - - - - - - - - + + + + + + + + - - + + - - - - + + + - - + + - - - - - - + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl1_lpChanged.svg b/single-line-diagram-core/src/test/resources/vl1_lpChanged.svg index c68c96f60..07594d78d 100644 --- a/single-line-diagram-core/src/test/resources/vl1_lpChanged.svg +++ b/single-line-diagram-core/src/test/resources/vl1_lpChanged.svg @@ -168,22 +168,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -195,22 +195,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -222,43 +222,43 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -271,91 +271,90 @@ vl1_d1 - - - - - - - - + + + + + + + + vl1_b1 - - - - - - - - - + + + + + + + + + vl1_d2 - - - - - - - - + + + + + + + + vl1_load1 - - - -vl1_load1 + + + + vl1_load1 vl1_bload1 - - - - - - - - - + + + + + + + + + vl1_dload1 - - - - - - - - + + + + + + + + vl1_trf1 - - - -vl1_trf1 + + + vl1_trf1 vl1_btrf1 - - - - - - - - - + + + + + + + + + vl1_dtrf1 - - - - - - - - + + + + + + + + vl1_trf2 @@ -364,32 +363,30 @@ vl1_trf2 - - - - - - + + + + vl1_btrf2 - - - - - - - - - + + + + + + + + + vl1_dtrf2 - - - - - - - - + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl1_lpChanged_opt.svg b/single-line-diagram-core/src/test/resources/vl1_lpChanged_opt.svg index 256f3cdad..bf885f6af 100644 --- a/single-line-diagram-core/src/test/resources/vl1_lpChanged_opt.svg +++ b/single-line-diagram-core/src/test/resources/vl1_lpChanged_opt.svg @@ -119,49 +119,46 @@ ]]> - - - - - - - + + + + + + + - - - - + + + + - - - - - - - - + + + + + + + + - - - - + + + - - - - - - + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl1_nominal_voltage_style.svg b/single-line-diagram-core/src/test/resources/vl1_nominal_voltage_style.svg index 14060b078..52f934a74 100644 --- a/single-line-diagram-core/src/test/resources/vl1_nominal_voltage_style.svg +++ b/single-line-diagram-core/src/test/resources/vl1_nominal_voltage_style.svg @@ -178,24 +178,21 @@ - - - -l + + + + l - - - -2WT_1 + + + 2WT_1 - - - - - - + + + + 3WT_1 @@ -203,70 +200,70 @@ 3WT_1 - - + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl1_optimized.svg b/single-line-diagram-core/src/test/resources/vl1_optimized.svg index bad25b0d4..7ea2a3d0e 100644 --- a/single-line-diagram-core/src/test/resources/vl1_optimized.svg +++ b/single-line-diagram-core/src/test/resources/vl1_optimized.svg @@ -119,49 +119,46 @@ ]]> - - - - - - - + + + + + + + - - - - + + + + - - - - - - - - + + + + + + + + - - - - + + + - - - - - - + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl2.svg b/single-line-diagram-core/src/test/resources/vl2.svg index 60caf3df8..d9845b481 100644 --- a/single-line-diagram-core/src/test/resources/vl2.svg +++ b/single-line-diagram-core/src/test/resources/vl2.svg @@ -146,22 +146,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -173,22 +173,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -200,43 +200,43 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -248,55 +248,54 @@ - - - -vl2_gen1 + + + + vl2_gen1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - - -vl2_trf1 + + + vl2_trf1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl2_trf2 @@ -304,30 +303,28 @@ vl2_trf2 - - - - - - + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl2_nominal_voltage_style.svg b/single-line-diagram-core/src/test/resources/vl2_nominal_voltage_style.svg index e71e1faa4..9805c6a93 100644 --- a/single-line-diagram-core/src/test/resources/vl2_nominal_voltage_style.svg +++ b/single-line-diagram-core/src/test/resources/vl2_nominal_voltage_style.svg @@ -162,18 +162,15 @@ - - - -2WT_2 + + + 2WT_2 - - - - - - + + + + 3WT_2 @@ -181,48 +178,48 @@ 3WT_2 - - + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl2_optimized.svg b/single-line-diagram-core/src/test/resources/vl2_optimized.svg index fbf6d0920..281f63424 100644 --- a/single-line-diagram-core/src/test/resources/vl2_optimized.svg +++ b/single-line-diagram-core/src/test/resources/vl2_optimized.svg @@ -119,49 +119,46 @@ ]]> - - - - + + + + - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - - - + + + - - - - - - + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl3.svg b/single-line-diagram-core/src/test/resources/vl3.svg index 1bb00b660..128c5290b 100644 --- a/single-line-diagram-core/src/test/resources/vl3.svg +++ b/single-line-diagram-core/src/test/resources/vl3.svg @@ -143,22 +143,22 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -170,43 +170,43 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 @@ -218,31 +218,31 @@ - - - - -vl3_capa1 + + + + + vl3_capa1 - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + vl3_trf2 @@ -250,30 +250,28 @@ vl3_trf2 - - - - - - + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl3_nominal_voltage_style.svg b/single-line-diagram-core/src/test/resources/vl3_nominal_voltage_style.svg index b6c2326a4..178452abb 100644 --- a/single-line-diagram-core/src/test/resources/vl3_nominal_voltage_style.svg +++ b/single-line-diagram-core/src/test/resources/vl3_nominal_voltage_style.svg @@ -146,12 +146,10 @@ - - - - - - + + + + 3WT_3 @@ -159,26 +157,26 @@ 3WT_3 - - + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/vl3_optimized.svg b/single-line-diagram-core/src/test/resources/vl3_optimized.svg index 14e658136..822412bef 100644 --- a/single-line-diagram-core/src/test/resources/vl3_optimized.svg +++ b/single-line-diagram-core/src/test/resources/vl3_optimized.svg @@ -119,45 +119,43 @@ ]]> - - - - - - - + + + + + + + - - - - - + + + + + - - - - - - - - + + + + + + + + - - - - - - + + + + - - - - - - - - - + + + + + + + + + diff --git a/single-line-diagram-core/src/test/resources/zone.svg b/single-line-diagram-core/src/test/resources/zone.svg index ad22f4ba0..dc423f16a 100644 --- a/single-line-diagram-core/src/test/resources/zone.svg +++ b/single-line-diagram-core/src/test/resources/zone.svg @@ -132,49 +132,49 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - -Load + + + + Load Transformer @@ -187,43 +187,43 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 Transformer @@ -232,10 +232,9 @@ Line - - - - + + + @@ -250,49 +249,49 @@ - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - - - - -10 + + + + + + + 10 - - - - - - -20 + + + + + + + 20 - - - -Generator + + + + Generator Line