}
}
+ 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;
package org.apache.poi.hwpf.model.hdftypes;
+import org.apache.poi.hwpf.sprm.SprmBuffer;
/**
* Comment me
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();
+ }
+
+
}
}
}
+ 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;
package org.apache.poi.hwpf.model.hdftypes;
+
+import org.apache.poi.hwpf.usermodel.Paragraph;
+import org.apache.poi.hwpf.sprm.SprmBuffer;
+
/**
* Comment me
*
public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe)
{
- super(fcStart, fcEnd, papx);
+ super(fcStart, fcEnd, new SprmBuffer(papx));
_phe = phe;
}
public byte[] getGrpprl()
{
- return super.getBuf();
+ return ((SprmBuffer)_buf).toByteArray();
+ }
+
+ public byte[] getBuf()
+ {
+ return getGrpprl();
}
public boolean equals(Object o)
*/
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;
}
/**
{
return _cpStart;
}
+
+ void setStart(int start)
+ {
+ _cpStart = start;
+ }
+
/**
* @retrun The offset of the end of this property's text.
*/
{
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)
{
// 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
{
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;
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();
package org.apache.poi.hwpf.model.hdftypes;
-
+import java.io.UnsupportedEncodingException;
/**
* Lightweight representation of a text piece.
*
* @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;
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))
}
return false;
}
+
}
{
ArrayList _textPieces = new ArrayList();
int _multiple;
+ int _cpMin;
public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset,
int size, int fcMin)
}
}
+ _cpMin = pieces[0].getFilePosition() - fcMin;
// using the PieceDescriptors, build our list of TextPieces.
for (int x = 0; x < pieces.length; x++)
{
}
}
+ public int getCpMin()
+ {
+ return _cpMin;
+ }
+
public List getTextPieces()
{
return _textPieces;
}
+
+ 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;