Fields Summary |
---|
public static final int | TYPE_PARAGRAPH |
public static final int | TYPE_CHARACTER |
public static final int | TYPE_SECTION |
public static final int | TYPE_TEXT |
public static final int | TYPE_LISTENTRY |
public static final int | TYPE_TABLE |
public static final int | TYPE_UNDEFINED |
private WeakReference | _parentNeeded so inserts and deletes will ripple up through containing Ranges |
protected int | _startThe starting character offset of this range. |
protected int | _endThe ending character offset of this range. |
protected HWPFDocument | _docThe document this range blongs to. |
boolean | _sectionRangeFoundHave we loaded the section indexes yet |
protected List | _sectionsAll sections that belong to the document this Range belongs to. |
protected int | _sectionStartThe start index in the sections list for this Range |
protected int | _sectionEndThe end index in the sections list for this Range. |
protected boolean | _parRangeFoundHave we loaded the paragraph indexes yet. |
protected List | _paragraphsAll paragraphs that belong to the document this Range belongs to. |
protected int | _parStartThe start index in the paragraphs list for this Range |
protected int | _parEndThe end index in the paragraphs list for this Range. |
protected boolean | _charRangeFoundHave we loaded the characterRun indexes yet. |
protected List | _charactersAll CharacterRuns that belong to the document this Range belongs to. |
protected int | _charStartThe start index in the characterRuns list for this Range |
protected int | _charEndThe end index in the characterRuns list for this Range. |
protected boolean | _textRangeFoundHave we loaded the Text indexes yet |
protected List | _textAll text pieces that belong to the document this Range belongs to. |
protected int | _textStartThe start index in the text list for this Range. |
protected int | _textEndThe end index in the text list for this Range. |
Methods Summary |
---|
private void | adjustForInsert(int length)adjust this range after an insert happens.
_end += length;
reset();
Range parent = (Range)_parent.get();
if (parent != null)
{
parent.adjustForInsert(length);
}
|
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 = (CHPX)_characters.get(x);
chpx.adjustForDelete(_start, _end - _start);
}
for (int x = _parStart; x < numParagraphs; x++)
{
PAPX papx = (PAPX)_paragraphs.get(x);
papx.adjustForDelete(_start, _end - _start);
}
for (int x = _sectionStart; x < numSections; x++)
{
SEPX sepx = (SEPX)_sections.get(x);
sepx.adjustForDelete(_start, _end - _start);
}
|
private int[] | findRange(java.util.List rpl, int min, int start, int end)Used to find the list indexes of a particular property.
int x = min;
PropertyNode node = (PropertyNode)rpl.get(x);
while(node.getEnd() <= start && x < rpl.size()-1)
{
x++;
node = (PropertyNode)rpl.get(x);
}
int y = x;
node = (PropertyNode)rpl.get(y);
while(node.getEnd() < end && y < rpl.size()-1)
{
y++;
node = (PropertyNode)rpl.get(y);
}
return new int[]{x, y + 1};
|
public org.apache.poi.hwpf.usermodel.CharacterRun | getCharacterRun(int index)Gets the character run at index. The index is relative to this range.
initCharacterRuns();
CHPX chpx = (CHPX)_characters.get(index + _charStart);
int[] point = findRange(_paragraphs, _parStart, Math.max(chpx.getStart(), _start),
chpx.getEnd());
PAPX papx = (PAPX)_paragraphs.get(point[0]);
short istd = papx.getIstd();
CharacterRun chp = new CharacterRun(chpx, _doc.getStyleSheet(), istd, this);
return chp;
|
public org.apache.poi.hwpf.usermodel.Paragraph | getParagraph(int index)Gets the paragraph at index. The index is relative to this range.
initParagraphs();
PAPX papx = (PAPX)_paragraphs.get(index + _parStart);
ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet());
Paragraph pap = null;
if (props.getIlfo() > 0)
{
pap = new ListEntry(papx, this, _doc.getListTables());
}
else
{
pap = new Paragraph(papx, this);
}
return pap;
|
public org.apache.poi.hwpf.usermodel.Section | getSection(int index)Gets the section at index. The index is relative to this range.
initSections();
SEPX sepx = (SEPX)_sections.get(index + _sectionStart);
Section sep = new Section(sepx, this);
return sep;
|
public org.apache.poi.hwpf.usermodel.Table | getTable(org.apache.poi.hwpf.usermodel.Paragraph paragraph)Gets the table that starts with paragraph. In a Word file, a table consists
of a group of paragraphs with certain flags set.
if (!paragraph.isInTable())
{
throw new IllegalArgumentException("This paragraph doesn't belong to a table");
}
Range r = (Range)paragraph;
if (r._parent.get() != this)
{
throw new IllegalArgumentException("This paragraph is not a child of this range");
}
r.initAll();
int tableEnd = r._parEnd;
if (r._parStart != 0 && getParagraph(r._parStart - 1).isInTable()
&& getParagraph(r._parStart - 1)._sectionEnd >= r._sectionStart)
{
throw new IllegalArgumentException("This paragraph is not the first one in the table");
}
int limit = _paragraphs.size();
for (; tableEnd < limit; tableEnd++)
{
if (!getParagraph(tableEnd).isInTable())
{
break;
}
}
initAll();
if (tableEnd > _parEnd)
{
throw new ArrayIndexOutOfBoundsException("The table's bounds fall outside of this Range");
}
return new Table(r._parStart, tableEnd, r._doc.getRange(), paragraph.getTableLevel());
|
protected void | initAll()loads all of the list indexes.
initText();
initCharacterRuns();
initParagraphs();
initSections();
|
private void | initCharacterRuns()inits the character run list indexes.
if (!_charRangeFound)
{
int[] point = findRange(_characters, _charStart, _start, _end);
_charStart = point[0];
_charEnd = point[1];
_charRangeFound = true;
}
|
private void | initParagraphs()inits the paragraph list indexes.
if (!_parRangeFound)
{
int[] point = findRange(_paragraphs, _parStart, _start, _end);
_parStart = point[0];
_parEnd = point[1];
_parRangeFound = true;
}
|
private void | initSections()inits the section list indexes.
if (!_sectionRangeFound)
{
int[] point = findRange(_sections, _sectionStart, _start, _end);
_sectionStart = point[0];
_sectionEnd = point[1];
_sectionRangeFound = true;
}
|
private void | initText()inits the text piece list indexes.
if (!_textRangeFound)
{
int[] point = findRange(_text, _textStart, _start, _end);
_textStart = point[0];
_textEnd = point[1];
_textRangeFound = true;
}
|
public org.apache.poi.hwpf.usermodel.CharacterRun | insertAfter(java.lang.String text, org.apache.poi.hwpf.usermodel.CharacterProperties props)Inserts text onto the end of this range and gives that text the
CharacterProperties specified in props.
initAll();
PAPX papx = (PAPX)_paragraphs.get(_parEnd - 1);
short istd = papx.getIstd();
StyleSheet ss = _doc.getStyleSheet();
CharacterProperties baseStyle = ss.getCharacterStyle(istd);
byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
SprmBuffer buf = new SprmBuffer(grpprl);
_doc.getCharacterTable().insert(_charEnd, _end, buf);
_charEnd++;
return insertAfter(text);
|
public org.apache.poi.hwpf.usermodel.Paragraph | insertAfter(org.apache.poi.hwpf.usermodel.ParagraphProperties props, int styleIndex)Inserts and empty paragraph into the end of this range.
return this.insertAfter(props, styleIndex, "\r");
|
protected org.apache.poi.hwpf.usermodel.Paragraph | insertAfter(org.apache.poi.hwpf.usermodel.ParagraphProperties props, int styleIndex, java.lang.String text)Inserts a paragraph into the end of this range. The paragraph will
contain one character run that has the default properties for the
paragraph's style.
It is necessary for the text to end with the character '\r'
initAll();
StyleSheet ss = _doc.getStyleSheet();
ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex);
CharacterProperties baseChp = ss.getCharacterStyle(styleIndex);
byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
LittleEndian.putShort(withIndex, (short)styleIndex);
System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
SprmBuffer buf = new SprmBuffer(withIndex);
_doc.getParagraphTable().insert(_parEnd, _end, buf);
_parEnd++;
insertAfter(text, baseChp);
return getParagraph(numParagraphs() - 1);
|
public org.apache.poi.hwpf.usermodel.ListEntry | insertAfter(org.apache.poi.hwpf.usermodel.ParagraphProperties props, int listID, int level, int styleIndex)Inserts a list into the beginning of this range.
ListTables lt = _doc.getListTables();
if (lt.getLevel(listID, level) == null)
{
throw new NoSuchElementException("The specified list and level do not exist");
}
int ilfo = lt.getOverrideIndexFromListID(listID);
props.setIlfo(ilfo);
props.setIlvl((byte)level);
return (ListEntry)insertAfter(props, styleIndex);
|
public org.apache.poi.hwpf.usermodel.CharacterRun | insertAfter(java.lang.String text)Inserts text onto the end of this range
initAll();
int listIndex = _textEnd - 1;
TextPiece tp = (TextPiece)_text.get(listIndex);
StringBuffer sb = (StringBuffer)tp.getStringBuffer();
int insertIndex = _end - tp.getStart();
if (tp.getStringBuffer().charAt(_end - 1) == '\r" && text.charAt(0) != '\u0007")
{
insertIndex--;
}
sb.insert(insertIndex, text);
int adjustedLength = _doc.getTextTable().adjustForInsert(listIndex, text.length());
_doc.getCharacterTable().adjustForInsert(_charEnd - 1, adjustedLength);
_doc.getParagraphTable().adjustForInsert(_parEnd - 1, adjustedLength);
_doc.getSectionTable().adjustForInsert(_sectionEnd - 1, adjustedLength);
adjustForInsert(text.length());
return getCharacterRun(numCharacterRuns() - 1);
|
public org.apache.poi.hwpf.usermodel.CharacterRun | insertBefore(java.lang.String text, org.apache.poi.hwpf.usermodel.CharacterProperties props)Inserts text into the front of this range and it gives that text the
CharacterProperties specified in props.
initAll();
PAPX papx = (PAPX)_paragraphs.get(_parStart);
short istd = papx.getIstd();
StyleSheet ss = _doc.getStyleSheet();
CharacterProperties baseStyle = ss.getCharacterStyle(istd);
byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
SprmBuffer buf = new SprmBuffer(grpprl);
_doc.getCharacterTable().insert(_charStart, _start, buf);
return insertBefore(text);
|
public org.apache.poi.hwpf.usermodel.Paragraph | insertBefore(org.apache.poi.hwpf.usermodel.ParagraphProperties props, int styleIndex)Inserts and empty paragraph into the front of this range.
return this.insertBefore(props, styleIndex, "\r");
|
protected org.apache.poi.hwpf.usermodel.Paragraph | insertBefore(org.apache.poi.hwpf.usermodel.ParagraphProperties props, int styleIndex, java.lang.String text)Inserts a paragraph into the front of this range. The paragraph will
contain one character run that has the default properties for the
paragraph's style.
It is necessary for the text to end with the character '\r'
initAll();
StyleSheet ss = _doc.getStyleSheet();
ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex);
CharacterProperties baseChp = ss.getCharacterStyle(styleIndex);
byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
LittleEndian.putShort(withIndex, (short)styleIndex);
System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
SprmBuffer buf = new SprmBuffer(withIndex);
_doc.getParagraphTable().insert(_parStart, _start, buf);
insertBefore(text, baseChp);
return getParagraph(0);
|
public org.apache.poi.hwpf.usermodel.Table | insertBefore(org.apache.poi.hwpf.usermodel.TableProperties props, int rows)Inserts a simple table into the beginning of this range. The number of
columns is determined by the TableProperties passed into this function.
ParagraphProperties parProps = new ParagraphProperties();
parProps.setFInTable((byte)1);
parProps.setTableLevel((byte)1);
int columns = props.getItcMac();
for (int x = 0; x < rows; x++)
{
Paragraph cell = this.insertBefore(parProps, StyleSheet.NIL_STYLE);
cell.insertAfter(String.valueOf('\u0007"));
for(int y = 1; y < columns; y++)
{
cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE);
cell.insertAfter(String.valueOf('\u0007"));
}
cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE, String.valueOf('\u0007"));
cell.setTableRowEnd(props);
}
return new Table(_start, _start + (rows * (columns + 1)), this, 1);
|
public org.apache.poi.hwpf.usermodel.ListEntry | insertBefore(org.apache.poi.hwpf.usermodel.ParagraphProperties props, int listID, int level, int styleIndex)Inserts a list into the beginning of this range.
ListTables lt = _doc.getListTables();
if (lt.getLevel(listID, level) == null)
{
throw new NoSuchElementException("The specified list and level do not exist");
}
int ilfo = lt.getOverrideIndexFromListID(listID);
props.setIlfo(ilfo);
props.setIlvl((byte)level);
return (ListEntry)insertBefore(props, styleIndex);
|
public org.apache.poi.hwpf.usermodel.CharacterRun | insertBefore(java.lang.String text)Inserts text into the front of this range.
initAll();
TextPiece tp = (TextPiece)_text.get(_textStart);
StringBuffer sb = (StringBuffer)tp.getStringBuffer();
// Since this is the first item in our list, it is safe to assume that
// _start >= tp.getStart()
int insertIndex = _start - tp.getStart();
sb.insert(insertIndex, text);
int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length());
_doc.getCharacterTable().adjustForInsert(_charStart, adjustedLength);
_doc.getParagraphTable().adjustForInsert(_parStart, adjustedLength);
_doc.getSectionTable().adjustForInsert(_sectionStart, adjustedLength);
adjustForInsert(text.length());
return getCharacterRun(0);
|
public int | numCharacterRuns()
initCharacterRuns();
return _charEnd - _charStart;
|
public int | numParagraphs()Used to get the number of paragraphs in a range. If this range is smaller
than a paragraph, it will return 1 for its containing paragraph.
initParagraphs();
return _parEnd - _parStart;
|
public int | numSections()Used to get the number of sections in a range. If this range is smaller
than a section, it will return 1 for its containing section.
initSections();
return _sectionEnd - _sectionStart;
|
private void | reset()resets the list indexes.
_textRangeFound = false;
_charRangeFound = false;
_parRangeFound = false;
_sectionRangeFound = false;
|
public java.lang.String | text()Gets the text that this Range contains.
initText();
StringBuffer sb = new StringBuffer();
for (int x = _textStart; x < _textEnd; x++)
{
TextPiece piece = (TextPiece)_text.get(x);
int start = _start > piece.getStart() ? _start - piece.getStart() : 0;
int end = _end <= piece.getEnd() ? _end - piece.getStart() : piece.getEnd() - piece.getStart();
if(piece.usesUnicode()) // convert the byte pointers to char pointers
{
start/=2;
end/=2;
}
sb.append(piece.getStringBuffer().substring(start, end));
}
return sb.toString();
|
public int | type()This method is used to determine the type. Handy for switch statements
compared to the instanceof operator.
return TYPE_UNDEFINED;
|