hwpf.usermodel.Range: use generics & remove redundant type casts
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@961347 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
de525d07cd
commit
7aba97ba6e
@ -22,11 +22,6 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
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.usermodel.CharacterRun;
|
|
||||||
import org.apache.poi.hwpf.usermodel.Paragraph;
|
|
||||||
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
|
|
||||||
import org.apache.poi.hwpf.usermodel.Section;
|
|
||||||
|
|
||||||
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;
|
||||||
import org.apache.poi.hwpf.model.PropertyNode;
|
import org.apache.poi.hwpf.model.PropertyNode;
|
||||||
@ -84,7 +79,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
boolean _sectionRangeFound;
|
boolean _sectionRangeFound;
|
||||||
|
|
||||||
/** All sections that belong to the document this Range belongs to. */
|
/** All sections that belong to the document this Range belongs to. */
|
||||||
protected List _sections;
|
protected List<SEPX> _sections;
|
||||||
|
|
||||||
/** The start index in the sections list for this Range */
|
/** The start index in the sections list for this Range */
|
||||||
protected int _sectionStart;
|
protected int _sectionStart;
|
||||||
@ -96,7 +91,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
protected boolean _parRangeFound;
|
protected boolean _parRangeFound;
|
||||||
|
|
||||||
/** All paragraphs that belong to the document this Range belongs to. */
|
/** All paragraphs that belong to the document this Range belongs to. */
|
||||||
protected List _paragraphs;
|
protected List<PAPX> _paragraphs;
|
||||||
|
|
||||||
/** The start index in the paragraphs list for this Range */
|
/** The start index in the paragraphs list for this Range */
|
||||||
protected int _parStart;
|
protected int _parStart;
|
||||||
@ -108,7 +103,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
protected boolean _charRangeFound;
|
protected boolean _charRangeFound;
|
||||||
|
|
||||||
/** All CharacterRuns that belong to the document this Range belongs to. */
|
/** All CharacterRuns that belong to the document this Range belongs to. */
|
||||||
protected List _characters;
|
protected List<CHPX> _characters;
|
||||||
|
|
||||||
/** The start index in the characterRuns list for this Range */
|
/** The start index in the characterRuns list for this Range */
|
||||||
protected int _charStart;
|
protected int _charStart;
|
||||||
@ -120,7 +115,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
protected boolean _textRangeFound;
|
protected boolean _textRangeFound;
|
||||||
|
|
||||||
/** All text pieces that belong to the document this Range belongs to. */
|
/** All text pieces that belong to the document this Range belongs to. */
|
||||||
protected List _text;
|
protected List<TextPiece> _text;
|
||||||
|
|
||||||
/** The start index in the text list for this Range. */
|
/** The start index in the text list for this Range. */
|
||||||
protected int _textStart;
|
protected int _textStart;
|
||||||
@ -206,29 +201,29 @@ public class Range { // TODO -instantiable superclass
|
|||||||
case TYPE_PARAGRAPH:
|
case TYPE_PARAGRAPH:
|
||||||
_parStart = parent._parStart + startIdx;
|
_parStart = parent._parStart + startIdx;
|
||||||
_parEnd = parent._parStart + endIdx;
|
_parEnd = parent._parStart + endIdx;
|
||||||
_start = ((PropertyNode) _paragraphs.get(_parStart)).getStart();
|
_start = _paragraphs.get(_parStart).getStart();
|
||||||
_end = ((PropertyNode) _paragraphs.get(_parEnd)).getEnd();
|
_end = _paragraphs.get(_parEnd).getEnd();
|
||||||
_parRangeFound = true;
|
_parRangeFound = true;
|
||||||
break;
|
break;
|
||||||
case TYPE_CHARACTER:
|
case TYPE_CHARACTER:
|
||||||
_charStart = parent._charStart + startIdx;
|
_charStart = parent._charStart + startIdx;
|
||||||
_charEnd = parent._charStart + endIdx;
|
_charEnd = parent._charStart + endIdx;
|
||||||
_start = ((PropertyNode) _characters.get(_charStart)).getStart();
|
_start = _characters.get(_charStart).getStart();
|
||||||
_end = ((PropertyNode) _characters.get(_charEnd)).getEnd();
|
_end = _characters.get(_charEnd).getEnd();
|
||||||
_charRangeFound = true;
|
_charRangeFound = true;
|
||||||
break;
|
break;
|
||||||
case TYPE_SECTION:
|
case TYPE_SECTION:
|
||||||
_sectionStart = parent._sectionStart + startIdx;
|
_sectionStart = parent._sectionStart + startIdx;
|
||||||
_sectionEnd = parent._sectionStart + endIdx;
|
_sectionEnd = parent._sectionStart + endIdx;
|
||||||
_start = ((PropertyNode) _sections.get(_sectionStart)).getStart();
|
_start = _sections.get(_sectionStart).getStart();
|
||||||
_end = ((PropertyNode) _sections.get(_sectionEnd)).getEnd();
|
_end = _sections.get(_sectionEnd).getEnd();
|
||||||
_sectionRangeFound = true;
|
_sectionRangeFound = true;
|
||||||
break;
|
break;
|
||||||
case TYPE_TEXT:
|
case TYPE_TEXT:
|
||||||
_textStart = parent._textStart + startIdx;
|
_textStart = parent._textStart + startIdx;
|
||||||
_textEnd = parent._textStart + endIdx;
|
_textEnd = parent._textStart + endIdx;
|
||||||
_start = ((PropertyNode) _text.get(_textStart)).getStart();
|
_start = _text.get(_textStart).getStart();
|
||||||
_end = ((PropertyNode) _text.get(_textEnd)).getEnd();
|
_end = _text.get(_textEnd).getEnd();
|
||||||
_textRangeFound = true;
|
_textRangeFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -260,7 +255,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
initText();
|
initText();
|
||||||
|
|
||||||
for (int i = _textStart; i < _textEnd; i++) {
|
for (int i = _textStart; i < _textEnd; i++) {
|
||||||
TextPiece piece = (TextPiece) _text.get(i);
|
TextPiece piece = _text.get(i);
|
||||||
if (piece.isUnicode())
|
if (piece.isUnicode())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -279,7 +274,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
for (int x = _textStart; x < _textEnd; x++) {
|
for (int x = _textStart; x < _textEnd; x++) {
|
||||||
TextPiece piece = (TextPiece) _text.get(x);
|
TextPiece piece = _text.get(x);
|
||||||
|
|
||||||
// Figure out where in this piece the text
|
// Figure out where in this piece the text
|
||||||
// we're after lives
|
// we're after lives
|
||||||
@ -396,7 +391,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
{
|
{
|
||||||
initAll();
|
initAll();
|
||||||
|
|
||||||
TextPiece tp = (TextPiece) _text.get(_textStart);
|
TextPiece tp = _text.get(_textStart);
|
||||||
StringBuffer sb = tp.getStringBuffer();
|
StringBuffer sb = tp.getStringBuffer();
|
||||||
|
|
||||||
// Since this is the first item in our list, it is safe to assume that
|
// Since this is the first item in our list, it is safe to assume that
|
||||||
@ -427,7 +422,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
initAll();
|
initAll();
|
||||||
|
|
||||||
int listIndex = _textEnd - 1;
|
int listIndex = _textEnd - 1;
|
||||||
TextPiece tp = (TextPiece) _text.get(listIndex);
|
TextPiece tp = _text.get(listIndex);
|
||||||
StringBuffer sb = tp.getStringBuffer();
|
StringBuffer sb = tp.getStringBuffer();
|
||||||
|
|
||||||
int insertIndex = _end - tp.getStart();
|
int insertIndex = _end - tp.getStart();
|
||||||
@ -461,7 +456,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
// throws UnsupportedEncodingException
|
// throws UnsupportedEncodingException
|
||||||
{
|
{
|
||||||
initAll();
|
initAll();
|
||||||
PAPX papx = (PAPX) _paragraphs.get(_parStart);
|
PAPX papx = _paragraphs.get(_parStart);
|
||||||
short istd = papx.getIstd();
|
short istd = papx.getIstd();
|
||||||
|
|
||||||
StyleSheet ss = _doc.getStyleSheet();
|
StyleSheet ss = _doc.getStyleSheet();
|
||||||
@ -488,7 +483,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
// throws UnsupportedEncodingException
|
// throws UnsupportedEncodingException
|
||||||
{
|
{
|
||||||
initAll();
|
initAll();
|
||||||
PAPX papx = (PAPX) _paragraphs.get(_parEnd - 1);
|
PAPX papx = _paragraphs.get(_parEnd - 1);
|
||||||
short istd = papx.getIstd();
|
short istd = papx.getIstd();
|
||||||
|
|
||||||
StyleSheet ss = _doc.getStyleSheet();
|
StyleSheet ss = _doc.getStyleSheet();
|
||||||
@ -610,12 +605,12 @@ public class Range { // TODO -instantiable superclass
|
|||||||
int numTextPieces = _text.size();
|
int numTextPieces = _text.size();
|
||||||
|
|
||||||
for (int x = _charStart; x < numRuns; x++) {
|
for (int x = _charStart; x < numRuns; x++) {
|
||||||
CHPX chpx = (CHPX) _characters.get(x);
|
CHPX chpx = _characters.get(x);
|
||||||
chpx.adjustForDelete(_start, _end - _start);
|
chpx.adjustForDelete(_start, _end - _start);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = _parStart; x < numParagraphs; x++) {
|
for (int x = _parStart; x < numParagraphs; x++) {
|
||||||
PAPX papx = (PAPX) _paragraphs.get(x);
|
PAPX papx = _paragraphs.get(x);
|
||||||
// System.err.println("Paragraph " + x + " was " + papx.getStart() +
|
// System.err.println("Paragraph " + x + " was " + papx.getStart() +
|
||||||
// " -> " + papx.getEnd());
|
// " -> " + papx.getEnd());
|
||||||
papx.adjustForDelete(_start, _end - _start);
|
papx.adjustForDelete(_start, _end - _start);
|
||||||
@ -624,7 +619,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int x = _sectionStart; x < numSections; x++) {
|
for (int x = _sectionStart; x < numSections; x++) {
|
||||||
SEPX sepx = (SEPX) _sections.get(x);
|
SEPX sepx = _sections.get(x);
|
||||||
// System.err.println("Section " + x + " was " + sepx.getStart() +
|
// System.err.println("Section " + x + " was " + sepx.getStart() +
|
||||||
// " -> " + sepx.getEnd());
|
// " -> " + sepx.getEnd());
|
||||||
sepx.adjustForDelete(_start, _end - _start);
|
sepx.adjustForDelete(_start, _end - _start);
|
||||||
@ -633,7 +628,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int x = _textStart; x < numTextPieces; x++) {
|
for (int x = _textStart; x < numTextPieces; x++) {
|
||||||
TextPiece piece = (TextPiece) _text.get(x);
|
TextPiece piece = _text.get(x);
|
||||||
piece.adjustForDelete(_start, _end - _start);
|
piece.adjustForDelete(_start, _end - _start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,11 +783,11 @@ public class Range { // TODO -instantiable superclass
|
|||||||
*/
|
*/
|
||||||
public CharacterRun getCharacterRun(int index) {
|
public CharacterRun getCharacterRun(int index) {
|
||||||
initCharacterRuns();
|
initCharacterRuns();
|
||||||
CHPX chpx = (CHPX) _characters.get(index + _charStart);
|
CHPX chpx = _characters.get(index + _charStart);
|
||||||
|
|
||||||
int[] point = findRange(_paragraphs, _parStart, Math.max(chpx.getStart(), _start), chpx
|
int[] point = findRange(_paragraphs, _parStart, Math.max(chpx.getStart(), _start), chpx
|
||||||
.getEnd());
|
.getEnd());
|
||||||
PAPX papx = (PAPX) _paragraphs.get(point[0]);
|
PAPX papx = _paragraphs.get(point[0]);
|
||||||
short istd = papx.getIstd();
|
short istd = papx.getIstd();
|
||||||
|
|
||||||
CharacterRun chp = new CharacterRun(chpx, _doc.getStyleSheet(), istd, this);
|
CharacterRun chp = new CharacterRun(chpx, _doc.getStyleSheet(), istd, this);
|
||||||
@ -809,7 +804,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
*/
|
*/
|
||||||
public Section getSection(int index) {
|
public Section getSection(int index) {
|
||||||
initSections();
|
initSections();
|
||||||
SEPX sepx = (SEPX) _sections.get(index + _sectionStart);
|
SEPX sepx = _sections.get(index + _sectionStart);
|
||||||
Section sep = new Section(sepx, this);
|
Section sep = new Section(sepx, this);
|
||||||
return sep;
|
return sep;
|
||||||
}
|
}
|
||||||
@ -824,7 +819,7 @@ public class Range { // TODO -instantiable superclass
|
|||||||
|
|
||||||
public Paragraph getParagraph(int index) {
|
public Paragraph getParagraph(int index) {
|
||||||
initParagraphs();
|
initParagraphs();
|
||||||
PAPX papx = (PAPX) _paragraphs.get(index + _parStart);
|
PAPX papx = _paragraphs.get(index + _parStart);
|
||||||
|
|
||||||
ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet());
|
ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet());
|
||||||
Paragraph pap = null;
|
Paragraph pap = null;
|
||||||
@ -1060,17 +1055,14 @@ public class Range { // TODO -instantiable superclass
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getStartOffset() {
|
public int getStartOffset() {
|
||||||
|
|
||||||
return _start;
|
return _start;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndOffset() {
|
public int getEndOffset() {
|
||||||
|
|
||||||
return _end;
|
return _end;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HWPFDocumentCore getDocument() {
|
protected HWPFDocumentCore getDocument() {
|
||||||
|
|
||||||
return _doc;
|
return _doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user