use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class TestDifferentRoutes method testExtractFromModel.
/**
* Test model based extraction
*/
@Test
public void testExtractFromModel() {
Range r = doc.getRange();
String[] text = new String[r.numParagraphs()];
for (int i = 0; i < r.numParagraphs(); i++) {
Paragraph p = r.getParagraph(i);
text[i] = p.text();
}
assertArrayEquals(p_text, text);
}
use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class TestHWPFRangeParts method testContents.
/**
* Note - this test runs several times, to ensure that things
* don't get broken as we write out and read back in again
* TODO - Make this work with 3+ runs
*/
public void testContents() {
HWPFDocument doc = docAscii;
for (int run = 0; run < 3; run++) {
Range r;
// Now check the real ranges
r = doc.getRange();
assertEquals(a_page_1 + page_break + "\r" + a_page_2, r.text());
r = doc.getHeaderStoryRange();
assertEquals(headerDef + a_header + footerDef + a_footer + endHeaderFooter, r.text());
r = doc.getOverallRange();
assertEquals(a_page_1 + page_break + "\r" + a_page_2 + headerDef + a_header + footerDef + a_footer + endHeaderFooter + "\r", r.text());
// TODO run more than once
if (run < 1)
doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
}
}
use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class AbstractWordUtilsTest method testBuildTableCellEdgesArray.
/**
* Test case for {@link AbstractWordUtils#buildTableCellEdgesArray(Table)}
*/
public void testBuildTableCellEdgesArray() {
HWPFDocument document = HWPFTestDataSamples.openSampleFile("table-merges.doc");
final Range range = document.getRange();
Table table = range.getTable(range.getParagraph(0));
int[] result = AbstractWordUtils.buildTableCellEdgesArray(table);
assertEquals(6, result.length);
assertEquals(0000, result[0]);
assertEquals(1062, result[1]);
assertEquals(5738, result[2]);
assertEquals(6872, result[3]);
assertEquals(8148, result[4]);
assertEquals(9302, result[5]);
}
use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class TestBug46610 method runExtract.
private static String runExtract(String sampleName) throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName);
StringBuffer out = new StringBuffer();
Range globalRange = doc.getRange();
for (int i = 0; i < globalRange.numParagraphs(); i++) {
Paragraph p = globalRange.getParagraph(i);
out.append(p.text());
out.append("\n");
for (int j = 0; j < p.numCharacterRuns(); j++) {
CharacterRun characterRun = p.getCharacterRun(j);
characterRun.text();
}
doc.close();
}
return out.toString();
}
use of org.apache.poi.hwpf.usermodel.Range in project tika by apache.
the class WordExtractor method handleHeaderFooter.
private void handleHeaderFooter(Range[] ranges, String type, HWPFDocument document, PicturesSource pictures, PicturesTable pictureTable, XHTMLContentHandler xhtml) throws SAXException, IOException, TikaException {
if (countParagraphs(ranges) > 0) {
xhtml.startElement("div", "class", type);
ListManager listManager = new ListManager(document);
for (Range r : ranges) {
if (r != null) {
for (int i = 0; i < r.numParagraphs(); i++) {
Paragraph p = r.getParagraph(i);
i += handleParagraph(p, 0, r, document, FieldsDocumentPart.HEADER, pictures, pictureTable, listManager, xhtml);
}
}
}
xhtml.endElement("div");
}
}
Aggregations