i don't know if it's the good post but i think it's interessting for the beandoc users
i've modified the org.springframework.beandoc.DefaultContextProcesso r to handle the includes in the files
Code:
<beans>
<import resource="classpath:/ent-context.xml"/>
<beans>
in the method buildDomsFromInputFiles() i have added a called to handleIncludes
Code:
/**
* generate in memory DOM representations from the input files on disk
*
* @return a Document[]
* @throws IOException
*/
private Document[] buildDomsFromInputFiles() throws IOException {
logger.debug("Starting building DOM trees from input files");
....
// set an attribute on the root element to mark the original input
// file
Element root = contextDocuments[i].getRootElement();
root.setAttribute(Tags.ATTRIBUTE_BD_FILENAME,
normalisedFileNames[i]);
logger.debug("Attribute [" + Tags.ATTRIBUTE_BD_FILENAME
+ "] set to [" + normalisedFileNames[i] + "]");
handleIncludes(contextDocuments, builder, i);
...
and here's the code of the handleIncludes method
Code:
private void handleIncludes(Document[] contextDocuments, SAXBuilder builder, int i) throws IOException {
List imports = contextDocuments[i].getRootElement().getChildren(
"import");
List importedbeans = new ArrayList();
for (Iterator iter = imports.iterator(); iter.hasNext();) {
Element includedImport = (Element) iter.next();
String importfile = includedImport
.getAttributeValue("resource");
ResourceLoader loader = new DefaultResourceLoader();
Resource res = loader.getResource(importfile);
try {
Document importDocument = builder.build(res
.getInputStream());
List beans = importDocument.getRootElement().getChildren(
"bean");
for (Iterator iterator = beans.iterator(); iterator
.hasNext();) {
Element bean = (Element) iterator.next();
importedbeans.add(bean);
}
} catch (JDOMException e) {
throw new BeanDocException(
"Unable to parse or validate input resource ["
+ res + "]", e);
}
}
// move the bean nodes to the current contextDocuments
for (Iterator iter = importedbeans.iterator(); iter.hasNext();) {
Element bean = (Element) iter.next(); contextDocuments[i].getRootElement().addContent(bean.detach());
}
}
and voila...