EventBridgepublic class EventBridge extends Object implements HDFLowLevelParsingListener
Fields Summary |
---|
private static int | HEADER_EVEN_INDEX | private static int | HEADER_ODD_INDEX | private static int | FOOTER_EVEN_INDEX | private static int | FOOTER_ODD_INDEX | private static int | HEADER_FIRST_INDEX | private static int | FOOTER_FIRST_INDEX | HDFParsingListener | _listenerThis class translates low level events into high level events for this
listener | StyleSheet | _stshstylesheet for this document | DocumentProperties | _dopname says it all | StyleDescription | _currentStdStyleDescription for the current paragraph. | ListTables | _listTablesList info for this doc | byte[] | _mainDocument"WordDocument" from the POIFS | byte[] | _tableStreamTable0 or Table1 from POIFS | int | _fcMintext offset in main stream | int | _ccpText | int | _ccpFtn | int | _hdrSize | int | _hdrOffset | BTreeSet | _texttext pieces | private boolean | _beginHeaders | BTreeSet | _hdrSections | BTreeSet | _hdrParagraphs | BTreeSet | _hdrCharacterRuns | int | _sectionCounter | ArrayList | _hdrs | private boolean | _holdParagraph | private int | _endHoldIndex | private ArrayList | _onHold |
Methods Summary |
---|
public void | bodySection(org.apache.poi.hdf.model.hdftypes.SepxNode sepx)
SectionProperties sep = (SectionProperties)StyleSheet.uncompressProperty(sepx.getSepx(), new SectionProperties(), _stsh);
HeaderFooter[] hdrArray = findSectionHdrFtrs(_sectionCounter);
_hdrs.add(hdrArray);
_listener.section(sep, sepx.getStart() - _fcMin, sepx.getEnd() - _fcMin);
_sectionCounter++;
| public void | characterRun(org.apache.poi.hdf.model.hdftypes.ChpxNode chpx)
if (_beginHeaders)
{
_hdrCharacterRuns.add(chpx);
}
int start = chpx.getStart();
int end = chpx.getEnd();
//check to see if we should hold this characterRun
if (_holdParagraph)
{
_onHold.add(chpx);
if (end >= _endHoldIndex)
{
_holdParagraph = false;
_endHoldIndex = -1;
flushHeldParagraph();
_onHold = new ArrayList();
}
}
byte[] byteChpx = chpx.getChpx();
CharacterProperties chp = (CharacterProperties)StyleSheet.uncompressProperty(byteChpx, _currentStd.getCHP(), _stsh);
ArrayList textList = BTreeSet.findProperties(start, end, _text.root);
String text = getTextFromNodes(textList, start, end);
_listener.characterRun(chp, text, start - _fcMin, end - _fcMin);
| private org.apache.poi.hdf.model.hdftypes.HeaderFooter | createSectionHdrFtr(int index, int type)
if(_hdrSize < 50)
{
return new HeaderFooter(0,0,0);
}
int start = _fcMin + _ccpText + _ccpFtn;
int end = start;
int arrayIndex = 0;
switch(type)
{
case HeaderFooter.HEADER_EVEN:
arrayIndex = (HEADER_EVEN_INDEX + (index * 6));
break;
case HeaderFooter.FOOTER_EVEN:
arrayIndex = (FOOTER_EVEN_INDEX + (index * 6));
break;
case HeaderFooter.HEADER_ODD:
arrayIndex = (HEADER_ODD_INDEX + (index * 6));
break;
case HeaderFooter.FOOTER_ODD:
arrayIndex = (FOOTER_ODD_INDEX + (index * 6));
break;
case HeaderFooter.HEADER_FIRST:
arrayIndex = (HEADER_FIRST_INDEX + (index * 6));
break;
case HeaderFooter.FOOTER_FIRST:
arrayIndex = (FOOTER_FIRST_INDEX + (index * 6));
break;
}
start += LittleEndian.getInt(_tableStream, _hdrOffset + (arrayIndex * 4));
end += LittleEndian.getInt(_tableStream, _hdrOffset + (arrayIndex + 1) * 4);
HeaderFooter retValue = new HeaderFooter(type, start, end);
if((end - start) == 0 && index > 1)
{
retValue = createSectionHdrFtr(type, index - 1);
}
return retValue;
| public void | document(org.apache.poi.hdf.model.hdftypes.DocumentProperties dop)
_dop = dop;
| public void | endSections()
for (int x = 1; x < _sectionCounter; x++)
{
HeaderFooter[] hdrArray = (HeaderFooter[])_hdrs.get(x-1);
HeaderFooter hf = null;
if (!hdrArray[HeaderFooter.HEADER_EVEN - 1].isEmpty())
{
hf = hdrArray[HeaderFooter.HEADER_EVEN - 1];
_listener.header(x - 1, HeaderFooter.HEADER_EVEN);
flushHeaderProps(hf.getStart(), hf.getEnd());
}
if (!hdrArray[HeaderFooter.HEADER_ODD - 1].isEmpty())
{
hf = hdrArray[HeaderFooter.HEADER_ODD - 1];
_listener.header(x - 1, HeaderFooter.HEADER_ODD);
flushHeaderProps(hf.getStart(), hf.getEnd());
}
if (!hdrArray[HeaderFooter.FOOTER_EVEN - 1].isEmpty())
{
hf = hdrArray[HeaderFooter.FOOTER_EVEN - 1];
_listener.footer(x - 1, HeaderFooter.FOOTER_EVEN);
flushHeaderProps(hf.getStart(), hf.getEnd());
}
if (!hdrArray[HeaderFooter.FOOTER_ODD - 1].isEmpty())
{
hf = hdrArray[HeaderFooter.FOOTER_EVEN - 1];
_listener.footer(x - 1, HeaderFooter.FOOTER_EVEN);
flushHeaderProps(hf.getStart(), hf.getEnd());
}
if (!hdrArray[HeaderFooter.HEADER_FIRST - 1].isEmpty())
{
hf = hdrArray[HeaderFooter.HEADER_FIRST - 1];
_listener.header(x - 1, HeaderFooter.HEADER_FIRST);
flushHeaderProps(hf.getStart(), hf.getEnd());
}
if (!hdrArray[HeaderFooter.FOOTER_FIRST - 1].isEmpty())
{
hf = hdrArray[HeaderFooter.FOOTER_FIRST - 1];
_listener.footer(x - 1, HeaderFooter.FOOTER_FIRST);
flushHeaderProps(hf.getStart(), hf.getEnd());
}
}
| private org.apache.poi.hdf.model.hdftypes.HeaderFooter[] | findSectionHdrFtrs(int index)
HeaderFooter[] hdrArray = new HeaderFooter[6];
for (int x = 1; x < 7; x++)
{
hdrArray[x-1] = createSectionHdrFtr(index, x);
}
return hdrArray;
| private void | flushHeaderProps(int start, int end)
ArrayList list = BTreeSet.findProperties(start, end, _hdrSections.root);
int size = list.size();
for (int x = 0; x < size; x++)
{
SepxNode oldNode = (SepxNode)list.get(x);
int secStart = Math.max(oldNode.getStart(), start);
int secEnd = Math.min(oldNode.getEnd(), end);
//SepxNode node = new SepxNode(-1, secStart, secEnd, oldNode.getSepx());
//bodySection(node);
ArrayList parList = BTreeSet.findProperties(secStart, secEnd, _hdrParagraphs.root);
int parSize = parList.size();
for (int y = 0; y < parSize; y++)
{
PapxNode oldParNode = (PapxNode)parList.get(y);
int parStart = Math.max(oldParNode.getStart(), secStart);
int parEnd = Math.min(oldParNode.getEnd(), secEnd);
PapxNode parNode = new PapxNode(parStart, parEnd, oldParNode.getPapx());
paragraph(parNode);
ArrayList charList = BTreeSet.findProperties(parStart, parEnd, _hdrCharacterRuns.root);
int charSize = charList.size();
for (int z = 0; z < charSize; z++)
{
ChpxNode oldCharNode = (ChpxNode)charList.get(z);
int charStart = Math.max(oldCharNode.getStart(), parStart);
int charEnd = Math.min(oldCharNode.getEnd(), parEnd);
ChpxNode charNode = new ChpxNode(charStart, charEnd, oldCharNode.getChpx());
characterRun(charNode);
}
}
}
| private void | flushHeldParagraph()
PapxNode papx = (PapxNode)_onHold.get(0);
byte[] bytePapx = papx.getPapx();
int istd = LittleEndian.getShort(bytePapx, 0);
StyleDescription std = _stsh.getStyleDescription(istd);
ParagraphProperties pap = (ParagraphProperties)StyleSheet.uncompressProperty(bytePapx, _currentStd.getPAP(), _stsh);
LVL lvl = _listTables.getLevel(pap.getIlfo(), pap.getIlvl());
pap = (ParagraphProperties)StyleSheet.uncompressProperty(lvl._papx, pap, _stsh, false);
int size = _onHold.size() - 1;
CharacterProperties numChp = (CharacterProperties)StyleSheet.uncompressProperty(((ChpxNode)_onHold.get(size)).getChpx(), std.getCHP(), _stsh);
numChp = (CharacterProperties)StyleSheet.uncompressProperty(lvl._chpx, numChp, _stsh);
String bulletText = getBulletText(lvl, pap);
_listener.listEntry(bulletText, numChp, pap, papx.getStart() - _fcMin, papx.getEnd() - _fcMin);
for (int x = 1; x <= size; x++)
{
characterRun((ChpxNode)_onHold.get(x));
}
| public void | fonts(org.apache.poi.hdf.model.hdftypes.FontTable fontTbl)
| private java.lang.String | getBulletText(org.apache.poi.hdf.model.hdftypes.LVL lvl, org.apache.poi.hdf.model.hdftypes.ParagraphProperties pap)
StringBuffer bulletBuffer = new StringBuffer();
for(int x = 0; x < lvl._xst.length; x++)
{
if(lvl._xst[x] < 9)
{
LVL numLevel = _listTables.getLevel(pap.getIlfo(), lvl._xst[x]);
int num = numLevel._iStartAt;
if(lvl == numLevel)
{
numLevel._iStartAt++;
}
else if(num > 1)
{
num--;
}
bulletBuffer.append(NumberFormatter.getNumber(num, lvl._nfc));
}
else
{
bulletBuffer.append(lvl._xst[x]);
}
}
switch (lvl._ixchFollow)
{
case 0:
bulletBuffer.append('\u0009");
break;
case 1:
bulletBuffer.append(' ");
break;
}
return bulletBuffer.toString();
| private java.lang.String | getTextFromNodes(java.util.ArrayList list, int start, int end)
int size = list.size();
StringBuffer sb = new StringBuffer();
for (int x = 0; x < size; x++)
{
TextPiece piece = (TextPiece)list.get(x);
int charStart = Math.max(start, piece.getStart());
int charEnd = Math.min(end, piece.getEnd());
if(piece.usesUnicode())
{
for (int y = charStart; y < charEnd; y += 2)
{
sb.append((char)LittleEndian.getShort(_mainDocument, y));
}
}
else
{
for (int y = charStart; y < charEnd; y++)
{
sb.append(_mainDocument[y]);
}
}
}
return sb.toString();
| public void | hdrSection(org.apache.poi.hdf.model.hdftypes.SepxNode sepx)
_beginHeaders = true;
_hdrSections.add(sepx);
| public void | lists(org.apache.poi.hdf.model.hdftypes.ListTables listTbl)
_listTables = listTbl;
| public void | mainDocument(byte[] mainDocument)
_mainDocument = mainDocument;
| public void | miscellaneous(int fcMin, int ccpText, int ccpFtn, int fcPlcfhdd, int lcbPlcfhdd)
_fcMin = fcMin;
_ccpText = ccpText;
_ccpFtn = ccpFtn;
_hdrOffset = fcPlcfhdd;
_hdrSize = lcbPlcfhdd;
| public void | paragraph(org.apache.poi.hdf.model.hdftypes.PapxNode papx)
if (_beginHeaders)
{
_hdrParagraphs.add(papx);
}
byte[] bytePapx = papx.getPapx();
int istd = LittleEndian.getShort(bytePapx, 0);
_currentStd = _stsh.getStyleDescription(istd);
ParagraphProperties pap = (ParagraphProperties)StyleSheet.uncompressProperty(bytePapx, _currentStd.getPAP(), _stsh);
if (pap.getFTtp() > 0)
{
TableProperties tap = (TableProperties)StyleSheet.uncompressProperty(bytePapx, new TableProperties(), _stsh);
_listener.tableRowEnd(tap, papx.getStart() - _fcMin, papx.getEnd() - _fcMin);
}
else if (pap.getIlfo() > 0)
{
_holdParagraph = true;
_endHoldIndex = papx.getEnd();
_onHold.add(papx);
}
else
{
_listener.paragraph(pap, papx.getStart() - _fcMin, papx.getEnd() - _fcMin);
}
| public void | styleSheet(org.apache.poi.hdf.model.hdftypes.StyleSheet stsh)
_stsh = stsh;
| public void | tableStream(byte[] tableStream)
_tableStream = tableStream;
| public void | text(org.apache.poi.hdf.model.hdftypes.TextPiece t)
_text.add(t);
|
|