23
23
import org .codehaus .plexus .util .xml .pull .XmlSerializer ;
24
24
25
25
/** @author Jason van Zyl */
26
+ @ Deprecated
26
27
public class Xpp3DomUtils
27
28
{
28
- public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = "combine.children" ;
29
-
30
- public static final String CHILDREN_COMBINATION_MERGE = "merge" ;
29
+ /**
30
+ * @deprecated use {@link Xpp3Dom#CHILDREN_COMBINATION_MODE_ATTRIBUTE}
31
+ */
32
+ @ Deprecated
33
+ public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = Xpp3Dom .CHILDREN_COMBINATION_MODE_ATTRIBUTE ;
31
34
32
- public static final String CHILDREN_COMBINATION_APPEND = "append" ;
35
+ /**
36
+ * @deprecated use {@link Xpp3Dom#CHILDREN_COMBINATION_MERGE}
37
+ */
38
+ @ Deprecated
39
+ public static final String CHILDREN_COMBINATION_MERGE = Xpp3Dom .CHILDREN_COMBINATION_MERGE ;
33
40
34
41
/**
35
- * This default mode for combining children DOMs during merge means that where element names match, the process will
36
- * try to merge the element data, rather than putting the dominant and recessive elements (which share the same
37
- * element name) as siblings in the resulting DOM.
42
+ * @deprecated use {@link Xpp3Dom#CHILDREN_COMBINATION_APPEND}
38
43
*/
39
- public static final String DEFAULT_CHILDREN_COMBINATION_MODE = CHILDREN_COMBINATION_MERGE ;
44
+ @ Deprecated
45
+ public static final String CHILDREN_COMBINATION_APPEND = Xpp3Dom .CHILDREN_COMBINATION_APPEND ;
40
46
41
- public static final String SELF_COMBINATION_MODE_ATTRIBUTE = "combine.self" ;
47
+ /**
48
+ * @deprecated use {@link Xpp3Dom#DEFAULT_CHILDREN_COMBINATION_MODE}
49
+ */
50
+ @ Deprecated
51
+ public static final String DEFAULT_CHILDREN_COMBINATION_MODE = Xpp3Dom .DEFAULT_CHILDREN_COMBINATION_MODE ;
42
52
43
- public static final String SELF_COMBINATION_OVERRIDE = "override" ;
53
+ /**
54
+ * @deprecated use {@link Xpp3Dom#SELF_COMBINATION_MODE_ATTRIBUTE}
55
+ */
56
+ @ Deprecated
57
+ public static final String SELF_COMBINATION_MODE_ATTRIBUTE = Xpp3Dom .SELF_COMBINATION_MODE_ATTRIBUTE ;
44
58
45
- public static final String SELF_COMBINATION_MERGE = "merge" ;
59
+ /**
60
+ * @deprecated use {@link Xpp3Dom#SELF_COMBINATION_OVERRIDE}
61
+ */
62
+ @ Deprecated
63
+ public static final String SELF_COMBINATION_OVERRIDE = Xpp3Dom .SELF_COMBINATION_OVERRIDE ;
46
64
47
65
/**
48
- * In case of complex XML structures, combining can be done based on id.
49
- *
50
- * @since 3.0.22
66
+ * @deprecated use {@link Xpp3Dom#SELF_COMBINATION_MERGE}
51
67
*/
52
- public static final String ID_COMBINATION_MODE_ATTRIBUTE = "combine.id" ;
53
-
68
+ @ Deprecated
69
+ public static final String SELF_COMBINATION_MERGE = Xpp3Dom .SELF_COMBINATION_MERGE ;
70
+
54
71
/**
55
- * In case of complex XML structures, combining can be done based on keys.
56
- * This is a comma separated list of attribute names.
57
- *
58
- * @since 3.4.0
72
+ * @deprecated use {@link Xpp3Dom#ID_COMBINATION_MODE_ATTRIBUTE}
59
73
*/
60
- public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = "combine.keys" ;
74
+ @ Deprecated
75
+ public static final String ID_COMBINATION_MODE_ATTRIBUTE = Xpp3Dom .ID_COMBINATION_MODE_ATTRIBUTE ;
61
76
62
77
/**
63
- * This default mode for combining a DOM node during merge means that where element names match, the process will
64
- * try to merge the element attributes and values, rather than overriding the recessive element completely with the
65
- * dominant one. This means that wherever the dominant element doesn't provide the value or a particular attribute,
66
- * that value or attribute will be set from the recessive DOM node.
78
+ * @deprecated use {@link Xpp3Dom#KEYS_COMBINATION_MODE_ATTRIBUTE}
67
79
*/
68
- public static final String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE ;
80
+ @ Deprecated
81
+ public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = Xpp3Dom .KEYS_COMBINATION_MODE_ATTRIBUTE ;
69
82
70
- public void writeToSerializer ( String namespace , XmlSerializer serializer , Xpp3Dom dom )
71
- throws IOException
72
- {
73
- // TODO: WARNING! Later versions of plexus-utils psit out an <?xml ?> header due to thinking this is a new
74
- // document - not the desired behaviour!
75
- SerializerXMLWriter xmlWriter = new SerializerXMLWriter ( namespace , serializer );
76
- Xpp3DomWriter .write ( xmlWriter , dom );
77
- if ( xmlWriter .getExceptions ().size () > 0 )
78
- {
79
- throw (IOException ) xmlWriter .getExceptions ().get ( 0 );
80
- }
81
- }
83
+ /**
84
+ * @deprecated use {@link Xpp3Dom#DEFAULT_SELF_COMBINATION_MODE}
85
+ */
86
+ @ Deprecated
87
+ public static final String DEFAULT_SELF_COMBINATION_MODE = Xpp3Dom .DEFAULT_SELF_COMBINATION_MODE ;
82
88
83
89
/**
84
- * Merges one DOM into another, given a specific algorithm and possible override points for that algorithm.<p>
85
- * The algorithm is as follows:
86
- * <ol>
87
- * <li> if the recessive DOM is null, there is nothing to do... return.</li>
88
- * <li> Determine whether the dominant node will suppress the recessive one (flag=mergeSelf).
89
- * <ol type="A">
90
- * <li> retrieve the 'combine.self' attribute on the dominant node, and try to match against 'override'...
91
- * if it matches 'override', then set mergeSelf == false...the dominant node suppresses the recessive one
92
- * completely.</li>
93
- * <li> otherwise, use the default value for mergeSelf, which is true...this is the same as specifying
94
- * 'combine.self' == 'merge' as an attribute of the dominant root node.</li>
95
- * </ol></li>
96
- * <li> If mergeSelf == true
97
- * <ol type="A">
98
- * <li> Determine whether children from the recessive DOM will be merged or appended to the dominant DOM as
99
- * siblings (flag=mergeChildren).
100
- * <ol type="i">
101
- * <li> if childMergeOverride is set (non-null), use that value (true/false)</li>
102
- * <li> retrieve the 'combine.children' attribute on the dominant node, and try to match against
103
- * 'append'...</li>
104
- * <li> if it matches 'append', then set mergeChildren == false...the recessive children will be appended as
105
- * siblings of the dominant children.</li>
106
- * <li> otherwise, use the default value for mergeChildren, which is true...this is the same as specifying
107
- * 'combine.children' == 'merge' as an attribute on the dominant root node.</li>
108
- * </ol></li>
109
- * <li> Iterate through the recessive children, and:
110
- * <ol type="i">
111
- * <li> if 'combine.id' is set and there is a corresponding dominant child (matched by value of 'combine.id'),
112
- * merge the two.</li>
113
- * <li> if 'combine.keys' is set and there is a corresponding dominant child (matched by value of key elements),
114
- * merge the two.</li>
115
- * <li> if mergeChildren == true and there is a corresponding dominant child (matched by element name),
116
- * merge the two.</li>
117
- * <li> otherwise, add the recessive child as a new child on the dominant root node.</li>
118
- * </ol></li>
119
- * </ol></li>
120
- * </ol>
90
+ * @deprecated use {@link Xpp3Dom#writeToSerializer(String, XmlSerializer)}
121
91
*/
122
- private static void mergeIntoXpp3Dom ( Xpp3Dom dominant , Xpp3Dom recessive , Boolean childMergeOverride )
92
+ @ Deprecated
93
+ public void writeToSerializer ( String namespace , XmlSerializer serializer , Xpp3Dom dom )
94
+ throws IOException
123
95
{
124
- // TODO: share this as some sort of assembler, implement a walk interface?
125
- if ( recessive == null )
126
- {
127
- return ;
128
- }
129
-
130
- boolean mergeSelf = true ;
131
-
132
- String selfMergeMode = dominant .getAttribute ( SELF_COMBINATION_MODE_ATTRIBUTE );
133
-
134
- if ( isNotEmpty ( selfMergeMode ) && SELF_COMBINATION_OVERRIDE .equals ( selfMergeMode ) )
135
- {
136
- mergeSelf = false ;
137
- }
138
-
139
- if ( mergeSelf )
140
- {
141
- String [] recessiveAttrs = recessive .getAttributeNames ();
142
- for ( String attr : recessiveAttrs )
143
- {
144
- if ( isEmpty ( dominant .getAttribute ( attr ) ) )
145
- {
146
- dominant .setAttribute ( attr , recessive .getAttribute ( attr ) );
147
- }
148
- }
149
-
150
- boolean mergeChildren = true ;
151
-
152
- if ( childMergeOverride != null )
153
- {
154
- mergeChildren = childMergeOverride ;
155
- }
156
- else
157
- {
158
- String childMergeMode = dominant .getAttribute ( CHILDREN_COMBINATION_MODE_ATTRIBUTE );
159
-
160
- if ( isNotEmpty ( childMergeMode ) && CHILDREN_COMBINATION_APPEND .equals ( childMergeMode ) )
161
- {
162
- mergeChildren = false ;
163
- }
164
- }
165
-
166
- final String keysValue = recessive .getAttribute ( KEYS_COMBINATION_MODE_ATTRIBUTE );
167
-
168
- Xpp3Dom [] children = recessive .getChildren ();
169
- for ( Xpp3Dom recessiveChild : children )
170
- {
171
- String idValue = recessiveChild .getAttribute ( ID_COMBINATION_MODE_ATTRIBUTE );
172
-
173
- Xpp3Dom childDom = null ;
174
- if ( isNotEmpty ( idValue ) )
175
- {
176
- for ( Xpp3Dom dominantChild : dominant .getChildren () )
177
- {
178
- if ( idValue .equals ( dominantChild .getAttribute ( ID_COMBINATION_MODE_ATTRIBUTE ) ) )
179
- {
180
- childDom = dominantChild ;
181
- // we have a match, so don't append but merge
182
- mergeChildren = true ;
183
- }
184
- }
185
- }
186
- else if ( isNotEmpty ( keysValue ) )
187
- {
188
- String [] keys = keysValue .split ( "," );
189
- Map <String , String > recessiveKeyValues = new HashMap <>( keys .length );
190
- for ( String key : keys )
191
- {
192
- recessiveKeyValues .put ( key , recessiveChild .getAttribute ( key ) );
193
- }
194
-
195
- for ( Xpp3Dom dominantChild : dominant .getChildren () )
196
- {
197
- Map <String , String > dominantKeyValues = new HashMap <>( keys .length );
198
- for ( String key : keys )
199
- {
200
- dominantKeyValues .put ( key , dominantChild .getAttribute ( key ) );
201
- }
202
-
203
- if ( recessiveKeyValues .equals ( dominantKeyValues ) )
204
- {
205
- childDom = dominantChild ;
206
- // we have a match, so don't append but merge
207
- mergeChildren = true ;
208
- }
209
- }
210
-
211
- }
212
- else
213
- {
214
- childDom = dominant .getChild ( recessiveChild .getName () );
215
- }
216
-
217
- if ( mergeChildren && childDom != null )
218
- {
219
- mergeIntoXpp3Dom ( childDom , recessiveChild , childMergeOverride );
220
- }
221
- else
222
- {
223
- dominant .addChild ( new Xpp3Dom ( recessiveChild ) );
224
- }
225
- }
226
- }
96
+ dom .writeToSerializer ( namespace , serializer );
227
97
}
228
98
229
99
/**
@@ -236,15 +106,12 @@ else if ( isNotEmpty( keysValue ) )
236
106
* @param childMergeOverride Overrides attribute flags to force merging or appending of child elements into the
237
107
* dominant DOM
238
108
* @return merged DOM
109
+ * @deprecated use {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom, Boolean)}
239
110
*/
111
+ @ Deprecated
240
112
public static Xpp3Dom mergeXpp3Dom ( Xpp3Dom dominant , Xpp3Dom recessive , Boolean childMergeOverride )
241
113
{
242
- if ( dominant != null )
243
- {
244
- mergeIntoXpp3Dom ( dominant , recessive , childMergeOverride );
245
- return dominant ;
246
- }
247
- return recessive ;
114
+ return Xpp3Dom .mergeXpp3Dom ( dominant , recessive , childMergeOverride );
248
115
}
249
116
250
117
/**
@@ -256,15 +123,12 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean
256
123
* @param dominant The dominant DOM into which the recessive value/attributes/children will be merged
257
124
* @param recessive The recessive DOM, which will be merged into the dominant DOM
258
125
* @return merged DOM
126
+ * @deprecated use {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom)}
259
127
*/
128
+ @ Deprecated
260
129
public static Xpp3Dom mergeXpp3Dom ( Xpp3Dom dominant , Xpp3Dom recessive )
261
130
{
262
- if ( dominant != null )
263
- {
264
- mergeIntoXpp3Dom ( dominant , recessive , null );
265
- return dominant ;
266
- }
267
- return recessive ;
131
+ return Xpp3Dom .mergeXpp3Dom ( dominant , recessive );
268
132
}
269
133
270
134
/**
0 commit comments