final Path resource ) {
if ( packageHeaderInfo.getHeader() == null ) {
return xml;
}
final Imports imports = ImportsParser.parseImports( packageHeaderInfo.getHeader() );
if ( imports == null ) {
return xml;
}
DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder dombuilder = domfac.newDocumentBuilder();
Document doc = dombuilder.parse( new ByteArrayInputStream( xml.getBytes() ) );
if ( doc.getElementsByTagName( "imports" ).getLength() != 0 ) {
return xml;
}
Element root = doc.getDocumentElement();
Element importsElement = doc.createElement( "imports" );
for ( final Import i : imports.getImports() ) {
Element importElement = doc.createElement( "import" );
importElement.appendChild( doc.createTextNode( i.getType() ) );
importsElement.appendChild( importElement );
}