add TOC support

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1189217 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-10-26 13:50:07 +00:00
parent ef237c3eb6
commit 9e530bcf96

View File

@ -58,6 +58,21 @@ import org.w3c.dom.Element;
@Beta
public abstract class AbstractWordConverter
{
private static class DeadFieldBoundaries
{
final int beginMark;
final int endMark;
final int separatorMark;
public DeadFieldBoundaries( int beginMark, int separatorMark,
int endMark )
{
this.beginMark = beginMark;
this.separatorMark = separatorMark;
this.endMark = endMark;
}
}
private static final class Structure implements Comparable<Structure>
{
final int end;
@ -71,6 +86,13 @@ public abstract class AbstractWordConverter
this.structure = bookmark;
}
Structure( DeadFieldBoundaries deadFieldBoundaries, int start, int end )
{
this.start = start;
this.end = end;
this.structure = deadFieldBoundaries;
}
Structure( Field field )
{
this.start = field.getFieldStartOffset();
@ -78,13 +100,6 @@ public abstract class AbstractWordConverter
this.structure = field;
}
Structure( int start, int end )
{
this.start = start;
this.end = end;
this.structure = null;
}
public int compareTo( Structure o )
{
return start < o.start ? -1 : start == o.start ? 0 : 1;
@ -334,7 +349,9 @@ public abstract class AbstractWordConverter
wordDocument, range, c );
if ( separatorEnd != null )
{
addToStructures( structures, new Structure(
addToStructures( structures,
new Structure( new DeadFieldBoundaries( c,
separatorEnd[0], separatorEnd[1] ),
characterRun.getStartOffset(),
separatorEnd[1] + 1 ) );
c = separatorEnd[1];
@ -407,6 +424,13 @@ public abstract class AbstractWordConverter
processField( (HWPFDocument) wordDocument, range,
currentTableLevel, field, block );
}
else if ( structure.structure instanceof DeadFieldBoundaries )
{
DeadFieldBoundaries boundaries = (DeadFieldBoundaries) structure.structure;
processDeadField( wordDocument, block, range,
currentTableLevel, boundaries.beginMark,
boundaries.separatorMark, boundaries.endMark );
}
else
{
throw new UnsupportedOperationException( "NYI: "
@ -660,25 +684,6 @@ public abstract class AbstractWordConverter
return;
}
protected Field processDeadField( HWPFDocumentCore wordDocument,
Range charactersRange, int currentTableLevel, int startOffset,
Element currentBlock )
{
if ( !( wordDocument instanceof HWPFDocument ) )
return null;
HWPFDocument hwpfDocument = (HWPFDocument) wordDocument;
Field field = hwpfDocument.getFields().getFieldByStartOffset(
FieldsDocumentPart.MAIN, startOffset );
if ( field == null )
return null;
processField( hwpfDocument, charactersRange, currentTableLevel, field,
currentBlock );
return field;
}
public void processDocument( HWPFDocumentCore wordDocument )
{
try