PAPBinTablepublic class PAPBinTable extends Object This class represents the bin table of Word document but it also serves as a
holder for all of the paragraphs of document that have been loaded into
memory. |
Fields Summary |
---|
protected ArrayList | _paragraphs | byte[] | _dataStream |
Constructors Summary |
---|
public PAPBinTable()
| public PAPBinTable(byte[] documentStream, byte[] tableStream, byte[] dataStream, int offset, int size, int fcMin)
PlexOfCps binTable = new PlexOfCps(tableStream, offset, size, 4);
int length = binTable.length();
for (int x = 0; x < length; x++)
{
GenericPropertyNode node = binTable.getProperty(x);
int pageNum = LittleEndian.getInt(node.getBytes());
int pageOffset = POIFSConstants.BIG_BLOCK_SIZE * pageNum;
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(documentStream,
dataStream, pageOffset, fcMin);
int fkpSize = pfkp.size();
for (int y = 0; y < fkpSize; y++)
{
_paragraphs.add(pfkp.getPAPX(y));
}
}
_dataStream = dataStream;
|
Methods Summary |
---|
public void | adjustForDelete(int listIndex, int offset, int length)
int size = _paragraphs.size();
int endMark = offset + length;
int endIndex = listIndex;
PAPX papx = (PAPX)_paragraphs.get(endIndex);
while (papx.getEnd() < endMark)
{
papx = (PAPX)_paragraphs.get(++endIndex);
}
if (listIndex == endIndex)
{
papx = (PAPX)_paragraphs.get(endIndex);
papx.setEnd((papx.getEnd() - endMark) + offset);
}
else
{
papx = (PAPX)_paragraphs.get(listIndex);
papx.setEnd(offset);
for (int x = listIndex + 1; x < endIndex; x++)
{
papx = (PAPX)_paragraphs.get(x);
papx.setStart(offset);
papx.setEnd(offset);
}
papx = (PAPX)_paragraphs.get(endIndex);
papx.setEnd((papx.getEnd() - endMark) + offset);
}
for (int x = endIndex + 1; x < size; x++)
{
papx = (PAPX)_paragraphs.get(x);
papx.setStart(papx.getStart() - length);
papx.setEnd(papx.getEnd() - length);
}
| public void | adjustForInsert(int listIndex, int length)
int size = _paragraphs.size();
PAPX papx = (PAPX)_paragraphs.get(listIndex);
papx.setEnd(papx.getEnd() + length);
for (int x = listIndex + 1; x < size; x++)
{
papx = (PAPX)_paragraphs.get(x);
papx.setStart(papx.getStart() + length);
papx.setEnd(papx.getEnd() + length);
}
| public java.util.ArrayList | getParagraphs()
return _paragraphs;
| public void | insert(int listIndex, int cpStart, org.apache.poi.hwpf.sprm.SprmBuffer buf)
PAPX forInsert = new PAPX(cpStart, cpStart, buf, _dataStream);
if (listIndex == _paragraphs.size())
{
_paragraphs.add(forInsert);
}
else
{
PAPX currentPap = (PAPX)_paragraphs.get(listIndex);
if (currentPap != null && currentPap.getStart() < cpStart)
{
SprmBuffer clonedBuf = null;
try
{
clonedBuf = (SprmBuffer)currentPap.getSprmBuf().clone();
}
catch (CloneNotSupportedException exc)
{
exc.printStackTrace();
}
currentPap.setEnd(cpStart);
PAPX splitPap = new PAPX(cpStart, currentPap.getEnd(), clonedBuf, _dataStream);
_paragraphs.add(++listIndex, forInsert);
_paragraphs.add(++listIndex, splitPap);
}
else
{
_paragraphs.add(listIndex, forInsert);
}
}
| public void | writeTo(org.apache.poi.hwpf.model.io.HWPFFileSystem sys, int fcMin)
HWPFOutputStream docStream = sys.getStream("WordDocument");
OutputStream tableStream = sys.getStream("1Table");
PlexOfCps binTable = new PlexOfCps(4);
// each FKP must start on a 512 byte page.
int docOffset = docStream.getOffset();
int mod = docOffset % POIFSConstants.BIG_BLOCK_SIZE;
if (mod != 0)
{
byte[] padding = new byte[POIFSConstants.BIG_BLOCK_SIZE - mod];
docStream.write(padding);
}
// get the page number for the first fkp
docOffset = docStream.getOffset();
int pageNum = docOffset/POIFSConstants.BIG_BLOCK_SIZE;
// get the ending fc
int endingFc = ((PropertyNode)_paragraphs.get(_paragraphs.size() - 1)).getEnd();
endingFc += fcMin;
ArrayList overflow = _paragraphs;
do
{
PropertyNode startingProp = (PropertyNode)overflow.get(0);
int start = startingProp.getStart() + fcMin;
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(_dataStream);
pfkp.fill(overflow);
byte[] bufFkp = pfkp.toByteArray(fcMin);
docStream.write(bufFkp);
overflow = pfkp.getOverflow();
int end = endingFc;
if (overflow != null)
{
end = ((PropertyNode)overflow.get(0)).getStart() + fcMin;
}
byte[] intHolder = new byte[4];
LittleEndian.putInt(intHolder, pageNum++);
binTable.addProperty(new GenericPropertyNode(start, end, intHolder));
}
while (overflow != null);
tableStream.write(binTable.toByteArray());
|
|