use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestLists method testOrderedLists.
public void testOrderedLists() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
Range r = doc.getRange();
assertEquals(40, r.numParagraphs());
assertEquals("Next up is an ordered list:\r", r.getParagraph(5).text());
assertEquals("Ordered list 1\r", r.getParagraph(6).text());
assertEquals("OL 2\r", r.getParagraph(7).text());
assertEquals("OL 3\r", r.getParagraph(8).text());
assertEquals("Now for an un-ordered list with a different bullet style:\r", r.getParagraph(9).text());
assertEquals(9, r.getParagraph(5).getLvl());
assertEquals(9, r.getParagraph(6).getLvl());
assertEquals(9, r.getParagraph(7).getLvl());
assertEquals(9, r.getParagraph(8).getLvl());
assertEquals(9, r.getParagraph(9).getLvl());
assertEquals(0, r.getParagraph(5).getIlvl());
assertEquals(0, r.getParagraph(6).getIlvl());
assertEquals(0, r.getParagraph(7).getIlvl());
assertEquals(0, r.getParagraph(8).getIlvl());
assertEquals(0, r.getParagraph(9).getIlvl());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestOfficeDrawings method testWatermark.
/**
* Tests watermark text extraction
*/
public void testWatermark() throws Exception {
HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile("watermark.doc");
OfficeDrawing drawing = hwpfDocument.getOfficeDrawingsHeaders().getOfficeDrawings().iterator().next();
EscherContainerRecord escherContainerRecord = drawing.getOfficeArtSpContainer();
EscherOptRecord officeArtFOPT = escherContainerRecord.getChildById((short) 0xF00B);
EscherComplexProperty gtextUNICODE = (EscherComplexProperty) officeArtFOPT.lookup(0x00c0);
String text = StringUtil.getFromUnicodeLE(gtextUNICODE.getComplexData());
assertEquals("DRAFT CONTRACT\0", text);
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBugs method test50936.
/**
* Bug 50936 - Exception parsing MS Word 8.0 file
*/
@Test
public void test50936() throws Exception {
String[] filenames = { "Bug50936_1.doc", "Bug50936_2.doc", "Bug50936_3.doc" };
for (String filename : filenames) {
HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile(filename);
assertNotNull(filename, hwpfDocument.getPicturesTable().getAllPictures());
hwpfDocument.close();
}
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBugs method test47287.
/**
* [RESOLVED FIXED] Bug 47287 - StringIndexOutOfBoundsException in
* CharacterRun.replaceText()
*/
@Test
public void test47287() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug47287.doc");
String[] values = { "1-1", "1-2", "1-3", "1-4", "1-5", "1-6", "1-7", "1-8", "1-9", "1-10", "1-11", "1-12", "1-13", "1-14", "1-15" };
int usedVal = 0;
String PLACEHOLDER = " ";
Range r = doc.getRange();
for (int x = 0; x < r.numSections(); x++) {
Section s = r.getSection(x);
for (int y = 0; y < s.numParagraphs(); y++) {
Paragraph p = s.getParagraph(y);
for (int z = 0; z < p.numCharacterRuns(); z++) {
boolean isFound = false;
// character run
CharacterRun run = p.getCharacterRun(z);
// character run text
String text = run.text();
String oldText = text;
int c = text.indexOf("FORMTEXT ");
if (c < 0) {
int k = text.indexOf(PLACEHOLDER);
if (k >= 0) {
text = text.substring(0, k) + values[usedVal] + text.substring(k + PLACEHOLDER.length());
usedVal++;
isFound = true;
}
} else {
for (; c >= 0; c = text.indexOf("FORMTEXT ", c + "FORMTEXT ".length())) {
int k = text.indexOf(PLACEHOLDER, c);
if (k >= 0) {
text = text.substring(0, k) + values[usedVal] + text.substring(k + PLACEHOLDER.length());
usedVal++;
isFound = true;
}
}
}
if (isFound) {
run.replaceText(oldText, text, 0);
}
}
}
}
String docText = r.text();
assertContains(docText, "1-1");
assertContains(docText, "1-12");
assertNotContained(docText, "1-13");
assertNotContained(docText, "1-15");
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBugs method testRegressionIn315beta2.
@Test
public void testRegressionIn315beta2() {
HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile("cap.stanford.edu_profiles_viewbiosketch_facultyid=4009&name=m_maciver.doc");
assertNotNull(hwpfDocument);
}
Aggregations