package org.apache.poi.hdf.extractor;
+
import org.apache.poi.hdf.extractor.util.*;
import org.apache.poi.hdf.extractor.data.*;
import java.util.*;
//import javax.swing.text.StyleContext;
import java.awt.*;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.POIFSDocument;
+import org.apache.poi.poifs.filesystem.Entry;
+
+import org.apache.poi.util.LittleEndian;
+
/**
* Comment me
*
* @author Ryan Ackley
*/
-public class WordDocument extends NewOleFile
+public class WordDocument
{
byte[] _header;
StringBuffer _bodyBuffer = new StringBuffer();
StringBuffer _cellBuffer;
- Vector _cells;
- Vector _table;
+ ArrayList _cells;
+ ArrayList _table;
byte[] _plcfHdd;
int _fcMin;
int _ccpFtn;
+ private InputStream istream;
+ private POIFSFileSystem filesystem;
+
private static int HEADER_EVEN_INDEX = 0;
private static int HEADER_ODD_INDEX = 1;
private static int FOOTER_EVEN_INDEX = 2;
{
int textStart = Utils.convertBytesToInt(_header, 0x18);
int textEnd = Utils.convertBytesToInt(_header, 0x1c);
- Vector textPieces = findProperties(textStart, textEnd, _text.root);
+ ArrayList textPieces = findProperties(textStart, textEnd, _text.root);
int size = textPieces.size();
for(int x = 0; x < size; x++)
}
public WordDocument(String fileName, String mode) throws IOException
{
- super(fileName, mode);
-
+// super(fileName, mode);
+
+
+ istream = new FileInputStream(fileName);
+ filesystem = new POIFSFileSystem(istream);
+
readFIB();
- Vector sections = findProperties(_fcMin, _fcMin + _ccpText, _sectionTable.root);
+ ArrayList sections = findProperties(_fcMin, _fcMin + _ccpText, _sectionTable.root);
int size = sections.size();
for(int x = 0; x < size; x++)
SEP sep = (SEP)StyleSheet.uncompressProperty(node.getSepx(), new SEP(), _styleSheet);
writeSection(Math.max(_fcMin, start), Math.min(_fcMin + _ccpText, end), sep, _text, _paragraphTable, _characterTable, _styleSheet);
}
+
+ istream.close();
}
private void readFIB() throws IOException
{
- PropertySet headerProps = (PropertySet)_propertySetsHT.get("WordDocument");
-
- if(headerProps.getSize() >= 4096)
- {
- _header = createBufferFromBBD(headerProps.getStartBlock());
- }
- int info = Utils.convertBytesToShort(_header, 0xa);
+ //PropertySet headerProps = (PropertySet)_propertySetsHT.get("WordDocument");
+ Entry headerProps = filesystem.getRoot().getEntry("WordDocument");
+
+ // if(headerProps.getSize() >= 4096)
+ // {
+ //_header = createBufferFromBBD(headerProps.getStartBlock());
+ _header = new byte[4096];
+ filesystem.createDocumentInputStream("WordDocument").read(_header);
+ // }
+ int info = LittleEndian.getShort(_header, 0xa);
_fcMin = Utils.convertBytesToInt(_header, 0x18);
_ccpText = Utils.convertBytesToInt(_header, 0x4c);
// return false;
//}
- PropertySet tableProps = null;
+ String tablename=null;
+ Entry tableProps = null;
if(useTable1)
{
- tableProps = (PropertySet)_propertySetsHT.get("1Table");
+ tableProps = filesystem.getRoot().getEntry("1Table");
+ tablename="1Table";
}
else
{
- tableProps = (PropertySet)_propertySetsHT.get("0Table");
+ tableProps = filesystem.getRoot().getEntry("0Table");
+ tablename="0Table";
}
//get table properties
- int size = tableProps.getSize();
- int startBlock = tableProps.getStartBlock();
+ //int size = tableProps.getSize();
+ int size = 4096; //hardcoded -- need to learn more about new POIFS api..??
+ //int startBlock = tableProps.getStartBlock();
- byte[] tableStream = null;
+ byte[] tableStream = new byte[size];
//big enough to use BBD?
if(size >= 4096)
{
- tableStream = createBufferFromBBD(startBlock);
+ filesystem.createDocumentInputStream(tablename).read(tableStream); //createBufferFromBBD(startBlock);
}
initDocProperties(tableStream);
initPclfHdd(tableStream);
private int calculateHeaderHeight(int start, int end, int pageWidth)
{
- Vector paragraphs = findProperties(start, end, _paragraphTable.root);
+ ArrayList paragraphs = findProperties(start, end, _paragraphTable.root);
int size = paragraphs.size();
- Vector lineHeights = new Vector();
+ ArrayList lineHeights = new ArrayList();
//StyleContext context = StyleContext.getDefaultStyleContext();
for(int x = 0; x < size; x++)
int lineWidth = 0;
int maxHeight = 0;
- Vector textRuns = findProperties(parStart, parEnd, _characterTable.root);
+ ArrayList textRuns = findProperties(parStart, parEnd, _characterTable.root);
int charSize = textRuns.size();
//StringBuffer lineBuffer = new StringBuffer();
int charStart = Math.max(parStart, charNode.getStart());
int charEnd = Math.min(parEnd, charNode.getEnd());
- Vector text = findProperties(charStart, charEnd, _text.root);
+ ArrayList text = findProperties(charStart, charEnd, _text.root);
int textSize = text.size();
StringBuffer buf = new StringBuffer();
{
BTreeSet.BTreeNode root = paragraphTable.root;
- Vector pars = findProperties(start, end, root);
+ ArrayList pars = findProperties(start, end, root);
//root = characterTable.root;
int size = pars.size();
{
if(_table == null)
{
- _table = new Vector();
+ _table = new ArrayList();
}
TAP tap = (TAP)StyleSheet.uncompressProperty(papx, new TAP(), _styleSheet);
TableRow nextRow = new TableRow(_cells, tap);
addParagraphProperties(pap, blockBuffer);
- Vector charRuns = findProperties(Math.max(currentNode.getStart(), start),
+ ArrayList charRuns = findProperties(Math.max(currentNode.getStart(), start),
Math.min(currentNode.getEnd(), end),
_characterTable.root);
int len = charRuns.size();
int charStart = Math.max(charNode.getStart(), currentNode.getStart());
int charEnd = Math.min(charNode.getEnd(), currentNode.getEnd());
- Vector textRuns = findProperties(charStart, charEnd, _text.root);
+ ArrayList textRuns = findProperties(charStart, charEnd, _text.root);
int textRunLen = textRuns.size();
for(int y = 0; y < textRunLen; y++)
{
{
addParagraphProperties(pap, blockBuffer);
- Vector charRuns = findProperties(Math.max(currentNode.getStart(), start),
+ ArrayList charRuns = findProperties(Math.max(currentNode.getStart(), start),
Math.min(currentNode.getEnd(), end),
_characterTable.root);
int len = charRuns.size();
int charStart = Math.max(charNode.getStart(), currentNode.getStart());
int charEnd = Math.min(charNode.getEnd(), currentNode.getEnd());
- Vector textRuns = findProperties(charStart, charEnd, _text.root);
+ ArrayList textRuns = findProperties(charStart, charEnd, _text.root);
int textRunLen = textRuns.size();
for(int y = 0; y < textRunLen; y++)
{
if(_cells == null)
{
- _cells = new Vector();
+ _cells = new ArrayList();
}
closeLine(_cellBuffer);
closeBlock(_cellBuffer);
/**
* finds all chpx's that are between start and end
*/
- private Vector findProperties(int start, int end, BTreeSet.BTreeNode root)
+ private ArrayList findProperties(int start, int end, BTreeSet.BTreeNode root)
{
- Vector results = new Vector();
+ ArrayList results = new ArrayList();
BTreeSet.Entry[] entries = root.entries;
for(int x = 0; x < entries.length; x++)
{
if(child != null)
{
- Vector beforeItems = findProperties(start, end, child);
+ ArrayList beforeItems = findProperties(start, end, child);
results.addAll(beforeItems);
}
results.add(xNode);
{
if(child != null)
{
- Vector beforeItems = findProperties(start, end, child);
+ ArrayList beforeItems = findProperties(start, end, child);
results.addAll(beforeItems);
}
break;
}
else if(child != null)
{
- Vector afterItems = findProperties(start, end, child);
+ ArrayList afterItems = findProperties(start, end, child);
results.addAll(afterItems);
}
}
{
buf.append("</fo:block>\r\n");
}
- private Vector findPAPProperties(int start, int end, BTreeSet.BTreeNode root)
+ private ArrayList findPAPProperties(int start, int end, BTreeSet.BTreeNode root)
{
- Vector results = new Vector();
+ ArrayList results = new ArrayList();
BTreeSet.Entry[] entries = root.entries;
for(int x = 0; x < entries.length; x++)
{
if(child != null)
{
- Vector beforeItems = findPAPProperties(start, end, child);
+ ArrayList beforeItems = findPAPProperties(start, end, child);
results.addAll(beforeItems);
}
results.add(papxNode);
{
if(child != null)
{
- Vector beforeItems = findPAPProperties(start, end, child);
+ ArrayList beforeItems = findPAPProperties(start, end, child);
results.addAll(beforeItems);
}
break;
}
else if(child != null)
{
- Vector afterItems = findPAPProperties(start, end, child);
+ ArrayList afterItems = findPAPProperties(start, end, child);
results.addAll(afterItems);
}
}
_fonts = new FontTable(fontTable);
}
- private byte[] createBufferFromBBD(int startBlock) throws IOException
- {
-
- int[] blockChain = readChain(_big_block_depot, startBlock);
- byte[] streamBuffer = new byte[512 * blockChain.length];
-
-
- for(int x = 0; x < blockChain.length; x++)
- {
- byte[] bigBlock = new byte[512];
- seek((blockChain[x] + 1) * 512);
- read(bigBlock);
- System.arraycopy(bigBlock, 0, streamBuffer, x * 512, 512);
- }
- return streamBuffer;
-
- }
+// private byte[] createBufferFromBBD(int startBlock) throws IOException
+// {
+//
+// int[] blockChain = readChain(_big_block_depot, startBlock);
+// byte[] streamBuffer = new byte[512 * blockChain.length];
+//
+//
+// for(int x = 0; x < blockChain.length; x++)
+// {
+// byte[] bigBlock = new byte[512];
+// seek((blockChain[x] + 1) * 512);
+// read(bigBlock);
+// System.arraycopy(bigBlock, 0, streamBuffer, x * 512, 512);
+// }
+// return streamBuffer;
+//
+// }
private void overrideCellBorder(int row, int col, int height,
int width, TC tc, TAP tap)
{
StringBuffer rowBuffer = tableBodyBuffer;
TableRow row = (TableRow)_table.get(x);
TAP tap = row.getTAP();
- Vector cells = row.getCells();
+ ArrayList cells = row.getCells();
if(tap._fTableHeader)
{