From: Said Ryan Ackley Date: Wed, 12 Nov 2003 01:33:58 +0000 (+0000) Subject: latest changes X-Git-Tag: PERF_BEFORE_MERGE~89 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1456812faf05cbf5891055e014721c2005cb7278;p=poi.git latest changes git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353446 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPBinTable.java index a40d71939a..cb1016ee56 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPBinTable.java @@ -109,6 +109,58 @@ public class CHPBinTable } } + public void adjustForDelete(int listIndex, int offset, int length) + { + int size = _textRuns.size(); + int endMark = offset + length; + int endIndex = listIndex; + + CHPX chpx = (CHPX)_textRuns.get(endIndex); + while (chpx.getEnd() < endMark) + { + chpx = (CHPX)_textRuns.get(++endIndex); + } + if (listIndex == endIndex) + { + chpx = (CHPX)_textRuns.get(endIndex); + chpx.setEnd((chpx.getEnd() - endMark) + offset); + } + else + { + chpx = (CHPX)_textRuns.get(listIndex); + chpx.setEnd(offset); + for (int x = listIndex + 1; x < endIndex; x++) + { + chpx = (CHPX)_textRuns.get(x); + chpx.setStart(offset); + chpx.setEnd(offset); + } + chpx = (CHPX)_textRuns.get(endIndex); + chpx.setEnd((chpx.getEnd() - endMark) + offset); + } + + for (int x = endIndex + 1; x < size; x++) + { + chpx = (CHPX)_textRuns.get(x); + chpx.setStart(chpx.getStart() - length); + chpx.setEnd(chpx.getEnd() - length); + } + } + + public void adjustForInsert(int listIndex, int length) + { + int size = _textRuns.size(); + CHPX chpx = (CHPX)_textRuns.get(listIndex); + chpx.setEnd(chpx.getEnd() + length); + + for (int x = listIndex + 1; x < size; x++) + { + chpx = (CHPX)_textRuns.get(x); + chpx.setStart(chpx.getStart() + length); + chpx.setEnd(chpx.getEnd() + length); + } + } + public List getTextRuns() { return _textRuns; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPX.java index 5543148ead..4e27728750 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPX.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPX.java @@ -55,6 +55,7 @@ package org.apache.poi.hwpf.model.hdftypes; +import org.apache.poi.hwpf.sprm.SprmBuffer; /** * Comment me @@ -67,12 +68,18 @@ public class CHPX extends PropertyNode public CHPX(int fcStart, int fcEnd, byte[] grpprl) { - super(fcStart, fcEnd, grpprl); + super(fcStart, fcEnd, new SprmBuffer(grpprl)); } public byte[] getGrpprl() { - return super.getBuf(); + return ((SprmBuffer)_buf).toByteArray(); } + public byte[] getBuf() + { + return getGrpprl(); + } + + } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPBinTable.java index 92b4698f5b..ae9651231c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPBinTable.java @@ -93,6 +93,60 @@ public class PAPBinTable } } + 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 ArrayList getParagraphs() { return _paragraphs; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPX.java index cc67c4400e..0d76518464 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPX.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPX.java @@ -55,6 +55,10 @@ package org.apache.poi.hwpf.model.hdftypes; + +import org.apache.poi.hwpf.usermodel.Paragraph; +import org.apache.poi.hwpf.sprm.SprmBuffer; + /** * Comment me * @@ -68,7 +72,7 @@ public class PAPX extends PropertyNode public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe) { - super(fcStart, fcEnd, papx); + super(fcStart, fcEnd, new SprmBuffer(papx)); _phe = phe; } @@ -79,7 +83,12 @@ public class PAPX extends PropertyNode public byte[] getGrpprl() { - return super.getBuf(); + return ((SprmBuffer)_buf).toByteArray(); + } + + public byte[] getBuf() + { + return getGrpprl(); } public boolean equals(Object o) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java index b070d833d5..8ff76816da 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java @@ -66,21 +66,21 @@ import org.apache.poi.hwpf.sprm.SprmBuffer; */ public class PropertyNode implements Comparable { - private SprmBuffer _buf; + protected Object _buf; private int _cpStart; private int _cpEnd; - private SoftReference _propCache; + protected SoftReference _propCache; /** * @param fcStart The start of the text for this property. * @param fcEnd The end of the text for this property. * @param grpprl The property description in compressed form. */ - public PropertyNode(int fcStart, int fcEnd, byte[] buf) + public PropertyNode(int fcStart, int fcEnd, Object buf) { _cpStart = fcStart; _cpEnd = fcEnd; - _buf = new SprmBuffer(buf); + _buf = buf; } /** @@ -90,6 +90,12 @@ public class PropertyNode implements Comparable { return _cpStart; } + + void setStart(int start) + { + _cpStart = start; + } + /** * @retrun The offset of the end of this property's text. */ @@ -97,17 +103,23 @@ public class PropertyNode implements Comparable { return _cpEnd; } + + void setEnd(int end) + { + _cpEnd = end; + } + /** * @return This property's property in copmpressed form. */ public byte[] getBuf() { - return _buf.toByteArray(); + return ((byte[])_buf); } public boolean equals(Object o) { - byte[] buf = _buf.toByteArray(); + byte[] buf = getBuf(); if (((PropertyNode)o).getStart() == _cpStart && ((PropertyNode)o).getEnd() == _cpEnd) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SectionTable.java index 85962f7ced..50dba85fda 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SectionTable.java @@ -86,7 +86,7 @@ public class SectionTable // check for the optimization if (fileOffset == 0xffffffff) { - _sections.add(new SEPX(sed, node.getStart() - fcMin, node.getEnd() - fcMin, new byte[0])); + _sections.add(new SEPX(sed, node.getStart(), node.getEnd(), new byte[0])); } else { @@ -95,11 +95,26 @@ public class SectionTable byte[] buf = new byte[sepxSize]; fileOffset += LittleEndian.SHORT_SIZE; System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); - _sections.add(new SEPX(sed, node.getStart() - fcMin, node.getEnd() - fcMin, buf)); + _sections.add(new SEPX(sed, node.getStart(), node.getEnd(), buf)); } } } + public void adjustForInsert(int listIndex, int length) + { + int size = _sections.size(); + SEPX sepx = (SEPX)_sections.get(listIndex); + sepx.setEnd(sepx.getEnd() + length); + + for (int x = listIndex + 1; x < size; x++) + { + sepx = (SEPX)_sections.get(x); + sepx.setStart(sepx.getStart() + length); + sepx.setEnd(sepx.getEnd() + length); + } + } + + public ArrayList getSections() { return _sections; @@ -133,7 +148,7 @@ public class SectionTable sed.setFc(offset); // add the section descriptor bytes to the PlexOfCps. - PropertyNode property = new PropertyNode(sepx.getStart() - fcMin, sepx.getEnd() - fcMin, sed.toByteArray()); + PropertyNode property = new PropertyNode(sepx.getStart(), sepx.getEnd(), sed.toByteArray()); plex.addProperty(property); offset = docStream.getOffset(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPiece.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPiece.java index 16df6d2d35..4c9db04671 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPiece.java @@ -55,7 +55,7 @@ package org.apache.poi.hwpf.model.hdftypes; - +import java.io.UnsupportedEncodingException; /** * Lightweight representation of a text piece. * @@ -75,8 +75,9 @@ public class TextPiece extends PropertyNode implements Comparable * @param unicode true if this text is unicode. */ public TextPiece(int start, int end, byte[] text, PieceDescriptor pd) + throws UnsupportedEncodingException { - super(start, end, text); + super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252"))); _usesUnicode = pd.isUnicode(); _length = end - start; _pd = pd; @@ -94,6 +95,27 @@ public class TextPiece extends PropertyNode implements Comparable return _pd; } + public StringBuffer getStringBuffer() + { + return (StringBuffer)_buf; + } + + public byte[] getBuf() + { + try + { + return ((StringBuffer)_buf).toString().getBytes(_usesUnicode ? + "UTF-16LE" : "Cp1252"); + } + catch (UnsupportedEncodingException ignore) + { + // shouldn't ever happen considering we wouldn't have been able to + // create the StringBuffer w/o getting this exception + return ((StringBuffer)_buf).toString().getBytes(); + } + + } + public boolean equals(Object o) { if (super.equals(o)) @@ -103,4 +125,5 @@ public class TextPiece extends PropertyNode implements Comparable } return false; } + } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPieceTable.java index db2ac44efc..c6ccb1c3ad 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPieceTable.java @@ -69,6 +69,7 @@ public class TextPieceTable { ArrayList _textPieces = new ArrayList(); int _multiple; + int _cpMin; public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset, int size, int fcMin) @@ -94,6 +95,7 @@ public class TextPieceTable } } + _cpMin = pieces[0].getFilePosition() - fcMin; // using the PieceDescriptors, build our list of TextPieces. for (int x = 0; x < pieces.length; x++) { @@ -115,6 +117,11 @@ public class TextPieceTable } } + public int getCpMin() + { + return _cpMin; + } + public List getTextPieces() { return _textPieces; @@ -151,6 +158,24 @@ public class TextPieceTable } + + public int adjustForInsert(int listIndex, int length) + { + int size = _textPieces.size(); + + TextPiece tp = (TextPiece)_textPieces.get(listIndex); + length = length * (tp.usesUnicode() ? 2 : 1); + tp.setEnd(tp.getEnd() + length); + for (int x = listIndex + 1; x < size; x++) + { + tp = (TextPiece)_textPieces.get(x); + tp.setStart(tp.getStart() + length); + tp.setEnd(tp.getEnd() + length); + } + return length; + } + + public boolean equals(Object o) { TextPieceTable tpt = (TextPieceTable)o;