private PicturesManager picturesManager;
+ /**
+ * Special actions that need to be called after processing complete, like
+ * updating stylesheets or building document notes list. Usually they are
+ * called once, but it's okay to call them several times.
+ */
+ protected void afterProcess()
+ {
+ // by default no such actions needed
+ }
+
protected Triplet getCharacterRunTriplet( CharacterRun characterRun )
{
Triplet original = new Triplet();
processDocumentInformation( summaryInformation );
}
- processDocumentPart( wordDocument, wordDocument.getRange() );
+ final Range docRange = wordDocument.getRange();
+
+ if ( docRange.numSections() == 1 )
+ {
+ processSingleSection( wordDocument, docRange.getSection( 0 ) );
+ afterProcess();
+ return;
+ }
+
+ processDocumentPart( wordDocument, docRange );
+ afterProcess();
}
protected abstract void processDocumentInformation(
protected void processDocumentPart( HWPFDocumentCore wordDocument,
final Range range )
{
- if ( range.numSections() == 1 )
- {
- processSingleSection( wordDocument, range.getSection( 0 ) );
- return;
- }
-
for ( int s = 0; s < range.numSections(); s++ )
{
processSection( wordDocument, range.getSection( s ), s );
this.htmlDocumentFacade = new HtmlDocumentFacade( document );
}
+ @Override
+ protected void afterProcess()
+ {
+ if ( notes != null )
+ htmlDocumentFacade.getBody().appendChild( notes );
+
+ htmlDocumentFacade.updateStylesheet();
+ }
+
public Document getDocument()
{
return htmlDocumentFacade.getDocument();
processCharacters( wordDocument, currentTableLevel, range, parent );
}
- @Override
- public void processDocument( HWPFDocumentCore wordDocument )
- {
- super.processDocument( wordDocument );
-
- if ( notes != null )
- htmlDocumentFacade.getBody().appendChild( notes );
-
- htmlDocumentFacade.updateStylesheet();
- }
-
@Override
protected void processDocumentInformation(
SummaryInformation summaryInformation )
.addDescription( summaryInformation.getComments() );
}
+ @Override
+ public void processDocumentPart( HWPFDocumentCore wordDocument, Range range )
+ {
+ super.processDocumentPart( wordDocument, range );
+ afterProcess();
+ }
+
@Override
protected void processDrawnObject( HWPFDocument doc,
CharacterRun characterRun, OfficeDrawing officeDrawing,
this.textDocumentFacade = new TextDocumentFacade( document );
}
+ @Override
+ protected void afterProcess()
+ {
+ if ( notes != null )
+ textDocumentFacade.getBody().appendChild( notes );
+ }
+
public Document getDocument()
{
return textDocumentFacade.getDocument();
processCharacters( wordDocument, currentTableLevel, range, currentBlock );
}
- @Override
- public void processDocument( HWPFDocumentCore wordDocument )
- {
- super.processDocument( wordDocument );
-
- if ( notes != null )
- textDocumentFacade.getBody().appendChild( notes );
- }
-
@Override
protected void processDocumentInformation(
SummaryInformation summaryInformation )
}
}
+ @Override
+ public void processDocumentPart( HWPFDocumentCore wordDocument,
+ Range range )
+ {
+ super.processDocumentPart( wordDocument, range );
+ afterProcess();
+ }
+
@Override
protected void processDrawnObject( HWPFDocument doc,
CharacterRun characterRun, OfficeDrawing officeDrawing,
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.apache.poi.hwpf.converter.WordToTextConverter;
import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.converter.WordToTextConverter;
import org.apache.poi.hwpf.usermodel.HeaderStories;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
* @deprecated Use {@link #WordExtractor(DirectoryNode)} instead
*/
@Deprecated
+ @SuppressWarnings( "unused" )
public WordExtractor( DirectoryNode dir, POIFSFileSystem fs )
throws IOException
{
{
try
{
- final StringWriter stringWriter = new StringWriter();
- @SuppressWarnings( "unused" )
- WordToTextConverter wordToTextConverter = new WordToTextConverter()
- {
- {
- HeaderStories hs = new HeaderStories( doc );
-
- if ( hs.getFirstHeaderSubrange() != null )
- processDocumentPart( doc, hs.getFirstHeaderSubrange() );
- if ( hs.getEvenHeaderSubrange() != null )
- processDocumentPart( doc, hs.getEvenHeaderSubrange() );
- if ( hs.getOddHeaderSubrange() != null )
- processDocumentPart( doc, hs.getOddHeaderSubrange() );
-
- processDocument( doc );
- processDocumentPart( doc, doc.getMainTextboxRange() );
-
- if ( hs.getFirstFooterSubrange() != null )
- processDocumentPart( doc, hs.getFirstFooterSubrange() );
- if ( hs.getEvenFooterSubrange() != null )
- processDocumentPart( doc, hs.getEvenFooterSubrange() );
- if ( hs.getOddFooterSubrange() != null )
- processDocumentPart( doc, hs.getOddFooterSubrange() );
-
- stringWriter.append( getText() );
- }
- };
- return stringWriter.toString();
+ WordToTextConverter wordToTextConverter = new WordToTextConverter();
+
+ HeaderStories hs = new HeaderStories( doc );
+
+ if ( hs.getFirstHeaderSubrange() != null )
+ wordToTextConverter.processDocumentPart( doc,
+ hs.getFirstHeaderSubrange() );
+ if ( hs.getEvenHeaderSubrange() != null )
+ wordToTextConverter.processDocumentPart( doc,
+ hs.getEvenHeaderSubrange() );
+ if ( hs.getOddHeaderSubrange() != null )
+ wordToTextConverter.processDocumentPart( doc,
+ hs.getOddHeaderSubrange() );
+
+ wordToTextConverter.processDocument( doc );
+ wordToTextConverter.processDocumentPart( doc,
+ doc.getMainTextboxRange() );
+
+ if ( hs.getFirstFooterSubrange() != null )
+ wordToTextConverter.processDocumentPart( doc,
+ hs.getFirstFooterSubrange() );
+ if ( hs.getEvenFooterSubrange() != null )
+ wordToTextConverter.processDocumentPart( doc,
+ hs.getEvenFooterSubrange() );
+ if ( hs.getOddFooterSubrange() != null )
+ wordToTextConverter.processDocumentPart( doc,
+ hs.getOddFooterSubrange() );
+
+ return wordToTextConverter.getText();
}
catch ( Exception exc )
{