]> source.dussan.org Git - poi.git/commitdiff
fix XLS:FO footnotes and endnotes processing fo Word-to-FO converter
authorSergey Vladimirov <sergey@apache.org>
Thu, 21 Jul 2011 02:47:04 +0000 (02:47 +0000)
committerSergey Vladimirov <sergey@apache.org>
Thu, 21 Jul 2011 02:47:04 +0000 (02:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1149011 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/converter/FoDocumentFacade.java
src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java

index 03c8b2da213a31553c58e063dbbb55679032fb1f..5aad12fd3e08a78d37c47686796c9984fd33e385 100644 (file)
@@ -137,6 +137,11 @@ public class FoDocumentFacade
         return result;
     }
 
+    public Element createFootnote()
+    {
+        return document.createElementNS( NS_XSLFO, "fo:footnote" );
+    }
+
     public Element createFootnoteBody()
     {
         return document.createElementNS( NS_XSLFO, "fo:footnote-body" );
index 38e95995db2a91c6bc4aa1ccdc4c3f050d24df10..0c4d31e005438f47a3a8e3d2796ae55dc0ee69a9 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.poi.hwpf.converter;
 
 import java.io.File;
 import java.io.FileWriter;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Stack;
 
@@ -97,45 +98,6 @@ public class WordToFoConverter extends AbstractWordConverter
         }
     }
 
-    @Override
-    protected void processEndnoteAutonumbered( HWPFDocument doc, int noteIndex,
-            Element block, Range endnoteTextRange )
-    {
-        // TODO: add endnote implementation?
-        processFootnoteAutonumbered( doc, noteIndex, block, endnoteTextRange );
-    }
-
-    @Override
-    protected void processFootnoteAutonumbered( HWPFDocument doc,
-            int noteIndex, Element block, Range footnoteTextRange )
-    {
-        String textIndex = String.valueOf( noteIndex + 1 );
-
-        {
-            Element inline = foDocumentFacade.createInline();
-            inline.setTextContent( textIndex );
-            inline.setAttribute( "baseline-shift", "super" );
-            inline.setAttribute( "font-size", "smaller" );
-            block.appendChild( inline );
-        }
-
-        Element footnoteBody = foDocumentFacade.createFootnoteBody();
-        Element footnoteBlock = foDocumentFacade.createBlock();
-        footnoteBody.appendChild( footnoteBlock );
-        block.appendChild( footnoteBody );
-
-        {
-            Element inline = foDocumentFacade.createInline();
-            inline.setTextContent( textIndex );
-            inline.setAttribute( "baseline-shift", "super" );
-            inline.setAttribute( "font-size", "smaller" );
-            footnoteBlock.appendChild( inline );
-        }
-
-        processCharacters( doc, Integer.MIN_VALUE, footnoteTextRange,
-                footnoteBlock );
-    }
-
     static Document process( File docFile ) throws Exception
     {
         final HWPFDocumentCore hwpfDocument = WordToFoUtils.loadDoc( docFile );
@@ -148,6 +110,8 @@ public class WordToFoConverter extends AbstractWordConverter
 
     private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
 
+    private List<Element> endnotes = new ArrayList<Element>( 0 );
+
     protected final FoDocumentFacade foDocumentFacade;
 
     /**
@@ -163,6 +127,15 @@ public class WordToFoConverter extends AbstractWordConverter
         this.foDocumentFacade = new FoDocumentFacade( document );
     }
 
+    protected Element createNoteInline( String noteIndexText )
+    {
+        Element inline = foDocumentFacade.createInline();
+        inline.setTextContent( noteIndexText );
+        inline.setAttribute( "baseline-shift", "super" );
+        inline.setAttribute( "font-size", "smaller" );
+        return inline;
+    }
+
     protected String createPageMaster( Section section, String type,
             int sectionIndex )
     {
@@ -291,6 +264,63 @@ public class WordToFoConverter extends AbstractWordConverter
             foDocumentFacade.setDescription( summaryInformation.getComments() );
     }
 
+    @Override
+    protected void processEndnoteAutonumbered( HWPFDocument doc, int noteIndex,
+            Element block, Range endnoteTextRange )
+    {
+        final String textIndex = String.valueOf( noteIndex + 1 );
+        final String forwardLinkName = "endnote_" + textIndex;
+        final String backwardLinkName = "endnote_back_" + textIndex;
+
+        Element forwardLink = foDocumentFacade
+                .createBasicLinkInternal( forwardLinkName );
+        forwardLink.appendChild( createNoteInline( textIndex ) );
+        forwardLink.setAttribute( "id", backwardLinkName );
+        block.appendChild( forwardLink );
+
+        Element endnote = foDocumentFacade.createBlock();
+        Element backwardLink = foDocumentFacade
+                .createBasicLinkInternal( backwardLinkName );
+        backwardLink.appendChild( createNoteInline( textIndex + " " ) );
+        backwardLink.setAttribute( "id", forwardLinkName );
+        endnote.appendChild( backwardLink );
+        processCharacters( doc, Integer.MIN_VALUE, endnoteTextRange, endnote );
+        this.endnotes.add( endnote );
+    }
+
+    @Override
+    protected void processFootnoteAutonumbered( HWPFDocument doc,
+            int noteIndex, Element block, Range footnoteTextRange )
+    {
+        final String textIndex = String.valueOf( noteIndex + 1 );
+        final String forwardLinkName = "footnote_" + textIndex;
+        final String backwardLinkName = "footnote_back_" + textIndex;
+
+        Element footNote = foDocumentFacade.createFootnote();
+        block.appendChild( footNote );
+
+        Element inline = foDocumentFacade.createInline();
+        Element forwardLink = foDocumentFacade
+                .createBasicLinkInternal( forwardLinkName );
+        forwardLink.appendChild( createNoteInline( textIndex ) );
+        forwardLink.setAttribute( "id", backwardLinkName );
+        inline.appendChild( forwardLink );
+        footNote.appendChild( inline );
+
+        Element footnoteBody = foDocumentFacade.createFootnoteBody();
+        Element footnoteBlock = foDocumentFacade.createBlock();
+        Element backwardLink = foDocumentFacade
+                .createBasicLinkInternal( backwardLinkName );
+        backwardLink.appendChild( createNoteInline( textIndex + " " ) );
+        backwardLink.setAttribute( "id", forwardLinkName );
+        footnoteBlock.appendChild( backwardLink );
+        footnoteBody.appendChild( footnoteBlock );
+        footNote.appendChild( footnoteBody );
+
+        processCharacters( doc, Integer.MIN_VALUE, footnoteTextRange,
+                footnoteBlock );
+    }
+
     protected void processHyperlink( HWPFDocumentCore wordDocument,
             Element currentBlock, Range textRange, int currentTableLevel,
             String hyperlink )
@@ -421,6 +451,13 @@ public class WordToFoConverter extends AbstractWordConverter
                 "xsl-region-body" );
 
         processParagraphes( wordDocument, flow, section, Integer.MIN_VALUE );
+
+        if ( endnotes != null && !endnotes.isEmpty() )
+        {
+            for ( Element endnote : endnotes )
+                flow.appendChild( endnote );
+            endnotes.clear();
+        }
     }
 
     protected void processTable( HWPFDocumentCore wordDocument, Element flow,