simplify some HWPFDocument.get*Range() methods
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6d8949ef0c
commit
b71c78c384
@ -299,90 +299,103 @@ public final class HWPFDocument extends HWPFDocumentCore
|
|||||||
return new Range(0, p.getEnd(), this);
|
return new Range(0, p.getEnd(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the range which covers the whole of the
|
* Returns the range which covers the whole of the document, but excludes
|
||||||
* document, but excludes any headers and footers.
|
* any headers and footers.
|
||||||
*/
|
*/
|
||||||
public Range getRange()
|
public Range getRange()
|
||||||
{
|
{
|
||||||
// First up, trigger a full-recalculate
|
// // First up, trigger a full-recalculate
|
||||||
// Needed in case of deletes etc
|
// // Needed in case of deletes etc
|
||||||
getOverallRange();
|
// getOverallRange();
|
||||||
|
//
|
||||||
|
// if ( getFileInformationBlock().isFComplex() )
|
||||||
|
// {
|
||||||
|
// /*
|
||||||
|
// * Page 31:
|
||||||
|
// *
|
||||||
|
// * main document must be found by examining the piece table entries
|
||||||
|
// * from the 0th piece table entry from the piece table entry that
|
||||||
|
// * describes cp=fib.ccpText.
|
||||||
|
// */
|
||||||
|
// // TODO: review
|
||||||
|
// return new Range( _cpSplit.getMainDocumentStart(),
|
||||||
|
// _cpSplit.getMainDocumentEnd(), this );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /*
|
||||||
|
// * Page 31:
|
||||||
|
// *
|
||||||
|
// * "In a non-complex file, this means text of the: main document
|
||||||
|
// begins
|
||||||
|
// * at fib.fcMin in the file and continues through
|
||||||
|
// * fib.fcMin+fib.ccpText."
|
||||||
|
// */
|
||||||
|
// int bytesStart = getFileInformationBlock().getFcMin();
|
||||||
|
//
|
||||||
|
// int charsStart = getTextTable().getCharIndex( bytesStart );
|
||||||
|
// int charsEnd = charsStart
|
||||||
|
// + getFileInformationBlock().getSubdocumentTextStreamLength(
|
||||||
|
// SubdocumentType.MAIN );
|
||||||
|
|
||||||
if ( getFileInformationBlock().isFComplex() )
|
// it seems much simpler -- sergey
|
||||||
{
|
return getRange(SubdocumentType.MAIN);
|
||||||
/*
|
|
||||||
* Page 31:
|
|
||||||
*
|
|
||||||
* main document must be found by examining the piece table entries
|
|
||||||
* from the 0th piece table entry from the piece table entry that
|
|
||||||
* describes cp=fib.ccpText.
|
|
||||||
*/
|
|
||||||
// TODO: review
|
|
||||||
return new Range( _cpSplit.getMainDocumentStart(),
|
|
||||||
_cpSplit.getMainDocumentEnd(), this );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Page 31:
|
|
||||||
*
|
|
||||||
* "In a non-complex file, this means text of the: main document begins
|
|
||||||
* at fib.fcMin in the file and continues through
|
|
||||||
* fib.fcMin+fib.ccpText."
|
|
||||||
*/
|
|
||||||
int bytesStart = getFileInformationBlock().getFcMin();
|
|
||||||
|
|
||||||
int charsStart = getTextTable().getCharIndex( bytesStart );
|
|
||||||
int charsEnd = charsStart
|
|
||||||
+ getFileInformationBlock().getSubdocumentTextStreamLength(
|
|
||||||
SubdocumentType.MAIN );
|
|
||||||
|
|
||||||
return new Range( charsStart, charsEnd, this );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private Range getRange( SubdocumentType subdocument )
|
||||||
* Returns the range which covers all the Footnotes.
|
{
|
||||||
*/
|
int startCp = 0;
|
||||||
public Range getFootnoteRange() {
|
for ( SubdocumentType previos : SubdocumentType.ORDERED )
|
||||||
return new Range(
|
{
|
||||||
_cpSplit.getFootnoteStart(),
|
int length = getFileInformationBlock()
|
||||||
_cpSplit.getFootnoteEnd(),
|
.getSubdocumentTextStreamLength( previos );
|
||||||
this
|
if ( subdocument == previos )
|
||||||
);
|
return new Range( startCp, startCp + length, this );
|
||||||
}
|
startCp += length;
|
||||||
|
}
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"Subdocument type not supported: " + subdocument );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the range which covers all the Endnotes.
|
* Returns the {@link Range} which covers all the Footnotes.
|
||||||
*/
|
*
|
||||||
public Range getEndnoteRange() {
|
* @return the {@link Range} which covers all the Footnotes.
|
||||||
return new Range(
|
*/
|
||||||
_cpSplit.getEndNoteStart(),
|
public Range getFootnoteRange()
|
||||||
_cpSplit.getEndNoteEnd(),
|
{
|
||||||
this
|
return getRange( SubdocumentType.FOOTNOTE );
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the range which covers all the Endnotes.
|
* Returns the {@link Range} which covers all endnotes.
|
||||||
*/
|
*
|
||||||
public Range getCommentsRange() {
|
* @return the {@link Range} which covers all endnotes.
|
||||||
return new Range(
|
*/
|
||||||
_cpSplit.getCommentsStart(),
|
public Range getEndnoteRange()
|
||||||
_cpSplit.getCommentsEnd(),
|
{
|
||||||
this
|
return getRange( SubdocumentType.ENDNOTE );
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the range which covers all the Endnotes.
|
* Returns the {@link Range} which covers all annotations.
|
||||||
*/
|
*
|
||||||
public Range getMainTextboxRange() {
|
* @return the {@link Range} which covers all annotations.
|
||||||
return new Range(
|
*/
|
||||||
_cpSplit.getMainTextboxStart(),
|
public Range getCommentsRange()
|
||||||
_cpSplit.getMainTextboxEnd(),
|
{
|
||||||
this
|
return getRange( SubdocumentType.ANNOTATION );
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link Range} which covers all textboxes.
|
||||||
|
*
|
||||||
|
* @return the {@link Range} which covers all textboxes.
|
||||||
|
*/
|
||||||
|
public Range getMainTextboxRange()
|
||||||
|
{
|
||||||
|
return getRange( SubdocumentType.TEXTBOX );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the range which covers all "Header Stories".
|
* Returns the range which covers all "Header Stories".
|
||||||
|
Loading…
Reference in New Issue
Block a user