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/02/20 12:33:10 UTC
svn commit: r746211 - in
/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo:
FoAggregateSink.java FoSink.java
Author: ltheussl
Date: Fri Feb 20 11:33:10 2009
New Revision: 746211
URL: http://svn.apache.org/viewvc?rev=746211&view=rev
Log:
Resolve image links relative to base
Modified:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.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=746211&r1=746210&r2=746211&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 Fri Feb 20 11:33:10 2009
@@ -223,6 +223,23 @@
//
// -----------------------------------------------------------------------
+ /** {@inheritDoc} */
+ public void figureGraphics( String name )
+ {
+ if ( !isFigure() )
+ {
+ write( "<fo:external-graphic" + getFoConfiguration().getAttributeString( "figure.graphics" ) );
+ }
+
+ String anchor = name;
+
+ if ( name.startsWith( "../" ) && docName != null )
+ {
+ anchor = resolveLinkRelativeToBase( name );
+ }
+
+ writeln( " src=\"" + anchor + "\"/>" );
+ }
/** {@inheritDoc} */
@@ -292,30 +309,16 @@
{
// local link (ie anchor is not in the same source document)
- String anchor = name;
-
if ( docName == null )
{
// can't resolve link without base, fop will issue a warning
- writeStartTag( BASIC_LINK_TAG, "internal-destination", HtmlTools.escapeHTML( anchor ) );
+ writeStartTag( BASIC_LINK_TAG, "internal-destination", HtmlTools.escapeHTML( name ) );
writeStartTag( INLINE_TAG, "href.internal" );
return;
}
- String base = docName.substring( 0, docName.lastIndexOf( "/" ) );
-
- if ( base.indexOf( "/" ) != -1 )
- {
- while ( anchor.startsWith( "../" ) )
- {
- base = base.substring( 0, base.lastIndexOf( "/" ) );
-
- anchor = anchor.substring( 3 );
- }
- }
-
- anchor = base + "/" + chopExtension ( anchor );
+ String anchor = resolveLinkRelativeToBase( chopExtension( name ) );
writeStartTag( BASIC_LINK_TAG, "internal-destination", HtmlTools.escapeHTML( anchor ) );
writeStartTag( INLINE_TAG, "href.internal" );
@@ -341,8 +344,30 @@
}
}
- private String chopExtension( String anchor )
+ // only call this if docName != null !!!
+ private String resolveLinkRelativeToBase( String name )
{
+ String anchor = name;
+
+ String base = docName.substring( 0, docName.lastIndexOf( "/" ) );
+
+ if ( base.indexOf( "/" ) != -1 )
+ {
+ while ( anchor.startsWith( "../" ) )
+ {
+ base = base.substring( 0, base.lastIndexOf( "/" ) );
+
+ anchor = anchor.substring( 3 );
+ }
+ }
+
+ return base + "/" + anchor;
+ }
+
+ private String chopExtension( String name )
+ {
+ String anchor = name;
+
int dot = anchor.indexOf( "." );
if ( dot != -1 )
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=746211&r1=746210&r2=746211&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 20 11:33:10 2009
@@ -592,15 +592,24 @@
/** {@inheritDoc} */
public void figureGraphics( String name )
{
- if ( !figure )
+ if ( !isFigure() )
{
- write( "<fo:external-graphic"
- + config.getAttributeString( "figure.graphics" ) );
+ write( "<fo:external-graphic" + config.getAttributeString( "figure.graphics" ) );
}
- // TODO name should be relative to site!
+
writeln( " src=\"" + name + "\"/>" );
}
+ /**
+ * Flags if we are inside a figure.
+ *
+ * @return True if we are between {@link #figure()} and {@link #figure_()} calls.
+ */
+ protected boolean isFigure()
+ {
+ return this.figure;
+ }
+
/** {@inheritDoc} */
public void figureCaption()
{