use of org.apache.poi.hwpf.model.SEPX in project poi by apache.
the class Range method delete.
public void delete() {
initAll();
int numSections = _sections.size();
int numRuns = _characters.size();
int numParagraphs = _paragraphs.size();
for (int x = _charStart; x < numRuns; x++) {
CHPX chpx = _characters.get(x);
chpx.adjustForDelete(_start, _end - _start);
}
for (int x = _parStart; x < numParagraphs; x++) {
PAPX papx = _paragraphs.get(x);
// System.err.println("Paragraph " + x + " was " + papx.getStart() +
// " -> " + papx.getEnd());
papx.adjustForDelete(_start, _end - _start);
// System.err.println("Paragraph " + x + " is now " +
// papx.getStart() + " -> " + papx.getEnd());
}
for (int x = _sectionStart; x < numSections; x++) {
SEPX sepx = _sections.get(x);
// System.err.println("Section " + x + " was " + sepx.getStart() +
// " -> " + sepx.getEnd());
sepx.adjustForDelete(_start, _end - _start);
// System.err.println("Section " + x + " is now " + sepx.getStart()
// + " -> " + sepx.getEnd());
}
if (_doc instanceof HWPFDocument) {
((BookmarksImpl) ((HWPFDocument) _doc).getBookmarks()).afterDelete(_start, (_end - _start));
}
_text.delete(_start, _end);
Range parent = _parent.get();
if (parent != null) {
parent.adjustForInsert(-(_end - _start));
}
// update the FIB.CCPText + friends field
adjustFIB(-(_end - _start));
}
use of org.apache.poi.hwpf.model.SEPX in project poi by apache.
the class Range method getSection.
/**
* Gets the section at index. The index is relative to this range.
*
* @param index
* The index of the section to get.
* @return The section at the specified index in this range.
*/
public Section getSection(int index) {
initSections();
SEPX sepx = _sections.get(index + _sectionStart);
return new Section(sepx, this);
}
use of org.apache.poi.hwpf.model.SEPX in project poi by apache.
the class TestRange method testBug46817.
@Test
public void testBug46817() throws IOException {
InputStream is = SAMPLES.openResourceAsStream("Bug46817.doc");
HWPFDocument hwpfDocument = new HWPFDocument(is);
is.close();
final List<SEPX> sections = hwpfDocument.getSectionTable().getSections();
assertEquals(sections.size(), 1);
// whole document, including additional text from shape
SEPX sepx = sections.get(0);
assertEquals(sepx.getStart(), 0);
assertEquals(sepx.getEnd(), 1428);
// only main range
Range range = hwpfDocument.getRange();
assertEquals(range.getStartOffset(), 0);
assertEquals(range.getEndOffset(), 766);
Paragraph lastInMainRange = range.getParagraph(range.numParagraphs() - 1);
assertTrue(lastInMainRange.getEndOffset() <= 766);
Section section = range.getSection(0);
assertTrue(section.getEndOffset() <= 766);
Paragraph lastInMainSection = section.getParagraph(section.numParagraphs() - 1);
assertTrue(lastInMainSection.getEndOffset() <= 766);
hwpfDocument.close();
}
Aggregations