Author: ltheussl
Date: Fri May 21 14:04:46 2010
New Revision: 947013

URL: http://svn.apache.org/viewvc?rev=947013&view=rev
Log:
ad DOXIA-392, DOXIASITETOOLS-37: also make DocumentRenderer validate xml

Modified:
    
maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/AbstractDocumentRenderer.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=947013&r1=947012&r2=947013&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
 Fri May 21 14:04:46 2010
@@ -19,6 +19,7 @@ package org.apache.maven.doxia.docrender
  * under the License.
  */
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
@@ -44,6 +45,8 @@ import org.apache.maven.doxia.parser.man
 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.maven.doxia.util.XmlValidator;
+
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.context.Context;
 
@@ -211,7 +214,6 @@ public abstract class AbstractDocumentRe
      * @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
@@ -473,6 +475,10 @@ public abstract class AbstractDocumentRe
                     {
                         reader = getVelocityReader( f, ( (XmlStreamReader) 
reader ).getEncoding(), context );
                     }
+                    if ( context != null && Boolean.TRUE.equals( (Boolean) 
context.get( "validate" ) ) )
+                    {
+                        reader = validate( reader, fullDocPath );
+                    }
                     break;
 
                 case Parser.TXT_TYPE:
@@ -504,7 +510,7 @@ public abstract class AbstractDocumentRe
         catch ( ParserNotFoundException e )
         {
             throw new DocumentRendererException( "No parser '" + parserId
-                        + "' found for " + fullDocPath + ": " + e.getMessage() 
);
+                        + "' found for " + fullDocPath + ": " + 
e.getMessage(), e );
         }
         catch ( ParseException e )
         {
@@ -664,4 +670,23 @@ public abstract class AbstractDocumentRe
     {
         return FileUtils.getExtension( f.getAbsolutePath() ).toLowerCase( 
Locale.ENGLISH ).endsWith( "vm" );
     }
+
+    private Reader validate( Reader source, String resource )
+            throws ParseException, IOException
+    {
+        getLogger().debug( "Validating: " + resource );
+
+        try
+        {
+            String content = IOUtil.toString( new BufferedReader( source ) );
+
+            new XmlValidator( new PlexusLoggerWrapper( getLogger() ) 
).validate( content );
+
+            return new StringReader( content );
+        }
+        finally
+        {
+            IOUtil.close( source );
+        }
+    }
 }


Reply via email to