in maven-utils/src/main/java/org/apache/myfaces/extensions/cdi/maven/BeansXmlTransformer.java [62:137]
public void processResource(String resource, InputStream is, List relocators) throws IOException
{
Document r;
try
{
SAXBuilder builder = new SAXBuilder(false);
builder.setExpandEntities(false);
if (ignoreDtd)
{
builder.setEntityResolver(new EntityResolver()
{
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
{
return new InputSource(new StringReader(""));
}
});
}
r = builder.build(is);
}
catch (JDOMException e)
{
throw new RuntimeException(e);
}
if (doc == null)
{
doc = r;
}
else
{
Element root = r.getRootElement();
for (Iterator itr = root.getAttributes().iterator(); itr.hasNext();)
{
Attribute a = (Attribute) itr.next();
itr.remove();
Element mergedEl = doc.getRootElement();
Attribute mergedAtt = mergedEl.getAttribute(a.getName(), a.getNamespace());
if (mergedAtt == null)
{
mergedEl.setAttribute(a);
}
}
Element docRoot = doc.getRootElement();
for (Iterator itr = root.getChildren().iterator(); itr.hasNext();)
{
Element child = (Element) itr.next();
itr.remove();
// check if the given element already exists as a child of the
// root element and if so, only add the grandchildren to the
// already existing child and not the whole child again
Element docChild = docRoot.getChild(child.getName(), child.getNamespace());
if (docChild != null)
{
// the docRoot already has this child
// --> add the grandchildren to the existing element
for (Iterator childrenItr = child.getChildren().iterator(); childrenItr.hasNext();)
{
Element grandchild = (Element) childrenItr.next();
childrenItr.remove();
docChild.addContent(grandchild);
}
}
else
{
// the docRoot does not have this child yet
docRoot.addContent(child);
}
}
}
}