]> source.dussan.org Git - poi.git/commitdiff
add TOC support
authorSergey Vladimirov <sergey@apache.org>
Wed, 26 Oct 2011 13:50:07 +0000 (13:50 +0000)
committerSergey Vladimirov <sergey@apache.org>
Wed, 26 Oct 2011 13:50:07 +0000 (13:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1189217 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java

index af4c0be1f79d968e43fb045d210d85ec2297c145..d8331eb8225732852d1a89f3e579565946245f39 100644 (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,9 +349,11 @@ public abstract class AbstractWordConverter
                             wordDocument, range, c );
                     if ( separatorEnd != null )
                     {
-                        addToStructures( structures, new Structure(
-                                characterRun.getStartOffset(),
-                                separatorEnd[1] + 1 ) );
+                        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