|
22 | 22 | import java.io.Serializable;
|
23 | 23 | import java.io.StringWriter;
|
24 | 24 | import java.util.ArrayList;
|
25 |
| -import java.util.Arrays; |
26 | 25 | import java.util.Collections;
|
27 | 26 | import java.util.HashMap;
|
28 | 27 | import java.util.Iterator;
|
@@ -76,6 +75,8 @@ public class Xpp3Dom
|
76 | 75 |
|
77 | 76 | public static final String SELF_COMBINATION_MERGE = "merge";
|
78 | 77 |
|
| 78 | + public static final String SELF_COMBINATION_REMOVE = "remove"; |
| 79 | + |
79 | 80 | /**
|
80 | 81 | * This default mode for combining a DOM node during merge means that where element names match, the process will
|
81 | 82 | * try to merge the element attributes and values, rather than overriding the recessive element completely with the
|
@@ -301,6 +302,13 @@ public void removeChild( int i )
|
301 | 302 | child.setParent( null );
|
302 | 303 | }
|
303 | 304 |
|
| 305 | + public void removeChild( Xpp3Dom child ) |
| 306 | + { |
| 307 | + childList.remove( child ); |
| 308 | + // In case of any dangling references |
| 309 | + child.setParent( null ); |
| 310 | + } |
| 311 | + |
304 | 312 | // ----------------------------------------------------------------------
|
305 | 313 | // Parent handling
|
306 | 314 | // ----------------------------------------------------------------------
|
@@ -418,7 +426,7 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
|
418 | 426 | {
|
419 | 427 | for ( String attr : recessive.attributes.keySet() )
|
420 | 428 | {
|
421 |
| - if ( isEmpty( dominant.getAttribute( attr ) ) ) |
| 429 | + if ( isEmpty( dominant.getAttribute( attr ) ) && !SELF_COMBINATION_MODE_ATTRIBUTE.equals( attr ) ) |
422 | 430 | {
|
423 | 431 | dominant.setAttribute( attr, recessive.getAttribute( attr ) );
|
424 | 432 | }
|
@@ -489,7 +497,17 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
|
489 | 497 | else if ( it.hasNext() )
|
490 | 498 | {
|
491 | 499 | Xpp3Dom dominantChild = it.next();
|
492 |
| - mergeIntoXpp3Dom( dominantChild, recessiveChild, childMergeOverride ); |
| 500 | + |
| 501 | + String dominantChildCombinationMode = |
| 502 | + dominantChild.getAttribute( SELF_COMBINATION_MODE_ATTRIBUTE ); |
| 503 | + if ( SELF_COMBINATION_REMOVE.equals( dominantChildCombinationMode ) ) |
| 504 | + { |
| 505 | + dominant.removeChild( dominantChild ); |
| 506 | + } |
| 507 | + else |
| 508 | + { |
| 509 | + mergeIntoXpp3Dom( dominantChild, recessiveChild, childMergeOverride ); |
| 510 | + } |
493 | 511 | }
|
494 | 512 | }
|
495 | 513 | }
|
|
0 commit comments