}
render( siteDirectory, outputDirectory );
return;
}
DocumentModel documentModel;
Reader reader = null;
try
{
reader = ReaderFactory.newXmlReader( documentDescriptor );
documentModel = new DocumentXpp3Reader().read( reader );
}
catch ( XmlPullParserException e )
{
throw new DocumentRendererException( "Error parsing document descriptor", e );
}
catch ( IOException e )
{
throw new DocumentRendererException( "Error reading document descriptor", e );
}
finally
{
IOUtil.close( reader );
}
if ( documentModel.getOutputName() == null )
{
if ( getLogger().isInfoEnabled() )
{
getLogger().info( "No outputName is defined in the document descriptor. Using 'generated_itext'" );
}
documentModel.setOutputName( "generated_itext" );
}
if ( ( documentModel.getToc() == null ) || ( documentModel.getToc().getItems() == null ) )
{
if ( getLogger().isInfoEnabled() )
{
getLogger().info( "No TOC is defined in the document descriptor. Merging all documents." );
}
}
List<File> iTextFiles = new LinkedList<File>();
Collection<SiteModule> modules = siteModuleManager.getSiteModules();
for ( SiteModule module : modules )
{
File moduleBasedir = new File( siteDirectory, module.getSourceDirectory() );
if ( moduleBasedir.exists() )
{
@SuppressWarnings ( "unchecked" )
List<String> docs =
FileUtils.getFileNames( moduleBasedir, "**/*." + module.getExtension(), null, false );
for ( String doc : docs )
{
String fullPathDoc = new File( moduleBasedir, doc ).getPath();
String outputITextName = doc.substring( 0, doc.lastIndexOf( '.') + 1 ) + "xml";
File outputITextFile = new File( outputDirectory, outputITextName );
if ( ( documentModel.getToc() == null ) || ( documentModel.getToc().getItems() == null ) )
{
iTextFiles.add( outputITextFile );
if ( !outputITextFile.getParentFile().exists() )
{
outputITextFile.getParentFile().mkdirs();
}
parse( fullPathDoc, module, outputITextFile );
}
else
{
for ( Iterator<DocumentTOCItem> k = documentModel.getToc().getItems().iterator(); k.hasNext(); )
{
DocumentTOCItem tocItem = k.next();
if ( tocItem.getRef() == null )
{
if ( getLogger().isInfoEnabled() )
{
getLogger().info( "No ref defined for an tocItem in the document descriptor." );
}
continue;
}
String outTmp = StringUtils.replace( outputITextFile.getAbsolutePath(), "\\", "/" );
outTmp = outTmp.substring( 0, outTmp.lastIndexOf( '.') );
String outRef = StringUtils.replace( tocItem.getRef(), "\\", "/" );
if ( outRef.lastIndexOf( '.') != -1 )
{
outRef = outRef.substring( 0, outRef.lastIndexOf( '.') );
}
else
{
outRef = outRef.substring( 0, outRef.length() );
}
if ( outTmp.indexOf( outRef ) != -1 )
{
iTextFiles.add( outputITextFile );
if ( !outputITextFile.getParentFile().exists() )
{
outputITextFile.getParentFile().mkdirs();
}
parse( fullPathDoc, module, outputITextFile );
}
}
}
}
}
}
File iTextFile = new File( outputDirectory, documentModel.getOutputName() + ".xml" );
File iTextOutput = new File( outputDirectory, documentModel.getOutputName() + "." + getOutputExtension() );
Document document = generateDocument( iTextFiles );
transform( documentModel, document, iTextFile );
generateOutput( iTextFile, iTextOutput );
}