import java.io.File;
import java.io.FileWriter;
+import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
}
}
- @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 );
private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
+ private List<Element> endnotes = new ArrayList<Element>( 0 );
+
protected final FoDocumentFacade foDocumentFacade;
/**
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 )
{
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 )
"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,