From 24ed675b037802bf710e2092f265814935aeba78 Mon Sep 17 00:00:00 2001 From: Said Ryan Ackley Date: Mon, 19 Apr 2004 23:49:49 +0000 Subject: [PATCH] git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353551 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/apache/poi/hwpf/HWPFDocument.java | 25 ++++++++++++++++--- .../apache/poi/hwpf/model/CHPBinTable.java | 2 +- .../poi/hwpf/model/CHPFormattedDiskPage.java | 3 +-- .../poi/hwpf/model/ComplexFileTable.java | 2 +- .../hwpf/model/ListFormatOverrideLevel.java | 15 ++++++++--- .../apache/poi/hwpf/model/PAPBinTable.java | 2 +- .../apache/poi/hwpf/model/PropertyNode.java | 13 +++++++--- .../apache/poi/hwpf/model/SectionTable.java | 4 +-- .../org/apache/poi/hwpf/model/StyleSheet.java | 3 ++- .../org/apache/poi/hwpf/model/TextPiece.java | 5 ++++ .../apache/poi/hwpf/model/TextPieceTable.java | 2 +- .../poi/hwpf/model/io/HWPFFileSystem.java | 1 + .../org/apache/poi/hwpf/usermodel/Range.java | 2 +- .../poi/hwpf/model/TestCHPBinTable.java | 1 - 14 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index f34847306b..36baa95528 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -89,6 +89,11 @@ public class HWPFDocument /** Hold list tables */ protected ListTables _lt; + protected HWPFDocument() + { + + } + /** * This constructor loads a Word document from an InputStream. * @@ -181,11 +186,21 @@ public class HWPFDocument return _ss; } + public FileInformationBlock getFileInformationBlock() + { + return _fib; + } + + public DocumentProperties getDocProperties() + { + return _dop; + } + public Range getRange() { // hack to get the ending cp of the document, Have to revisit this. - java.util.List paragraphs = _pbt.getParagraphs(); - PAPX p = (PAPX)paragraphs.get(paragraphs.size() - 1); + java.util.List text = _tpt.getTextPieces(); + PropertyNode p = (PropertyNode)text.get(text.size() - 1); return new Range(0, p.getEnd(), this); } @@ -226,7 +241,7 @@ public class HWPFDocument HWPFFileSystem docSys = new HWPFFileSystem(); HWPFOutputStream mainStream = docSys.getStream("WordDocument"); HWPFOutputStream tableStream = docSys.getStream("1Table"); - HWPFOutputStream dataStream = docSys.getStream("Data"); + //HWPFOutputStream dataStream = docSys.getStream("Data"); int tableOffset = 0; // FileInformationBlock fib = (FileInformationBlock)_fib.clone(); @@ -332,6 +347,10 @@ public class HWPFDocument } byte[] dataBuf = _dataStream; + if (dataBuf == null) + { + dataBuf = new byte[4096]; + } if (dataBuf.length < 4096) { byte[] tempBuf = new byte[4096]; 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 0e9096132e..6ef0418a0d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java @@ -34,7 +34,7 @@ import org.apache.poi.hwpf.sprm.SprmBuffer; public class CHPBinTable { /** List of character properties.*/ - ArrayList _textRuns = new ArrayList(); + protected ArrayList _textRuns = new ArrayList(); public CHPBinTable() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java index fa0675fb0c..2e645c93c6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java @@ -114,7 +114,7 @@ public class CHPFormattedDiskPage extends FormattedDiskPage int fcOffset = 0; // total size is currently the size of one FC - int totalSize = FC_SIZE + 1; + int totalSize = FC_SIZE + 2; int index = 0; for (; index < size; index++) @@ -165,7 +165,6 @@ public class CHPFormattedDiskPage extends FormattedDiskPage buf[grpprlOffset] = (byte)grpprl.length; System.arraycopy(grpprl, 0, buf, grpprlOffset + 1, grpprl.length); - offsetOffset += 1; fcOffset += FC_SIZE; } 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 4ed8a89b92..d1405f3ac2 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java @@ -30,7 +30,7 @@ public class ComplexFileTable private static final byte GRPPRL_TYPE = 1; private static final byte TEXT_PIECE_TABLE_TYPE = 2; - TextPieceTable _tpt; + protected TextPieceTable _tpt; public ComplexFileTable() { 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 6304084416..65acf13a06 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java @@ -80,10 +80,19 @@ public class ListFormatOverrideLevel { return false; } - ListFormatOverrideLevel lfolvl = (ListFormatOverrideLevel)obj; - return lfolvl._iStartAt == _iStartAt && lfolvl._info == _info && - lfolvl._lvl.equals(_lvl) && Arrays.equals(lfolvl._reserved, _reserved); + boolean lvlEquality = false; + if (_lvl != null) + { + lvlEquality = _lvl.equals(lfolvl._lvl); + } + else + { + lvlEquality = lfolvl._lvl == null; + } + + return lvlEquality && lfolvl._iStartAt == _iStartAt && lfolvl._info == _info && + Arrays.equals(lfolvl._reserved, _reserved); } public byte[] toByteArray() 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 9464db3c0b..f5b5586e16 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java @@ -35,7 +35,7 @@ import org.apache.poi.util.LittleEndian; */ public class PAPBinTable { - ArrayList _paragraphs = new ArrayList(); + protected ArrayList _paragraphs = new ArrayList(); byte[] _dataStream; public PAPBinTable() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java index 3b412f9b73..9ebd5ed91f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java @@ -28,7 +28,7 @@ import org.apache.poi.hwpf.sprm.SprmBuffer; * * @author Ryan Ackley */ -public abstract class PropertyNode implements Comparable +public abstract class PropertyNode implements Comparable, Cloneable { protected Object _buf; private int _cpStart; @@ -56,7 +56,7 @@ public abstract class PropertyNode implements Comparable return _cpStart; } - void setStart(int start) + public void setStart(int start) { _cpStart = start; } @@ -69,7 +69,7 @@ public abstract class PropertyNode implements Comparable return _cpEnd; } - void setEnd(int end) + public void setEnd(int end) { _cpEnd = end; } @@ -118,6 +118,13 @@ public abstract class PropertyNode implements Comparable } return false; } + + public Object clone() + throws CloneNotSupportedException + { + return super.clone(); + } + /** * Used for sorting in collections. */ 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 89028b1822..01f698cb16 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -31,8 +31,8 @@ public class SectionTable { private static final int SED_SIZE = 12; - private ArrayList _sections = new ArrayList(); - private List _text; + protected ArrayList _sections = new ArrayList(); + protected List _text; public SectionTable() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java index e4969a2d70..602931f30e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java @@ -159,7 +159,8 @@ public class StyleSheet implements HDFType { byte[] std = _styleDescriptions[x].toByteArray(); - LittleEndian.putShort(sizeHolder, (short)(std.length)); + // adjust the size so it is always on a word boundary + LittleEndian.putShort(sizeHolder, (short)((std.length) + (std.length % 2))); out.write(sizeHolder); out.write(std); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java index e1a856a444..a9a3f1fb0d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java @@ -64,6 +64,11 @@ public class TextPiece extends PropertyNode implements Comparable return (StringBuffer)_buf; } + public void setStringBuffer(StringBuffer buf) + { + _buf = buf; + } + public byte[] getRawBytes() { try 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 9febfa36e5..db9f27511c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java @@ -33,7 +33,7 @@ import org.apache.poi.hwpf.model.io.*; */ public class TextPieceTable { - ArrayList _textPieces = new ArrayList(); + protected ArrayList _textPieces = new ArrayList(); //int _multiple; int _cpMin; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFFileSystem.java b/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFFileSystem.java index 1458019071..d7dadcfb2e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFFileSystem.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFFileSystem.java @@ -38,6 +38,7 @@ public class HWPFFileSystem { _streams.put("WordDocument", new HWPFOutputStream()); _streams.put("1Table", new HWPFOutputStream()); + _streams.put("Data", new HWPFOutputStream()); } public HWPFOutputStream getStream(String name) 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 ad7259cc5d..a13931aa3f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -719,7 +719,7 @@ public class Range /** * loads all of the list indexes. */ - private void initAll() + protected void initAll() { initText(); initCharacterRuns(); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java index b8bcfabaf1..65256a6175 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java @@ -68,7 +68,6 @@ public class TestCHPBinTable { PropertyNode oldNode = (PropertyNode)oldTextRuns.get(x); PropertyNode newNode = (PropertyNode)newTextRuns.get(x); - assertTrue(oldNode.equals(newNode)); } -- 2.39.5