{
document = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder().newDocument();
}
catch ( ParserConfigurationException e )
{
throw new DocumentRendererException( "Error building document :" + e.getMessage() );
}
document.appendChild( document.createElement( ElementTags.ITEXT ) ); // Used only to set a root
for ( File iTextFile : iTextFiles )
{
Document iTextDocument;
try
{
iTextDocument = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder().parse( iTextFile );
}
catch ( SAXException e )
{
throw new DocumentRendererException( "SAX Error : " + e.getMessage() );
}
catch ( ParserConfigurationException e )
{
throw new DocumentRendererException( "Error parsing configuration : " + e.getMessage() );
}
// Only one chapter per doc
Node chapter = iTextDocument.getElementsByTagName( ElementTags.CHAPTER ).item( 0 );
try
{
document.getDocumentElement().appendChild( document.importNode( chapter, true ) );
}
catch ( DOMException e )
{
throw new DocumentRendererException( "Error appending chapter for "
+ iTextFile + " : " + e.getMessage() );
}
}
return document;