Author: vsiveton Date: Sat Jun 6 10:30:37 2009 New Revision: 782221 URL: http://svn.apache.org/viewvc?rev=782221&view=rev Log: DOXIA-332: Problem with Tables, Doxia, APT Maven site and PDF/RTF generation
o fixed tableCaption for fo sink Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.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/FoSink.java?rev=782221&r1=782220&r2=782221&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java Sat Jun 6 10:30:37 2009 @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; +import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -42,6 +43,8 @@ import org.apache.maven.doxia.util.HtmlTools; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; +import org.codehaus.plexus.util.xml.XMLWriter; /** * FO Sink implementation. @@ -98,6 +101,10 @@ private String languageId; + private StringWriter tableCaptionWriter = null; + + private XMLWriter tableCaptionXMLWriter = null; + /** Map of warn messages with a String as key to describe the error type and a Set as value. * Using to reduce warn messages. */ protected Map warnMessages; @@ -909,6 +916,14 @@ /** {...@inheritdoc} */ public void table_() { + String tableCaption = null; + if ( tableCaptionXMLWriter != null ) + { + tableCaption = tableCaptionWriter.toString(); + tableCaptionXMLWriter = null; + tableCaptionWriter = null; + } + String content = tempWriter.toString(); if ( content.lastIndexOf( "<fo:table " ) != -1 || content.lastIndexOf( "<fo:table>" ) != -1 ) { @@ -952,6 +967,16 @@ writeEndTag( BLOCK_TAG ); writeEOL(); + + if ( tableCaption != null ) + { + SinkEventAttributeSet atts = new SinkEventAttributeSet(); + atts.addAttribute( SinkEventAttributes.ALIGN, "center" ); + + paragraph( atts ); + write( tableCaption ); + paragraph_(); + } } /** {...@inheritdoc} */ @@ -1108,6 +1133,9 @@ /** {...@inheritdoc} */ public void tableCaption( SinkEventAttributes attributes ) { + tableCaptionWriter = new StringWriter(); + tableCaptionXMLWriter = new PrettyPrintXMLWriter( tableCaptionWriter ); + // <fo:table-caption> is XSL-FO 1.0 standard but not implemented in FOP 0.95 //writeStartTag( TABLE_CAPTION_TAG ); @@ -1536,7 +1564,14 @@ */ protected void write( String text ) { - tempWriter.write( unifyEOLs( text ) ); + if ( tableCaptionXMLWriter == null ) + { + tempWriter.write( unifyEOLs( text ) ); + } + else + { + tableCaptionXMLWriter.writeText( unifyEOLs( text ) ); + } } /** @@ -1619,6 +1654,50 @@ return buffer.toString(); } + /** {...@inheritdoc} */ + protected void writeStartTag( Tag t, MutableAttributeSet att, boolean isSimpleTag ) + { + if ( tableCaptionXMLWriter == null ) + { + super.writeStartTag ( t, att, isSimpleTag ); + } + else + { + String tag = ( getNameSpace() != null ? getNameSpace() + ":" : "" ) + t.toString(); + tableCaptionXMLWriter.startElement( tag ); + + if ( att != null ) + { + Enumeration names = att.getAttributeNames(); + while ( names.hasMoreElements() ) + { + Object key = names.nextElement(); + Object value = att.getAttribute( key ); + + tableCaptionXMLWriter.addAttribute( key.toString(), value.toString() ); + } + } + + if ( isSimpleTag ) + { + tableCaptionXMLWriter.endElement(); + } + } + } + + /** {...@inheritdoc} */ + protected void writeEndTag( Tag t ) + { + if ( tableCaptionXMLWriter == null ) + { + super.writeEndTag( t ); + } + else + { + tableCaptionXMLWriter.endElement(); + } + } + private static final char UPPER_ALPHA = 0x391; private static final char PIV = 0x3d6; private static final char OLINE = 0x203e; Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.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/FoSinkTest.java?rev=782221&r1=782220&r2=782221&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java Sat Jun 6 10:30:37 2009 @@ -298,8 +298,13 @@ + "keep-together.within-column=\"always\" padding-start=\"2.5pt\" " + "background-color=\"#eeeeee\" padding-before=\"4pt\">" + EOL + "<fo:block line-height=\"1.2em\" " + "text-align=\"center\" font-family=\"Helvetica,sans-serif\" font-size=\"9pt\">" + EOL + cell - + "</fo:block>" + EOL + "</fo:table-cell>" + EOL + "</fo:table-row>" + EOL + "</fo:table-body>" - + EOL + caption + "</fo:table>" + EOL + "</fo:block>" + EOL; + + "</fo:block>" + EOL + "</fo:table-cell>" + EOL + "</fo:table-row>" + EOL + "</fo:table-body>" + EOL + + "</fo:table>"+ EOL + + "</fo:block>"+ EOL + + EOL + + "<fo:block white-space-collapse=\"true\" space-after=\"6pt\" space-before=\"3pt\" " + + "font-family=\"Garamond,serif\" line-height=\"12pt\" text-align=\"center\" font-size=\"11pt\">" + + "Table_caption</fo:block>" + EOL; } /** {...@inheritdoc} */