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/02/06 05:08:16 UTC
svn commit: r741395 - in
/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src:
main/java/org/apache/maven/doxia/module/fo/FoSink.java
test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
Author: vsiveton
Date: Fri Feb 6 04:08:16 2009
New Revision: 741395
URL: http://svn.apache.org/viewvc?rev=741395&view=rev
Log:
o fixed potential error for tables using a tempWriter similar to r735477
o updated test case
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=741395&r1=741394&r2=741395&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 Fri Feb 6 04:08:16 2009
@@ -20,6 +20,7 @@
*/
import java.io.IOException;
+import java.io.StringWriter;
import java.io.Writer;
import java.util.Stack;
@@ -33,6 +34,7 @@
import org.apache.maven.doxia.sink.SinkEventAttributes;
import org.apache.maven.doxia.util.DoxiaUtils;
import org.apache.maven.doxia.util.HtmlTools;
+import org.codehaus.plexus.util.StringUtils;
/**
* FO Sink implementation.
@@ -48,6 +50,10 @@
/** For writing the result. */
private final Writer out;
+ /** The StringWriter to write the result temporary, so we could play with the output and fix fo.
+ * Calling the method {@link #close()} is needed to perform the changes in the {@link #out}. */
+ private StringWriter tempWriter;
+
/** Used to get the current position in numbered lists. */
private final Stack listStack = new Stack();
@@ -103,6 +109,7 @@
protected FoSink( Writer writer, String encoding )
{
this.out = writer;
+ this.tempWriter = new StringWriter();
this.encoding = encoding;
this.config = new FoConfiguration();
@@ -664,6 +671,41 @@
/** {@inheritDoc} */
public void table_()
{
+ String content = tempWriter.toString();
+ if ( content.lastIndexOf( "<fo:table " ) != -1 || content.lastIndexOf( "<fo:table>" ) != -1 )
+ {
+ StringBuffer sb = new StringBuffer();
+ // FOP hack to center the table, see
+ // http://xmlgraphics.apache.org/fop/fo.html#fo-center-table-horizon
+ sb.append( "<fo:table-column column-width=\"proportional-column-width(1)\"/>" );
+ sb.append( EOL );
+
+ int percent = 100 / cellCount;
+ for ( int i = 0; i < cellCount; i++ )
+ {
+ sb.append( "<fo:table-column column-width=\"" + percent + "%\"/>" );
+ sb.append( EOL );
+ }
+
+ sb.append( "<fo:table-column column-width=\"proportional-column-width(1)\"/>" );
+ sb.append( EOL );
+
+ String subContent;
+ if ( content.lastIndexOf( "<fo:table " ) != -1 )
+ {
+ subContent = content.substring( content.lastIndexOf( "<fo:table " ) );
+ }
+ else
+ {
+ subContent = content.substring( content.lastIndexOf( "<fo:table>" ) );
+ }
+ String table = subContent.substring( 0, subContent.indexOf( ">" ) + 1 );
+ String subContentUpdated = StringUtils.replace( subContent, table, table + EOL + sb.toString() );
+
+ tempWriter = new StringWriter();
+ tempWriter.write( StringUtils.replace( content, subContent, subContentUpdated ) );
+ }
+
writeEndTag( TABLE_TAG );
writeEOL();
@@ -680,23 +722,6 @@
this.tableGrid = grid;
this.cellJustif = justification;
this.isCellJustif = true;
-
- // FOP hack to center the table, see
- // http://xmlgraphics.apache.org/fop/fo.html#fo-center-table-horizon
- writeln( "<fo:table-column column-width=\"proportional-column-width(1)\"/>" );
-
- // TODO: calculate width[i]
- // FIXME: XhtmlBaseParser always calls tableRows with a justification array of length one
- // that's why the pdf plugin can't handle xdoc tables. How to determine the number of columns?
- if ( cellJustif != null )
- {
- for ( int i = 0; i < cellJustif.length; i++ )
- {
- writeln( "<fo:table-column column-width=\"1in\"/>" );
- }
- }
-
- writeln( "<fo:table-column column-width=\"proportional-column-width(1)\"/>" );
writeStartTag( TABLE_BODY_TAG, "" );
}
@@ -985,6 +1010,8 @@
{
try
{
+ out.write( tempWriter.toString() );
+ tempWriter = new StringWriter();
out.close();
}
catch ( IOException e )
@@ -1169,14 +1196,7 @@
*/
protected void write( String text )
{
- try
- {
- out.write( unifyEOLs( text ) );
- }
- catch ( IOException e )
- {
- getLog().debug( e );
- }
+ tempWriter.write( unifyEOLs( text ) );
}
/**
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=741395&r1=741394&r2=741395&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 Fri Feb 6 04:08:16 2009
@@ -288,9 +288,9 @@
String dtAtts = getConfig().getAttributeString( "table.layout" );
String ddAtts = getConfig().getAttributeString( "table.body.row" );
String deAtts = getConfig().getAttributeString( "table.body.cell" );
- return EOL + EOL + "<fo:block" + dlAtts + ">" + EOL + "<fo:table" + dtAtts + ">"
+ return EOL + EOL + "<fo:block" + dlAtts + ">" + EOL + "<fo:table" + dtAtts + ">" + EOL
+ "<fo:table-column column-width=\"proportional-column-width(1)\"/>"
- + EOL + "<fo:table-column column-width=\"1in\"/>"
+ + EOL + "<fo:table-column column-width=\"100%\"/>"
+ EOL + "<fo:table-column column-width=\"proportional-column-width(1)\"/>"
+ EOL + EOL + "<fo:table-body>" + EOL + "<fo:table-row" + ddAtts
+ "><fo:table-cell column-number=\"2\"" + deAtts