You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by sa...@apache.org on 2003/11/12 02:33:59 UTC
cvs commit: jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes CHPBinTable.java CHPX.java PAPBinTable.java PAPX.java PropertyNode.java SectionTable.java TextPieceTable.java TextPiece.java
sackley 2003/11/11 17:33:59
Modified: src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes
CHPBinTable.java CHPX.java PAPBinTable.java
PAPX.java PropertyNode.java SectionTable.java
TextPieceTable.java TextPiece.java
Log:
latest changes
Revision Changes Path
1.6 +52 -0 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPBinTable.java
Index: CHPBinTable.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPBinTable.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CHPBinTable.java 10 Nov 2003 11:48:55 -0000 1.5
+++ CHPBinTable.java 12 Nov 2003 01:33:59 -0000 1.6
@@ -109,6 +109,58 @@
}
}
+ 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;
1.3 +9 -2 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPX.java
Index: CHPX.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPX.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CHPX.java 10 Nov 2003 11:49:02 -0000 1.2
+++ CHPX.java 12 Nov 2003 01:33:59 -0000 1.3
@@ -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 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();
+ }
+
}
1.6 +54 -0 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPBinTable.java
Index: PAPBinTable.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPBinTable.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PAPBinTable.java 15 Jul 2003 03:22:53 -0000 1.5
+++ PAPBinTable.java 12 Nov 2003 01:33:59 -0000 1.6
@@ -93,6 +93,60 @@
}
}
+ 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;
1.4 +11 -2 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPX.java
Index: PAPX.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPX.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PAPX.java 10 Nov 2003 11:50:16 -0000 1.3
+++ PAPX.java 12 Nov 2003 01:33:59 -0000 1.4
@@ -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 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 byte[] getGrpprl()
{
- return super.getBuf();
+ return ((SprmBuffer)_buf).toByteArray();
+ }
+
+ public byte[] getBuf()
+ {
+ return getGrpprl();
}
public boolean equals(Object o)
1.5 +18 -6 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java
Index: PropertyNode.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PropertyNode.java 10 Nov 2003 11:50:32 -0000 1.4
+++ PropertyNode.java 12 Nov 2003 01:33:59 -0000 1.5
@@ -66,21 +66,21 @@
*/
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 @@
{
return _cpStart;
}
+
+ void setStart(int start)
+ {
+ _cpStart = start;
+ }
+
/**
* @retrun The offset of the end of this property's text.
*/
@@ -97,17 +103,23 @@
{
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)
{
1.5 +18 -3 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SectionTable.java
Index: SectionTable.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SectionTable.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SectionTable.java 9 Jul 2003 01:01:27 -0000 1.4
+++ SectionTable.java 12 Nov 2003 01:33:59 -0000 1.5
@@ -86,7 +86,7 @@
// 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 @@
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 @@
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();
1.5 +25 -0 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPieceTable.java
Index: TextPieceTable.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPieceTable.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TextPieceTable.java 10 Nov 2003 11:51:14 -0000 1.4
+++ TextPieceTable.java 12 Nov 2003 01:33:59 -0000 1.5
@@ -69,6 +69,7 @@
{
ArrayList _textPieces = new ArrayList();
int _multiple;
+ int _cpMin;
public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset,
int size, int fcMin)
@@ -94,6 +95,7 @@
}
}
+ _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 int getCpMin()
+ {
+ return _cpMin;
+ }
+
public List getTextPieces()
{
return _textPieces;
@@ -150,6 +157,24 @@
return textPlex.toByteArray();
}
+
+
+ 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)
{
1.5 +25 -2 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPiece.java
Index: TextPiece.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/TextPiece.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TextPiece.java 11 Jul 2003 11:29:31 -0000 1.4
+++ TextPiece.java 12 Nov 2003 01:33:59 -0000 1.5
@@ -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 @@
* @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 @@
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 @@
}
return false;
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org