Author: vsiveton
Date: Sun Jun 7 13:32:11 2009
New Revision: 782388
URL: http://svn.apache.org/viewvc?rev=782388&view=rev
Log:
DOXIASITETOOLS-25: Add a way to render all sources individually in addition to
an aggregated document
o add logic for documentModel, ie if null, generate all documents individually
o update code to take care of null DocumentModel
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/AbstractDocumentRenderer.java
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRenderer.java
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/AbstractDocumentRenderer.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/AbstractDocumentRenderer.java?rev=782388&r1=782387&r2=782388&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/AbstractDocumentRenderer.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/AbstractDocumentRenderer.java
Sun Jun 7 13:32:11 2009
@@ -79,11 +79,11 @@
//--------------------------------------------
/**
- * Render a document from the files found in a Map.
+ * Render an aggregate document from the files found in a Map.
*
* @param filesToProcess the Map of Files to process. The Map should
contain as keys the paths of the
* source files (relative to {...@link #getBaseDir() baseDir}), and
the corresponding SiteModule as values.
- * @param outputDirectory the output directory where the document should
be generated.
+ * @param outputDirectory the output directory where the aggregate
document should be generated.
* @param documentModel the document model, containing all the metadata,
etc.
* @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if
any
* @throws java.io.IOException if any
@@ -91,6 +91,19 @@
public abstract void render( Map filesToProcess, File outputDirectory,
DocumentModel documentModel )
throws DocumentRendererException, IOException;
+ /**
+ * Render documents separately for each file found in a Map.
+ *
+ * @param filesToProcess the Map of Files to process. The Map should
contain as keys the paths of the
+ * source files (relative to {...@link #getBaseDir() baseDir}), and
the corresponding SiteModule as values.
+ * @param outputDirectory the output directory where the documents should
be generated.
+ * @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if
any
+ * @throws java.io.IOException if any
+ * @since 1.1.1
+ */
+ public abstract void renderIndividual( Map filesToProcess, File
outputDirectory )
+ throws DocumentRendererException, IOException;
+
//--------------------------------------------
//
//--------------------------------------------
@@ -118,11 +131,12 @@
* @param outputDirectory the output directory where the document should
be generated.
* @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if
any
* @throws java.io.IOException if any
+ * @see #render(File, File, DocumentModel)
*/
public void render( File baseDirectory, File outputDirectory )
throws DocumentRendererException, IOException
{
- render( baseDirectory, outputDirectory, new DocumentModel() );
+ render( baseDirectory, outputDirectory, (DocumentModel) null );
}
/**
@@ -135,6 +149,8 @@
* If this file does not exist or is null, some default
settings will be used.
* @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if
any
* @throws java.io.IOException if any
+ * @see #render(File, File) if documentDescriptor does not exist or is null
+ * @see #render(Map, File, DocumentModel) otherwise
*/
public void render( File baseDirectory, File outputDirectory, File
documentDescriptor )
throws DocumentRendererException, IOException
@@ -340,6 +356,11 @@
protected void parse( String fullDocPath, String parserId, Sink sink )
throws DocumentRendererException, IOException
{
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "Parsing file " + fullDocPath );
+ }
+
Reader reader = null;
try
{
@@ -391,10 +412,17 @@
{
File resourcesDirectory = new File( getBaseDir(), "resources" );
- if ( resourcesDirectory.isDirectory() && outputDirectory.isDirectory()
)
+ if ( !resourcesDirectory.isDirectory() )
{
- copyDirectory( resourcesDirectory, outputDirectory );
+ return;
}
+
+ if ( !outputDirectory.exists() )
+ {
+ outputDirectory.mkdirs();
+ }
+
+ copyDirectory( resourcesDirectory, outputDirectory );
}
/**
@@ -435,4 +463,34 @@
}
}
}
+
+ /**
+ * @param documentModel not null
+ * @return the output name defined in the documentModel without the output
extension. If the output name is not
+ * defined, return target by default.
+ * @since 1.1.1
+ * @see org.apache.maven.doxia.document.DocumentModel#getOutputName()
+ * @see #getOutputExtension()
+ */
+ protected String getOutputName( DocumentModel documentModel )
+ {
+ String outputName = documentModel.getOutputName();
+ if ( outputName == null )
+ {
+ getLogger().info( "No outputName is defined in the document
descriptor. Using 'target'" );
+
+ documentModel.setOutputName( "target" );
+ }
+
+ outputName = outputName.trim();
+ if ( outputName.toLowerCase( Locale.ENGLISH ).endsWith( "." +
getOutputExtension() ) )
+ {
+ outputName =
+ outputName.substring( 0, outputName.toLowerCase(
Locale.ENGLISH )
+ .lastIndexOf( "." +
getOutputExtension() ) );
+ }
+ documentModel.setOutputName( outputName );
+
+ return documentModel.getOutputName();
+ }
}
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRenderer.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRenderer.java?rev=782388&r1=782387&r2=782388&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRenderer.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRenderer.java
Sun Jun 7 13:32:11 2009
@@ -47,6 +47,7 @@
* @param documentModel the document model, containing all the metadata,
etc.
* If the model contains a TOC, only the files found in this
TOC are rendered,
* otherwise all files from the Collection of files will be
processed.
+ * If the model is null, render all files individually.
* @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if
any.
* @throws java.io.IOException if any.
*/
@@ -62,6 +63,7 @@
* @param documentModel the document model, containing all the metadata,
etc.
* If the model contains a TOC, only the files found in this
TOC are rendered,
* otherwise all files found under baseDirectory will be
processed.
+ * If the model is null, render all files from baseDirectory
individually.
* @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if
any
* @throws java.io.IOException if any
*/
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java?rev=782388&r1=782387&r2=782388&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java
Sun Jun 7 13:32:11 2009
@@ -35,6 +35,8 @@
import org.apache.maven.doxia.document.DocumentTOC;
import org.apache.maven.doxia.document.DocumentTOCItem;
import org.apache.maven.doxia.module.fo.FoAggregateSink;
+import org.apache.maven.doxia.module.fo.FoSink;
+import org.apache.maven.doxia.module.fo.FoSinkFactory;
import org.apache.maven.doxia.module.fo.FoUtils;
import org.apache.maven.doxia.module.site.SiteModule;
@@ -70,41 +72,31 @@
public void render( Map filesToProcess, File outputDirectory,
DocumentModel documentModel )
throws DocumentRendererException, IOException
{
- String outputName = documentModel.getOutputName();
+ // copy resources, images, etc.
+ copyResources( outputDirectory );
- if ( outputName == null )
+ if ( documentModel == null )
{
- getLogger().info( "No outputName is defined in the document
descriptor. Using 'target.pdf'" );
+ getLogger().debug( "No document model, generating all documents
individually." );
- documentModel.setOutputName( "target" );
- }
-
- outputName = outputName.trim();
- if ( outputName.toLowerCase( Locale.ENGLISH ).endsWith( ".pdf" ) )
- {
- documentModel.setOutputName( outputName.substring( 0,
outputName.toLowerCase( Locale.ENGLISH )
-
.lastIndexOf( ".pdf" ) ) );
+ renderIndividual( filesToProcess, outputDirectory );
+ return;
}
- outputName = documentModel.getOutputName();
+ String outputName = getOutputName( documentModel );
File outputFOFile = new File( outputDirectory, outputName + ".fo" );
-
if ( !outputFOFile.getParentFile().exists() )
{
outputFOFile.getParentFile().mkdirs();
}
File pdfOutputFile = new File( outputDirectory, outputName + ".pdf" );
-
if ( !pdfOutputFile.getParentFile().exists() )
{
pdfOutputFile.getParentFile().mkdirs();
}
- // copy resources, images, etc.
- copyResources( outputDirectory );
-
Writer writer = null;
try
{
@@ -136,6 +128,8 @@
}
else
{
+ getLogger().debug( "Using TOC defined in the document
descriptor." );
+
mergeSourcesFromTOC( documentModel.getToc(), sink );
}
@@ -149,22 +143,58 @@
generatePdf( outputFOFile, pdfOutputFile, documentModel );
}
- private void mergeAllSources( Map filesToProcess, FoAggregateSink sink )
- throws DocumentRendererException, IOException
+ /** {...@inheritdoc} */
+ public void renderIndividual( Map filesToProcess, File outputDirectory )
+ throws DocumentRendererException, IOException
{
for ( Iterator j = filesToProcess.keySet().iterator(); j.hasNext(); )
{
String key = (String) j.next();
SiteModule module = (SiteModule) filesToProcess.get( key );
- sink.setDocumentName( key );
- String fullDocPath = getBaseDir() + File.separator +
module.getSourceDirectory() + File.separator + key;
- if ( getLogger().isDebugEnabled() )
+ File fullDoc = new File( getBaseDir(), module.getSourceDirectory()
+ File.separator + key );
+
+ String output = key;
+ String lowerCaseExtension = module.getExtension().toLowerCase(
Locale.ENGLISH );
+ if ( output.toLowerCase( Locale.ENGLISH ).indexOf( "." +
lowerCaseExtension ) != -1 )
+ {
+ output =
+ output.substring( 0, output.toLowerCase( Locale.ENGLISH
).indexOf( "." + lowerCaseExtension ) );
+ }
+
+ File outputFOFile = new File( outputDirectory, output + ".fo" );
+ if ( !outputFOFile.getParentFile().exists() )
{
- getLogger().debug( "Parsing file " + fullDocPath );
+ outputFOFile.getParentFile().mkdirs();
}
- parse( fullDocPath, module.getParserId(), sink );
+ File pdfOutputFile = new File( outputDirectory, output + ".pdf" );
+ if ( !pdfOutputFile.getParentFile().exists() )
+ {
+ pdfOutputFile.getParentFile().mkdirs();
+ }
+
+ FoSink sink =
+ (FoSink) new FoSinkFactory().createSink(
outputFOFile.getParentFile(), outputFOFile.getName() );
+ sink.beginDocument();
+ parse( fullDoc.getAbsolutePath(), module.getParserId(), sink );
+ sink.endDocument();
+
+ generatePdf( outputFOFile, pdfOutputFile, null );
+ }
+ }
+
+ private void mergeAllSources( Map filesToProcess, FoAggregateSink sink )
+ throws DocumentRendererException, IOException
+ {
+ for ( Iterator j = filesToProcess.keySet().iterator(); j.hasNext(); )
+ {
+ String key = (String) j.next();
+ SiteModule module = (SiteModule) filesToProcess.get( key );
+ sink.setDocumentName( key );
+ File fullDoc = new File( getBaseDir(), module.getSourceDirectory()
+ File.separator + key );
+
+ parse( fullDoc.getAbsolutePath(), module.getParserId(), sink );
}
}
@@ -192,7 +222,6 @@
}
String href = StringUtils.replace( tocItem.getRef(), "\\", "/" );
-
if ( href.lastIndexOf( "." ) != -1 )
{
href = href.substring( 0, href.lastIndexOf( "." ) );
@@ -222,11 +251,6 @@
if ( source.exists() )
{
- if ( getLogger().isDebugEnabled() )
- {
- getLogger().debug( "Parsing file " + source );
- }
-
sink.setDocumentName( doc );
sink.setDocumentTitle( tocItem.getName() );
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java?rev=782388&r1=782387&r2=782388&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java
Sun Jun 7 13:32:11 2009
@@ -28,7 +28,9 @@
import java.net.URLClassLoader;
import java.util.Date;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -45,12 +47,14 @@
import org.apache.maven.doxia.docrenderer.DocumentRendererException;
import org.apache.maven.doxia.docrenderer.pdf.AbstractPdfRenderer;
import org.apache.maven.doxia.document.DocumentModel;
+import org.apache.maven.doxia.document.DocumentTOCItem;
import org.apache.maven.doxia.module.itext.ITextSink;
import org.apache.maven.doxia.module.itext.ITextSinkFactory;
import org.apache.maven.doxia.module.itext.ITextUtil;
import org.apache.maven.doxia.module.site.SiteModule;
import org.apache.xml.utils.DefaultErrorHandler;
import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
@@ -109,71 +113,91 @@
}
/** {...@inheritdoc} */
- public void render( Map filesToProcess, File outputDirectory,
DocumentModel documentModel )
+ public void render( Map filesToProcess, File outputDirectory,
DocumentModel documentModel )
throws DocumentRendererException, IOException
{
- String outputName = documentModel.getOutputName();
+ // copy resources, images, etc.
+ copyResources( outputDirectory );
- if ( outputName == null )
+ if ( documentModel == null )
{
- if ( getLogger().isInfoEnabled() )
- {
- getLogger().info( "No outputName is defined in the document
descriptor. Using 'target.pdf'" );
- }
+ getLogger().debug( "No document model, generating all documents
individually." );
- documentModel.setOutputName( "target" );
+ renderIndividual( filesToProcess, outputDirectory );
+ return;
}
- else if ( outputName.lastIndexOf( "." ) != -1 )
+
+ String outputName = getOutputName( documentModel );
+
+ File outputITextFile = new File( outputDirectory, outputName + ".xml"
);
+ if ( !outputITextFile.getParentFile().exists() )
{
- documentModel.setOutputName( outputName.substring( 0,
outputName.lastIndexOf( "." ) ) );
+ outputITextFile.getParentFile().mkdirs();
}
-// TODO: adjust from o.a.m.d.docrenderer.itext.AbstractITextRender
-// if ( ( documentModel.getToc() == null ) || (
documentModel.getToc().getItems() == null ) )
-// {
-// getLogger().info( "No TOC is defined in the document descriptor.
Generating all documents." );
-
- for ( Iterator j = filesToProcess.keySet().iterator();
j.hasNext(); )
- {
- String key = (String) j.next();
+ File pdfOutputFile = new File( outputDirectory, outputName + ".pdf" );
+ if ( !pdfOutputFile.getParentFile().exists() )
+ {
+ pdfOutputFile.getParentFile().mkdirs();
+ }
- SiteModule module = (SiteModule) filesToProcess.get( key );
+ List iTextFiles;
+ if ( ( documentModel.getToc() == null ) || (
documentModel.getToc().getItems() == null ) )
+ {
+ getLogger().info( "No TOC is defined in the document descriptor.
Merging all documents." );
+ iTextFiles = parseAllFiles( filesToProcess, outputDirectory );
+ }
+ else
+ {
+ getLogger().debug( "Using TOC defined in the document descriptor."
);
- String fullDocPath = getBaseDir() + File.separator
- + module.getSourceDirectory() + File.separator +
key;
+ iTextFiles = parseTOCFiles( filesToProcess, outputDirectory,
documentModel );
+ }
- String iTextFileName = key.substring( 0, key.indexOf( "." ) +
1 ) + "xml";
+ File iTextFile = new File( outputDirectory, outputName + ".xml" );
+ File iTextOutput = new File( outputDirectory, outputName + "." +
getOutputExtension() );
+ Document document = generateDocument( iTextFiles );
+ transform( documentModel, document, iTextFile );
+ generatePdf( iTextFile, iTextOutput );
+ }
- File iTextFile = new File( outputDirectory, iTextFileName );
- if ( !iTextFile.getParentFile().exists() )
- {
- iTextFile.getParentFile().mkdirs();
- }
+ /** {...@inheritdoc} */
+ public void renderIndividual( Map filesToProcess, File outputDirectory )
+ throws DocumentRendererException, IOException
+ {
+ for ( Iterator it = filesToProcess.keySet().iterator(); it.hasNext(); )
+ {
+ String key = (String) it.next();
+ SiteModule module = (SiteModule) filesToProcess.get( key );
+ File fullDoc = new File( getBaseDir(), module.getSourceDirectory()
+ File.separator + key );
+
+ String output = key;
+ String lowerCaseExtension = module.getExtension().toLowerCase(
Locale.ENGLISH );
+ if ( output.toLowerCase( Locale.ENGLISH ).indexOf( "." +
lowerCaseExtension ) != -1 )
+ {
+ output =
+ output.substring( 0, output.toLowerCase( Locale.ENGLISH
).indexOf( "." + lowerCaseExtension ) );
+ }
- String pdfFileName = key.substring( 0, key.indexOf( "." ) + 1
) + getOutputExtension();
+ File outputITextFile = new File( outputDirectory, output + ".xml"
);
+ if ( !outputITextFile.getParentFile().exists() )
+ {
+ outputITextFile.getParentFile().mkdirs();
+ }
- File pdfFile = new File( outputDirectory, pdfFileName );
- if ( !pdfFile.getParentFile().exists() )
- {
- pdfFile.getParentFile().mkdirs();
- }
+ File pdfOutputFile = new File( outputDirectory, output + ".pdf" );
+ if ( !pdfOutputFile.getParentFile().exists() )
+ {
+ pdfOutputFile.getParentFile().mkdirs();
+ }
- parse( fullDocPath, module, iTextFile );
+ parse( fullDoc, module, outputITextFile );
- generatePdf( iTextFile, pdfFile );
- }
-/*
+ generatePdf( outputITextFile, pdfOutputFile );
}
- else
- {
- // TODO: adjust from o.a.m.d.docrenderer.itext.AbstractITextRender
- }
-*/
-
}
-
//--------------------------------------------
//
//--------------------------------------------
@@ -182,15 +206,20 @@
/**
* Parse a source document and emit results into a sink.
*
- * @param fullDocPath absolute path to the source document.
+ * @param fullDocPath file to the source document.
* @param module the site module associated with the source document
(determines the parser to use).
* @param iTextFile the resulting iText xml file.
* @throws DocumentRendererException in case of a parsing problem.
* @throws IOException if the source and/or target document cannot be
opened.
*/
- private void parse( String fullDocPath, SiteModule module, File iTextFile )
+ private void parse( File fullDoc, SiteModule module, File iTextFile )
throws DocumentRendererException, IOException
{
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "Parsing file " + fullDoc.getAbsolutePath() );
+ }
+
System.setProperty( "itext.basedir",
iTextFile.getParentFile().getAbsolutePath() );
Writer writer = null;
@@ -202,7 +231,7 @@
sink.setClassLoader( new URLClassLoader( new URL[] {
iTextFile.getParentFile().toURI().toURL() } ) );
- parse( fullDocPath, module.getParserId(), sink );
+ parse( fullDoc.getAbsolutePath(), module.getParserId(), sink );
}
finally
{
@@ -318,10 +347,15 @@
* Add transformer parameters from a DocumentModel.
*
* @param transformer the Transformer to set the parameters.
- * @param documentModel the DocumentModel to take the parameters from.
+ * @param documentModel the DocumentModel to take the parameters from,
could be null.
*/
private void addTransformerParameters( Transformer transformer,
DocumentModel documentModel )
{
+ if ( documentModel == null )
+ {
+ return;
+ }
+
if ( documentModel.getMeta().getTitle() != null )
{
transformer.setParameter( "title",
documentModel.getMeta().getTitle() );
@@ -368,7 +402,7 @@
/**
* Transform a document to an iTextFile.
*
- * @param documentModel the DocumentModel to take the parameters from.
+ * @param documentModel the DocumentModel to take the parameters from,
could be null.
* @param document the Document to transform.
* @param iTextFile the resulting iText xml file.
* @throws DocumentRendererException in case of a transformation error.
@@ -389,4 +423,95 @@
throw new DocumentRendererException( "Error transforming Document
" + document + ": " + e.getMessage() );
}
}
+
+ /**
+ * @param filesToProcess not null
+ * @param outputDirectory not null
+ * @return a list of all parsed files.
+ * @throws DocumentRendererException if any
+ * @throws IOException if any
+ * @since 1.1.1
+ */
+ private List parseAllFiles( Map filesToProcess, File outputDirectory )
+ throws DocumentRendererException, IOException
+ {
+ List iTextFiles = new LinkedList();
+ for ( Iterator it = filesToProcess.keySet().iterator(); it.hasNext(); )
+ {
+ String key = (String) it.next();
+ SiteModule module = (SiteModule) filesToProcess.get( key );
+ File fullDoc = new File( getBaseDir(), module.getSourceDirectory()
+ File.separator + key );
+
+ String outputITextName = key.substring( 0, key.lastIndexOf( "." )
+ 1 ) + "xml";
+ File outputITextFileTmp = new File( outputDirectory,
outputITextName );
+ if ( !outputITextFileTmp.getParentFile().exists() )
+ {
+ outputITextFileTmp.getParentFile().mkdirs();
+ }
+
+ iTextFiles.add( outputITextFileTmp );
+ parse( fullDoc, module, outputITextFileTmp );
+ }
+
+ return iTextFiles;
+ }
+
+ /**
+ * @param filesToProcess not null
+ * @param outputDirectory not null
+ * @return a list of all parsed files.
+ * @throws DocumentRendererException if any
+ * @throws IOException if any
+ * @since 1.1.1
+ */
+ private List parseTOCFiles( Map filesToProcess, File outputDirectory,
DocumentModel documentModel )
+ throws DocumentRendererException, IOException
+ {
+ List iTextFiles = new LinkedList();
+ for ( Iterator it = documentModel.getToc().getItems().iterator();
it.hasNext(); )
+ {
+ DocumentTOCItem tocItem = (DocumentTOCItem) it.next();
+
+ if ( tocItem.getRef() == null )
+ {
+ getLogger().debug(
+ "No ref defined for the tocItem '" +
tocItem.getName()
+ + "' in the document descriptor.
IGNORING" );
+ continue;
+ }
+
+ String href = StringUtils.replace( tocItem.getRef(), "\\", "/" );
+ if ( href.lastIndexOf( "." ) != -1 )
+ {
+ href = href.substring( 0, href.lastIndexOf( "." ) );
+ }
+
+ for ( Iterator i = siteModuleManager.getSiteModules().iterator();
i.hasNext(); )
+ {
+ SiteModule module = (SiteModule) i.next();
+ File moduleBasedir = new File( getBaseDir(),
module.getSourceDirectory() );
+
+ if ( moduleBasedir.exists() )
+ {
+ String doc = href + "." + module.getExtension();
+ File source = new File( moduleBasedir, doc );
+
+ if ( source.exists() )
+ {
+ String outputITextName = doc.substring( 0,
doc.lastIndexOf( "." ) + 1 ) + "xml";
+ File outputITextFileTmp = new File( outputDirectory,
outputITextName );
+ if ( !outputITextFileTmp.getParentFile().exists() )
+ {
+ outputITextFileTmp.getParentFile().mkdirs();
+ }
+
+ iTextFiles.add( outputITextFileTmp );
+ parse( source, module, outputITextFileTmp );
+ }
+ }
+ }
+ }
+
+ return iTextFiles;
+ }
}