PrefixRewriter { public static void rewritePrefix( Element element, String oldPrefix, String newPrefix ) { rewritePrefix( element, oldPrefix, newPrefix, new ArrayList<Element>( 0 ) ); } private  PrefixRewriter(); static void rewritePrefix( Element element, String oldPrefix, String newPrefix ); static void rewritePrefix( Element element, String oldPrefix, String newPrefix,
                                      List<Element> untouchedElementList );  }
@Test public void testRewritePrefix() { Document saml = generatePayloadElementOfDummySamlDocument().getOwnerDocument(); String docString = DomUtilities.domToString( saml, true ); assertFalse( docString.contains( "<xyz:" ) ); assertTrue( docString.contains( "<samlp:" ) ); PrefixRewriter.rewritePrefix( saml.getDocumentElement(), "samlp", "xyz" ); docString = DomUtilities.domToString( saml, true ); assertTrue( docString.contains( "<xyz:" ) ); assertFalse( docString.contains( "<samlp:" ) ); }
@Test public void testRewritePrefix_with_untouched_Elements() { Element payload = generatePayloadElementOfDummySamlDocument(); Document saml = payload.getOwnerDocument(); String docString = DomUtilities.domToString( saml, true ); assertFalse( docString.contains( "<xyz:" ) ); assertTrue( docString.contains( "<samlp:" ) ); List<Element> untouchedList = new ArrayList<Element>( 1 ); untouchedList.add( payload ); PrefixRewriter.rewritePrefix( saml.getDocumentElement(), "samlp", "xyz", untouchedList ); String payloadString = DomUtilities.domToString( payload, true ); assertFalse( payloadString.contains( "<xyz:" ) ); assertTrue( payloadString.contains( "<samlp:" ) ); payload.getParentNode().removeChild( payload ); docString = DomUtilities.domToString( saml, true ); assertTrue( docString.contains( "<xyz:" ) ); assertFalse( docString.contains( "<samlp:" ) ); }