You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2013/03/29 20:59:54 UTC

svn commit: r1462625 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo: pom.xml src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java

Author: rfscholte
Date: Fri Mar 29 19:59:53 2013
New Revision: 1462625

URL: http://svn.apache.org/r1462625
Log:
[DOXIA-455] No XML Entity Encoding (Escaping) is done in FO Footer Generation 
Patch contributed by Birger Zimmermann, reviewed by Robert Scholte
Only code formatting has been changed

Modified:
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/pom.xml
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/pom.xml?rev=1462625&r1=1462624&r2=1462625&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/pom.xml (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/pom.xml Fri Mar 29 19:59:53 2013
@@ -50,6 +50,12 @@ under the License.
       <timezone>+1</timezone>
     </developer>
   </developers>
+  
+  <contributors>
+    <contributor>
+      <name>Birger Zimmermann</name>
+    </contributor>
+  </contributors>
 
   <dependencies>
     <!-- Doxia -->

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java?rev=1462625&r1=1462624&r2=1462625&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java Fri Mar 29 19:59:53 2013
@@ -791,7 +791,7 @@ public class FoAggregateSink
             actualYear = Calendar.getInstance().get( Calendar.YEAR );
         }
 
-        return "&#169;" + actualYear + ", " + companyName + add;
+        return "&#169;" + actualYear + ", " + escaped( companyName, false ) + add;
     }
 
     /**
@@ -884,11 +884,11 @@ public class FoAggregateSink
 
         if ( headerText == null )
         {
-            write( docTitle );
+            text( docTitle );
         }
         else
         {
-            write( headerText );
+            text( headerText );
         }
 
         writeEndTag( BLOCK_TAG );
@@ -985,7 +985,7 @@ public class FoAggregateSink
             atts.addAttribute( "text-align-last", "justify" );
             writeStartTag( BLOCK_TAG, atts );
             writeStartTag( BASIC_LINK_TAG, "internal-destination", ref );
-            write( tocItem.getName() );
+            text( tocItem.getName() );
             writeEndTag( BASIC_LINK_TAG );
             writeEmptyTag( LEADER_TAG, "toc.leader.style" );
             writeStartTag( INLINE_TAG, "page.number" );
@@ -1043,7 +1043,7 @@ public class FoAggregateSink
 
             writeStartTag( BOOKMARK_TAG, "internal-destination", ref );
             writeStartTag( BOOKMARK_TITLE_TAG );
-            write( tocItem.getName() );
+            text( tocItem.getName() );
             writeEndTag( BOOKMARK_TITLE_TAG );
 
             if ( tocItem.getItems() != null )
@@ -1192,7 +1192,7 @@ public class FoAggregateSink
 
         writeStartTag( TABLE_CELL_TAG, "number-columns-spanned", "2", "cover.border.left" );
         writeStartTag( BLOCK_TAG, "cover.title" );
-        write( title == null ? "" : title );
+        text( title == null ? "" : title );
         writeEndTag( BLOCK_TAG );
         writeEndTag( TABLE_CELL_TAG );
         writeEndTag( TABLE_ROW_TAG );
@@ -1204,10 +1204,10 @@ public class FoAggregateSink
 
         writeStartTag( TABLE_CELL_TAG, "number-columns-spanned", "2", "cover.border.left.bottom" );
         writeStartTag( BLOCK_TAG, "cover.subtitle" );
-        write( subtitle == null ? ( version == null ? "" : " v. " + version ) : subtitle );
+        text( subtitle == null ? ( version == null ? "" : " v. " + version ) : subtitle );
         writeEndTag( BLOCK_TAG );
         writeStartTag( BLOCK_TAG, "cover.subtitle" );
-        write( type == null ? "" : type );
+        text( type == null ? "" : type );
         writeEndTag( BLOCK_TAG );
         writeEndTag( TABLE_CELL_TAG );
         writeEndTag( TABLE_ROW_TAG );
@@ -1272,7 +1272,7 @@ public class FoAggregateSink
         att.addAttribute( "height", "0.3in" );
         att.addAttribute( "text-align", "left" );
         writeStartTag( BLOCK_TAG, att );
-        write( compName == null ? ( cover.getAuthor() == null ? "" : cover.getAuthor() ) : compName );
+        text( compName == null ? ( cover.getAuthor() == null ? "" : cover.getAuthor() ) : compName );
         writeEndTag( BLOCK_TAG );
         writeEndTag( TABLE_CELL_TAG );
 
@@ -1281,7 +1281,7 @@ public class FoAggregateSink
         att.addAttribute( "height", "0.3in" );
         att.addAttribute( "text-align", "right" );
         writeStartTag( BLOCK_TAG, att );
-        write( date == null ? "" : date );
+        text( date == null ? "" : date );
         writeEndTag( BLOCK_TAG );
         writeEndTag( TABLE_CELL_TAG );
 

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java?rev=1462625&r1=1462624&r2=1462625&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java Fri Mar 29 19:59:53 2013
@@ -19,9 +19,18 @@ package org.apache.maven.doxia.module.fo
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
 
+import javax.xml.transform.TransformerException;
+
+import org.apache.maven.doxia.document.DocumentCover;
+import org.apache.maven.doxia.document.DocumentModel;
+import org.codehaus.plexus.util.WriterFactory;
+import org.xml.sax.SAXParseException;
+
 import junit.framework.TestCase;
 
 /**
@@ -86,6 +95,62 @@ public class FoAggregateSinkTest
 
         assertTrue( writer.toString().indexOf( "<fo:block id=\"./folder/documentName\">" ) != -1 );
     }
+    
+    /**
+     * Test the FO PDF generation with some special characters in company name.
+     */
+    public void testSpecialCharacters()
+        throws IOException, TransformerException
+    {
+        DocumentModel model = new DocumentModel();
+        DocumentCover cover = new DocumentCover();
+
+        cover.setCompanyName( "Partner & Friends" );
+        cover.setCoverTitle( "A Masterpice in Encoding Theory <>&" );
+        cover.setCoverSubTitle( "Some nice Encodings & <METHODS>" );
+        cover.setProjectName( "A Masterpice in Encoding Theory <>&" );
+        cover.setAuthor( "Partner & Friends" );
+        model.setCover( cover );
+
+        File foFile = File.createTempFile( "fo-test", ".fo" );
+        File pdfFile = File.createTempFile( "fo-test", ".pdf" );
+        try
+        {
+
+            sink = new FoAggregateSink( WriterFactory.newXmlWriter( foFile ) );
+
+            sink.setDocumentModel( model );
+            sink.setDocumentTitle( "A Masterpice in Encoding Theory <>&" );
+            sink.beginDocument();
+            sink.coverPage();
+            // sink.toc();
+            sink.endDocument();
+        }
+        finally
+        {
+            sink.close();
+        }
+
+        try
+        {
+            FoUtils.convertFO2PDF( foFile, pdfFile, null, model );
+        }
+        catch ( TransformerException e )
+        {
+            if ( ( e.getCause() != null ) && ( e.getCause() instanceof SAXParseException ) )
+            {
+                SAXParseException sax = (SAXParseException) e.getCause();
+
+                StringBuffer sb = new StringBuffer();
+                sb.append( "Error creating PDF from " ).append( foFile.getAbsolutePath() ).append( ":" ).append( sax.getLineNumber() ).append( ":" ).append( sax.getColumnNumber() ).append( "\n" );
+                sb.append( e.getMessage() );
+
+                throw new RuntimeException( sb.toString() );
+            }
+
+            throw new TransformerException( "Error creating PDF from " + foFile + ": " + e.getMessage() );
+        }
+    }
 
     /**
      * Test of figureGraphics method, of class FoAggregateSink.