You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by lt...@apache.org on 2007/08/17 21:05:36 UTC
svn commit: r567110 - in /maven/sandbox/trunk/doxia/doxia-module-fo: ./
src/main/java/org/apache/maven/doxia/module/fo/ src/main/resources/
src/test/java/org/apache/maven/doxia/module/fo/
Author: ltheussl
Date: Fri Aug 17 12:05:35 2007
New Revision: 567110
URL: http://svn.apache.org/viewvc?view=rev&rev=567110
Log:
Use new test classes. Add some layout master sets.
Modified:
maven/sandbox/trunk/doxia/doxia-module-fo/pom.xml
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt
maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoConfigurationTest.java
maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoTestUtils.java
Modified: maven/sandbox/trunk/doxia/doxia-module-fo/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/pom.xml?view=diff&rev=567110&r1=567109&r2=567110
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-fo/pom.xml (original)
+++ maven/sandbox/trunk/doxia/doxia-module-fo/pom.xml Fri Aug 17 12:05:35 2007
@@ -69,11 +69,11 @@
<version>3.8.1</version>
<scope>test</scope>
</dependency>
- <!-- This should'n be needed, see DOXIA-101 -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
- <artifactId>doxia-module-apt</artifactId>
+ <artifactId>doxia-core</artifactId>
<version>${projectVersion}</version>
+ <classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
Modified: maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java?view=diff&rev=567110&r1=567109&r2=567110
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java Fri Aug 17 12:05:35 2007
@@ -936,13 +936,23 @@
writeln( "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">" );
writeStartTag( "layout-master-set", null );
- writeStartTag( "simple-page-master", "layout.master.set.body" );
+ writeStartTag( "simple-page-master", "layout.master.set.cover-page" );
+ writeEmptyTag( "region-body", "layout.master.set.cover-page.region-body" );
+ writeEndTag( "simple-page-master" );
+
+ writeStartTag( "simple-page-master", "layout.master.set.toc" );
+ writeEmptyTag( "region-body", "layout.master.set.toc.region-body" );
+ writeEmptyTag( "region-before", "layout.master.set.toc.region-before" );
+ writeEmptyTag( "region-after", "layout.master.set.toc.region-after" );
+ writeEndTag( "simple-page-master" );
+
+ writeStartTag( "simple-page-master", "layout.master.set.body" );
writeEmptyTag( "region-body", "layout.master.set.body.region-body" );
writeEmptyTag( "region-before", "layout.master.set.body.region-before" );
writeEmptyTag( "region-after", "layout.master.set.body.region-after" );
-
writeEndTag( "simple-page-master" );
+
writeEndTag( "layout-master-set" );
}
Modified: maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt?view=diff&rev=567110&r1=567109&r2=567110
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt (original)
+++ maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt Fri Aug 17 12:05:35 2007
@@ -29,9 +29,14 @@
<xsl:attribute name="margin-left">1in</xsl:attribute>
<xsl:attribute name="margin-right">1in</xsl:attribute>
</xsl:attribute-set>
+
<xsl:attribute-set name="layout.master.set.cover-page" use-attribute-sets="layout.master.set.base">
<xsl:attribute name="master-name">cover-page</xsl:attribute>
</xsl:attribute-set>
+ <xsl:attribute-set name="layout.master.set.cover-page.region-body">
+ <xsl:attribute name="margin-top">0.7in</xsl:attribute>
+ </xsl:attribute-set>
+
<xsl:attribute-set name="layout.master.set.cover-inside" use-attribute-sets="layout.master.set.base">
<xsl:attribute name="master-name">cover-inside</xsl:attribute>
<xsl:attribute name="margin-top">0in</xsl:attribute>
@@ -39,13 +44,24 @@
<xsl:attribute name="margin-left">0in</xsl:attribute>
<xsl:attribute name="margin-right">0in</xsl:attribute>
</xsl:attribute-set>
+
<xsl:attribute-set name="layout.master.set.toc" use-attribute-sets="layout.master.set.base">
<xsl:attribute name="master-name">toc</xsl:attribute>
</xsl:attribute-set>
+ <xsl:attribute-set name="layout.master.set.toc.region-body">
+ <xsl:attribute name="margin-top">0.7in</xsl:attribute>
+ <xsl:attribute name="margin-bottom">0.8in</xsl:attribute>
+ </xsl:attribute-set>
+ <xsl:attribute-set name="layout.master.set.toc.region-before">
+ <xsl:attribute name="extent">0.35in</xsl:attribute>
+ </xsl:attribute-set>
+ <xsl:attribute-set name="layout.master.set.toc.region-after">
+ <xsl:attribute name="extent">0.125in</xsl:attribute>
+ </xsl:attribute-set>
+
<xsl:attribute-set name="layout.master.set.body" use-attribute-sets="layout.master.set.base">
<xsl:attribute name="master-name">body</xsl:attribute>
</xsl:attribute-set>
-
<xsl:attribute-set name="layout.master.set.body.region-body">
<xsl:attribute name="margin-top">0.7in</xsl:attribute>
<xsl:attribute name="margin-bottom">0.8in</xsl:attribute>
Modified: maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoConfigurationTest.java?view=diff&rev=567110&r1=567109&r2=567110
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoConfigurationTest.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoConfigurationTest.java Fri Aug 17 12:05:35 2007
@@ -39,7 +39,7 @@
"", attributes.getAttributeSet( "a.dummy.attribute" ) );
assertEquals(
- "Wrong attributes returned!",
+ "Wrong attributes returned for body.pre!",
" font-size=\"10pt\" font-family=\"monospace\"",
attributes.getAttributeSet( "body.pre" ) );
}
Modified: maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java?view=diff&rev=567110&r1=567109&r2=567110
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java Fri Aug 17 12:05:35 2007
@@ -20,47 +20,60 @@
*/
import java.io.File;
-import java.io.Reader;
-import java.io.FileWriter;
import java.io.Writer;
-
-import org.apache.maven.doxia.module.apt.AptParser;
-import org.apache.maven.doxia.parser.Parser;
import org.apache.maven.doxia.sink.Sink;
-import org.apache.maven.doxia.sink.AbstractSinkTestCase;
+import org.apache.maven.doxia.sink.AbstractSinkTest;
+import org.apache.maven.doxia.sink.SinkTestDocument;
/**
* <code>FO Sink</code> Test case.
*/
-public class FoSinkTest extends AbstractSinkTestCase
+public class FoSinkTest extends AbstractSinkTest
{
+ private FoConfiguration config;
+ // ----------------------------------------------------------------------
+ // Specific test methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Uses fop to generate a pdf from a test document.
+ * @throws Exception If the conversion fails.
+ */
public void testConvertFO2PDF() throws Exception
{
- // first create fo file from apt
- new AptParser().parse( getTestReader(), createSink() );
+ String fileName = "test";
+ // first create fo
+ FoSink fosink = new FoSink( getTestWriter( fileName ) );
+ SinkTestDocument.generate( fosink );
+ fosink.close();
// then generate PDF
- fo2pdf( "test" );
+ fo2pdf( fileName );
}
+ /**
+ * Uses fop to generate an aggregated pdf from two test documents.
+ * @throws Exception If the conversion fails.
+ */
public void testAggregateMode() throws Exception
{
- AptParser parser = new AptParser();
- Reader source = getTestReader();
- FoSink fosink = new FoSink( getFOTestWriter( "aggregate" ), true );
+ FoSink fosink = new FoSink( getTestWriter( "aggregate" ), true );
fosink.beginDocument();
- parser.parse( source, fosink );
+ SinkTestDocument.generate( fosink );
// re-use the same source
- source = getTestReader();
- parser.parse( source, fosink );
+ SinkTestDocument.generate( fosink );
fosink.endDocument();
// then generate PDF
fo2pdf( "aggregate" );
}
+ // ----------------------------------------------------------------------
+ // Abstract methods the individual SinkTests must provide
+ // ----------------------------------------------------------------------
+
/** {@inheritDoc} */
protected String outputExtension()
{
@@ -68,39 +81,274 @@
}
/** {@inheritDoc} */
- protected Parser createParser()
+ protected Sink createSink( Writer writer )
+ {
+ return new FoSink( writer );
+ }
+
+ /** {@inheritDoc} */
+ protected String getTitleBlock( String title )
+ {
+ String attribs = getConfig().getAttributeSet( "doc.header.title" );
+ return "<fo:block" + attribs + ">" + title + "</fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getAuthorBlock( String author )
+ {
+ String attribs = getConfig().getAttributeSet( "doc.header.author" );
+ return "<fo:block" + attribs + ">" + author + "</fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getDateBlock( String date )
+ {
+ String attribs = getConfig().getAttributeSet( "doc.header.date" );
+ return "<fo:block" + attribs + ">" + date + "</fo:block>";
+ }
+
+ // TODO
+ protected String getHeadBlock()
+ {
+ return "";
+ }
+
+ // TODO: remove
+ public void testHead()
+ {
+ String expected = "";
+ assertEquals( "Wrong head!", expected, getHeadBlock() );
+ }
+
+ /** {@inheritDoc} */
+ protected String getBodyBlock()
+ {
+ return "</fo:flow></fo:page-sequence></fo:root>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getSectionTitleBlock( String title )
+ {
+ return title;
+ }
+
+ /** {@inheritDoc} */
+ protected String getSection1Block( String title )
+ {
+ String attribs = getConfig().getAttributeSet( "body.text" );
+ String attrib2 = getConfig().getAttributeSet( "body.h1" );
+ return "<fo:block" + attribs + "><fo:block" + attrib2 + ">1 "
+ + title + "</fo:block></fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getSection2Block( String title )
+ {
+ String attribs = getConfig().getAttributeSet( "body.text" );
+ String attrib2 = getConfig().getAttributeSet( "body.h2" );
+ return "<fo:block" + attribs + "><fo:block" + attrib2 + ">0.1 "
+ + title + "</fo:block></fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getSection3Block( String title )
+ {
+ String attribs = getConfig().getAttributeSet( "body.text" );
+ String attrib2 = getConfig().getAttributeSet( "body.h3" );
+ return "<fo:block" + attribs + "><fo:block" + attrib2 + ">0.0.1 "
+ + title + "</fo:block></fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getSection4Block( String title )
+ {
+ String attribs = getConfig().getAttributeSet( "body.text" );
+ String attrib2 = getConfig().getAttributeSet( "body.h4" );
+ return "<fo:block" + attribs + "><fo:block" + attrib2 + ">"
+ + title + "</fo:block></fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getSection5Block( String title )
+ {
+ String attribs = getConfig().getAttributeSet( "body.text" );
+ String attrib2 = getConfig().getAttributeSet( "body.h5" );
+ return "<fo:block" + attribs + "><fo:block" + attrib2 + ">"
+ + title + "</fo:block></fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getListBlock( String item )
+ {
+ String attribs = getConfig().getAttributeSet( "list" );
+ String itemAttribs = getConfig().getAttributeSet( "list.item" );
+ return "<fo:list-block" + attribs + "><fo:list-item" + itemAttribs
+ + "><fo:list-item-label><fo:block>•</fo:block></fo:list-item-label><fo:list-item-body"
+ + itemAttribs + "><fo:block>" + item
+ + "</fo:block></fo:list-item-body></fo:list-item></fo:list-block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getNumberedListBlock( String item )
+ {
+ String attribs = getConfig().getAttributeSet( "list" );
+ String itemAttribs = getConfig().getAttributeSet( "list.item" );
+ return "<fo:list-block" + attribs + "><fo:list-item" + itemAttribs
+ + "><fo:list-item-label><fo:block>i</fo:block></fo:list-item-label>"
+ + "<fo:list-item-body" + itemAttribs
+ + "><fo:block>" + item + "</fo:block></fo:list-item-body>"
+ + "</fo:list-item></fo:list-block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getDefinitionListBlock( String definum, String definition )
{
- // fo parser?
- return new AptParser();
+ String dlAtts = getConfig().getAttributeSet( "dl" );
+ String dtAtts = getConfig().getAttributeSet( "dt" );
+ String ddAtts = getConfig().getAttributeSet( "dd" );
+ return "<fo:block" + dlAtts + "><fo:block" + dtAtts + ">" + definum
+ + "</fo:block><fo:block" + ddAtts + ">" + definition
+ + "</fo:block></fo:block>";
}
/** {@inheritDoc} */
- protected Sink createSink() throws Exception
+ protected String getFigureBlock( String source, String caption )
{
- return new FoSink( getTestWriter() );
+ String dlAtts = getConfig().getAttributeSet( "figure.display" );
+ String dtAtts = getConfig().getAttributeSet( "figure.graphics" );
+ String ddAtts = getConfig().getAttributeSet( "figure.caption" );
+ return "<fo:block" + dlAtts + "><fo:external-graphic" + dtAtts
+ + " src=\"" + source + ".png" + "\"/><fo:block" + ddAtts
+ + ">" + caption + "</fo:block></fo:block>";
}
+ /** {@inheritDoc} */
+ protected String getTableBlock( String cell, String caption )
+ {
+ String dlAtts = getConfig().getAttributeSet( "table.padding" );
+ String dtAtts = getConfig().getAttributeSet( "table.layout" );
+ String ddAtts = getConfig().getAttributeSet( "table.body.row" );
+ String deAtts = getConfig().getAttributeSet( "table.body.cell" );
+ return "<fo:block" + dlAtts + "><fo:table" + dtAtts + ">"
+ + "<fo:table-column column-width=\"proportional-column-width(1)\"/>"
+ + "<fo:table-column column-width=\"1in\"/>"
+ + "<fo:table-column column-width=\"proportional-column-width(1)\"/>"
+ + "<fo:table-body><fo:table-row" + ddAtts
+ + "><fo:table-cell column-number=\"2\"" + deAtts
+ + "><fo:block text-align=\"center\">" + cell
+ + "</fo:block></fo:table-cell></fo:table-row></fo:table-body>"
+ + caption + "</fo:table></fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getParagraphBlock( String text )
+ {
+ String attribs = getConfig().getAttributeSet( "normal.paragraph" );
+ return "<fo:block" + attribs + ">" + text + "</fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getVerbatimBlock( String text )
+ {
+ String attribs = getConfig().getAttributeSet( "body.source" );
+ return "<fo:block" + attribs + ">" + text + "</fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getHorizontalRuleBlock()
+ {
+ String attribs = getConfig().getAttributeSet( "body.rule" );
+ return "<fo:block><fo:leader" + attribs + "/></fo:block>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getPageBreakBlock()
+ {
+ return "<fo:block break-before=\"page\"/>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getAnchorBlock( String anchor )
+ {
+ return "<fo:inline id=\"" + anchor + "\">" + anchor + "</fo:inline>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getLinkBlock( String link, String text )
+ {
+ String attribs = getConfig().getAttributeSet( "href.internal" );
+ return "<fo:basic-link internal-destination=\"" + link + "\"><fo:inline"
+ + attribs + ">" + text + "</fo:inline></fo:basic-link>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getItalicBlock( String text )
+ {
+ String attribs = getConfig().getAttributeSet( "italic" );
+ return "<fo:inline" + attribs + ">" + text + "</fo:inline>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getBoldBlock( String text )
+ {
+ String attribs = getConfig().getAttributeSet( "bold" );
+ return "<fo:inline" + attribs + ">" + text + "</fo:inline>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getMonospacedBlock( String text )
+ {
+ String attribs = getConfig().getAttributeSet( "monospace" );
+ return "<fo:inline" + attribs + ">" + text + "</fo:inline>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getLineBreakBlock()
+ {
+ return "<fo:block/>";
+ }
+
+ /** {@inheritDoc} */
+ protected String getNonBreakingSpaceBlock()
+ {
+ return " ";
+ }
+
+ /** {@inheritDoc} */
+ protected String getTextBlock( String text )
+ {
+ return FoSink.escaped( text, false );
+ }
+
+ /** {@inheritDoc} */
+ protected String getRawTextBlock( String text )
+ {
+ return text;
+ }
+
+ // ----------------------------------------------------------------------
+ // Auxiliary methods
+ // ----------------------------------------------------------------------
+
+
private void fo2pdf( String baseName ) throws Exception
{
- File outputDirectory = new File( getBasedirFile(), "target/output" );
+ //File outputDirectory = new File( getBasedirFile(), getOutputDir() );
+ File outputDirectory = new File( getBasedir(), outputBaseDir() + getOutputDir() );
File resourceDirectory = new File( getBasedirFile(), "target/test-classes" );
File foFile = new File( outputDirectory, baseName + "." + outputExtension() );
File pdfFile = new File( outputDirectory, baseName + ".pdf" );
FoTestUtils.convertFO2PDF( foFile, pdfFile, resourceDirectory.getCanonicalPath() );
}
- private Writer getFOTestWriter( String baseName )
- throws Exception
+ private FoConfiguration getConfig()
{
- File outputDirectory = new File( getBasedirFile(), "target/output" );
-
- if ( !outputDirectory.exists() )
+ if ( config == null )
{
- outputDirectory.mkdirs();
+ config = ((FoSink) getSink()).getFoConfiguration();
}
- return new FileWriter( new File( outputDirectory, baseName + "." + outputExtension() ) );
+ return config;
}
-
}
Modified: maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoTestUtils.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoTestUtils.java?view=diff&rev=567110&r1=567109&r2=567110
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoTestUtils.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoTestUtils.java Fri Aug 17 12:05:35 2007
@@ -83,7 +83,10 @@
}
finally
{
- out.close();
+ if ( out != null )
+ {
+ out.close();
+ }
}
}