diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index 56024d9fd9..0548dd4490 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -48,12 +48,10 @@ import org.apache.poi.hwpf.usermodel.*; * @author Ryan Ackley */ public class HWPFDocument +// implements Cloneable { - /** OLE stuff*/ - private POIFSFileSystem _filesystem; - /** The FIB*/ - private FileInformationBlock _fib; + protected FileInformationBlock _fib; /** main document stream buffer*/ private byte[] _mainStream; @@ -62,34 +60,34 @@ public class HWPFDocument private byte[] _tableStream; /** data stream buffer*/ - private byte[] _dataStream; + protected byte[] _dataStream; /** Document wide Properties*/ - private DocumentProperties _dop; + protected DocumentProperties _dop; - /** Contains text of the document wrapped in a obfuscated Wod data structure*/ - private ComplexFileTable _cft; + /** Contains text of the document wrapped in a obfuscated Word data + * structure*/ + protected ComplexFileTable _cft; - private TextPieceTable _tpt; + protected TextPieceTable _tpt; /** Contains formatting properties for text*/ - private CHPBinTable _cbt; + protected CHPBinTable _cbt; /** Contains formatting properties for paragraphs*/ - private PAPBinTable _pbt; + protected PAPBinTable _pbt; /** Contains formatting properties for sections.*/ - private SectionTable _st; + protected SectionTable _st; /** Holds styles for this document.*/ - private StyleSheet _ss; + protected StyleSheet _ss; /** Holds fonts for this document.*/ - private FontTable _ft; + protected FontTable _ft; /** Hold list tables */ - private ListTables _lt; - + protected ListTables _lt; /** * This constructor loads a Word document from an InputStream. @@ -101,13 +99,13 @@ public class HWPFDocument public HWPFDocument(InputStream istream) throws IOException { //do Ole stuff - _filesystem = new POIFSFileSystem(istream); + POIFSFileSystem filesystem = new POIFSFileSystem(istream); // read in the main stream. DocumentEntry documentProps = - (DocumentEntry)_filesystem.getRoot().getEntry("WordDocument"); + (DocumentEntry)filesystem.getRoot().getEntry("WordDocument"); _mainStream = new byte[documentProps.getSize()]; - _filesystem.createDocumentInputStream("WordDocument").read(_mainStream); + filesystem.createDocumentInputStream("WordDocument").read(_mainStream); // use the fib to determine the name of the table stream. _fib = new FileInformationBlock(_mainStream); @@ -120,9 +118,9 @@ public class HWPFDocument // read in the table stream. DocumentEntry tableProps = - (DocumentEntry)_filesystem.getRoot().getEntry(name); + (DocumentEntry)filesystem.getRoot().getEntry(name); _tableStream = new byte[tableProps.getSize()]; - _filesystem.createDocumentInputStream(name).read(_tableStream); + filesystem.createDocumentInputStream(name).read(_tableStream); _fib.fillVariableFields(_mainStream, _tableStream); @@ -130,9 +128,9 @@ public class HWPFDocument try { DocumentEntry dataProps = - (DocumentEntry) _filesystem.getRoot().getEntry("Data"); + (DocumentEntry) filesystem.getRoot().getEntry("Data"); _dataStream = new byte[dataProps.getSize()]; - _filesystem.createDocumentInputStream("Data").read(_dataStream); + filesystem.createDocumentInputStream("Data").read(_dataStream); } catch(java.io.FileNotFoundException e) { @@ -431,4 +429,17 @@ public class HWPFDocument t.printStackTrace(); } } + +// public Object clone() +// throws CloneNotSupportedException +// { +// _tpt; +// +// _cbt; +// +// _pbt; +// +// _st; +// +// } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java index 089730815c..0e9096132e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java @@ -1,58 +1,18 @@ -/* - * ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2003 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache POI" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache POI", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ package org.apache.poi.hwpf.model; @@ -76,6 +36,11 @@ public class CHPBinTable /** List of character properties.*/ ArrayList _textRuns = new ArrayList(); + + public CHPBinTable() + { + } + /** * Constructor used to read a binTable in from a Word document. * diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java index 9801bc1ad7..43a7e91ab2 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java @@ -69,6 +69,11 @@ public class ComplexFileTable TextPieceTable _tpt; + public ComplexFileTable() + { + _tpt = new TextPieceTable(); + } + public ComplexFileTable(byte[] documentStream, byte[] tableStream, int offset, int fcMin) throws IOException { //skips through the prms before we reach the piece table. These contain data @@ -110,7 +115,6 @@ public class ComplexFileTable LittleEndian.putInt(numHolder, table.length); tableStream.write(numHolder); tableStream.write(table); - } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java index f99c5b0cf2..ffcd6007e2 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java @@ -73,10 +73,6 @@ public class ListFormatOverrideLevel public ListFormatOverrideLevel(byte[] buf, int offset) { - while(buf[offset] == -1) - { - offset++; - } _iStartAt = LittleEndian.getInt(buf, offset); offset += LittleEndian.INT_SIZE; _info = buf[offset++]; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java index efa3b0c1dc..b621adaa62 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java @@ -112,6 +112,10 @@ public class ListTables int num = lfo.numOverrides(); for (int y = 0; y < num; y++) { + while(tableStream[lfolvlOffset] == -1) + { + lfolvlOffset++; + } ListFormatOverrideLevel lfolvl = new ListFormatOverrideLevel(tableStream, lfolvlOffset); lfo.setOverride(y, lfolvl); lfolvlOffset += lfolvl.getSizeInBytes(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java index 318153b1cd..9464db3c0b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java @@ -1,57 +1,18 @@ -/* - * ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2003 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache POI" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache POI", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ package org.apache.poi.hwpf.model; @@ -69,12 +30,18 @@ import org.apache.poi.util.LittleEndian; * 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. + * + * @author Ryan Ackley */ public class PAPBinTable { ArrayList _paragraphs = new ArrayList(); byte[] _dataStream; + public PAPBinTable() + { + } + public PAPBinTable(byte[] documentStream, byte[] tableStream, byte[] dataStream, int offset, int size, int fcMin) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java index fba9d4500a..ba0fee98fc 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -1,58 +1,18 @@ -/* - * ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2003 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache POI" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache POI", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ package org.apache.poi.hwpf.model; @@ -63,12 +23,19 @@ import java.io.IOException; import org.apache.poi.util.LittleEndian; import org.apache.poi.hwpf.model.io.*; +/** + * @author Ryan Ackley + */ public class SectionTable { private static final int SED_SIZE = 12; private ArrayList _sections = new ArrayList(); + public SectionTable() + { + } + public SectionTable(byte[] documentStream, byte[] tableStream, int offset, int size, int fcMin) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java index 2d13d4c54f..9febfa36e5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java @@ -1,57 +1,18 @@ -/* - * ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2003 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache POI" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache POI", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ package org.apache.poi.hwpf.model; @@ -67,13 +28,19 @@ import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.hwpf.model.io.*; - +/** + * @author Ryan Ackley + */ public class TextPieceTable { ArrayList _textPieces = new ArrayList(); //int _multiple; int _cpMin; + public TextPieceTable() + { + } + public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset, int size, int fcMin) throws UnsupportedEncodingException @@ -236,5 +203,4 @@ public class TextPieceTable } return false; } - } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java index 64642c3040..ed5b64c8bc 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -444,7 +444,7 @@ public class ParagraphSprmUncompressor for (int x = 0; x < delSize; x++) { tabMap.remove(new Integer(LittleEndian.getInt(grpprl, offset))); - offset += LittleEndian.INT_SIZE;; + offset += LittleEndian.SHORT_SIZE; } int addSize = grpprl[offset++]; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java index 78a8b97345..0028e26e52 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java @@ -268,7 +268,7 @@ public class CharacterProperties return isFDStrike(); } - public void setDoubleStrikethrough(boolean dstrike) + public void setDoubleStrikeThrough(boolean dstrike) { super.setFDStrike(dstrike); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index ed991e1c65..29360ec94b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -662,15 +662,15 @@ public class Range r.initAll(); int tableEnd = r._parEnd; - if (r._parStart != 0 && ((Paragraph)r._paragraphs.get(r._parStart - 1)).isInTable()) + if (r._parStart != 0 && getParagraph(r._parStart - 1).isInTable()) { throw new IllegalArgumentException("This paragraph is not the first one in the table"); } - int limit = r._paragraphs.size(); + int limit = _paragraphs.size(); for (; tableEnd < limit; tableEnd++) { - if (!((Paragraph)r._paragraphs.get(tableEnd)).isInTable()) + if (!getParagraph(tableEnd).isInTable()) { break; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java index 9b67897f94..ec37d7c475 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java @@ -1,16 +1,90 @@ package org.apache.poi.hwpf.usermodel; - public class TableCell extends Range { - int _levelNum; + private int _levelNum; + private TableCellDescriptor _tcd; + private int _leftEdge; + private int _width; - public TableCell(int startIdx, int endIdx, TableRow parent, int levelNum, TableCellDescriptor tcd) + public TableCell(int startIdx, int endIdx, TableRow parent, int levelNum, TableCellDescriptor tcd, int leftEdge, int width) { super(startIdx, endIdx, Range.TYPE_PARAGRAPH, parent); + _tcd = tcd; + _leftEdge = leftEdge; + _width = width; _levelNum = levelNum; } + public boolean isFirstMerged() + { + return _tcd.isFFirstMerged(); + } + + public boolean isMerged() + { + return _tcd.isFMerged(); + } + + public boolean isVertical() + { + return _tcd.isFVertical(); + } + + public boolean isBackward() + { + return _tcd.isFBackward(); + } + + public boolean isRotateFont() + { + return _tcd.isFRotateFont(); + } + + public boolean isVerticallyMerged() + { + return _tcd.isFVertMerge(); + } + + public boolean isFirstVerticallyMerged() + { + return _tcd.isFVertRestart(); + } + + public byte getVertAlign() + { + return _tcd.getVertAlign(); + } + + public BorderCode getBrcTop() + { + return _tcd.getBrcTop(); + } + + public BorderCode getBrcBottom() + { + return _tcd.getBrcBottom(); + } + + public BorderCode getBrcLeft() + { + return _tcd.getBrcLeft(); + } + + public BorderCode getBrcRight() + { + return _tcd.getBrcRight(); + } + + public int getLeftEdge() // twips + { + return _leftEdge; + } + + public int getWidth() // twips + { + return _width; + } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java index bc7f0e6775..24817d8cdf 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java @@ -1,6 +1,5 @@ package org.apache.poi.hwpf.usermodel; - import org.apache.poi.hwpf.sprm.TableSprmUncompressor; import org.apache.poi.hwpf.sprm.SprmBuffer; @@ -16,8 +15,8 @@ public class TableRow private final static short SPRM_DYAROWHEIGHT = (short)0x9407; int _levelNum; - TableProperties _tprops; - TableCell[] _cells; + private TableProperties _tprops; + private TableCell[] _cells; public TableRow(int startIdx, int endIdx, Table parent, int levelNum) { @@ -28,17 +27,26 @@ public class TableRow _cells = new TableCell[_tprops.getItcMac()]; int start = 0; - int cellIndex = 0; - for (int x = 0; x < numParagraphs(); x++) + int end = 0; + + for (int cellIndex = 0; cellIndex < _cells.length; cellIndex++) { - Paragraph p = getParagraph(x); + Paragraph p = getParagraph(start); String s = p.text(); - if ((levelNum == 1 && s.charAt(s.length()-1) == TABLE_CELL_MARK) || - p.isEmbeddedCellMark() && p.getTableLevel() == levelNum) + while (! ( (levelNum == 1 && s.charAt(s.length() - 1) == TABLE_CELL_MARK) || + p.isEmbeddedCellMark() && p.getTableLevel() == levelNum)) { - _cells[cellIndex] = new TableCell(start, x+1, this, levelNum, _tprops.getRgtc()[cellIndex]); + end++; + p = getParagraph(end); + s = p.text(); } + _cells[cellIndex] = new TableCell(start, end, this, levelNum, + _tprops.getRgtc()[cellIndex], + _tprops.getRgdxaCenter()[cellIndex], + _tprops.getRgdxaCenter()[cellIndex+1]-_tprops.getRgdxaCenter()[cellIndex]); + end++; + start = end; } } @@ -97,4 +105,13 @@ public class TableRow _papx.updateSprm(SPRM_FTABLEHEADER, (byte)(tableHeader ? 1 : 0)); } + public int numCells() + { + return _cells.length; + } + + public TableCell getCell(int index) + { + return _cells[index]; + } }