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 lt...@apache.org on 2009/04/11 09:03:26 UTC
svn commit: r764174 - in
/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src:
main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
Author: ltheussl
Date: Sat Apr 11 07:03:25 2009
New Revision: 764174
URL: http://svn.apache.org/viewvc?rev=764174&view=rev
Log:
[DOXIA-306] fix link resolution to images in other source folders
Added:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java (with props)
Modified:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
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=764174&r1=764173&r2=764174&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 Sat Apr 11 07:03:25 2009
@@ -205,7 +205,7 @@
return "";
}
- String idName = name;
+ String idName = name.replace( '\\', '/' );
// prepend "./" and strip extension
if ( !idName.startsWith( "./" ) )
@@ -236,9 +236,14 @@
{
String anchor = src;
- if ( src.startsWith( "../" ) && docName != null )
+ while ( anchor.startsWith( "./" ) )
{
- anchor = resolveLinkRelativeToBase( src );
+ anchor = anchor.substring( 2 );
+ }
+
+ if ( anchor.startsWith( "../" ) && docName != null )
+ {
+ anchor = resolveLinkRelativeToBase( anchor );
}
super.figureGraphics( anchor, attributes );
@@ -335,7 +340,8 @@
if ( anchor.startsWith( "./" ) )
{
- anchor = anchor.substring( 2 );
+ this.link( anchor.substring( 2 ) );
+ return;
}
anchor = chopExtension ( anchor );
@@ -372,9 +378,9 @@
{
String anchor = name;
- int dot = anchor.indexOf( "." );
+ int dot = anchor.lastIndexOf( "." );
- if ( dot != -1 )
+ if ( dot != -1 && dot != anchor.length() && anchor.charAt( dot + 1 ) != '/' )
{
int hash = anchor.indexOf( "#", dot );
Added: 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=764174&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java Sat Apr 11 07:03:25 2009
@@ -0,0 +1,158 @@
+package org.apache.maven.doxia.module.fo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.StringWriter;
+import java.io.Writer;
+
+import junit.framework.TestCase;
+
+/**
+ * Test FoAggregateSink.
+ *
+ * @author ltheussl
+ */
+public class FoAggregateSinkTest
+ extends TestCase
+{
+ private FoAggregateSink sink;
+ private Writer writer;
+
+ /**
+ * Set up the writer.
+ *
+ * @throws java.lang.Exception if any.
+ */
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ writer = new StringWriter();
+ }
+
+ /**
+ * Test of body method, of class FoAggregateSink.
+ */
+ public void testBody()
+ {
+ try
+ {
+ sink = new FoAggregateSink( writer );
+
+ sink.setDocumentName( "folder/documentName.apt" );
+ sink.setDocumentTitle( "documentTitle" );
+ sink.body();
+ sink.body_();
+ }
+ finally
+ {
+ sink.close();
+ }
+
+ assertTrue( writer.toString().indexOf( "<fo:block id=\"./folder/documentName\">" ) != -1 );
+ }
+
+ /**
+ * Test of setDocumentName method, of class FoAggregateSink.
+ */
+ public void testSetDocumentName()
+ {
+ try
+ {
+ sink = new FoAggregateSink( writer );
+
+ sink.setDocumentName( "folder\\documentName.boo" );
+ sink.body();
+ }
+ finally
+ {
+ sink.close();
+ }
+
+ assertTrue( writer.toString().indexOf( "<fo:block id=\"./folder/documentName\">" ) != -1 );
+ }
+
+ /**
+ * Test of figureGraphics method, of class FoAggregateSink.
+ */
+ public void testFigureGraphics()
+ {
+ try
+ {
+ sink = new FoAggregateSink( writer );
+ sink.setDocumentName( "./folder\\docName.xml" );
+ sink.figureGraphics( "./../images/fig.png", null );
+ }
+ finally
+ {
+ sink.close();
+ }
+
+ assertTrue( writer.toString().indexOf( "<fo:external-graphic src=\"./images/fig.png\"" ) != -1 );
+ }
+
+ /**
+ * Test of anchor method, of class FoAggregateSink.
+ */
+ public void testAnchor()
+ {
+ try
+ {
+ sink = new FoAggregateSink( writer );
+ sink.anchor( "invalid Anchor" );
+ sink.setDocumentName( "./folder\\docName.xml" );
+ sink.anchor( "validAnchor" );
+ }
+ finally
+ {
+ sink.close();
+ }
+
+ assertTrue( writer.toString().indexOf( "<fo:inline id=\"#invalid_Anchor\">" ) != -1 );
+ assertTrue( writer.toString().indexOf( "<fo:inline id=\"./folder/docName#validAnchor\">" ) != -1 );
+ }
+
+ /**
+ * Test of link method, of class FoAggregateSink.
+ */
+ public void testLink()
+ {
+ try
+ {
+ sink = new FoAggregateSink( writer );
+ sink.link( "http://www.example.com/" );
+ sink.setDocumentName( "./folder\\docName.xml" );
+ sink.link( "#anchor" );
+ sink.link( "./././index.html" );
+ sink.link( "./../download.html" );
+ }
+ finally
+ {
+ sink.close();
+ }
+
+ String result = writer.toString();
+
+ assertTrue( result.indexOf( "<fo:basic-link external-destination=\"http://www.example.com/\">" ) != -1 );
+ assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./folder/docName#anchor\">" ) != -1 );
+ assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./folder/index\">" ) != -1 );
+ assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./download\">" ) != -1 );
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"