Skip to content

Commit 85fe71e

Browse files
authored
Deprecate Xpp3DomUtils (fixes #6) (#9)
1 parent 8351c4e commit 85fe71e

File tree

4 files changed

+175
-419
lines changed

4 files changed

+175
-419
lines changed

src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,38 @@ public class Xpp3Dom
3535
{
3636
private static final String[] EMPTY_STRING_ARRAY = new String[0];
3737

38-
public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = "combine.children";
38+
public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = XmlNode.CHILDREN_COMBINATION_MODE_ATTRIBUTE;
3939

40-
public static final String CHILDREN_COMBINATION_MERGE = "merge";
40+
public static final String CHILDREN_COMBINATION_MERGE = XmlNode.CHILDREN_COMBINATION_MERGE;
4141

42-
public static final String CHILDREN_COMBINATION_APPEND = "append";
42+
public static final String CHILDREN_COMBINATION_APPEND = XmlNode.CHILDREN_COMBINATION_APPEND;
4343

4444
/**
4545
* This default mode for combining children DOMs during merge means that where element names match, the process will
4646
* try to merge the element data, rather than putting the dominant and recessive elements (which share the same
4747
* element name) as siblings in the resulting DOM.
4848
*/
49-
public static final String DEFAULT_CHILDREN_COMBINATION_MODE = CHILDREN_COMBINATION_MERGE;
49+
public static final String DEFAULT_CHILDREN_COMBINATION_MODE = XmlNode.DEFAULT_CHILDREN_COMBINATION_MODE;
5050

51-
public static final String SELF_COMBINATION_MODE_ATTRIBUTE = "combine.self";
51+
public static final String SELF_COMBINATION_MODE_ATTRIBUTE = XmlNode.SELF_COMBINATION_MODE_ATTRIBUTE;
5252

53-
public static final String SELF_COMBINATION_OVERRIDE = "override";
53+
public static final String SELF_COMBINATION_OVERRIDE = XmlNode.SELF_COMBINATION_OVERRIDE;
5454

55-
public static final String SELF_COMBINATION_MERGE = "merge";
55+
public static final String SELF_COMBINATION_MERGE = XmlNode.SELF_COMBINATION_MERGE;
5656

57-
public static final String SELF_COMBINATION_REMOVE = "remove";
57+
public static final String SELF_COMBINATION_REMOVE = XmlNode.SELF_COMBINATION_REMOVE;
5858

5959
/**
6060
* This default mode for combining a DOM node during merge means that where element names match, the process will
6161
* try to merge the element attributes and values, rather than overriding the recessive element completely with the
6262
* dominant one. This means that wherever the dominant element doesn't provide the value or a particular attribute,
6363
* that value or attribute will be set from the recessive DOM node.
6464
*/
65-
public static final String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE;
65+
public static final String DEFAULT_SELF_COMBINATION_MODE = XmlNode.DEFAULT_SELF_COMBINATION_MODE;
66+
67+
public static final String ID_COMBINATION_MODE_ATTRIBUTE = XmlNode.ID_COMBINATION_MODE_ATTRIBUTE;
68+
69+
public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = XmlNode.KEYS_COMBINATION_MODE_ATTRIBUTE;
6670

6771
private ChildrenTracking childrenTracking;
6872
private XmlNode dom;

src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java

+55-191
Original file line numberDiff line numberDiff line change
@@ -23,207 +23,77 @@
2323
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
2424

2525
/** @author Jason van Zyl */
26+
@Deprecated
2627
public class Xpp3DomUtils
2728
{
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;
3134

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;
3340

3441
/**
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}
3843
*/
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;
4046

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;
4252

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;
4458

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;
4664

4765
/**
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}
5167
*/
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+
5471
/**
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}
5973
*/
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;
6176

6277
/**
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}
6779
*/
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;
6982

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;
8288

8389
/**
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)}
12191
*/
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
12395
{
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 );
22797
}
22898

22999
/**
@@ -236,15 +106,12 @@ else if ( isNotEmpty( keysValue ) )
236106
* @param childMergeOverride Overrides attribute flags to force merging or appending of child elements into the
237107
* dominant DOM
238108
* @return merged DOM
109+
* @deprecated use {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom, Boolean)}
239110
*/
111+
@Deprecated
240112
public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride )
241113
{
242-
if ( dominant != null )
243-
{
244-
mergeIntoXpp3Dom( dominant, recessive, childMergeOverride );
245-
return dominant;
246-
}
247-
return recessive;
114+
return Xpp3Dom.mergeXpp3Dom( dominant, recessive, childMergeOverride );
248115
}
249116

250117
/**
@@ -256,15 +123,12 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean
256123
* @param dominant The dominant DOM into which the recessive value/attributes/children will be merged
257124
* @param recessive The recessive DOM, which will be merged into the dominant DOM
258125
* @return merged DOM
126+
* @deprecated use {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom)}
259127
*/
128+
@Deprecated
260129
public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
261130
{
262-
if ( dominant != null )
263-
{
264-
mergeIntoXpp3Dom( dominant, recessive, null );
265-
return dominant;
266-
}
267-
return recessive;
131+
return Xpp3Dom.mergeXpp3Dom( dominant, recessive );
268132
}
269133

270134
/**

0 commit comments

Comments
 (0)