latest changes

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353446 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Said Ryan Ackley 2003-11-12 01:33:58 +00:00
parent a23dfd03ea
commit fbd57dadd9
8 changed files with 212 additions and 15 deletions

View File

@ -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() public List getTextRuns()
{ {
return _textRuns; return _textRuns;

View File

@ -55,6 +55,7 @@
package org.apache.poi.hwpf.model.hdftypes; package org.apache.poi.hwpf.model.hdftypes;
import org.apache.poi.hwpf.sprm.SprmBuffer;
/** /**
* Comment me * Comment me
@ -67,12 +68,18 @@ public class CHPX extends PropertyNode
public CHPX(int fcStart, int fcEnd, byte[] grpprl) public CHPX(int fcStart, int fcEnd, byte[] grpprl)
{ {
super(fcStart, fcEnd, grpprl); super(fcStart, fcEnd, new SprmBuffer(grpprl));
} }
public byte[] getGrpprl() public byte[] getGrpprl()
{ {
return super.getBuf(); return ((SprmBuffer)_buf).toByteArray();
} }
public byte[] getBuf()
{
return getGrpprl();
}
} }

View File

@ -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() public ArrayList getParagraphs()
{ {
return _paragraphs; return _paragraphs;

View File

@ -55,6 +55,10 @@
package org.apache.poi.hwpf.model.hdftypes; package org.apache.poi.hwpf.model.hdftypes;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.sprm.SprmBuffer;
/** /**
* Comment me * Comment me
* *
@ -68,7 +72,7 @@ public class PAPX extends PropertyNode
public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe) public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe)
{ {
super(fcStart, fcEnd, papx); super(fcStart, fcEnd, new SprmBuffer(papx));
_phe = phe; _phe = phe;
} }
@ -79,7 +83,12 @@ public class PAPX extends PropertyNode
public byte[] getGrpprl() public byte[] getGrpprl()
{ {
return super.getBuf(); return ((SprmBuffer)_buf).toByteArray();
}
public byte[] getBuf()
{
return getGrpprl();
} }
public boolean equals(Object o) public boolean equals(Object o)

View File

@ -66,21 +66,21 @@ import org.apache.poi.hwpf.sprm.SprmBuffer;
*/ */
public class PropertyNode implements Comparable public class PropertyNode implements Comparable
{ {
private SprmBuffer _buf; protected Object _buf;
private int _cpStart; private int _cpStart;
private int _cpEnd; private int _cpEnd;
private SoftReference _propCache; protected SoftReference _propCache;
/** /**
* @param fcStart The start of the text for this property. * @param fcStart The start of the text for this property.
* @param fcEnd The end of the text for this property. * @param fcEnd The end of the text for this property.
* @param grpprl The property description in compressed form. * @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; _cpStart = fcStart;
_cpEnd = fcEnd; _cpEnd = fcEnd;
_buf = new SprmBuffer(buf); _buf = buf;
} }
/** /**
@ -90,6 +90,12 @@ public class PropertyNode implements Comparable
{ {
return _cpStart; return _cpStart;
} }
void setStart(int start)
{
_cpStart = start;
}
/** /**
* @retrun The offset of the end of this property's text. * @retrun The offset of the end of this property's text.
*/ */
@ -97,17 +103,23 @@ public class PropertyNode implements Comparable
{ {
return _cpEnd; return _cpEnd;
} }
void setEnd(int end)
{
_cpEnd = end;
}
/** /**
* @return This property's property in copmpressed form. * @return This property's property in copmpressed form.
*/ */
public byte[] getBuf() public byte[] getBuf()
{ {
return _buf.toByteArray(); return ((byte[])_buf);
} }
public boolean equals(Object o) public boolean equals(Object o)
{ {
byte[] buf = _buf.toByteArray(); byte[] buf = getBuf();
if (((PropertyNode)o).getStart() == _cpStart && if (((PropertyNode)o).getStart() == _cpStart &&
((PropertyNode)o).getEnd() == _cpEnd) ((PropertyNode)o).getEnd() == _cpEnd)
{ {

View File

@ -86,7 +86,7 @@ public class SectionTable
// check for the optimization // check for the optimization
if (fileOffset == 0xffffffff) 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 else
{ {
@ -95,11 +95,26 @@ public class SectionTable
byte[] buf = new byte[sepxSize]; byte[] buf = new byte[sepxSize];
fileOffset += LittleEndian.SHORT_SIZE; fileOffset += LittleEndian.SHORT_SIZE;
System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); 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() public ArrayList getSections()
{ {
return _sections; return _sections;
@ -133,7 +148,7 @@ public class SectionTable
sed.setFc(offset); sed.setFc(offset);
// add the section descriptor bytes to the PlexOfCps. // 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); plex.addProperty(property);
offset = docStream.getOffset(); offset = docStream.getOffset();

View File

@ -55,7 +55,7 @@
package org.apache.poi.hwpf.model.hdftypes; package org.apache.poi.hwpf.model.hdftypes;
import java.io.UnsupportedEncodingException;
/** /**
* Lightweight representation of a text piece. * 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. * @param unicode true if this text is unicode.
*/ */
public TextPiece(int start, int end, byte[] text, PieceDescriptor pd) 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(); _usesUnicode = pd.isUnicode();
_length = end - start; _length = end - start;
_pd = pd; _pd = pd;
@ -94,6 +95,27 @@ public class TextPiece extends PropertyNode implements Comparable
return _pd; 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) public boolean equals(Object o)
{ {
if (super.equals(o)) if (super.equals(o))
@ -103,4 +125,5 @@ public class TextPiece extends PropertyNode implements Comparable
} }
return false; return false;
} }
} }

View File

@ -69,6 +69,7 @@ public class TextPieceTable
{ {
ArrayList _textPieces = new ArrayList(); ArrayList _textPieces = new ArrayList();
int _multiple; int _multiple;
int _cpMin;
public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset, public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset,
int size, int fcMin) int size, int fcMin)
@ -94,6 +95,7 @@ public class TextPieceTable
} }
} }
_cpMin = pieces[0].getFilePosition() - fcMin;
// using the PieceDescriptors, build our list of TextPieces. // using the PieceDescriptors, build our list of TextPieces.
for (int x = 0; x < pieces.length; x++) for (int x = 0; x < pieces.length; x++)
{ {
@ -115,6 +117,11 @@ public class TextPieceTable
} }
} }
public int getCpMin()
{
return _cpMin;
}
public List getTextPieces() public List getTextPieces()
{ {
return _textPieces; 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) public boolean equals(Object o)
{ {
TextPieceTable tpt = (TextPieceTable)o; TextPieceTable tpt = (TextPieceTable)o;