Author: ltheussl Date: Tue Sep 18 06:47:11 2007 New Revision: 576915 URL: http://svn.apache.org/viewvc?rev=576915&view=rev Log: Fix link/anchor handling for the single-document sink.
Modified: 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/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java 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?rev=576915&r1=576914&r2=576915&view=diff ============================================================================== --- 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 Tue Sep 18 06:47:11 2007 @@ -742,7 +742,14 @@ /** [EMAIL PROTECTED] */ public void anchor( String name ) { - writeStartTag( "inline", "id", name ); + String anchor = name; + + if ( !anchor.startsWith( "#" ) ) + { + anchor = "#" + anchor; + } + + writeStartTag( "inline", "id", anchor ); } /** [EMAIL PROTECTED] */ @@ -754,21 +761,24 @@ /** [EMAIL PROTECTED] */ public void link( String name ) { - if ( name.startsWith( "http", 0 ) || name.startsWith( "mailto", 0 ) - || name.startsWith( "ftp", 0 ) ) + if ( name.startsWith( "http" ) || name.startsWith( "mailto" ) + || name.startsWith( "ftp" ) ) { writeStartTag( "basic-link", "external-destination", HtmlTools.escapeHTML( name ) ); writeStartTag( "inline", "href.external" ); } - else if ( name.startsWith( "#", 0 ) ) - { - writeStartTag( "basic-link", "internal-destination", HtmlTools.escapeHTML( name ) ); - writeStartTag( "inline", "href.internal" ); - } else { - // TODO: aggregate mode: link to another document, construct relative path - writeStartTag( "basic-link", "internal-destination", name ); + // treat everything else as internal, local (ie anchor is in the same source document) + + String anchor = name; + + if ( !anchor.startsWith( "#" ) ) + { + anchor = "#" + anchor; + } + + writeStartTag( "basic-link", "internal-destination", HtmlTools.escapeHTML( anchor ) ); writeStartTag( "inline", "href.internal" ); } } @@ -868,7 +878,7 @@ } /** - * Writes the beginning of a FO document in aggregate mode. + * Writes the beginning of a FO document. */ public void beginDocument() { @@ -898,7 +908,7 @@ } /** - * Writes the end of a FO document in aggregate mode, flushes and closes the stream. + * Writes the end of a FO document, flushes and closes the stream. */ public void endDocument() { 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?rev=576915&r1=576914&r2=576915&view=diff ============================================================================== --- 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 Tue Sep 18 06:47:11 2007 @@ -23,6 +23,8 @@ import java.io.Writer; import org.apache.maven.doxia.docrenderer.document.DocumentMeta; +import org.apache.maven.doxia.docrenderer.document.DocumentTOC; +import org.apache.maven.doxia.docrenderer.document.DocumentTOCItem; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.AbstractSinkTest; @@ -67,11 +69,15 @@ fosink.coverPage( getMeta() ); + fosink.toc( getToc() ); + fosink.setDocumentName( "doc1" ); + fosink.setDocumentTitle( "Document 1" ); SinkTestDocument.generate( fosink ); // re-use the same source fosink.setDocumentName( "doc2" ); + fosink.setDocumentTitle( "Document 2" ); SinkTestDocument.generate( fosink ); fosink.endDocument(); @@ -88,6 +94,24 @@ return meta; } + private DocumentTOC getToc() + { + DocumentTOCItem item1 = new DocumentTOCItem(); + item1.setName( "First document" ); + item1.setRef( "doc1.apt" ); + + DocumentTOCItem item2 = new DocumentTOCItem(); + item2.setName( "Second document" ); + item2.setRef( "doc2.xml" ); + + DocumentTOC toc = new DocumentTOC(); + toc.setName( "What's in here" ); + toc.addItem( item1 ); + toc.addItem( item2 ); + + return toc; + } + // ---------------------------------------------------------------------- // Abstract methods the individual SinkTests must provide // ---------------------------------------------------------------------- @@ -288,14 +312,16 @@ /** [EMAIL PROTECTED] */ protected String getAnchorBlock( String anchor ) { - return "<fo:inline id=\"" + anchor + "\">" + anchor + "</fo:inline>"; + // assume that anchor doesn't start with # + return "<fo:inline id=\"#" + anchor + "\">" + anchor + "</fo:inline>"; } /** [EMAIL PROTECTED] */ protected String getLinkBlock( String link, String text ) { String attribs = getConfig().getAttributeSet( "href.internal" ); - return "<fo:basic-link internal-destination=\"" + link + "\"><fo:inline" + // assume that link doesn't start with # + return "<fo:basic-link internal-destination=\"#" + link + "\"><fo:inline" + attribs + ">" + text + "</fo:inline></fo:basic-link>"; }