Bug 53453: Apply patch to add methods to set margins in sections of HWPF documents
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1649176 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0ea9f5fff9
commit
5a20499263
@ -95,6 +95,66 @@ public final class Section extends Range
|
|||||||
return _props.getXaPage();
|
return _props.getXaPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the height of the bottom margin in twips. In the AbstractWordUtils class, a constant
|
||||||
|
* is defined that indicates how many twips there are per inch and it can be used in setting
|
||||||
|
* the margins width a little like this;
|
||||||
|
*
|
||||||
|
* section.setMarginBottom( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
|
||||||
|
*
|
||||||
|
* @param marginWidth A primitive int whose value will indciate how high the margin should
|
||||||
|
* be - in twips.
|
||||||
|
*/
|
||||||
|
public void setMarginBottom(int marginWidth)
|
||||||
|
{
|
||||||
|
this._props.setDyaBottom(marginWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the width of the left hand margin in twips. In the AbstractWordUtils class, a constant
|
||||||
|
* is defined that indicates how many twips there are per inch and it can be used in setting
|
||||||
|
* the margins width a little like this;
|
||||||
|
*
|
||||||
|
* section.setMarginLeft( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
|
||||||
|
*
|
||||||
|
* @param marginWidth A primitive int whose value will indciate how high the margin should
|
||||||
|
* be - in twips.
|
||||||
|
*/
|
||||||
|
public void setMarginLeft(int marginWidth)
|
||||||
|
{
|
||||||
|
this._props.setDxaLeft(marginWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the width of the right hand margin in twips. In the AbstractWordUtils class, a constant
|
||||||
|
* is defined that indicates how many twips there are per inch and it can be used in setting
|
||||||
|
* the margins width a little like this;
|
||||||
|
*
|
||||||
|
* section.setMarginRight( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
|
||||||
|
*
|
||||||
|
* @param marginWidth A primitive int whose value will indciate how high the margin should
|
||||||
|
* be - in twips.
|
||||||
|
*/
|
||||||
|
public void setMarginRight(int marginWidth)
|
||||||
|
{
|
||||||
|
this._props.setDxaRight(marginWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the height of the top margin in twips. In the AbstractWordUtils class, a constant
|
||||||
|
* is defined that indicates how many twips there are per inch and it can be used in setting
|
||||||
|
* the margins width a little like this;
|
||||||
|
*
|
||||||
|
* section.setMarginTop( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
|
||||||
|
*
|
||||||
|
* @param marginWidth A primitive int whose value will indciate how high the margin should
|
||||||
|
* be - in twips.
|
||||||
|
*/
|
||||||
|
public void setMarginTop(int marginWidth)
|
||||||
|
{
|
||||||
|
this._props.setDyaTop(marginWidth);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isColumnsEvenlySpaced()
|
public boolean isColumnsEvenlySpaced()
|
||||||
{
|
{
|
||||||
return _props.getFEvenlySpaced();
|
return _props.getFEvenlySpaced();
|
||||||
|
@ -31,6 +31,7 @@ import org.apache.poi.POIDataSamples;
|
|||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.HWPFOldDocument;
|
import org.apache.poi.hwpf.HWPFOldDocument;
|
||||||
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
||||||
|
import org.apache.poi.hwpf.converter.AbstractWordUtils;
|
||||||
import org.apache.poi.hwpf.converter.WordToTextConverter;
|
import org.apache.poi.hwpf.converter.WordToTextConverter;
|
||||||
import org.apache.poi.hwpf.extractor.Word6Extractor;
|
import org.apache.poi.hwpf.extractor.Word6Extractor;
|
||||||
import org.apache.poi.hwpf.extractor.WordExtractor;
|
import org.apache.poi.hwpf.extractor.WordExtractor;
|
||||||
@ -55,7 +56,7 @@ public class TestBugs extends TestCase
|
|||||||
private static final POILogger logger = POILogFactory
|
private static final POILogger logger = POILogFactory
|
||||||
.getLogger(TestBugs.class);
|
.getLogger(TestBugs.class);
|
||||||
|
|
||||||
public static void assertEquals( String expected, String actual )
|
public static void assertEqualsIgnoreNewline(String expected, String actual )
|
||||||
{
|
{
|
||||||
String newExpected = expected.replaceAll("\r\n", "\n" )
|
String newExpected = expected.replaceAll("\r\n", "\n" )
|
||||||
.replaceAll("\r", "\n").trim();
|
.replaceAll("\r", "\n").trim();
|
||||||
@ -72,7 +73,7 @@ public class TestBugs extends TestCase
|
|||||||
Paragraph expParagraph = expected.getParagraph(p);
|
Paragraph expParagraph = expected.getParagraph(p);
|
||||||
Paragraph actParagraph = actual.getParagraph(p);
|
Paragraph actParagraph = actual.getParagraph(p);
|
||||||
|
|
||||||
assertEquals( expParagraph.text(), actParagraph.text() );
|
assertEqualsIgnoreNewline(expParagraph.text(), actParagraph.text());
|
||||||
assertEquals("Diffent isInTable flags for paragraphs #" + p
|
assertEquals("Diffent isInTable flags for paragraphs #" + p
|
||||||
+ " -- " + expParagraph + " -- " + actParagraph + ".",
|
+ " -- " + expParagraph + " -- " + actParagraph + ".",
|
||||||
expParagraph.isInTable(), actParagraph.isInTable());
|
expParagraph.isInTable(), actParagraph.isInTable());
|
||||||
@ -99,7 +100,7 @@ public class TestBugs extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fixed( String bugzillaId )
|
private static void fixed(String bugzillaId )
|
||||||
{
|
{
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Bug "
|
"Bug "
|
||||||
@ -108,25 +109,42 @@ public class TestBugs extends TestCase
|
|||||||
+ "Please resolve the issue in Bugzilla and remove fail() from the test");
|
+ "Please resolve the issue in Bugzilla and remove fail() from the test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getText(String samplefile) throws IOException {
|
||||||
|
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(samplefile);
|
||||||
|
WordExtractor extractor = new WordExtractor(doc);
|
||||||
|
try {
|
||||||
|
return extractor.getText();
|
||||||
|
} finally {
|
||||||
|
extractor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTextOldFile(String samplefile) throws IOException {
|
||||||
|
HWPFOldDocument doc = HWPFTestDataSamples.openOldSampleFile(samplefile);
|
||||||
|
Word6Extractor extractor = new Word6Extractor(doc);
|
||||||
|
try {
|
||||||
|
return extractor.getText();
|
||||||
|
} finally {
|
||||||
|
extractor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 33519 - HWPF fails to read a file
|
* Bug 33519 - HWPF fails to read a file
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void test33519()
|
public void test33519() throws IOException
|
||||||
{
|
{
|
||||||
HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug33519.doc" );
|
assertNotNull(getText("Bug33519.doc"));
|
||||||
WordExtractor extractor = new WordExtractor( doc );
|
|
||||||
extractor.getText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 34898 - WordExtractor doesn't read the whole string from the file
|
* Bug 34898 - WordExtractor doesn't read the whole string from the file
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void test34898()
|
public void test34898() throws IOException
|
||||||
{
|
{
|
||||||
HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug34898.doc" );
|
assertEqualsIgnoreNewline("\u30c7\u30a3\u30ec\u30af\u30c8\u30ea", getText("Bug34898.doc").trim());
|
||||||
WordExtractor extractor = new WordExtractor( doc );
|
|
||||||
assertEquals( "\u30c7\u30a3\u30ec\u30af\u30c8\u30ea", extractor
|
|
||||||
.getText().trim() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,32 +181,39 @@ public class TestBugs extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 44331 - HWPFDocument.write destroys fields
|
* Bug 44331 - HWPFDocument.write destroys fields
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void test44431()
|
public void test44431() throws IOException
|
||||||
{
|
{
|
||||||
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug44431.doc");
|
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug44431.doc");
|
||||||
|
|
||||||
WordExtractor extractor1 = new WordExtractor(doc1);
|
WordExtractor extractor1 = new WordExtractor(doc1);
|
||||||
|
try {
|
||||||
HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
|
HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
|
||||||
WordExtractor extractor2 = new WordExtractor( doc2 );
|
|
||||||
|
|
||||||
assertEquals( extractor1.getFooterText(), extractor2.getFooterText() );
|
WordExtractor extractor2 = new WordExtractor(doc2);
|
||||||
assertEquals( extractor1.getHeaderText(), extractor2.getHeaderText() );
|
try {
|
||||||
assertEquals( Arrays.toString( extractor1.getParagraphText() ),
|
assertEqualsIgnoreNewline(extractor1.getFooterText(), extractor2.getFooterText());
|
||||||
|
assertEqualsIgnoreNewline(extractor1.getHeaderText(), extractor2.getHeaderText());
|
||||||
|
assertEqualsIgnoreNewline(Arrays.toString(extractor1.getParagraphText() ),
|
||||||
Arrays.toString(extractor2.getParagraphText()));
|
Arrays.toString(extractor2.getParagraphText()));
|
||||||
|
|
||||||
assertEquals( extractor1.getText(), extractor2.getText() );
|
assertEqualsIgnoreNewline(extractor1.getText(), extractor2.getText());
|
||||||
|
} finally {
|
||||||
|
extractor2.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
extractor1.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 44331 - HWPFDocument.write destroys fields
|
* Bug 44331 - HWPFDocument.write destroys fields
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void test44431_2()
|
public void test44431_2() throws IOException
|
||||||
{
|
{
|
||||||
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile( "Bug44431.doc" );
|
assertEqualsIgnoreNewline("File name=FieldsTest.doc\n" +
|
||||||
WordExtractor extractor1 = new WordExtractor( doc1 );
|
|
||||||
|
|
||||||
assertEquals( "File name=FieldsTest.doc\n" +
|
|
||||||
"\n" +
|
"\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"STYLEREF test\n" +
|
"STYLEREF test\n" +
|
||||||
@ -207,23 +232,36 @@ public class TestBugs extends TestCase
|
|||||||
"\n" +
|
"\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"Page 3 of 3", extractor1.getText() );
|
"Page 3 of 3", getText("Bug44431.doc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 45473 - HWPF cannot read file after save
|
* Bug 45473 - HWPF cannot read file after save
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void test45473()
|
public void test45473() throws IOException
|
||||||
{
|
{
|
||||||
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug45473.doc");
|
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug45473.doc");
|
||||||
String text1 = new WordExtractor( doc1 ).getText().trim();
|
WordExtractor wordExtractor = new WordExtractor(doc1);
|
||||||
|
final String text1;
|
||||||
|
try {
|
||||||
|
text1 = wordExtractor.getText().trim();
|
||||||
|
} finally {
|
||||||
|
wordExtractor.close();
|
||||||
|
}
|
||||||
|
|
||||||
HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
|
HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
|
||||||
String text2 = new WordExtractor( doc2 ).getText().trim();
|
WordExtractor wordExtractor2 = new WordExtractor(doc2);
|
||||||
|
final String text2;
|
||||||
|
try {
|
||||||
|
text2 = wordExtractor2.getText().trim();
|
||||||
|
} finally {
|
||||||
|
wordExtractor2.close();
|
||||||
|
}
|
||||||
|
|
||||||
// the text in the saved document has some differences in line
|
// the text in the saved document has some differences in line
|
||||||
// separators but we tolerate that
|
// separators but we tolerate that
|
||||||
assertEquals( text1.replaceAll( "\n", "" ), text2.replaceAll( "\n", "" ) );
|
assertEqualsIgnoreNewline(text1.replaceAll("\n", "" ), text2.replaceAll("\n", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,19 +282,18 @@ public class TestBugs extends TestCase
|
|||||||
Picture pic = pics.get(i);
|
Picture pic = pics.get(i);
|
||||||
byte[] data = pic.getRawContent();
|
byte[] data = pic.getRawContent();
|
||||||
// use Apache Commons Codec utils to compute md5
|
// use Apache Commons Codec utils to compute md5
|
||||||
assertEquals( md5[i], DigestUtils.md5Hex( data ) );
|
assertEqualsIgnoreNewline(md5[i], DigestUtils.md5Hex(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [RESOLVED FIXED] Bug 46817 - Regression: Text from some table cells
|
* [RESOLVED FIXED] Bug 46817 - Regression: Text from some table cells
|
||||||
* missing
|
* missing
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void test46817()
|
public void test46817() throws IOException
|
||||||
{
|
{
|
||||||
HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug46817.doc" );
|
String text = getText("Bug46817.doc").trim();
|
||||||
WordExtractor extractor = new WordExtractor( doc );
|
|
||||||
String text = extractor.getText().trim();
|
|
||||||
|
|
||||||
assertTrue(text.contains("Nazwa wykonawcy"));
|
assertTrue(text.contains("Nazwa wykonawcy"));
|
||||||
assertTrue(text.contains("kujawsko-pomorskie"));
|
assertTrue(text.contains("kujawsko-pomorskie"));
|
||||||
@ -272,14 +309,26 @@ public class TestBugs extends TestCase
|
|||||||
public void test47286() throws IOException
|
public void test47286() throws IOException
|
||||||
{
|
{
|
||||||
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug47286.doc");
|
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug47286.doc");
|
||||||
String text1 = new WordExtractor( doc1 ).getText().trim();
|
WordExtractor wordExtractor = new WordExtractor(doc1);
|
||||||
|
final String text1;
|
||||||
|
try {
|
||||||
|
text1 = wordExtractor.getText().trim();
|
||||||
|
} finally {
|
||||||
|
wordExtractor.close();
|
||||||
|
}
|
||||||
|
|
||||||
HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
|
HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
|
||||||
String text2 = new WordExtractor( doc2 ).getText().trim();
|
WordExtractor wordExtractor2 = new WordExtractor(doc2);
|
||||||
|
final String text2;
|
||||||
|
try {
|
||||||
|
text2 = wordExtractor2.getText().trim();
|
||||||
|
} finally {
|
||||||
|
wordExtractor2.close();
|
||||||
|
}
|
||||||
|
|
||||||
// the text in the saved document has some differences in line
|
// the text in the saved document has some differences in line
|
||||||
// separators but we tolerate that
|
// separators but we tolerate that
|
||||||
assertEquals( text1.replaceAll( "\n", "" ), text2.replaceAll( "\n", "" ) );
|
assertEqualsIgnoreNewline(text1.replaceAll("\n", "" ), text2.replaceAll("\n", ""));
|
||||||
|
|
||||||
assertEquals(doc1.getCharacterTable().getTextRuns().size(), doc2
|
assertEquals(doc1.getCharacterTable().getTextRuns().size(), doc2
|
||||||
.getCharacterTable().getTextRuns().size());
|
.getCharacterTable().getTextRuns().size());
|
||||||
@ -374,8 +423,7 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void test47731() throws Exception
|
public void test47731() throws Exception
|
||||||
{
|
{
|
||||||
HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug47731.doc" );
|
String foundText = getText("Bug47731.doc");
|
||||||
String foundText = new WordExtractor( doc ).getText();
|
|
||||||
|
|
||||||
assertTrue(foundText
|
assertTrue(foundText
|
||||||
.contains("Soak the rice in water for three to four hours"));
|
.contains("Soak the rice in water for three to four hours"));
|
||||||
@ -386,10 +434,8 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void test47742() throws Exception
|
public void test47742() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
// (1) extract text from MS Word document via POI
|
// (1) extract text from MS Word document via POI
|
||||||
HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug47742.doc" );
|
String foundText = getText("Bug47742.doc");
|
||||||
String foundText = new WordExtractor( doc ).getText();
|
|
||||||
|
|
||||||
// (2) read text from text document (retrieved by saving the word
|
// (2) read text from text document (retrieved by saving the word
|
||||||
// document as text file using encoding UTF-8)
|
// document as text file using encoding UTF-8)
|
||||||
@ -400,7 +446,7 @@ public class TestBugs extends TestCase
|
|||||||
String expectedText = new String(expectedBytes, "utf-8" )
|
String expectedText = new String(expectedBytes, "utf-8" )
|
||||||
.substring(1); // strip-off the unicode marker
|
.substring(1); // strip-off the unicode marker
|
||||||
|
|
||||||
assertEquals( expectedText, foundText );
|
assertEqualsIgnoreNewline(expectedText, foundText);
|
||||||
} finally {
|
} finally {
|
||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
@ -427,20 +473,16 @@ public class TestBugs extends TestCase
|
|||||||
Range expected = doc1.getRange();
|
Range expected = doc1.getRange();
|
||||||
Range actual = doc2.getRange();
|
Range actual = doc2.getRange();
|
||||||
|
|
||||||
assertEquals(
|
assertEqualsIgnoreNewline(
|
||||||
expected.text().replace("\r", "\n").replaceAll("\n\n", "\n" ),
|
expected.text().replace("\r", "\n").replaceAll("\n\n", "\n" ),
|
||||||
actual.text().replace("\r", "\n").replaceAll("\n\n", "\n"));
|
actual.text().replace("\r", "\n").replaceAll("\n\n", "\n"));
|
||||||
|
|
||||||
assertTableStructures(expected, actual);
|
assertTableStructures(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test49933()
|
public void test49933() throws IOException
|
||||||
{
|
{
|
||||||
HWPFOldDocument document = HWPFTestDataSamples
|
String text = getTextOldFile("Bug49933.doc");
|
||||||
.openOldSampleFile( "Bug49933.doc" );
|
|
||||||
|
|
||||||
Word6Extractor word6Extractor = new Word6Extractor( document );
|
|
||||||
String text = word6Extractor.getText();
|
|
||||||
|
|
||||||
assertTrue( text.contains( "best.wine.jump.ru" ) );
|
assertTrue( text.contains( "best.wine.jump.ru" ) );
|
||||||
}
|
}
|
||||||
@ -477,21 +519,16 @@ public class TestBugs extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* [FAILING] Bug 50955 - error while retrieving the text file
|
* [FAILING] Bug 50955 - error while retrieving the text file
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void test50955()
|
public void test50955() throws IOException
|
||||||
{
|
{
|
||||||
try
|
try {
|
||||||
{
|
getTextOldFile("Bug50955.doc");
|
||||||
HWPFOldDocument doc = HWPFTestDataSamples
|
|
||||||
.openOldSampleFile( "Bug50955.doc" );
|
|
||||||
Word6Extractor extractor = new Word6Extractor( doc );
|
|
||||||
extractor.getText();
|
|
||||||
|
|
||||||
fixed("50955");
|
fixed("50955");
|
||||||
}
|
} catch (IllegalStateException e) {
|
||||||
catch ( Exception e )
|
// expected here
|
||||||
{
|
|
||||||
// expected exception
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +558,7 @@ public class TestBugs extends TestCase
|
|||||||
|
|
||||||
document = HWPFTestDataSamples.writeOutAndReadBack(document);
|
document = HWPFTestDataSamples.writeOutAndReadBack(document);
|
||||||
String text = document.getDocumentText();
|
String text = document.getDocumentText();
|
||||||
assertEquals( "+1+2+3+4+5+6+7+8+9+10+11+12", text );
|
assertEqualsIgnoreNewline("+1+2+3+4+5+6+7+8+9+10+11+12", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -583,7 +620,7 @@ public class TestBugs extends TestCase
|
|||||||
doc.getDocProperties().writeTo(outputStream);
|
doc.getDocProperties().writeTo(outputStream);
|
||||||
final byte[] oldData = outputStream.toByteArray();
|
final byte[] oldData = outputStream.toByteArray();
|
||||||
|
|
||||||
assertEquals( Arrays.toString( originalData ),
|
assertEqualsIgnoreNewline(Arrays.toString(originalData ),
|
||||||
Arrays.toString(oldData));
|
Arrays.toString(oldData));
|
||||||
|
|
||||||
Range range = doc.getRange();
|
Range range = doc.getRange();
|
||||||
@ -607,7 +644,7 @@ public class TestBugs extends TestCase
|
|||||||
doc.getDocProperties().writeTo(outputStream);
|
doc.getDocProperties().writeTo(outputStream);
|
||||||
final byte[] newData = outputStream.toByteArray();
|
final byte[] newData = outputStream.toByteArray();
|
||||||
|
|
||||||
assertEquals( Arrays.toString( oldData ), Arrays.toString( newData ) );
|
assertEqualsIgnoreNewline(Arrays.toString(oldData ), Arrays.toString(newData));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -619,16 +656,21 @@ public class TestBugs extends TestCase
|
|||||||
InputStream is = POIDataSamples.getDocumentInstance()
|
InputStream is = POIDataSamples.getDocumentInstance()
|
||||||
.openResourceAsStream("empty.doc");
|
.openResourceAsStream("empty.doc");
|
||||||
NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(is);
|
NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(is);
|
||||||
|
try {
|
||||||
HWPFDocument hwpfDocument = new HWPFDocument(
|
HWPFDocument hwpfDocument = new HWPFDocument(
|
||||||
npoifsFileSystem.getRoot());
|
npoifsFileSystem.getRoot());
|
||||||
hwpfDocument.write(new ByteArrayOutputStream());
|
hwpfDocument.write(new ByteArrayOutputStream());
|
||||||
|
} finally {
|
||||||
|
npoifsFileSystem.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 51678 - Extracting text from Bug51524.zip is slow Bug 51524 -
|
* Bug 51678 - Extracting text from Bug51524.zip is slow Bug 51524 -
|
||||||
* PapBinTable constructor is slow
|
* PapBinTable constructor is slow
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void test51678And51524()
|
public void test51678And51524() throws IOException
|
||||||
{
|
{
|
||||||
// YK: the test will run only if the poi.test.remote system property is
|
// YK: the test will run only if the poi.test.remote system property is
|
||||||
// set.
|
// set.
|
||||||
@ -640,7 +682,11 @@ public class TestBugs extends TestCase
|
|||||||
.openRemoteFile(href);
|
.openRemoteFile(href);
|
||||||
|
|
||||||
WordExtractor wordExtractor = new WordExtractor(hwpfDocument);
|
WordExtractor wordExtractor = new WordExtractor(hwpfDocument);
|
||||||
|
try {
|
||||||
wordExtractor.getText();
|
wordExtractor.getText();
|
||||||
|
} finally {
|
||||||
|
wordExtractor.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,7 +727,7 @@ public class TestBugs extends TestCase
|
|||||||
public void testBug51944() throws Exception
|
public void testBug51944() throws Exception
|
||||||
{
|
{
|
||||||
HWPFOldDocument doc = HWPFTestDataSamples.openOldSampleFile("Bug51944.doc");
|
HWPFOldDocument doc = HWPFTestDataSamples.openOldSampleFile("Bug51944.doc");
|
||||||
WordToTextConverter.getText( doc );
|
assertNotNull(WordToTextConverter.getText(doc));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -690,7 +736,7 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testBug52032_1() throws Exception
|
public void testBug52032_1() throws Exception
|
||||||
{
|
{
|
||||||
HWPFTestDataSamples.openSampleFile( "Bug52032_1.doc" );
|
assertNotNull(getText("Bug52032_1.doc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -699,7 +745,7 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testBug52032_2() throws Exception
|
public void testBug52032_2() throws Exception
|
||||||
{
|
{
|
||||||
HWPFTestDataSamples.openSampleFile( "Bug52032_2.doc" );
|
assertNotNull(getText("Bug52032_2.doc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -708,7 +754,7 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testBug52032_3() throws Exception
|
public void testBug52032_3() throws Exception
|
||||||
{
|
{
|
||||||
HWPFTestDataSamples.openSampleFile( "Bug52032_3.doc" );
|
assertNotNull(getText("Bug52032_3.doc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -716,7 +762,7 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testBug53380_1() throws Exception
|
public void testBug53380_1() throws Exception
|
||||||
{
|
{
|
||||||
HWPFTestDataSamples.openSampleFile( "Bug53380_1.doc" );
|
assertNotNull(getText("Bug53380_1.doc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -724,7 +770,7 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testBug53380_2() throws Exception
|
public void testBug53380_2() throws Exception
|
||||||
{
|
{
|
||||||
HWPFTestDataSamples.openSampleFile( "Bug53380_2.doc" );
|
assertNotNull(getText("Bug53380_2.doc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -732,7 +778,7 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testBug53380_3() throws Exception
|
public void testBug53380_3() throws Exception
|
||||||
{
|
{
|
||||||
HWPFTestDataSamples.openSampleFile( "Bug53380_3.doc" );
|
assertNotNull(getText("Bug53380_3.doc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -740,7 +786,7 @@ public class TestBugs extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testBug53380_4() throws Exception
|
public void testBug53380_4() throws Exception
|
||||||
{
|
{
|
||||||
HWPFTestDataSamples.openSampleFile( "Bug53380_4.doc" );
|
assertNotNull(getText("Bug53380_4.doc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -752,6 +798,91 @@ public class TestBugs extends TestCase
|
|||||||
public void DISABLEDtest56880() throws Exception {
|
public void DISABLEDtest56880() throws Exception {
|
||||||
HWPFDocument doc =
|
HWPFDocument doc =
|
||||||
HWPFTestDataSamples.openSampleFile("56880.doc");
|
HWPFTestDataSamples.openSampleFile("56880.doc");
|
||||||
assertEquals("Check Request", doc.getRange().text());
|
assertEqualsIgnoreNewline("Check Request", doc.getRange().text());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// These are the values the are explected to be read when the file
|
||||||
|
// is checked.
|
||||||
|
private int section1LeftMargin = 1440;
|
||||||
|
private int section1RightMargin = 1440;
|
||||||
|
private int section1TopMargin = 1440;
|
||||||
|
private int section1BottomMargin = 1440;
|
||||||
|
private int section1NumColumns = 1;
|
||||||
|
private int section2LeftMargin = 1440;
|
||||||
|
private int section2RightMargin = 1440;
|
||||||
|
private int section2TopMargin = 1440;
|
||||||
|
private int section2BottomMargin = 1440;
|
||||||
|
private int section2NumColumns = 3;
|
||||||
|
|
||||||
|
public void testHWPFSections() {
|
||||||
|
HWPFDocument document = null;
|
||||||
|
Paragraph para = null;
|
||||||
|
Section section = null;
|
||||||
|
Range overallRange = null;
|
||||||
|
int numParas = 0;
|
||||||
|
int numSections = 0;
|
||||||
|
document = HWPFTestDataSamples.openSampleFile("Bug53453Section.doc");
|
||||||
|
overallRange = document.getOverallRange();
|
||||||
|
numParas = overallRange.numParagraphs();
|
||||||
|
for(int i = 0; i < numParas; i++) {
|
||||||
|
para = overallRange.getParagraph(i);
|
||||||
|
numSections = para.numSections();
|
||||||
|
for(int j = 0; j < numSections; j++) {
|
||||||
|
section = para.getSection(j);
|
||||||
|
if(para.text().trim().equals("Section1")) {
|
||||||
|
assertEquals(section1BottomMargin, section.getMarginBottom());
|
||||||
|
assertEquals(section1LeftMargin, section.getMarginLeft());
|
||||||
|
assertEquals(section1RightMargin, section.getMarginRight());
|
||||||
|
assertEquals(section1TopMargin, section.getMarginTop());
|
||||||
|
assertEquals(section1NumColumns, section.getNumColumns());
|
||||||
|
}
|
||||||
|
else if(para.text().trim().equals("Section2")) {
|
||||||
|
assertEquals(section2BottomMargin, section.getMarginBottom());
|
||||||
|
assertEquals(section2LeftMargin, section.getMarginLeft());
|
||||||
|
assertEquals(section2RightMargin, section.getMarginRight());
|
||||||
|
assertEquals(section2TopMargin, section.getMarginTop());
|
||||||
|
assertEquals(section2NumColumns, section.getNumColumns());
|
||||||
|
|
||||||
|
// Change the margin widths
|
||||||
|
this.section2BottomMargin = (int)(1.5 * AbstractWordUtils.TWIPS_PER_INCH);
|
||||||
|
this.section2TopMargin = (int)(1.75 * AbstractWordUtils.TWIPS_PER_INCH);
|
||||||
|
this.section2LeftMargin = (int)(0.5 * AbstractWordUtils.TWIPS_PER_INCH);
|
||||||
|
this.section2RightMargin = (int)(0.75 * AbstractWordUtils.TWIPS_PER_INCH);
|
||||||
|
section.setMarginBottom(this.section2BottomMargin);
|
||||||
|
section.setMarginLeft(this.section2LeftMargin);
|
||||||
|
section.setMarginRight(this.section2RightMargin);
|
||||||
|
section.setMarginTop(this.section2TopMargin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save away and re-read the document to prove the chages are permanent
|
||||||
|
document = HWPFTestDataSamples.writeOutAndReadBack(document);
|
||||||
|
overallRange = document.getOverallRange();
|
||||||
|
numParas = overallRange.numParagraphs();
|
||||||
|
for(int i = 0; i < numParas; i++) {
|
||||||
|
para = overallRange.getParagraph(i);
|
||||||
|
numSections = para.numSections();
|
||||||
|
for(int j = 0; j < numSections; j++) {
|
||||||
|
section = para.getSection(j);
|
||||||
|
if(para.text().trim().equals("Section1")) {
|
||||||
|
// No changes to the margins in Section1
|
||||||
|
assertEquals(section1BottomMargin, section.getMarginBottom());
|
||||||
|
assertEquals(section1LeftMargin, section.getMarginLeft());
|
||||||
|
assertEquals(section1RightMargin, section.getMarginRight());
|
||||||
|
assertEquals(section1TopMargin, section.getMarginTop());
|
||||||
|
assertEquals(section1NumColumns, section.getNumColumns());
|
||||||
|
}
|
||||||
|
else if(para.text().trim().equals("Section2")) {
|
||||||
|
// The margins in Section2 have kept the new settings.
|
||||||
|
assertEquals(section2BottomMargin, section.getMarginBottom());
|
||||||
|
assertEquals(section2LeftMargin, section.getMarginLeft());
|
||||||
|
assertEquals(section2RightMargin, section.getMarginRight());
|
||||||
|
assertEquals(section2TopMargin, section.getMarginTop());
|
||||||
|
assertEquals(section2NumColumns, section.getNumColumns());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test-data/document/Bug53453Section.doc
Normal file
BIN
test-data/document/Bug53453Section.doc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user