From: Sergey Vladimirov Date: Sat, 9 Jul 2011 14:38:42 +0000 (+0000) Subject: sort PAPX and SEPX after loading X-Git-Tag: REL_3_8_BETA4~235 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=20afb87ed3282a553dd8b0d7c207f3c993bd94ae;p=poi.git sort PAPX and SEPX after loading git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1144679 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java index d616f51140..5d392bbf0c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.List; import org.apache.poi.hwpf.model.io.HWPFFileSystem; @@ -38,19 +37,6 @@ import org.apache.poi.util.LittleEndian; public class CHPBinTable { - private static final class CHPXStartComparator implements Comparator - { - static CHPXStartComparator instance = new CHPXStartComparator(); - - public int compare( CHPX o1, CHPX o2 ) - { - int thisVal = o1.getStart(); - int anotherVal = o2.getStart(); - return ( thisVal < anotherVal ? -1 : ( thisVal == anotherVal ? 0 - : 1 ) ); - } - } - /** List of character properties.*/ protected ArrayList _textRuns = new ArrayList(); @@ -104,7 +90,7 @@ public class CHPBinTable _textRuns.add(chpx); } } - Collections.sort( _textRuns, CHPXStartComparator.instance ); + Collections.sort( _textRuns, PropertyNode.StartComparator.instance ); } public void adjustForDelete(int listIndex, int offset, int length) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java index 129cbcc937..502e9e6def 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java @@ -20,6 +20,7 @@ package org.apache.poi.hwpf.model; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Collections; import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.hwpf.model.io.HWPFOutputStream; @@ -88,6 +89,7 @@ public class PAPBinTable _paragraphs.add(papx); } } + Collections.sort( _paragraphs, PropertyNode.StartComparator.instance ); _dataStream = dataStream; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java index 187e3db188..f0f6f4e921 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java @@ -18,6 +18,7 @@ package org.apache.poi.hwpf.model; import java.util.Arrays; +import java.util.Comparator; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -33,6 +34,20 @@ import org.apache.poi.util.POILogger; */ public abstract class PropertyNode> implements Comparable, Cloneable { + + static final class StartComparator implements Comparator> + { + static StartComparator instance = new StartComparator(); + + public int compare( PropertyNode o1, PropertyNode o2 ) + { + int thisVal = o1.getStart(); + int anotherVal = o2.getStart(); + return ( thisVal < anotherVal ? -1 : ( thisVal == anotherVal ? 0 + : 1 ) ); + } + } + private final static POILogger _logger = POILogFactory.getLogger(PropertyNode.class); protected Object _buf; /** The start, in characters */ diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java index f61efd5b37..5f1f08a7f9 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -19,6 +19,7 @@ package org.apache.poi.hwpf.model; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.poi.hwpf.model.io.HWPFFileSystem; @@ -105,6 +106,8 @@ public class SectionTable s.setEnd( CPtoFC(node.getEnd()) ); } } + + Collections.sort( _sections, PropertyNode.StartComparator.instance ); } public void adjustForInsert(int listIndex, int length) diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java index 0cee3e7e2e..6c86614315 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java @@ -124,6 +124,11 @@ public class TestWordToHtmlConverter extends TestCase assertTrue( result.contains( "" ) ); } + public void testO_kurs_doc() throws Exception + { + getHtmlText( "o_kurs.doc" ); + } + public void testPageref() throws Exception { String result = getHtmlText( "pageref.doc" );