Package org.apache.poi.hwpf.usermodel
Class Range
java.lang.Object
org.apache.poi.hwpf.usermodel.Range
This class is the central class of the HWPF object model. All properties that
apply to a range of characters in a Word document extend this class.
It is possible to insert text and/or properties at the beginning or end of a
range.
Ranges are only valid if there hasn't been an insert in a prior Range since
the Range's creation. Once an element (text, paragraph, etc.) has been
inserted into a Range, subsequent Ranges become unstable.
- Author:
- Ryan Ackley
-
Field Summary
FieldsModifier and TypeFieldDescriptionAll CharacterRuns that belong to the document this Range belongs to.protected int
The end index in the characterRuns list for this Range.protected boolean
Have we loaded the characterRun indexes yet.protected int
The start index in the characterRuns list for this Rangeprotected final HWPFDocumentCore
The document this range belongs to.protected int
The ending character offset of this range.All paragraphs that belong to the document this Range belongs to.protected int
The end index in the paragraphs list for this Range, exclusiveprotected boolean
Have we loaded the paragraph indexes yet.protected int
The start index in the paragraphs list for this Range, inclusiveprotected int
The end index in the sections list for this Range.All sections that belong to the document this Range belongs to.protected int
The start index in the sections list for this Rangeprotected final int
The starting character offset of this range.protected StringBuilder
static final int
Deprecated.POI 3.8 beta 5static final int
Deprecated.POI 3.8 beta 5static final int
Deprecated.POI 3.8 beta 5static final int
Deprecated.POI 3.8 beta 5static final int
Deprecated.POI 3.8 beta 5static final int
Deprecated.POI 3.8 beta 5static final int
Deprecated.POI 3.8 beta 5 -
Constructor Summary
ConstructorsModifierConstructorDescriptionRange
(int start, int end, HWPFDocumentCore doc) Used to construct a Range from a document.protected
Used to create Ranges that are children of other Ranges. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
adjustFIB
(int adjustment) Adjust the value of the various FIB character count fields, egFIB.CCPText
after an insert or a delete...void
delete()
getCharacterRun
(int index) Gets the character run at index.protected HWPFDocumentCore
int
getParagraph
(int index) Gets the paragraph at index.getSection
(int index) Gets the section at index.int
Gets the table that starts with paragraph.protected void
initAll()
loads all of the list indexes.insertAfter
(String text) Inserts text onto the end of this rangeinsertBefore
(String text) Inserts text into the front of this range.insertTableBefore
(short columns, int rows) Inserts a simple table into the beginning of this range.int
int
Used to get the number of paragraphs in a range.int
Used to get the number of sections in a range.void
replaceText
(String newText, boolean addAfter) Replace range text with new one, adding it to the range and deleting original text from documentvoid
replaceText
(String pPlaceHolder, String pValue) Replace (all instances of) a piece of text with another...void
replaceText
(String pPlaceHolder, String pValue, int pOffset) Replace (one instance of) a piece of text with another...protected void
reset()
resets the list indexes.boolean
Method for debug purposes.static String
stripFields
(String text) Removes any fields (eg macros, page markers etc) from the string.text()
Gets the text that this Range contains.toString()
-
Field Details
-
TYPE_PARAGRAPH
Deprecated.POI 3.8 beta 5- See Also:
-
TYPE_CHARACTER
Deprecated.POI 3.8 beta 5- See Also:
-
TYPE_SECTION
Deprecated.POI 3.8 beta 5- See Also:
-
TYPE_TEXT
Deprecated.POI 3.8 beta 5- See Also:
-
TYPE_LISTENTRY
Deprecated.POI 3.8 beta 5- See Also:
-
TYPE_TABLE
Deprecated.POI 3.8 beta 5- See Also:
-
TYPE_UNDEFINED
Deprecated.POI 3.8 beta 5- See Also:
-
_start
protected final int _startThe starting character offset of this range. -
_end
protected int _endThe ending character offset of this range. -
_doc
The document this range belongs to. -
_sections
All sections that belong to the document this Range belongs to. -
_sectionStart
protected int _sectionStartThe start index in the sections list for this Range -
_sectionEnd
protected int _sectionEndThe end index in the sections list for this Range. -
_parRangeFound
protected boolean _parRangeFoundHave we loaded the paragraph indexes yet. -
_paragraphs
All paragraphs that belong to the document this Range belongs to. -
_parStart
protected int _parStartThe start index in the paragraphs list for this Range, inclusive -
_parEnd
protected int _parEndThe end index in the paragraphs list for this Range, exclusive -
_charRangeFound
protected boolean _charRangeFoundHave we loaded the characterRun indexes yet. -
_characters
All CharacterRuns that belong to the document this Range belongs to. -
_charStart
protected int _charStartThe start index in the characterRuns list for this Range -
_charEnd
protected int _charEndThe end index in the characterRuns list for this Range. -
_text
-
-
Constructor Details
-
Range
Used to construct a Range from a document. This is generally used to create a Range that spans the whole document, or at least one whole part of the document (eg main text, header, comment)- Parameters:
start
- Starting character offset of the range.end
- Ending character offset of the range.doc
- The HWPFDocument the range is based on.
-
Range
Used to create Ranges that are children of other Ranges.- Parameters:
start
- Starting character offset of the range.end
- Ending character offset of the range.parent
- The parent this range belongs to.
-
-
Method Details
-
text
Gets the text that this Range contains.- Returns:
- The text for this range.
-
stripFields
Removes any fields (eg macros, page markers etc) from the string. Normally used to make some text suitable for showing to humans, and the resultant text should not normally be saved back into the document! -
numSections
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.- Returns:
- The number of sections in this range.
-
numParagraphs
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.- Returns:
- The number of paragraphs in this range.
-
numCharacterRuns
public int numCharacterRuns()- Returns:
- The number of characterRuns in this range.
-
insertBefore
Inserts text into the front of this range.- Parameters:
text
- The text to insert- Returns:
- The character run that text was inserted into.
-
insertAfter
Inserts text onto the end of this range- Parameters:
text
- The text to insert- Returns:
- The character run the text was inserted into.
-
delete
public void delete() -
insertTableBefore
Inserts a simple table into the beginning of this range.- Parameters:
columns
- The number of columnsrows
- The number of rows.- Returns:
- The empty Table that is now part of the document.
-
replaceText
Replace range text with new one, adding it to the range and deleting original text from document- Parameters:
newText
- The text to be replaced withaddAfter
- if true the text will be added at the end of current range, otherwise to the beginning
-
replaceText
Replace (one instance of) a piece of text with another...- Parameters:
pPlaceHolder
- The text to be replaced (e.g., "${organization}")pValue
- The replacement text (e.g., "Apache Software Foundation")pOffset
- The offset or index where the text to be replaced begins (relative to/within thisRange
)
-
replaceText
Replace (all instances of) a piece of text with another...- Parameters:
pPlaceHolder
- The text to be replaced (e.g., "${organization}")pValue
- The replacement text (e.g., "Apache Software Foundation")
-
getCharacterRun
Gets the character run at index. The index is relative to this range.- Parameters:
index
- The index of the character run to get.- Returns:
- The character run at the specified index in this range.
-
getSection
Gets the section at index. The index is relative to this range.- Parameters:
index
- The index of the section to get.- Returns:
- The section at the specified index in this range.
-
getParagraph
Gets the paragraph at index. The index is relative to this range.- Parameters:
index
- The index of the paragraph to get.- Returns:
- The paragraph at the specified index in this range.
-
getTable
Gets the table that starts with paragraph. In a Word file, a table consists of a group of paragraphs with certain flags set.- Parameters:
paragraph
- The paragraph that is the first paragraph in the table.- Returns:
- The table that starts with paragraph
-
initAll
protected void initAll()loads all of the list indexes. -
reset
protected void reset()resets the list indexes. -
adjustFIB
protected void adjustFIB(int adjustment) Adjust the value of the various FIB character count fields, egFIB.CCPText
after an insert or a delete... Works on all CCP fields from this range onwards- Parameters:
adjustment
- The (signed) value that should be added to the FIB CCP fields
-
getStartOffset
public int getStartOffset()- Returns:
- Starting character offset of the range
-
getEndOffset
public int getEndOffset()- Returns:
- The ending character offset of this range
-
getDocument
-
toString
-
sanityCheck
public boolean sanityCheck()Method for debug purposes. Checks that all resolved elements are inside of current range. ThrowsIllegalArgumentException
if checks fail.
-