You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by vs...@apache.org on 2009/08/04 16:02:48 UTC

svn commit: r800802 - in /maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer: ./ src/main/java/org/apache/maven/doxia/docrenderer/ src/main/java/org/apache/maven/doxia/docrenderer/pdf/ src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/ src/main...

Author: vsiveton
Date: Tue Aug  4 14:02:47 2009
New Revision: 800802

URL: http://svn.apache.org/viewvc?rev=800802&view=rev
Log:
DOXIASITETOOLS-21: Add Velocity support to DocRenderer

o added velocity 1.6.2
o added DocumentRendererContext Object
o updated code to handle vm files
o TODO we need to improve interface in 1.2

Added:
    maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRendererContext.java   (with props)
Modified:
    maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/pom.xml
    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/AbstractPdfRenderer.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/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/pom.xml?rev=800802&r1=800801&r2=800802&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/pom.xml (original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/pom.xml Tue Aug  4 14:02:47 2009
@@ -99,6 +99,37 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-velocity</artifactId>
+      <version>1.1.7</version>
+      <exclusions>
+        <exclusion>
+          <groupId>commons-collections</groupId>
+          <artifactId>commons-collections</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-component-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>velocity</groupId>
+          <artifactId>velocity</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+
+    <!-- misc -->
+    <dependency>
+      <groupId>org.apache.velocity</groupId>
+      <artifactId>velocity</artifactId>
+      <version>1.6.2</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>3.2.1</version>
+    </dependency>
 
     <!-- misc -->
     <dependency>

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=800802&r1=800801&r2=800802&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 Tue Aug  4 14:02:47 2009
@@ -22,6 +22,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
@@ -42,6 +44,8 @@
 import org.apache.maven.doxia.logging.PlexusLoggerWrapper;
 import org.apache.maven.doxia.module.site.SiteModule;
 import org.apache.maven.doxia.module.site.manager.SiteModuleManager;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.context.Context;
 
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
@@ -49,7 +53,10 @@
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.codehaus.plexus.velocity.SiteResourceLoader;
+import org.codehaus.plexus.velocity.VelocityComponent;
 
 /**
  * Abstract <code>document</code> renderer.
@@ -69,6 +76,9 @@
     /** @plexus.requirement */
     protected Doxia doxia;
 
+    /** @plexus.requirement */
+    private VelocityComponent velocity;
+
     /**
      * The common base directory of source files.
      */
@@ -87,6 +97,7 @@
      * @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
+     * @deprecated since 1.1.2, use {@link #render(Map, File, DocumentModel, DocumentRendererContext)}
      */
     public abstract void render( Map filesToProcess, File outputDirectory, DocumentModel documentModel )
         throws DocumentRendererException, IOException;
@@ -99,14 +110,54 @@
     public void render( Collection files, File outputDirectory, DocumentModel documentModel )
         throws DocumentRendererException, IOException
     {
-        render( getFilesToProcess( files ), outputDirectory, documentModel );
+        render( getFilesToProcess( files ), outputDirectory, documentModel, null );
     }
 
     /** {@inheritDoc} */
     public void render( File baseDirectory, File outputDirectory, DocumentModel documentModel )
         throws DocumentRendererException, IOException
     {
-        render( getFilesToProcess( baseDirectory ), outputDirectory, documentModel );
+        render( baseDirectory, outputDirectory, documentModel, null );
+    }
+
+    /**
+     * 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 aggregate document should be generated.
+     * @param documentModel the document model, containing all the metadata, etc.
+     * @param context the rendering context when processing files.
+     * @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if any
+     * @throws java.io.IOException if any
+     */
+    public void render( Map filesToProcess, File outputDirectory, DocumentModel documentModel,
+                        DocumentRendererContext context )
+        throws DocumentRendererException, IOException
+    {
+        // nop
+    }
+
+    /**
+     * Render a document from the files found in a source directory, depending on a rendering context.
+     *
+     * @param baseDirectory the directory containing the source files.
+     *              This should follow the standard Maven convention, ie containing all the site modules.
+     * @param outputDirectory the output directory where the document should be generated.
+     * @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.
+     * @param context the rendering context when processing files.
+     * @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if any
+     * @throws java.io.IOException if any
+     * @since 1.1.2
+     */
+    public void render( File baseDirectory, File outputDirectory, DocumentModel documentModel,
+                        DocumentRendererContext context )
+        throws DocumentRendererException, IOException
+    {
+        render( getFilesToProcess( baseDirectory ), outputDirectory, documentModel, context );
     }
 
     /**
@@ -150,7 +201,7 @@
         }
         else
         {
-            render( getFilesToProcess( baseDirectory ), outputDirectory, readDocumentModel( documentDescriptor ) );
+            render( getFilesToProcess( baseDirectory ), outputDirectory, readDocumentModel( documentDescriptor ), null );
         }
     }
 
@@ -160,9 +211,11 @@
      * @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.
+     * @param context the rendering context.
      * @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if any
      * @throws java.io.IOException if any
      * @since 1.1.1
+     * @deprecated since 1.1.2, use {@link #renderIndividual(Map, File, DocumentRendererContext)}
      */
     public void renderIndividual( Map filesToProcess, File outputDirectory )
         throws DocumentRendererException, IOException
@@ -171,6 +224,23 @@
     }
 
     /**
+     * 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.
+     * @param context the rendering context.
+     * @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if any
+     * @throws java.io.IOException if any
+     * @since 1.1.2
+     */
+    public void renderIndividual( Map filesToProcess, File outputDirectory, DocumentRendererContext context )
+        throws DocumentRendererException, IOException
+    {
+        // nop
+    }
+
+    /**
      * Returns a Map of files to process. The Map contains as keys the paths of the source files
      *      (relative to {@link #getBaseDir() baseDir}), and the corresponding SiteModule as values.
      *
@@ -219,6 +289,19 @@
                     }
                 }
 
+                List velocityFiles = new LinkedList( allFiles );
+                // *.xml.vm
+                for ( Iterator it = velocityFiles.iterator(); it.hasNext(); )
+                {
+                    String name = it.next().toString().trim();
+
+                    if ( !name.toLowerCase( Locale.ENGLISH ).endsWith( lowerCaseExtension + ".vm" ) )
+                    {
+                        it.remove();
+                    }
+                }
+                docs.addAll( velocityFiles );
+
                 for ( Iterator j = docs.iterator(); j.hasNext(); )
                 {
                     String filePath = j.next().toString().trim();
@@ -349,10 +432,27 @@
      * @param sink the sink to receive the events.
      * @throws org.apache.maven.doxia.docrenderer.DocumentRendererException in case of a parsing error.
      * @throws java.io.IOException if the source document cannot be opened.
+     * @deprecated since 1.1.2, use {@link #parse(String, String, Sink, DocumentRendererContext)}
      */
     protected void parse( String fullDocPath, String parserId, Sink sink )
         throws DocumentRendererException, IOException
     {
+        parse( fullDocPath, parserId, sink, null );
+    }
+
+    /**
+     * Parse a source document into a sink.
+     *
+     * @param fullDocPath absolute path to the source document.
+     * @param parserId determines the parser to use.
+     * @param sink the sink to receive the events.
+     * @param context the rendering context.
+     * @throws org.apache.maven.doxia.docrenderer.DocumentRendererException in case of a parsing error.
+     * @throws java.io.IOException if the source document cannot be opened.
+     */
+    protected void parse( String fullDocPath, String parserId, Sink sink, DocumentRendererContext context )
+        throws DocumentRendererException, IOException
+    {
         if ( getLogger().isDebugEnabled() )
         {
             getLogger().debug( "Parsing file " + fullDocPath );
@@ -368,13 +468,33 @@
             {
                 case Parser.XML_TYPE:
                     reader = ReaderFactory.newXmlReader( f );
+
+                    if ( isVelocityFile( f ) )
+                    {
+                        reader = getVelocityReader( f, ( (XmlStreamReader) reader ).getEncoding(), context );
+                    }
                     break;
 
                 case Parser.TXT_TYPE:
                 case Parser.UNKNOWN_TYPE:
                 default:
-                    // TODO Platform dependent?
-                    reader = ReaderFactory.newPlatformReader( f );
+                    if ( isVelocityFile( f ) )
+                    {
+                        reader =
+                            getVelocityReader( f, ( context == null ? ReaderFactory.FILE_ENCODING
+                                            : context.getInputEncoding() ), context );
+                    }
+                    else
+                    {
+                        if ( context == null )
+                        {
+                            reader = ReaderFactory.newPlatformReader( f );
+                        }
+                        else
+                        {
+                            reader = ReaderFactory.newReader( f, context.getInputEncoding() );
+                        }
+                    }
             }
 
             sink.enableLogging( new PlexusLoggerWrapper( getLogger() ) );
@@ -490,4 +610,54 @@
 
         return documentModel.getOutputName();
     }
+
+    /**
+     * TODO: DOXIA-111: we need a general filter here that knows how to alter the context
+     *
+     * @param f the file to process, not null
+     * @param encoding the wanted encoding, not null
+     * @param context the current render document context not null
+     * @return a reader with
+     * @throws DocumentRendererException
+     */
+    private Reader getVelocityReader( File f, String encoding, DocumentRendererContext context )
+        throws DocumentRendererException
+    {
+        SiteResourceLoader.setResource( f.getAbsolutePath() );
+
+        Context velocityContext = new VelocityContext();
+
+        if ( context.getKeys() != null )
+        {
+            for ( int i = 0; i < context.getKeys().length; i++ )
+            {
+                String key = (String) context.getKeys()[i];
+
+                velocityContext.put( key, context.get( key ) );
+            }
+        }
+
+        StringWriter sw = new StringWriter();
+
+        try
+        {
+            velocity.getEngine().mergeTemplate( f.getAbsolutePath(), encoding, velocityContext, sw );
+        }
+        catch ( Exception e )
+        {
+            throw new DocumentRendererException( "Error whenn parsing Velocity file " + f.getAbsolutePath() + ": "
+                + e.getMessage(), e );
+        }
+
+        return new StringReader( sw.toString() );
+    }
+
+    /**
+     * @param f not null
+     * @return <code>true</code> if file has a vm extension, <code>false</false> otherwise.
+     */
+    private static boolean isVelocityFile( File f )
+    {
+        return FileUtils.getExtension( f.getAbsolutePath() ).toLowerCase( Locale.ENGLISH ).endsWith( "vm" );
+    }
 }

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=800802&r1=800801&r2=800802&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 Tue Aug  4 14:02:47 2009
@@ -66,10 +66,29 @@
      *              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
+//     * @deprecated since 1.1.2, use {@link #render(File, File, DocumentModel, DocumentRendererContext)}
      */
     void render( File baseDirectory, File outputDirectory, DocumentModel documentModel )
         throws DocumentRendererException, IOException;
 
+//    /**
+//     * Render a document from the files found in a source directory, depending on a rendering context.
+//     *
+//     * @param baseDirectory the directory containing the source files.
+//     *              This should follow the standard Maven convention, ie containing all the site modules.
+//     * @param outputDirectory the output directory where the document should be generated.
+//     * @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.
+//     * @param context the rendering context when processing files.
+//     * @throws org.apache.maven.doxia.docrenderer.DocumentRendererException if any
+//     * @throws java.io.IOException if any
+//     * @since 1.1.2
+//     */
+//    void render( File baseDirectory, File outputDirectory, DocumentModel documentModel, DocumentRendererContext context )
+//        throws DocumentRendererException, IOException;
+
     /**
      * Read a document model from a file.
      *

Added: maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRendererContext.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRendererContext.java?rev=800802&view=auto
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRendererContext.java (added)
+++ maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRendererContext.java Tue Aug  4 14:02:47 2009
@@ -0,0 +1,141 @@
+package org.apache.maven.doxia.docrenderer;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.codehaus.plexus.util.ReaderFactory;
+
+/**
+ * Context when processing Velocity files using a {@link java.util.HashMap} for data storage.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.1.2
+ */
+public class DocumentRendererContext
+{
+    private String inputEncoding = ReaderFactory.UTF_8;
+
+    /**
+     *  Storage for key/value pairs.
+     */
+    private final Map context;
+
+    /**
+     *  Default constructor.
+     */
+    public DocumentRendererContext()
+    {
+        context = new HashMap();
+    }
+
+    /**
+     * @return The input encoding when processing files.
+     */
+    public String getInputEncoding()
+    {
+        return inputEncoding;
+    }
+
+    /**
+     * @param inputEncoding new input encoding value when processing files.
+     */
+    public void setInputEncoding( String inputEncoding )
+    {
+        this.inputEncoding = inputEncoding;
+    }
+
+    /**
+     * Adds a name/value pair to the context.
+     *
+     * @param key The name to key the provided value with.
+     * @param value The corresponding value.
+     * @return Object that was replaced in the the Context if applicable or null if not.
+     */
+    public Object put( String key, Object value )
+    {
+        if ( key == null )
+        {
+            return null;
+        }
+
+        return context.put( key, value );
+    }
+
+    /**
+     *  Gets the value corresponding to the provided key from the context.
+     *
+     *  @param key The name of the desired value.
+     *  @return The value corresponding to the provided key or null if the key param is null.
+     */
+    public Object get( String key )
+    {
+        if ( key == null )
+        {
+            return null;
+        }
+
+        return context.get( key );
+    }
+
+    /**
+     *  Indicates whether the specified key is in the context.
+     *
+     * @param key The key to look for.
+     * @return true if the key is in the context, false if not.
+     */
+    public boolean containsKey( Object key )
+    {
+        if ( key == null )
+        {
+            return false;
+        }
+
+        return context.containsKey( key );
+    }
+
+    /**
+     *  Get all the keys for the values in the context
+     *
+     *  @return Object[] of keys in the Context.
+     */
+    public Object[] getKeys()
+    {
+        return context.keySet().toArray();
+    }
+
+    /**
+     * Removes the value associated with the specified key from the context.
+     *
+     * @param key The name of the value to remove.
+     * @return The value that the key was mapped to, or <code>null</code> if unmapped.
+     */
+    public Object remove( Object key )
+    {
+        if ( key == null )
+        {
+            return null;
+        }
+
+        return context.remove( key );
+    }
+}

Propchange: maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRendererContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocumentRendererContext.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/AbstractPdfRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/AbstractPdfRenderer.java?rev=800802&r1=800801&r2=800802&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/AbstractPdfRenderer.java (original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/AbstractPdfRenderer.java Tue Aug  4 14:02:47 2009
@@ -19,7 +19,14 @@
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
 import org.apache.maven.doxia.docrenderer.AbstractDocumentRenderer;
+import org.apache.maven.doxia.docrenderer.DocumentRendererContext;
+import org.apache.maven.doxia.docrenderer.DocumentRendererException;
+import org.apache.maven.doxia.document.DocumentModel;
 
 /**
  * Abstract pdf renderer, this doesn't depend on the framework.
@@ -37,4 +44,11 @@
     {
         return "pdf";
     }
+
+    /** {@inheritDoc} */
+    public void render( Map filesToProcess, File outputDirectory, DocumentModel documentModel )
+        throws DocumentRendererException, IOException
+    {
+        render( filesToProcess, outputDirectory, documentModel, null );
+    }
 }

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=800802&r1=800801&r2=800802&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 Tue Aug  4 14:02:47 2009
@@ -29,6 +29,7 @@
 
 import javax.xml.transform.TransformerException;
 
+import org.apache.maven.doxia.docrenderer.DocumentRendererContext;
 import org.apache.maven.doxia.docrenderer.DocumentRendererException;
 import org.apache.maven.doxia.docrenderer.pdf.AbstractPdfRenderer;
 import org.apache.maven.doxia.document.DocumentModel;
@@ -72,6 +73,13 @@
     public void render( Map filesToProcess, File outputDirectory, DocumentModel documentModel )
         throws DocumentRendererException, IOException
     {
+        render( filesToProcess, outputDirectory, documentModel, null );
+    }
+
+    /** {@inheritDoc} */
+    public void render( Map filesToProcess, File outputDirectory, DocumentModel documentModel, DocumentRendererContext context )
+        throws DocumentRendererException, IOException
+    {
         // copy resources, images, etc.
         copyResources( outputDirectory );
 
@@ -79,7 +87,7 @@
         {
             getLogger().debug( "No document model, generating all documents individually." );
 
-            renderIndividual( filesToProcess, outputDirectory );
+            renderIndividual( filesToProcess, outputDirectory, context );
             return;
         }
 
@@ -124,13 +132,13 @@
             {
                 getLogger().info( "No TOC is defined in the document descriptor. Merging all documents." );
 
-                mergeAllSources( filesToProcess, sink );
+                mergeAllSources( filesToProcess, sink, context );
             }
             else
             {
                 getLogger().debug( "Using TOC defined in the document descriptor." );
 
-                mergeSourcesFromTOC( documentModel.getToc(), sink );
+                mergeSourcesFromTOC( documentModel.getToc(), sink, context );
             }
 
             sink.endDocument();
@@ -147,6 +155,13 @@
     public void renderIndividual( Map filesToProcess, File outputDirectory )
         throws DocumentRendererException, IOException
     {
+        renderIndividual( filesToProcess, outputDirectory, null );
+    }
+
+    /** {@inheritDoc} */
+    public void renderIndividual( Map filesToProcess, File outputDirectory, DocumentRendererContext context )
+        throws DocumentRendererException, IOException
+    {
         for ( Iterator j = filesToProcess.keySet().iterator(); j.hasNext(); )
         {
             String key = (String) j.next();
@@ -177,14 +192,14 @@
             FoSink sink =
                 (FoSink) new FoSinkFactory().createSink( outputFOFile.getParentFile(), outputFOFile.getName() );
             sink.beginDocument();
-            parse( fullDoc.getAbsolutePath(), module.getParserId(), sink );
+            parse( fullDoc.getAbsolutePath(), module.getParserId(), sink, context );
             sink.endDocument();
 
             generatePdf( outputFOFile, pdfOutputFile, null );
         }
     }
 
-    private void mergeAllSources( Map filesToProcess, FoAggregateSink sink )
+    private void mergeAllSources( Map filesToProcess, FoAggregateSink sink, DocumentRendererContext context )
             throws DocumentRendererException, IOException
     {
         for ( Iterator j = filesToProcess.keySet().iterator(); j.hasNext(); )
@@ -194,17 +209,17 @@
             sink.setDocumentName( key );
             File fullDoc = new File( getBaseDir(), module.getSourceDirectory() + File.separator + key );
 
-            parse( fullDoc.getAbsolutePath(), module.getParserId(), sink );
+            parse( fullDoc.getAbsolutePath(), module.getParserId(), sink, context );
         }
     }
 
-    private void mergeSourcesFromTOC( DocumentTOC toc, FoAggregateSink sink )
+    private void mergeSourcesFromTOC( DocumentTOC toc, FoAggregateSink sink, DocumentRendererContext context )
             throws IOException, DocumentRendererException
     {
-        parseTocItems( toc.getItems(), sink );
+        parseTocItems( toc.getItems(), sink, context );
     }
 
-    private void parseTocItems( List items, FoAggregateSink sink )
+    private void parseTocItems( List items, FoAggregateSink sink, DocumentRendererContext context )
             throws IOException, DocumentRendererException
     {
         for ( Iterator k = items.iterator(); k.hasNext(); )
@@ -227,16 +242,16 @@
                 href = href.substring( 0, href.lastIndexOf( "." ) );
             }
 
-            renderModules( href, sink, tocItem );
+            renderModules( href, sink, tocItem, context );
 
             if ( tocItem.getItems() != null )
             {
-                parseTocItems( tocItem.getItems(), sink );
+                parseTocItems( tocItem.getItems(), sink, context );
             }
         }
     }
 
-    private void renderModules( String href, FoAggregateSink sink, DocumentTOCItem tocItem )
+    private void renderModules( String href, FoAggregateSink sink, DocumentTOCItem tocItem, DocumentRendererContext context )
             throws DocumentRendererException, IOException
     {
         for ( Iterator i = siteModuleManager.getSiteModules().iterator(); i.hasNext(); )
@@ -249,12 +264,19 @@
                 String doc = href + "." + module.getExtension();
                 File source = new File( moduleBasedir, doc );
 
+                // Velocity file?
+                if ( !source.exists() )
+                {
+                    doc = href + "." + module.getExtension() + ".vm";
+                    source = new File( moduleBasedir, doc );
+                }
+
                 if ( source.exists() )
                 {
                     sink.setDocumentName( doc );
                     sink.setDocumentTitle( tocItem.getName() );
 
-                    parse( source.getPath(), module.getParserId(), sink );
+                    parse( source.getPath(), module.getParserId(), sink, context );
                 }
             }
         }

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=800802&r1=800801&r2=800802&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 Tue Aug  4 14:02:47 2009
@@ -47,6 +47,7 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.maven.doxia.docrenderer.DocumentRendererContext;
 import org.apache.maven.doxia.docrenderer.DocumentRendererException;
 import org.apache.maven.doxia.docrenderer.pdf.AbstractPdfRenderer;
 import org.apache.maven.doxia.document.DocumentCover;
@@ -133,6 +134,13 @@
     public void render( Map filesToProcess, File outputDirectory, DocumentModel documentModel )
         throws DocumentRendererException, IOException
     {
+        render( filesToProcess, outputDirectory, documentModel, null );
+    }
+
+    /** {@inheritDoc} */
+    public void render( Map filesToProcess, File outputDirectory, DocumentModel documentModel, DocumentRendererContext context )
+        throws DocumentRendererException, IOException
+    {
         // copy resources, images, etc.
         copyResources( outputDirectory );
 
@@ -140,7 +148,7 @@
         {
             getLogger().debug( "No document model, generating all documents individually." );
 
-            renderIndividual( filesToProcess, outputDirectory );
+            renderIndividual( filesToProcess, outputDirectory, context );
             return;
         }
 
@@ -163,13 +171,13 @@
         {
             getLogger().info( "No TOC is defined in the document descriptor. Merging all documents." );
 
-            iTextFiles = parseAllFiles( filesToProcess, outputDirectory );
+            iTextFiles = parseAllFiles( filesToProcess, outputDirectory, context );
         }
         else
         {
             getLogger().debug( "Using TOC defined in the document descriptor." );
 
-            iTextFiles = parseTOCFiles( outputDirectory, documentModel );
+            iTextFiles = parseTOCFiles( outputDirectory, documentModel, context );
         }
 
         File iTextFile = new File( outputDirectory, outputName + ".xml" );
@@ -183,6 +191,13 @@
     public void renderIndividual( Map filesToProcess, File outputDirectory )
         throws DocumentRendererException, IOException
     {
+        renderIndividual( filesToProcess, outputDirectory, null );
+    }
+
+    /** {@inheritDoc} */
+    public void renderIndividual( Map filesToProcess, File outputDirectory, DocumentRendererContext context )
+        throws DocumentRendererException, IOException
+    {
         for ( Iterator it = filesToProcess.keySet().iterator(); it.hasNext(); )
         {
             String key = (String) it.next();
@@ -209,7 +224,7 @@
                 pdfOutputFile.getParentFile().mkdirs();
             }
 
-            parse( fullDoc, module, outputITextFile );
+            parse( fullDoc, module, outputITextFile, context );
 
             generatePdf( outputITextFile, pdfOutputFile );
         }
@@ -229,7 +244,7 @@
      * @throws DocumentRendererException in case of a parsing problem.
      * @throws IOException if the source and/or target document cannot be opened.
      */
-    private void parse( File fullDoc, SiteModule module, File iTextFile )
+    private void parse( File fullDoc, SiteModule module, File iTextFile, DocumentRendererContext context )
         throws DocumentRendererException, IOException
     {
         if ( getLogger().isDebugEnabled() )
@@ -248,7 +263,7 @@
 
             sink.setClassLoader( new URLClassLoader( new URL[] { iTextFile.getParentFile().toURI().toURL() } ) );
 
-            parse( fullDoc.getAbsolutePath(), module.getParserId(), sink );
+            parse( fullDoc.getAbsolutePath(), module.getParserId(), sink, context );
         }
         finally
         {
@@ -494,7 +509,7 @@
      * @throws IOException if any
      * @since 1.1.1
      */
-    private List parseAllFiles( Map filesToProcess, File outputDirectory )
+    private List parseAllFiles( Map filesToProcess, File outputDirectory, DocumentRendererContext context )
         throws DocumentRendererException, IOException
     {
         List iTextFiles = new LinkedList();
@@ -513,7 +528,7 @@
             }
 
             iTextFiles.add( outputITextFileTmp );
-            parse( fullDoc, module, outputITextFileTmp );
+            parse( fullDoc, module, outputITextFileTmp, context );
         }
 
         return iTextFiles;
@@ -527,7 +542,7 @@
      * @throws IOException if any
      * @since 1.1.1
      */
-    private List parseTOCFiles( File outputDirectory, DocumentModel documentModel )
+    private List parseTOCFiles( File outputDirectory, DocumentModel documentModel, DocumentRendererContext context )
         throws DocumentRendererException, IOException
     {
         List iTextFiles = new LinkedList();
@@ -559,6 +574,13 @@
                     String doc = href + "." + module.getExtension();
                     File source = new File( moduleBasedir, doc );
 
+                    // Velocity file?
+                    if ( !source.exists() )
+                    {
+                        doc = href + "." + module.getExtension() + ".vm";
+                        source = new File( moduleBasedir, doc );
+                    }
+
                     if ( source.exists() )
                     {
                         String outputITextName = doc.substring( 0, doc.lastIndexOf( "." ) + 1 ) + "xml";
@@ -570,7 +592,7 @@
                         }
 
                         iTextFiles.add( outputITextFileTmp );
-                        parse( source, module, outputITextFileTmp );
+                        parse( source, module, outputITextFileTmp, context );
                     }
                 }
             }