maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r943453 - in /maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src: main/java/org/apache/maven/doxia/siterenderer/ test/java/org/apache/maven/doxia/siterenderer/ test/resources/site-validate/ test/resources/site-validate/xdoc/ test/res...
Date Wed, 12 May 2010 11:35:49 GMT
Author: ltheussl
Date: Wed May 12 11:35:48 2010
New Revision: 943453

URL: http://svn.apache.org/viewvc?rev=943453&view=rev
Log:
[DOXIASITETOOLS-37] Make SiteRenderer validate xml docs. Separate test resource files that
need validation.

Added:
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/resources/site-validate/
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/resources/site-validate/xdoc/
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/resources/site-validate/xdoc/entityTest.xml
Removed:
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/resources/site/xdoc/entityTest.xml
Modified:
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java

Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java?rev=943453&r1=943452&r2=943453&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
Wed May 12 11:35:48 2010
@@ -19,6 +19,7 @@ package org.apache.maven.doxia.siterende
  * under the License.
  */
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -63,6 +64,7 @@ import org.apache.maven.doxia.module.sit
 import org.apache.maven.doxia.module.site.manager.SiteModuleManager;
 import org.apache.maven.doxia.module.site.manager.SiteModuleNotFoundException;
 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
+import org.apache.maven.doxia.util.XmlValidator;
 
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
@@ -355,13 +357,13 @@ public class DefaultSiteRenderer
         Reader reader = null;
         try
         {
+            String resource = doc.getAbsolutePath();
+
             Parser parser = doxia.getParser( renderingContext.getParserId() );
 
             // TODO: DOXIA-111: the filter used here must be checked generally.
             if ( renderingContext.getAttribute( "velocity" ) != null )
             {
-                String resource = doc.getAbsolutePath();
-
                 try
                 {
                     SiteResourceLoader.setResource( resource );
@@ -392,6 +394,10 @@ public class DefaultSiteRenderer
                 {
                     case Parser.XML_TYPE:
                         reader = ReaderFactory.newXmlReader( doc );
+                        if ( context.isValidate() )
+                        {
+                            reader = validate( reader, resource );
+                        }
                         break;
 
                     case Parser.TXT_TYPE:
@@ -861,4 +867,23 @@ public class DefaultSiteRenderer
         }
     }
 
+    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 );
+        }
+    }
+
 }

Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java?rev=943453&r1=943452&r2=943453&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java
Wed May 12 11:35:48 2010
@@ -64,6 +64,31 @@ public class SiteRenderingContext
 
     private List modules = new ArrayList();
 
+    private boolean validate;
+
+    /**
+     * If input documents should be validated before parsing.
+     * By default no validation is performed.
+     *
+     * @return true if validation is switched on.
+     * @since 1.1.3
+     */
+    public boolean isValidate()
+    {
+        return validate;
+    }
+
+    /**
+     * Switch on/off validation.
+     *
+     * @param validate true to switch on validation.
+     * @since 1.1.3
+     */
+    public void setValidate( boolean validate )
+    {
+        this.validate = validate;
+    }
+
     /**
      * <p>Getter for the field <code>templateName</code>.</p>
      *

Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java?rev=943453&r1=943452&r2=943453&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java
Wed May 12 11:35:48 2010
@@ -124,16 +124,11 @@ public class DefaultSiteRendererTest
         DecorationModel decoration = new DecorationXpp3Reader()
             .read( new FileReader( getTestFile( "src/test/resources/site/site.xml" ) ) );
 
-        SiteRenderingContext ctxt = new SiteRenderingContext();
-        ctxt.setTemplateName( "default-site.vm" );
-        ctxt.setTemplateClassLoader( getClassLoader() );
-        ctxt.setUsingDefaultTemplate( true );
-        Map templateProp = new HashMap();
-        templateProp.put( "outputEncoding", "UTF-8" );
-        ctxt.setTemplateProperties( templateProp );
-        ctxt.setDecoration( decoration );
-        ctxt.addSiteDirectory( getTestFile( "src/test/resources/site" ) );
+        SiteRenderingContext ctxt = getSiteRenderingContext(
+                decoration, "src/test/resources/site", false );
+        renderer.render( renderer.locateDocumentFiles( ctxt ).values(), ctxt, getTestFile(
OUTPUT ) );
 
+        ctxt = getSiteRenderingContext( decoration, "src/test/resources/site-validate", true
);
         renderer.render( renderer.locateDocumentFiles( ctxt ).values(), ctxt, getTestFile(
OUTPUT ) );
 
         // ----------------------------------------------------------------------
@@ -158,6 +153,22 @@ public class DefaultSiteRendererTest
         validatePages();
     }
 
+    private SiteRenderingContext getSiteRenderingContext( DecorationModel decoration, String
siteDir, boolean validate )
+    {
+        SiteRenderingContext ctxt = new SiteRenderingContext();
+        ctxt.setTemplateName( "default-site.vm" );
+        ctxt.setTemplateClassLoader( getClassLoader() );
+        ctxt.setUsingDefaultTemplate( true );
+        Map templateProp = new HashMap();
+        templateProp.put( "outputEncoding", "UTF-8" );
+        ctxt.setTemplateProperties( templateProp );
+        ctxt.setDecoration( decoration );
+        ctxt.addSiteDirectory( getTestFile( siteDir ) );
+        ctxt.setValidate( validate );
+
+        return ctxt;
+    }
+
     /**
      * @throws Exception if something goes wrong.
      */

Added: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/resources/site-validate/xdoc/entityTest.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/resources/site-validate/xdoc/entityTest.xml?rev=943453&view=auto
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/resources/site-validate/xdoc/entityTest.xml
(added)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/resources/site-validate/xdoc/entityTest.xml
Wed May 12 11:35:48 2010
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<!DOCTYPE document [
+<!-- These are the entity sets for ISO Latin 1 characters for the XHTML -->
+<!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
+%HTMLlat1;
+<!-- Some entities from http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent -->
+<!ENTITY Alpha    "&#913;"> <!-- greek capital letter alpha, U+0391 -->
+<!ENTITY Beta     "&#914;"> <!-- greek capital letter beta, U+0392 -->
+<!ENTITY Gamma    "&#915;"> <!-- greek capital letter gamma, U+0393 ISOgrk3
-->
+<!ENTITY tritPos  "&#x1d7ed;"> <!-- MATHEMATICAL SANS-SERIF BOLD DIGIT ONE -->
+<!ENTITY flo "&#x159;">
+<!ENTITY myCustomEntity "&flo;">
+]>
+<document xmlns="http://maven.apache.org/XDOC/2.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 file:../../../../../../../doxia/doxia-modules/doxia-module-xdoc/src/main/resources/xdoc-2.0.xsd">
+  <properties>
+    <title>Test entities, cdatas and comments</title>
+    <!-- Test comment: DOXIA-312 -->
+    <author email="test@email.com">Ligature &AElig;</author>
+    <author email="test@email.com">Ampersand &amp;</author>
+    <author email="test@email.com">Less than &lt;</author>
+    <author email="test@email.com">Greater than &gt;</author>
+    <author email="test@email.com">Apostrophe &apos;</author>
+    <author email="test@email.com">Quote &quot;</author>
+    <author email="test@email.com">test@email.com</author>
+    <author email="test@email.com">test&copy;email.com</author>
+  </properties>
+
+  <body>
+
+    <section name="section name with entities: '&amp;' '&Alpha;' '&nbsp;'
'&tritPos;'">
+
+      <h4>Entities</h4>
+      <h3>Generic Entities: '&amp;' '&lt;' '&gt;' '&quot;' '&apos;'</h3>
+      <p>'&amp;' '&lt;' '&gt;' '&quot;' '&apos;'</p>
+
+      <h3>Local Entities: '&Alpha;' '&Beta;' '&Gamma;' '&tritPos;'</h3>
+      <p>'&Alpha;' '&Beta;' '&Gamma;' '&tritPos;&#x1d7ed;' '&flo;&#x159;'
'&myCustomEntity;'</p>
+
+      <h3>DTD Entities: '&nbsp;' '&iexcl;' '&cent;'</h3>
+      <p>'&nbsp;' '&iexcl;' '&cent;'</p>
+
+      <h4>CDATA</h4>
+      <source><![CDATA[<project xmlns:ant="jelly:ant">]]></source>
+      <p><![CDATA['&nbsp;' '&iexcl;']]></p>
+
+    </section>
+
+  </body>
+
+</document>



Mime
View raw message