fix inner tables handling by Range.getTable() method

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1142877 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-07-05 02:17:54 +00:00
parent 65881d12ea
commit efd149c834
2 changed files with 29 additions and 17 deletions

View File

@ -17,11 +17,12 @@
package org.apache.poi.hwpf.usermodel; package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.LittleEndian; import java.lang.ref.WeakReference;
import java.util.List;
import java.util.NoSuchElementException;
import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFDocumentCore; import org.apache.poi.hwpf.HWPFDocumentCore;
import org.apache.poi.hwpf.model.CHPX; import org.apache.poi.hwpf.model.CHPX;
import org.apache.poi.hwpf.model.CPSplitCalculator; import org.apache.poi.hwpf.model.CPSplitCalculator;
import org.apache.poi.hwpf.model.FileInformationBlock; import org.apache.poi.hwpf.model.FileInformationBlock;
@ -31,14 +32,10 @@ import org.apache.poi.hwpf.model.PropertyNode;
import org.apache.poi.hwpf.model.SEPX; import org.apache.poi.hwpf.model.SEPX;
import org.apache.poi.hwpf.model.StyleSheet; import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.hwpf.model.TextPiece; import org.apache.poi.hwpf.model.TextPiece;
import org.apache.poi.hwpf.sprm.CharacterSprmCompressor; import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor; import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.util.LittleEndian;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.NoSuchElementException;
/** /**
* This class is the central class of the HWPF object model. All properties that * This class is the central class of the HWPF object model. All properties that
@ -882,19 +879,29 @@ public class Range { // TODO -instantiable superclass
} }
r.initAll(); r.initAll();
int tableLevel = paragraph.getTableLevel();
int tableEnd = r._parEnd; int tableEnd = r._parEnd;
if (r._parStart != 0 && getParagraph(r._parStart - 1).isInTable() if ( r._parStart != 0 )
&& getParagraph(r._parStart - 1)._sectionEnd >= r._sectionStart) { {
throw new IllegalArgumentException("This paragraph is not the first one in the table"); Paragraph previous = new Paragraph(
} _paragraphs.get( r._parStart - 1 ), this );
if ( previous.isInTable() && //
previous.getTableLevel() == tableLevel //
&& previous._sectionEnd >= r._sectionStart )
{
throw new IllegalArgumentException(
"This paragraph is not the first one in the table" );
}
}
int limit = _paragraphs.size(); int limit = _paragraphs.size();
for (; tableEnd < limit; tableEnd++) { for ( ; tableEnd < limit; tableEnd++ )
if (!getParagraph(tableEnd).isInTable()) { {
break; Paragraph next = new Paragraph( _paragraphs.get( tableEnd ), this );
} if ( !next.isInTable() || next.getTableLevel() < tableLevel )
} break;
}
initAll(); initAll();
if (tableEnd > _parEnd) { if (tableEnd > _parEnd) {

View File

@ -92,6 +92,11 @@ public class TestWordToHtmlConverter extends TestCase
assertTrue( result.contains( "Hyperlink text" ) ); assertTrue( result.contains( "Hyperlink text" ) );
} }
public void testInnerTable() throws Exception
{
getHtmlText( "innertable.doc" );
}
public void testPageref() throws Exception public void testPageref() throws Exception
{ {
String result = getHtmlText( "pageref.doc" ); String result = getHtmlText( "pageref.doc" );