protected static String addMavenNamespace(String effectiveXml,boolean isPom){
  SAXBuilder builder=new SAXBuilder();
  try {
    Document document=builder.build(new StringReader(effectiveXml));
    Element rootElement=document.getRootElement();
    Namespace pomNamespace=Namespace.getNamespace("","http://maven.apache.org/POM/4.0.0");
    rootElement.setNamespace(pomNamespace);
    Namespace xsiNamespace=Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
    rootElement.addNamespaceDeclaration(xsiNamespace);
    if (rootElement.getAttribute("schemaLocation",xsiNamespace) == null) {
      rootElement.setAttribute("schemaLocation","http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL),xsiNamespace);
    }
    ElementFilter elementFilter=new ElementFilter(Namespace.getNamespace(""));
    for (Iterator<?> i=rootElement.getDescendants(elementFilter); i.hasNext(); ) {
      Element e=(Element)i.next();
      e.setNamespace(pomNamespace);
    }
    StringWriter w=new StringWriter();
    Format format=Format.getPrettyFormat();
    XMLOutputter out=new XMLOutputter(format);
    out.output(document.getRootElement(),w);
    return w.toString();
  }
 catch (  JDOMException e) {
    return effectiveXml;
  }
catch (  IOException e) {
    return effectiveXml;
  }
}

protected static String addMavenNamespace ( String effectiveXml , boolean isPom ) { SAXBuilder builder = new SAXBuilder ( ) ; try { Document document = builder . build ( new StringReader ( effectiveXml ) ) ; Element rootElement = document . getRootElement ( ) ; Namespace pomNamespace = Namespace . getNamespace ( "" , "http://maven.apache.org/POM/4.0.0" ) ; rootElement . setNamespace ( pomNamespace ) ; Namespace xsiNamespace = Namespace . getNamespace ( "xsi" , "http://www.w3.org/2001/XMLSchema-instance" ) ; rootElement . addNamespaceDeclaration ( xsiNamespace ) ; if ( rootElement . getAttribute ( "schemaLocation" , xsiNamespace ) == null ) { rootElement . setAttribute ( "schemaLocation" , "http://maven.apache.org/POM/4.0.0 " + ( isPom ? POM_XSD_URL : SETTINGS_XSD_URL ) , xsiNamespace ) ; } ElementFilter elementFilter = new ElementFilter ( Namespace . getNamespace ( "" ) ) ; for ( Iterator < ? > i = rootElement . getDescendants ( elementFilter ) ; i . hasNext ( ) ; ) { Element e = ( Element ) i . next ( ) ; e . setNamespace ( pomNamespace ) ; } StringWriter w = new StringWriter ( ) ; Format format = Format . getPrettyFormat ( ) ; XMLOutputter out = new XMLOutputter ( format ) ; out . output ( document . getRootElement ( ) , w ) ; return w . toString ( ) ; } catch ( JDOMException e ) { return effectiveXml ; } catch ( IOException e ) { return effectiveXml ; } }
method from org . apache . maven . plugins . help . abstracteffectivemojo add a pom / settings namespaces to the effective xml content .
