@@ -3,6 +3,7 @@ package com.sdl.dxa.builder.configuration.writers
33import com.sdl.dxa.builder.configuration.parameters.XmlProperty
44import org.jdom2.Document
55import org.jdom2.Element
6+ import org.jdom2.filter.Filters
67import org.jdom2.input.SAXBuilder
78import org.jdom2.output.Format
89import org.jdom2.output.XMLOutputter
@@ -53,15 +54,15 @@ class XmlWriter {
5354 this
5455 }
5556
56- XmlWriter addAttributes (Map<String , Tuple2<String , String > > mapToAdd ) {
57- bulkEdit mapToAdd, { nodes , Tuple2<String , String > value ->
57+ XmlWriter addAttributes (Map<String , Tuple2<String , String > > mapToAdd , XmlProperty xmlProperty ) {
58+ bulkEdit mapToAdd, xmlProperty, { nodes , Tuple2<String , String > value ->
5859 nodes* . setAttribute(value. first, value. second)
5960 }
6061 this
6162 }
6263
63- XmlWriter addNodesAfter (Map<String , Tuple2<String , String > > mapToAdd ) {
64- bulkEdit mapToAdd, { nodes , Tuple2<String , String > value ->
64+ XmlWriter addNodesAfter (Map<String , Tuple2<String , String > > mapToAdd , XmlProperty xmlProperty ) {
65+ bulkEdit mapToAdd, xmlProperty, { nodes , Tuple2<String , String > value ->
6566 def tagName = value. first
6667 def tagValue = value. second
6768
@@ -73,22 +74,41 @@ class XmlWriter {
7374 this
7475 }
7576
76- XmlWriter modifyByXPath (Map<String , String > mapToModify ) {
77- bulkEdit mapToModify, { nodes , value ->
77+ XmlWriter modifyByXPath (Map<String , String > mapToModify , XmlProperty xmlProperty ) {
78+ bulkEdit mapToModify, xmlProperty, { nodes , value ->
7879 nodes* . value = value
7980 }
8081 this
8182 }
8283
84+
85+ XmlWriter addAttributes (Map<String , Tuple2<String , String > > mapToAdd ) {
86+ addAttributes mapToAdd, null
87+ }
88+
89+ XmlWriter addNodesAfter (Map<String , Tuple2<String , String > > mapToAdd ) {
90+ addNodesAfter mapToAdd, null
91+ }
92+
93+ XmlWriter modifyByXPath (Map<String , String > mapToModify ) {
94+ modifyByXPath mapToModify, null
95+ }
96+
8397 XmlWriter modify (XmlProperty xmlProperty ) {
84- addNodesAfter(xmlProperty. addNodesMap)
85- addAttributes(xmlProperty. addAttributesMap)
86- modifyByXPath(xmlProperty. modifyMap)
98+ addNodesAfter(xmlProperty. addNodesMap, xmlProperty )
99+ addAttributes(xmlProperty. addAttributesMap, xmlProperty )
100+ modifyByXPath(xmlProperty. modifyMap, xmlProperty )
87101 }
88102
89- private bulkEdit (Map<String , ?> map , Closure callback ) {
103+ private bulkEdit (Map<String , ?> map , XmlProperty xmlProperty , Closure callback ) {
90104 map?. each {
91- callback xPathFactory. compile(it. key). evaluate(document), it. value
105+ if (xmlProperty != null && xmlProperty. namespace != null ) {
106+ return callback(xPathFactory. compile(it. key, Filters . fpassthrough(), null ,
107+ xmlProperty. namespace). evaluate(document), it. value)
108+ } else {
109+ return callback(xPathFactory. compile(it. key). evaluate(document), it. value)
110+ }
111+
92112 }
93113 }
94114}
0 commit comments