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/06/09 03:55:10 UTC
cvs commit: jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes PlexOfCps.java SEPX.java SectionDescriptor.java SectionTable.java
sackley 2003/06/08 18:55:10
Modified: src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes
PlexOfCps.java SEPX.java SectionDescriptor.java
SectionTable.java
Log:
Added stuff for writing
Revision Changes Path
1.2 +43 -3 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PlexOfCps.java
Index: PlexOfCps.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PlexOfCps.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PlexOfCps.java 5 Jun 2003 01:58:38 -0000 1.1
+++ PlexOfCps.java 9 Jun 2003 01:55:10 -0000 1.2
@@ -73,6 +73,13 @@
private int _sizeOfStruct;
private ArrayList _props;
+
+ public PlexOfCps(int sizeOfStruct)
+ {
+ _props = new ArrayList();
+ _sizeOfStruct = sizeOfStruct;
+ }
+
/**
* Constructor
*
@@ -97,7 +104,40 @@
return (PropertyNode)_props.get(index);
}
- protected PropertyNode getProperty(int index, byte[] buf, int offset)
+ public void addProperty(PropertyNode node)
+ {
+ _props.add(node);
+ }
+
+ public byte[] toByteArray()
+ {
+ int size = _props.size();
+ int cpBufSize = ((size + 1) * LittleEndian.INT_SIZE);
+ int structBufSize = + (_sizeOfStruct * size);
+ int bufSize = cpBufSize + structBufSize;
+
+ byte[] buf = new byte[bufSize];
+
+ PropertyNode node = null;
+ for (int x = 0; x < size; x++)
+ {
+ node = (PropertyNode)_props.get(x);
+
+ // put the starting offset of the property into the plcf.
+ LittleEndian.putInt(buf, (LittleEndian.INT_SIZE * x), node.getStart());
+
+ // put the struct into the plcf
+ System.arraycopy(node.getBuf(), 0, buf, cpBufSize + (x * _sizeOfStruct),
+ _sizeOfStruct);
+ }
+ // put the ending offset of the last property into the plcf.
+ LittleEndian.putInt(buf, LittleEndian.INT_SIZE * size, node.getEnd());
+
+ return buf;
+
+ }
+
+ private PropertyNode getProperty(int index, byte[] buf, int offset)
{
int start = LittleEndian.getInt(buf, offset + getIntOffset(index));
int end = LittleEndian.getInt(buf, offset + getIntOffset(index+1));
@@ -108,7 +148,7 @@
return new PropertyNode(start, end, struct);
}
- protected int getIntOffset(int index)
+ private int getIntOffset(int index)
{
return index * 4;
}
@@ -132,7 +172,7 @@
* @return The offset, in bytes, from the beginning if this PlexOfCps to
* the data structure at index.
*/
- protected int getStructOffset(int index)
+ private int getStructOffset(int index)
{
return (4 * (_count + 1)) + (_sizeOfStruct * index);
}
1.2 +9 -1 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SEPX.java
Index: SEPX.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SEPX.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SEPX.java 5 Jun 2003 01:58:38 -0000 1.1
+++ SEPX.java 9 Jun 2003 01:55:10 -0000 1.2
@@ -60,14 +60,22 @@
public class SEPX extends PropertyNode
{
- public SEPX(int start, int end, byte[] grpprl)
+ SectionDescriptor _sed;
+
+ public SEPX(SectionDescriptor sed, int start, int end, byte[] grpprl)
{
super(start, end, grpprl);
+ _sed = sed;
}
public byte[] getGrpprl()
{
return super.getBuf();
+ }
+
+ public SectionDescriptor getSectionDescriptor()
+ {
+ return _sed;
}
}
1.2 +24 -0 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SectionDescriptor.java
Index: SectionDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/SectionDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SectionDescriptor.java 5 Jun 2003 01:58:38 -0000 1.1
+++ SectionDescriptor.java 9 Jun 2003 01:55:10 -0000 1.2
@@ -66,6 +66,10 @@
private short fnMpr;
private int fcMpr;
+ public SectionDescriptor()
+ {
+ }
+
public SectionDescriptor(byte[] buf, int offset)
{
fn = LittleEndian.getShort(buf, offset);
@@ -82,4 +86,24 @@
return fc;
}
+ public void setFc(int fc)
+ {
+ this.fc = fc;
+ }
+
+ public byte[] toByteArray()
+ {
+ int offset = 0;
+ byte[] buf = new byte[12];
+
+ LittleEndian.putShort(buf, offset, fn);
+ offset += LittleEndian.SHORT_SIZE;
+ LittleEndian.putInt(buf, offset, fc);
+ offset += LittleEndian.INT_SIZE;
+ LittleEndian.putShort(buf, offset, fnMpr);
+ offset += LittleEndian.SHORT_SIZE;
+ LittleEndian.putInt(buf, offset, fcMpr);
+
+ return buf;
+ }
}
1.2 +48 -5 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SectionTable.java 5 Jun 2003 01:58:38 -0000 1.1
+++ SectionTable.java 9 Jun 2003 01:55:10 -0000 1.2
@@ -57,12 +57,17 @@
package org.apache.poi.hwpf.model.hdftypes;
import java.util.ArrayList;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.hwpf.model.io.*;
public class SectionTable
{
private static final int SED_SIZE = 12;
- private ArrayList sections;
+ private ArrayList _sections;
public SectionTable(byte[] documentStream, byte[] tableStream, int offset,
int size)
@@ -81,16 +86,54 @@
// check for the optimization
if (fileOffset == 0xffffffff)
{
- sections.add(new SEPX(node.getStart(), node.getEnd(), new byte[0]));
+ _sections.add(new SEPX(sed, node.getStart(), node.getEnd(), new byte[0]));
}
else
{
- // The first byte at the offset is the size of the grpprl.
- byte[] buf = new byte[documentStream[fileOffset++]];
+ // The first short at the offset is the size of the grpprl.
+ int sepxSize = LittleEndian.getShort(documentStream, fileOffset);
+ byte[] buf = new byte[sepxSize];
+ fileOffset += LittleEndian.SHORT_SIZE;
System.arraycopy(documentStream, fileOffset, buf, 0, buf.length);
- sections.add(new SEPX(node.getStart(), node.getEnd(), buf));
+ _sections.add(new SEPX(sed, node.getStart(), node.getEnd(), buf));
}
}
+ }
+
+ public void writeTo(HWPFFileSystem sys)
+ throws IOException
+ {
+ HWPFOutputStream docStream = sys.getStream("WordDocument");
+ HWPFOutputStream tableStream = sys.getStream("1Table");
+
+ int offset = docStream.getOffset();
+ int len = _sections.size();
+ PlexOfCps plex = new PlexOfCps(SED_SIZE);
+
+ for (int x = 0; x < len; x++)
+ {
+ SEPX sepx = (SEPX)_sections.get(x);
+ byte[] grpprl = sepx.getGrpprl();
+
+ // write the sepx to the document stream. starts with a 2 byte size
+ // followed by the grpprl
+ byte[] shortBuf = new byte[2];
+ LittleEndian.putShort(shortBuf, (short)grpprl.length);
+
+ docStream.write(shortBuf);
+ docStream.write(grpprl);
+
+ // set the fc in the section descriptor
+ SectionDescriptor sed = sepx.getSectionDescriptor();
+ sed.setFc(offset);
+
+ // add the section descriptor bytes to the PlexOfCps.
+ PropertyNode property = new PropertyNode(sepx.getStart(), sepx.getEnd(), sed.toByteArray());
+ plex.addProperty(property);
+
+ offset = docStream.getOffset();
+ }
+ tableStream.write(plex.toByteArray());
}
}