You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/11/19 01:06:07 UTC
svn commit: r718810 [2/2] - in /poi/trunk/src:
java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/record/
java/org/apache/poi/hssf/record/aggregates/
java/org/apache/poi/hssf/usermodel/
scratchpad/src/org/apache/poi/hssf/usermodel/ testcases/org/...
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/IndexRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/IndexRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/IndexRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/IndexRecord.java Tue Nov 18 16:06:06 2008
@@ -18,25 +18,23 @@
package org.apache.poi.hssf.record;
import org.apache.poi.util.IntList;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: Index Record<P>
+ * Title: Index Record (0x020B)<p/>
* Description: Occurs right after BOF, tells you where the DBCELL records are for a sheet
- * Important for locating cells<P>
+ * Important for locating cells<p/>
* NOT USED IN THIS RELEASE
- * REFERENCE: PG 323 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
+ * REFERENCE: PG 323 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au)
*/
-public class IndexRecord extends Record {
- public final static short sid = 0x020B;
- public final static int DBCELL_CAPACITY = 30;
- public int field_1_zero; // reserved must be 0
- public int field_2_first_row; // first row on the sheet
- public int field_3_last_row_add1; // last row
- public int field_4_zero; // reserved must be 0
- public IntList field_5_dbcells; // array of offsets to DBCELL records
+public class IndexRecord extends StandardRecord {
+ public final static short sid = 0x020B;
+ private int field_2_first_row; // first row on the sheet
+ private int field_3_last_row_add1; // last row
+ private int field_4_zero; // supposed to be zero
+ private IntList field_5_dbcells; // array of offsets to DBCELL records
public IndexRecord()
{
@@ -44,16 +42,17 @@
public IndexRecord(RecordInputStream in)
{
- field_5_dbcells =
- new IntList(DBCELL_CAPACITY); // initial capacity of 30
- field_1_zero = in.readInt();
+ int field_1_zero = in.readInt();
+ if (field_1_zero != 0) {
+ throw new RecordFormatException("Expected zero for field 1 but got " + field_1_zero);
+ }
field_2_first_row = in.readInt();
field_3_last_row_add1 = in.readInt();
- field_4_zero = in.readInt();
- while(in.remaining() > 0)
- {
-
- // System.out.println("getting " + k);
+ field_4_zero = in.readInt();
+
+ int nCells = in.remaining() / 4;
+ field_5_dbcells = new IntList(nCells);
+ for(int i=0; i<nCells; i++) {
field_5_dbcells.add(in.readInt());
}
}
@@ -115,50 +114,43 @@
.append(Integer.toHexString(getFirstRow())).append("\n");
buffer.append(" .lastrowadd1 = ")
.append(Integer.toHexString(getLastRowAdd1())).append("\n");
- for (int k = 0; k < getNumDbcells(); k++)
- {
- buffer.append(" .dbcell_" + k + " = ")
+ for (int k = 0; k < getNumDbcells(); k++) {
+ buffer.append(" .dbcell_").append(k).append(" = ")
.append(Integer.toHexString(getDbcellAt(k))).append("\n");
}
buffer.append("[/INDEX]\n");
return buffer.toString();
}
- public int serialize(int offset, byte [] data)
- {
- LittleEndian.putShort(data, 0 + offset, sid);
- LittleEndian.putShort(data, 2 + offset,
- ( short ) (16 + (getNumDbcells() * 4)));
- LittleEndian.putInt(data, 4 + offset, 0);
- LittleEndian.putInt(data, 8 + offset, getFirstRow());
- LittleEndian.putInt(data, 12 + offset, getLastRowAdd1());
- LittleEndian.putInt(data, 16 + offset, 0);
- for (int k = 0; k < getNumDbcells(); k++)
- {
- LittleEndian.putInt(data, (k * 4) + 20 + offset, getDbcellAt(k));
+ public void serialize(LittleEndianOutput out) {
+
+ out.writeInt(0);
+ out.writeInt(getFirstRow());
+ out.writeInt(getLastRowAdd1());
+ out.writeInt(field_4_zero);
+ for (int k = 0; k < getNumDbcells(); k++) {
+ out.writeInt(getDbcellAt(k));
}
- return getRecordSize();
}
protected int getDataSize() {
- return 16 + (getNumDbcells() * 4);
+ return 16 // 4 ints
+ + getNumDbcells() * 4;
}
- /** Returns the size of an INdexRecord when it needs to index the specified number of blocks
- *
- */
- public static int getRecordSizeForBlockCount(int blockCount) {
- return 20 + (4 * blockCount);
- }
+ /**
+ * @return the size of an INdexRecord when it needs to index the specified number of blocks
+ */
+ public static int getRecordSizeForBlockCount(int blockCount) {
+ return 20 + 4 * blockCount;
+ }
- public short getSid()
- {
+ public short getSid() {
return sid;
}
public Object clone() {
IndexRecord rec = new IndexRecord();
- rec.field_1_zero = field_1_zero;
rec.field_2_first_row = field_2_first_row;
rec.field_3_last_row_add1 = field_3_last_row_add1;
rec.field_4_zero = field_4_zero;
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataRecord.java Tue Nov 18 16:06:06 2008
@@ -17,17 +17,19 @@
package org.apache.poi.hssf.record;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.ss.formula.Formula;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
- * Describes a linked data record. This record referes to the series data or text.<p/>
+ * Describes a linked data record. This record refers to the series data or text.<p/>
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public final class LinkedDataRecord extends Record {
+public final class LinkedDataRecord extends StandardRecord {
public final static short sid = 0x1051;
private static final BitField customNumberFormat= BitFieldFactory.getInstance(0x1);
@@ -44,7 +46,7 @@
public final static byte REFERENCE_TYPE_ERROR_REPORTED = 4;
private short field_3_options;
private short field_4_indexNumberFmtRecord;
- private LinkedDataFormulaField field_5_formulaOfLink;
+ private Formula field_5_formulaOfLink;
public LinkedDataRecord()
@@ -58,8 +60,8 @@
field_2_referenceType = in.readByte();
field_3_options = in.readShort();
field_4_indexNumberFmtRecord = in.readShort();
- field_5_formulaOfLink = new LinkedDataFormulaField();
- field_5_formulaOfLink.fillField(in);
+ int encodedTokenLen = in.readUShort();
+ field_5_formulaOfLink = Formula.read(encodedTokenLen, in);
}
public String toString()
@@ -92,28 +94,19 @@
return buffer.toString();
}
- public int serialize(int offset, byte[] data)
- {
- int pos = 0;
-
- LittleEndian.putShort(data, 0 + offset, sid);
- LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
-
- data[ 4 + offset + pos ] = field_1_linkType;
- data[ 5 + offset + pos ] = field_2_referenceType;
- LittleEndian.putShort(data, 6 + offset + pos, field_3_options);
- LittleEndian.putShort(data, 8 + offset + pos, field_4_indexNumberFmtRecord);
- pos += field_5_formulaOfLink.serializeField( pos + 10 + offset, data );
-
- return getRecordSize();
+ public void serialize(LittleEndianOutput out) {
+ out.writeByte(field_1_linkType);
+ out.writeByte(field_2_referenceType);
+ out.writeShort(field_3_options);
+ out.writeShort(field_4_indexNumberFmtRecord);
+ field_5_formulaOfLink.serialize(out);
}
protected int getDataSize() {
- return 1 + 1 + 2 + 2 + field_5_formulaOfLink.getSize();
+ return 1 + 1 + 2 + 2 + field_5_formulaOfLink.getEncodedSize();
}
- public short getSid()
- {
+ public short getSid() {
return sid;
}
@@ -224,17 +217,16 @@
/**
* Get the formula of link field for the LinkedData record.
*/
- public LinkedDataFormulaField getFormulaOfLink()
- {
- return field_5_formulaOfLink;
+ public Ptg[] getFormulaOfLink() {
+ return field_5_formulaOfLink.getTokens();
}
/**
* Set the formula of link field for the LinkedData record.
*/
- public void setFormulaOfLink(LinkedDataFormulaField field_5_formulaOfLink)
+ public void setFormulaOfLink(Ptg[] ptgs)
{
- this.field_5_formulaOfLink = field_5_formulaOfLink;
+ this.field_5_formulaOfLink = Formula.create(ptgs);
}
/**
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java Tue Nov 18 16:06:06 2008
@@ -19,18 +19,15 @@
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Merged Cells Record (0x00E5)
* <br/>
- * Description: Optional record defining a square area of cells to "merged" into
- * one cell. <br>
- * REFERENCE: NONE (UNDOCUMENTED PRESENTLY) <br>
+ * Description: Optional record defining a square area of cells to "merged" into one cell. <br>
* @author Andrew C. Oliver (acoliver at apache dot org)
- * @version 2.0-pre
*/
-public final class MergeCellsRecord extends Record {
+public final class MergeCellsRecord extends StandardRecord {
public final static short sid = 0x00E5;
/** sometimes the regions array is shared with other MergedCellsRecords */
private CellRangeAddress[] _regions;
@@ -80,37 +77,26 @@
return sid;
}
- public int serialize(int offset, byte [] data) {
- int dataSize = CellRangeAddressList.getEncodedSize(_numberOfRegions);
-
- LittleEndian.putUShort(data, offset + 0, sid);
- LittleEndian.putUShort(data, offset + 2, dataSize);
+ public void serialize(LittleEndianOutput out) {
int nItems = _numberOfRegions;
- LittleEndian.putUShort(data, offset + 4, nItems);
- int pos = 6;
+ out.writeShort(nItems);
for (int i = 0; i < _numberOfRegions; i++) {
- pos += _regions[_startIndex + i].serialize(offset+pos, data);
+ _regions[_startIndex + i].serialize(out);
}
- return 4 + dataSize;
}
public String toString() {
StringBuffer retval = new StringBuffer();
retval.append("[MERGEDCELLS]").append("\n");
- retval.append(" .numregions =").append(getNumAreas())
- .append("\n");
+ retval.append(" .numregions =").append(getNumAreas()).append("\n");
for (int k = 0; k < _numberOfRegions; k++) {
- CellRangeAddress region = _regions[_startIndex + k];
+ CellRangeAddress r = _regions[_startIndex + k];
- retval.append(" .rowfrom =").append(region.getFirstRow())
- .append("\n");
- retval.append(" .rowto =").append(region.getLastRow())
- .append("\n");
- retval.append(" .colfrom =").append(region.getFirstColumn())
- .append("\n");
- retval.append(" .colto =").append(region.getLastColumn())
- .append("\n");
+ retval.append(" .rowfrom =").append(r.getFirstRow()).append("\n");
+ retval.append(" .rowto =").append(r.getLastRow()).append("\n");
+ retval.append(" .colfrom =").append(r.getFirstColumn()).append("\n");
+ retval.append(" .colto =").append(r.getLastColumn()).append("\n");
}
retval.append("[MERGEDCELLS]").append("\n");
return retval.toString();
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java Tue Nov 18 16:06:06 2008
@@ -17,6 +17,8 @@
package org.apache.poi.hssf.record;
+import org.apache.poi.util.LittleEndianOutput;
+
/**
* Title: Multiple Blank cell record(0x00BE) <P/>
* Description: Represents a set of columns in a row with no value but with styling.
@@ -27,7 +29,7 @@
* @author Glen Stampoultzis (glens at apache.org)
* @see BlankRecord
*/
-public final class MulBlankRecord extends Record {
+public final class MulBlankRecord extends StandardRecord {
public final static short sid = 0x00BE;
private int field_1_row;
@@ -124,7 +126,7 @@
return sid;
}
- public int serialize(int offset, byte [] data) {
+ public void serialize(LittleEndianOutput out) {
throw new RecordFormatException( "Sorry, you can't serialize MulBlank in this release");
}
protected int getDataSize() {
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/MulRKRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/MulRKRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/MulRKRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/MulRKRecord.java Tue Nov 18 16:06:06 2008
@@ -19,6 +19,7 @@
import org.apache.poi.hssf.util.RKUtil;
import org.apache.poi.util.HexDump;
+import org.apache.poi.util.LittleEndianOutput;
/**
* MULRK (0x00BD) <p/>
@@ -29,7 +30,7 @@
* @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*/
-public final class MulRKRecord extends Record {
+public final class MulRKRecord extends StandardRecord {
public final static short sid = 0x00BD;
private int field_1_row;
@@ -113,7 +114,7 @@
return sid;
}
- public int serialize(int offset, byte [] data) {
+ public void serialize(LittleEndianOutput out) {
throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release");
}
protected int getDataSize() {
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PageBreakRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PageBreakRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/PageBreakRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/PageBreakRecord.java Tue Nov 18 16:06:06 2008
@@ -23,7 +23,7 @@
import java.util.List;
import java.util.Map;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
* <p>Record that contains the functionality page breaks (horizontal and vertical)</p>
@@ -36,11 +36,11 @@
* @see VerticalPageBreakRecord
* @author Danny Mui (dmui at apache dot org)
*/
-public abstract class PageBreakRecord extends Record {
+public abstract class PageBreakRecord extends StandardRecord {
private static final int[] EMPTY_INT_ARRAY = { };
- private List _breaks;
- private Map _breakMap;
+ private List<Break> _breaks;
+ private Map<Integer, Break> _breakMap;
/**
* Since both records store 2byte integers (short), no point in
@@ -49,7 +49,7 @@
* The subs (rows or columns, don't seem to be able to set but excel sets
* them automatically)
*/
- public class Break {
+ public static final class Break {
public static final int ENCODED_SIZE = 6;
public int main;
@@ -69,24 +69,23 @@
subTo = in.readUShort();
}
- public int serialize(int offset, byte[] data) {
- LittleEndian.putUShort(data, offset + 0, main + 1);
- LittleEndian.putUShort(data, offset + 2, subFrom);
- LittleEndian.putUShort(data, offset + 4, subTo);
- return ENCODED_SIZE;
+ public void serialize(LittleEndianOutput out) {
+ out.writeShort(main + 1);
+ out.writeShort(subFrom);
+ out.writeShort(subTo);
}
}
protected PageBreakRecord() {
- _breaks = new ArrayList();
- _breakMap = new HashMap();
+ _breaks = new ArrayList<Break>();
+ _breakMap = new HashMap<Integer, Break>();
}
public PageBreakRecord(RecordInputStream in)
{
int nBreaks = in.readShort();
- _breaks = new ArrayList(nBreaks + 2);
- _breakMap = new HashMap();
+ _breaks = new ArrayList<Break>(nBreaks + 2);
+ _breakMap = new HashMap<Integer, Break>();
for(int k = 0; k < nBreaks; k++) {
Break br = new Break(in);
@@ -103,34 +102,25 @@
return 2 + _breaks.size() * Break.ENCODED_SIZE;
}
- public final int serialize(int offset, byte data[]) {
+ public final void serialize(LittleEndianOutput out) {
int nBreaks = _breaks.size();
- int dataSize = getDataSize();
- LittleEndian.putUShort(data, offset + 0, getSid());
- LittleEndian.putUShort(data, offset + 2, dataSize);
- LittleEndian.putUShort(data, offset + 4, nBreaks);
- int pos = 6;
+ out.writeShort(nBreaks);
for (int i=0; i<nBreaks; i++) {
- Break br = (Break)_breaks.get(i);
- pos += br.serialize(offset+pos, data);
+ _breaks.get(i).serialize(out);
}
-
- return 4 + dataSize;
}
public int getNumBreaks() {
return _breaks.size();
}
- public final Iterator getBreaksIterator() {
+ public final Iterator<Break> getBreaksIterator() {
return _breaks.iterator();
}
- public String toString()
- {
+ public String toString() {
StringBuffer retval = new StringBuffer();
-
String label;
String mainLabel;
String subLabel;
@@ -148,10 +138,10 @@
retval.append("["+label+"]").append("\n");
retval.append(" .sid =").append(getSid()).append("\n");
retval.append(" .numbreaks =").append(getNumBreaks()).append("\n");
- Iterator iterator = getBreaksIterator();
+ Iterator<Break> iterator = getBreaksIterator();
for(int k = 0; k < getNumBreaks(); k++)
{
- Break region = (Break)iterator.next();
+ Break region = iterator.next();
retval.append(" .").append(mainLabel).append(" (zero-based) =").append(region.main).append("\n");
retval.append(" .").append(subLabel).append("From =").append(region.subFrom).append("\n");
@@ -171,7 +161,7 @@
public void addBreak(int main, int subFrom, int subTo) {
Integer key = new Integer(main);
- Break region = (Break)_breakMap.get(key);
+ Break region = _breakMap.get(key);
if(region == null) {
region = new Break(main, subFrom, subTo);
_breakMap.put(key, region);
@@ -189,7 +179,7 @@
*/
public final void removeBreak(int main) {
Integer rowKey = new Integer(main);
- Break region = (Break)_breakMap.get(rowKey);
+ Break region = _breakMap.get(rowKey);
_breaks.remove(region);
_breakMap.remove(rowKey);
}
@@ -201,7 +191,7 @@
*/
public final Break getBreak(int main) {
Integer rowKey = new Integer(main);
- return (Break)_breakMap.get(rowKey);
+ return _breakMap.get(rowKey);
}
public final int[] getBreaks() {
@@ -211,7 +201,7 @@
}
int[] result = new int[count];
for (int i=0; i<count; i++) {
- Break breakItem = (Break)_breaks.get(i);
+ Break breakItem = _breaks.get(i);
result[i] = breakItem.main;
}
return result;
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PaletteRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PaletteRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/PaletteRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/PaletteRecord.java Tue Nov 18 16:06:06 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,52 +14,44 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.record;
import java.util.ArrayList;
import java.util.List;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
- * PaletteRecord - Supports custom palettes.
+ * PaletteRecord (0x0092) - Supports custom palettes.
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Brian Sanders (bsanders at risklabs dot com) - custom palette editing
- * @version 2.0-pre
+ *
*/
-
-public class PaletteRecord
- extends Record
-{
- public final static short sid = 0x92;
+public final class PaletteRecord extends StandardRecord {
+ public final static short sid = 0x0092;
/** The standard size of an XLS palette */
public final static byte STANDARD_PALETTE_SIZE = (byte) 56;
/** The byte index of the first color */
public final static short FIRST_COLOR_INDEX = (short) 0x8;
- private short field_1_numcolors;
- private List field_2_colors;
+ private List<PColor> field_2_colors;
public PaletteRecord()
{
- createDefaultPalette();
+ PColor[] defaultPalette = createDefaultPalette();
+ field_2_colors = new ArrayList<PColor>(defaultPalette.length);
+ for (int i = 0; i < defaultPalette.length; i++) {
+ field_2_colors.add(defaultPalette[i]);
+ }
}
public PaletteRecord(RecordInputStream in)
{
- field_1_numcolors = in.readShort();
- field_2_colors = new ArrayList(field_1_numcolors);
+ int field_1_numcolors = in.readShort();
+ field_2_colors = new ArrayList<PColor>(field_1_numcolors);
for (int k = 0; k < field_1_numcolors; k++) {
- field_2_colors.add(new PColor(
- in.readByte(),
- in.readByte(),
- in.readByte()
- )
- );
- //Read unused byte.
- in.readByte();
+ field_2_colors.add(new PColor(in));
}
}
@@ -69,35 +60,27 @@
StringBuffer buffer = new StringBuffer();
buffer.append("[PALETTE]\n");
- buffer.append(" numcolors = ").append(field_1_numcolors)
- .append('\n');
- for (int k = 0; k < field_1_numcolors; k++) {
- PColor c = (PColor) field_2_colors.get(k);
- buffer.append("* colornum = ").append(k)
- .append('\n');
- buffer.append(c.toString());
- buffer.append("/*colornum = ").append(k)
- .append('\n');
+ buffer.append(" numcolors = ").append(field_2_colors.size()).append('\n');
+ for (int i = 0; i < field_2_colors.size(); i++) {
+ PColor c = field_2_colors.get(i);
+ buffer.append("* colornum = ").append(i).append('\n');
+ buffer.append(c.toString());
+ buffer.append("/*colornum = ").append(i).append('\n');
}
buffer.append("[/PALETTE]\n");
return buffer.toString();
}
- public int serialize(int offset, byte [] data)
+ public void serialize(LittleEndianOutput out)
{
- LittleEndian.putShort(data, 0 + offset, sid);
- LittleEndian.putShort(data, 2 + offset, (short) (getRecordSize() - 4));
- LittleEndian.putShort(data, 4 + offset, field_1_numcolors);
- for (int k = 0; k < field_1_numcolors; k++) {
- PColor c = (PColor)field_2_colors.get(k);
- c.serialize(data, (6+offset+(k*4)));
+ out.writeShort(field_2_colors.size());
+ for (int i = 0; i < field_2_colors.size(); i++) {
+ field_2_colors.get(i).serialize(out);
}
-
- return getRecordSize();
}
protected int getDataSize() {
- return 2 + (field_1_numcolors * 4);
+ return 2 + field_2_colors.size() * PColor.ENCODED_SIZE;
}
public short getSid()
@@ -108,17 +91,16 @@
/**
* Returns the color value at a given index
*
- * @return the RGB triplet for the color, or null if the specified index
+ * @return the RGB triplet for the color, or <code>null</code> if the specified index
* does not exist
*/
- public byte[] getColor(short byteIndex)
- {
+ public byte[] getColor(short byteIndex) {
int i = byteIndex - FIRST_COLOR_INDEX;
if (i < 0 || i >= field_2_colors.size())
{
return null;
}
- PColor color = (PColor) field_2_colors.get(i);
+ PColor color = field_2_colors.get(i);
return new byte[] { color.red, color.green, color.blue };
}
@@ -138,9 +120,9 @@
{
return;
}
- while (field_2_colors.size() <= i)
- {
- field_2_colors.add(new PColor((byte) 0, (byte) 0, (byte) 0));
+ // may need to grow - fill intervening pallette entries with black
+ while (field_2_colors.size() <= i) {
+ field_2_colors.add(new PColor(0, 0, 0));
}
PColor custColor = new PColor(red, green, blue);
field_2_colors.set(i, custColor);
@@ -151,100 +133,99 @@
*
* @see org.apache.poi.hssf.model.Workbook#createPalette
*/
- private void createDefaultPalette()
+ private static PColor[] createDefaultPalette()
{
- field_1_numcolors = STANDARD_PALETTE_SIZE;
- field_2_colors = new ArrayList(field_1_numcolors);
- byte[] palette = new byte[]
- {
- (byte) 0, (byte) 0, (byte) 0, (byte) 0, //color 0...
- (byte) 255, (byte) 255, (byte) 255, (byte) 0,
- (byte) 255, (byte) 0, (byte) 0, (byte) 0,
- (byte) 0, (byte) 255, (byte) 0, (byte) 0,
- (byte) 0, (byte) 0, (byte) 255, (byte) 0,
- (byte) 255, (byte) 255, (byte) 0, (byte) 0,
- (byte) 255, (byte) 0, (byte) 255, (byte) 0,
- (byte) 0, (byte) 255, (byte) 255, (byte) 0,
- (byte) 128, (byte) 0, (byte) 0, (byte) 0,
- (byte) 0, (byte) 128, (byte) 0, (byte) 0,
- (byte) 0, (byte) 0, (byte) 128, (byte) 0,
- (byte) 128, (byte) 128, (byte) 0, (byte) 0,
- (byte) 128, (byte) 0, (byte) 128, (byte) 0,
- (byte) 0, (byte) 128, (byte) 128, (byte) 0,
- (byte) 192, (byte) 192, (byte) 192, (byte) 0,
- (byte) 128, (byte) 128, (byte) 128, (byte) 0,
- (byte) 153, (byte) 153, (byte) 255, (byte) 0,
- (byte) 153, (byte) 51, (byte) 102, (byte) 0,
- (byte) 255, (byte) 255, (byte) 204, (byte) 0,
- (byte) 204, (byte) 255, (byte) 255, (byte) 0,
- (byte) 102, (byte) 0, (byte) 102, (byte) 0,
- (byte) 255, (byte) 128, (byte) 128, (byte) 0,
- (byte) 0, (byte) 102, (byte) 204, (byte) 0,
- (byte) 204, (byte) 204, (byte) 255, (byte) 0,
- (byte) 0, (byte) 0, (byte) 128, (byte) 0,
- (byte) 255, (byte) 0, (byte) 255, (byte) 0,
- (byte) 255, (byte) 255, (byte) 0, (byte) 0,
- (byte) 0, (byte) 255, (byte) 255, (byte) 0,
- (byte) 128, (byte) 0, (byte) 128, (byte) 0,
- (byte) 128, (byte) 0, (byte) 0, (byte) 0,
- (byte) 0, (byte) 128, (byte) 128, (byte) 0,
- (byte) 0, (byte) 0, (byte) 255, (byte) 0,
- (byte) 0, (byte) 204, (byte) 255, (byte) 0,
- (byte) 204, (byte) 255, (byte) 255, (byte) 0,
- (byte) 204, (byte) 255, (byte) 204, (byte) 0,
- (byte) 255, (byte) 255, (byte) 153, (byte) 0,
- (byte) 153, (byte) 204, (byte) 255, (byte) 0,
- (byte) 255, (byte) 153, (byte) 204, (byte) 0,
- (byte) 204, (byte) 153, (byte) 255, (byte) 0,
- (byte) 255, (byte) 204, (byte) 153, (byte) 0,
- (byte) 51, (byte) 102, (byte) 255, (byte) 0,
- (byte) 51, (byte) 204, (byte) 204, (byte) 0,
- (byte) 153, (byte) 204, (byte) 0, (byte) 0,
- (byte) 255, (byte) 204, (byte) 0, (byte) 0,
- (byte) 255, (byte) 153, (byte) 0, (byte) 0,
- (byte) 255, (byte) 102, (byte) 0, (byte) 0,
- (byte) 102, (byte) 102, (byte) 153, (byte) 0,
- (byte) 150, (byte) 150, (byte) 150, (byte) 0,
- (byte) 0, (byte) 51, (byte) 102, (byte) 0,
- (byte) 51, (byte) 153, (byte) 102, (byte) 0,
- (byte) 0, (byte) 51, (byte) 0, (byte) 0,
- (byte) 51, (byte) 51, (byte) 0, (byte) 0,
- (byte) 153, (byte) 51, (byte) 0, (byte) 0,
- (byte) 153, (byte) 51, (byte) 102, (byte) 0,
- (byte) 51, (byte) 51, (byte) 153, (byte) 0,
- (byte) 51, (byte) 51, (byte) 51, (byte) 0
+ return new PColor[] {
+ pc(0, 0, 0),
+ pc(255, 255, 255),
+ pc(255, 0, 0),
+ pc(0, 255, 0),
+ pc(0, 0, 255),
+ pc(255, 255, 0),
+ pc(255, 0, 255),
+ pc(0, 255, 255),
+ pc(128, 0, 0),
+ pc(0, 128, 0),
+ pc(0, 0, 128),
+ pc(128, 128, 0),
+ pc(128, 0, 128),
+ pc(0, 128, 128),
+ pc(192, 192, 192),
+ pc(128, 128, 128),
+ pc(153, 153, 255),
+ pc(153, 51, 102),
+ pc(255, 255, 204),
+ pc(204, 255, 255),
+ pc(102, 0, 102),
+ pc(255, 128, 128),
+ pc(0, 102, 204),
+ pc(204, 204, 255),
+ pc(0, 0, 128),
+ pc(255, 0, 255),
+ pc(255, 255, 0),
+ pc(0, 255, 255),
+ pc(128, 0, 128),
+ pc(128, 0, 0),
+ pc(0, 128, 128),
+ pc(0, 0, 255),
+ pc(0, 204, 255),
+ pc(204, 255, 255),
+ pc(204, 255, 204),
+ pc(255, 255, 153),
+ pc(153, 204, 255),
+ pc(255, 153, 204),
+ pc(204, 153, 255),
+ pc(255, 204, 153),
+ pc(51, 102, 255),
+ pc(51, 204, 204),
+ pc(153, 204, 0),
+ pc(255, 204, 0),
+ pc(255, 153, 0),
+ pc(255, 102, 0),
+ pc(102, 102, 153),
+ pc(150, 150, 150),
+ pc(0, 51, 102),
+ pc(51, 153, 102),
+ pc(0, 51, 0),
+ pc(51, 51, 0),
+ pc(153, 51, 0),
+ pc(153, 51, 102),
+ pc(51, 51, 153),
+ pc(51, 51, 51),
};
-
- for (int k = 0; k < field_1_numcolors; k++) {
- field_2_colors.add(new PColor(
- palette[k*4],
- palette[k*4+1],
- palette[k*4+2]
- )
- );
- }
-
}
-}
+
+ private static PColor pc(int r, int g, int b) {
+ return new PColor(r, g, b);
+ }
/**
* PColor - element in the list of colors - consider it a "struct"
*/
-class PColor {
+private static final class PColor {
+ public static final short ENCODED_SIZE = 4;
public byte red;
public byte green;
public byte blue;
- public PColor(byte red, byte green, byte blue) {
- this.red=red;
- this.green=green;
- this.blue=blue;
+
+ public PColor(int red, int green, int blue) {
+ this.red=(byte) red;
+ this.green=(byte) green;
+ this.blue=(byte) blue;
+ }
+
+ public PColor(RecordInputStream in) {
+ red=in.readByte();
+ green=in.readByte();
+ blue=in.readByte();
+ in.readByte(); // unused
}
- public void serialize(byte[] data, int offset) {
- data[offset + 0] = red;
- data[offset + 1] = green;
- data[offset + 2] = blue;
- data[offset + 3] = 0;
+ public void serialize(LittleEndianOutput out) {
+ out.writeByte(red);
+ out.writeByte(green);
+ out.writeByte(blue);
+ out.writeByte(0);
}
public String toString() {
@@ -255,3 +236,4 @@
return buffer.toString();
}
}
+}
\ No newline at end of file
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java Tue Nov 18 16:06:06 2008
@@ -19,15 +19,16 @@
import org.apache.poi.hssf.util.RKUtil;
import org.apache.poi.util.HexDump;
+import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: RK Record (0x027E)
+ * Title: RK Record (0x027E)<p/>
* Description: An internal 32 bit number with the two most significant bits
* storing the type. This is part of a bizarre scheme to save disk
* space and memory (gee look at all the other whole records that
* are in the file just "cause"..,far better to waste processor
- * cycles on this then leave on of those "valuable" records out).<P>
- * We support this in READ-ONLY mode. HSSF converts these to NUMBER records<P>
+ * cycles on this then leave on of those "valuable" records out).<p/>
+ * We support this in READ-ONLY mode. HSSF converts these to NUMBER records<p/>
*
*
*
@@ -36,7 +37,7 @@
* @author Jason Height (jheight at chariot dot net dot au)
* @see org.apache.poi.hssf.record.NumberRecord
*/
-public final class RKRecord extends Record implements CellValueRecordInterface {
+public final class RKRecord extends StandardRecord implements CellValueRecordInterface {
public final static short sid = 0x027E;
public final static short RK_IEEE_NUMBER = 0;
public final static short RK_IEEE_NUMBER_TIMES_100 = 1;
@@ -47,7 +48,7 @@
private int field_3_xf_index;
private int field_4_rk_number;
- public RKRecord()
+ private RKRecord()
{
}
@@ -133,7 +134,7 @@
return sb.toString();
}
- public int serialize(int offset, byte [] data) {
+ public void serialize(LittleEndianOutput out) {
throw new RecordFormatException( "Sorry, you can't serialize RK in this release");
}
protected int getDataSize() {
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RecalcIdRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RecalcIdRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RecalcIdRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RecalcIdRecord.java Tue Nov 18 16:06:06 2008
@@ -17,10 +17,11 @@
package org.apache.poi.hssf.record;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.HexDump;
+import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: Recalc Id Record<P>
+ * Title: Recalc Id Record (0x01C1)<p/>
* Description: This record contains an ID that marks when a worksheet was last
* recalculated. It's an optimization Excel uses to determine if it
* needs to recalculate the spreadsheet when it's opened. So far, only
@@ -28,100 +29,51 @@
* (do not recalculate) and <code>0xC1 0x01 0x00 0x00 0x60 0x69 0x01
* 0x00</code> have been seen. If the field <code>isNeeded</code> is
* set to false (default), then this record is swallowed during the
- * serialization process<P>
- * REFERENCE: http://chicago.sourceforge.net/devel/docs/excel/biff8.html<P>
+ * serialization process<p/>
+ * REFERENCE: http://chicago.sourceforge.net/devel/docs/excel/biff8.html<p/>
* @author Luc Girardin (luc dot girardin at macrofocus dot com)
- * @version 2.0-pre
+ *
* @see org.apache.poi.hssf.model.Workbook
*/
-
-public final class RecalcIdRecord extends Record {
- public final static short sid = 0x1c1;
- public short[] field_1_recalcids;
-
- private boolean isNeeded = true;
-
- public RecalcIdRecord()
- {
- }
-
- public RecalcIdRecord(RecordInputStream in)
- {
- field_1_recalcids = new short[ in.remaining() / 2 ];
- for (int k = 0; k < field_1_recalcids.length; k++)
- {
- field_1_recalcids[ k ] = in.readShort();
- }
- }
-
- /**
- * set the recalc array.
- * @param array of recalc id's
- */
-
- public void setRecalcIdArray(short [] array)
- {
- field_1_recalcids = array;
- }
-
- /**
- * get the recalc array.
- * @return array of recalc id's
- */
-
- public short [] getRecalcIdArray()
- {
- return field_1_recalcids;
- }
-
- public void setIsNeeded(boolean isNeeded) {
- this.isNeeded = isNeeded;
+public final class RecalcIdRecord extends StandardRecord {
+ public final static short sid = 0x01C1;
+ private final int _reserved0;
+ private final int _engineId;
+
+ public RecalcIdRecord(RecordInputStream in) {
+ int rt = in.readUShort();
+ if (rt != sid) {
+ throw new RecordFormatException("expected " + sid + " but got " + rt);
+ }
+ _reserved0 = in.readUShort();
+ _engineId = in.readInt();
}
public boolean isNeeded() {
- return isNeeded;
+ return true;
}
- public String toString()
- {
+ public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[RECALCID]\n");
- buffer.append(" .elements = ").append(field_1_recalcids.length)
- .append("\n");
- for (int k = 0; k < field_1_recalcids.length; k++)
- {
- buffer.append(" .element_" + k + " = ")
- .append(field_1_recalcids[ k ]).append("\n");
- }
+ buffer.append(" .reserved = ").append(HexDump.shortToHex(_reserved0));
+ buffer.append(" .engineId = ").append(HexDump.intToHex(_engineId));
buffer.append("[/RECALCID]\n");
return buffer.toString();
}
- public int serialize(int offset, byte [] data)
- {
- short[] tabids = getRecalcIdArray();
- short length = ( short ) (tabids.length * 2);
- int byteoffset = 4;
-
- LittleEndian.putUShort(data, 0 + offset, sid);
- LittleEndian.putUShort(data, 2 + offset, length);
-
- // 2 (num bytes in a short)
- for (int k = 0; k < (length / 2); k++)
- {
- LittleEndian.putShort(data, byteoffset + offset, tabids[ k ]);
- byteoffset += 2;
- }
- return getRecordSize();
+ public void serialize(LittleEndianOutput out) {
+ out.writeShort(sid);
+ out.writeShort(_reserved0);
+ out.writeInt(_engineId);
}
protected int getDataSize() {
- return (getRecalcIdArray().length * 2);
+ return 8;
}
- public short getSid()
- {
+ public short getSid() {
return sid;
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/SelectionRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/SelectionRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/SelectionRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/SelectionRecord.java Tue Nov 18 16:06:06 2008
@@ -18,7 +18,9 @@
package org.apache.poi.hssf.record;
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
+import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Selection Record (0x001D)<P>
@@ -30,7 +32,7 @@
* @author Jason Height (jheight at chariot dot net dot au)
* @author Glen Stampoultzis (glens at apache.org)
*/
-public final class SelectionRecord extends Record {
+public final class SelectionRecord extends StandardRecord {
public final static short sid = 0x001D;
private byte field_1_pane;
private int field_2_row_active_cell;
@@ -123,45 +125,35 @@
* @return ref number of active cell
*/
public int getActiveCellRef() {
- return (short)field_4_active_cell_ref_index;
+ return field_4_active_cell_ref_index;
}
public String toString() {
- StringBuffer buffer = new StringBuffer();
+ StringBuffer sb = new StringBuffer();
- buffer.append("[SELECTION]\n");
- buffer.append(" .pane = ")
- .append(Integer.toHexString(getPane())).append("\n");
- buffer.append(" .activecellrow = ")
- .append(Integer.toHexString(getActiveCellRow())).append("\n");
- buffer.append(" .activecellcol = ")
- .append(Integer.toHexString(getActiveCellCol())).append("\n");
- buffer.append(" .activecellref = ")
- .append(Integer.toHexString(getActiveCellRef())).append("\n");
- buffer.append(" .numrefs = ")
- .append(Integer.toHexString(field_6_refs.length)).append("\n");
- buffer.append("[/SELECTION]\n");
- return buffer.toString();
+ sb.append("[SELECTION]\n");
+ sb.append(" .pane = ").append(HexDump.byteToHex(getPane())).append("\n");
+ sb.append(" .activecellrow = ").append(HexDump.shortToHex(getActiveCellRow())).append("\n");
+ sb.append(" .activecellcol = ").append(HexDump.shortToHex(getActiveCellCol())).append("\n");
+ sb.append(" .activecellref = ").append(HexDump.shortToHex(getActiveCellRef())).append("\n");
+ sb.append(" .numrefs = ").append(HexDump.shortToHex(field_6_refs.length)).append("\n");
+ sb.append("[/SELECTION]\n");
+ return sb.toString();
}
protected int getDataSize() {
return 9 // 1 byte + 4 shorts
+ CellRangeAddress8Bit.getEncodedSize(field_6_refs.length);
}
- public int serialize(int offset, byte [] data) {
- int dataSize = getDataSize();
- LittleEndian.putUShort(data, 0 + offset, sid);
- LittleEndian.putUShort(data, 2 + offset, dataSize);
- LittleEndian.putByte(data, 4 + offset, getPane());
- LittleEndian.putUShort(data, 5 + offset, getActiveCellRow());
- LittleEndian.putUShort(data, 7 + offset, getActiveCellCol());
- LittleEndian.putUShort(data, 9 + offset, getActiveCellRef());
+ public void serialize(LittleEndianOutput out) {
+ out.writeByte(getPane());
+ out.writeShort(getActiveCellRow());
+ out.writeShort(getActiveCellCol());
+ out.writeShort(getActiveCellRef());
int nRefs = field_6_refs.length;
- LittleEndian.putUShort(data, 11 + offset, nRefs);
+ out.writeShort(nRefs);
for (int i = 0; i < field_6_refs.length; i++) {
- CellRangeAddress8Bit r = field_6_refs[i];
- r.serialize(offset + 13 + i * CellRangeAddress8Bit.ENCODED_SIZE, data);
+ field_6_refs[i].serialize(out);
}
- return 4 + dataSize;
}
public short getSid() {
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/SeriesListRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/SeriesListRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/SeriesListRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/SeriesListRecord.java Tue Nov 18 16:06:06 2008
@@ -17,16 +17,19 @@
package org.apache.poi.hssf.record;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
+ * SERIESLIST (0x1016)
*
* The series list record defines the series displayed as an overlay to the main chart record.<br/>
- * TODO - does this record (0x1016) really exist. It doesn't seem to be referenced in either the OOO or MS doc
+ * This record doesn't seem to be referenced in either the OOO or MS doc, but this page mentions it
+ * http://ooxmlisdefectivebydesign.blogspot.com/2008/03/bad-surprise-in-microsoft-office-binary.html
+ *
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public final class SeriesListRecord extends Record {
+public final class SeriesListRecord extends StandardRecord {
public final static short sid = 0x1016;
private short[] field_1_seriesNumbers;
@@ -55,23 +58,13 @@
return buffer.toString();
}
- public int serialize(int offset, byte[] data) {
+ public void serialize(LittleEndianOutput out) {
int nItems = field_1_seriesNumbers.length;
- int dataSize = 2 + 2 * nItems;
-
- LittleEndian.putUShort(data, 0 + offset, sid);
- LittleEndian.putUShort(data, 2 + offset, dataSize);
-
- LittleEndian.putUShort(data, 4 + offset, nItems);
-
- int pos = offset + 6;
+ out.writeShort(nItems);
for (int i = 0; i < nItems; i++) {
- LittleEndian.putUShort(data, pos, field_1_seriesNumbers[i]);
- pos += 2;
+ out.writeShort(field_1_seriesNumbers[i]);
}
-
- return 4 + dataSize;
}
protected int getDataSize() {
@@ -84,7 +77,7 @@
}
public Object clone() {
- return new SeriesListRecord((short[]) field_1_seriesNumbers.clone());
+ return new SeriesListRecord(field_1_seriesNumbers.clone());
}
/**
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/StyleRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/StyleRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/StyleRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/StyleRecord.java Tue Nov 18 16:06:06 2008
@@ -20,7 +20,7 @@
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.util.StringUtil;
/**
@@ -30,11 +30,9 @@
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author aviks : string fixes for UserDefined Style
*/
-public final class StyleRecord extends Record {
+public final class StyleRecord extends StandardRecord {
public final static short sid = 0x0293;
- private static final BitField is16BitUnicodeFlag = BitFieldFactory.getInstance(0x01);
-
private static final BitField styleIndexMask = BitFieldFactory.getInstance(0x0FFF);
private static final BitField isBuiltinFlag = BitFieldFactory.getInstance(0x8000);
@@ -46,7 +44,7 @@
private int field_3_outline_style_level;
// only for user defined styles
- private int field_3_string_options;
+ private boolean field_3_stringHasMultibyte;
private String field_4_name;
/**
@@ -74,8 +72,8 @@
field_4_name = "";
} else {
- int is16BitUnicode = in.readByte();
- if (is16BitUnicodeFlag.isSet(is16BitUnicode)) {
+ field_3_stringHasMultibyte = in.readByte() != 0x00;
+ if (field_3_stringHasMultibyte) {
field_4_name = StringUtil.readUnicodeLE(in, field_2_name_length);
} else {
field_4_name = StringUtil.readCompressedUnicode(in, field_2_name_length);
@@ -107,7 +105,7 @@
*/
public void setName(String name) {
field_4_name = name;
- field_3_string_options = StringUtil.hasMultibyte(name) ? 0x01 : 0x00;
+ field_3_stringHasMultibyte = StringUtil.hasMultibyte(name);
field_1_xf_index = isBuiltinFlag.clear(field_1_xf_index);
}
@@ -162,34 +160,24 @@
if (isBuiltin()) {
return 4; // short, byte, byte
}
- int size = 2 + 3; // short
- if (is16BitUnicodeFlag.isSet(field_3_string_options)) {
- size += 2 * field_4_name.length();
- } else {
- size += field_4_name.length();
- }
- return size;
+ return 2 // short xf index
+ + 3 // str len + flag
+ + field_4_name.length() * (field_3_stringHasMultibyte ? 2 : 1);
}
- public int serialize(int offset, byte [] data) {
- int dataSize = getDataSize();
- LittleEndian.putShort(data, 0 + offset, sid);
- LittleEndian.putUShort(data, 2 + offset, dataSize);
-
- LittleEndian.putUShort(data, 4 + offset, field_1_xf_index);
+ public void serialize(LittleEndianOutput out) {
+ out.writeShort(field_1_xf_index);
if (isBuiltin()) {
- LittleEndian.putByte(data, 6 + offset, field_2_builtin_style);
- LittleEndian.putByte(data, 7 + offset, field_3_outline_style_level);
+ out.writeByte(field_2_builtin_style);
+ out.writeByte(field_3_outline_style_level);
} else {
- LittleEndian.putUShort(data, 6 + offset, field_4_name.length());
- LittleEndian.putByte(data, 8 + offset, field_3_string_options);
- StringUtil.putCompressedUnicode(getName(), data, 9 + offset);
+ out.writeShort(field_4_name.length());
+ out.writeByte(field_3_stringHasMultibyte ? 0x01 : 0x00);
+ StringUtil.putCompressedUnicode(getName(), out);
}
- return 4+dataSize;
}
- public short getSid()
- {
+ public short getSid() {
return sid;
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/TabIdRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/TabIdRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/TabIdRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/TabIdRecord.java Tue Nov 18 16:06:06 2008
@@ -17,30 +17,31 @@
package org.apache.poi.hssf.record;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: Sheet Tab Index Array Record<P>
+ * Title: Sheet Tab Index Array Record (0x013D)<p/>
* Description: Contains an array of sheet id's. Sheets always keep their ID
- * regardless of what their name is.<P>
- * REFERENCE: PG 412 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
+ * regardless of what their name is.<p/>
+ * REFERENCE: PG 412 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
- * @version 2.0-pre
+ *
*/
-public final class TabIdRecord extends Record {
+public final class TabIdRecord extends StandardRecord {
public final static short sid = 0x13d;
- public short[] field_1_tabids;
-
- public TabIdRecord()
- {
+ private static final short[] EMPTY_SHORT_ARRAY = { };
+
+ public short[] _tabids;
+
+ public TabIdRecord() {
+ _tabids = EMPTY_SHORT_ARRAY;
}
- public TabIdRecord(RecordInputStream in)
- {
- field_1_tabids = new short[ in.remaining() / 2 ];
- for (int k = 0; k < field_1_tabids.length; k++)
- {
- field_1_tabids[ k ] = in.readShort();
+ public TabIdRecord(RecordInputStream in) {
+ int nTabs = in.remaining() / 2;
+ _tabids = new short[nTabs];
+ for (int k = 0; k < _tabids.length; k++) {
+ _tabids[ k ] = in.readShort();
}
}
@@ -48,62 +49,36 @@
* set the tab array. (0,1,2).
* @param array of tab id's {0,1,2}
*/
-
- public void setTabIdArray(short [] array)
- {
- field_1_tabids = array;
- }
-
- /**
- * get the tab array. (0,1,2).
- * @return array of tab id's {0,1,2}
- */
-
- public short [] getTabIdArray()
- {
- return field_1_tabids;
+ public void setTabIdArray(short[] array) {
+ _tabids = array;
}
- public String toString()
- {
+ public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[TABID]\n");
- buffer.append(" .elements = ").append(field_1_tabids.length)
- .append("\n");
- for (int k = 0; k < field_1_tabids.length; k++)
+ buffer.append(" .elements = ").append(_tabids.length).append("\n");
+ for (int k = 0; k < _tabids.length; k++)
{
- buffer.append(" .element_" + k + " = ")
- .append(field_1_tabids[ k ]).append("\n");
+ buffer.append(" .element_").append(k).append(" = ").append(_tabids[ k ]).append("\n");
}
buffer.append("[/TABID]\n");
return buffer.toString();
}
- public int serialize(int offset, byte [] data)
- {
- short[] tabids = getTabIdArray();
- int length = tabids.length * 2;
- int byteoffset = 4;
+ public void serialize(LittleEndianOutput out) {
+ short[] tabids = _tabids;
- LittleEndian.putUShort(data, 0 + offset, sid);
- LittleEndian.putUShort(data, 2 + offset, length); // nubmer tabids *
-
- // 2 (num bytes in a short)
- for (int k = 0; k < (length / 2); k++)
- {
- LittleEndian.putShort(data, byteoffset + offset, tabids[ k ]);
- byteoffset += 2;
+ for (int k = 0; k < tabids.length; k++) {
+ out.writeShort(tabids[ k ]);
}
- return getRecordSize();
}
protected int getDataSize() {
- return (getTabIdArray().length * 2);
+ return _tabids.length * 2;
}
- public short getSid()
- {
+ public short getSid() {
return sid;
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java Tue Nov 18 16:06:06 2008
@@ -18,19 +18,19 @@
package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: Unknown Record (for debugging)<P>
+ * Title: Unknown Record (for debugging)<p/>
* Description: Unknown record just tells you the sid so you can figure out
* what records you are missing. Also helps us read/modify sheets we
- * don't know all the records to. (HSSF leaves these alone!) <P>
+ * don't know all the records to. (HSSF leaves these alone!) <p/>
* Company: SuperLink Software, Inc.<P>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au)
* @author Glen Stampoultzis (glens at apache.org)
*/
-public final class UnknownRecord extends Record {
+public final class UnknownRecord extends StandardRecord {
/*
* Some Record IDs used by POI as 'milestones' in the record stream
@@ -79,12 +79,8 @@
/**
* spit the record out AS IS. no interpretation or identification
*/
- public final int serialize(int offset, byte[] data) {
- LittleEndian.putUShort(data, 0 + offset, _sid);
- int dataSize = _rawData.length;
- LittleEndian.putUShort(data, 2 + offset, dataSize);
- System.arraycopy(_rawData, 0, data, 4 + offset, dataSize);
- return 4 + dataSize;
+ public void serialize(LittleEndianOutput out) {
+ out.write(_rawData);
}
protected int getDataSize() {
@@ -94,7 +90,7 @@
/**
* print a sort of string representation ([UNKNOWN RECORD] id = x [/UNKNOWN RECORD])
*/
- public final String toString() {
+ public String toString() {
String biffName = getBiffName(_sid);
if (biffName == null) {
biffName = "UNKNOWNRECORD";
@@ -110,7 +106,7 @@
return sb.toString();
}
- public final short getSid() {
+ public short getSid() {
return (short) _sid;
}
@@ -267,8 +263,8 @@
return false;
}
- public final Object clone() {
- // immutable - ok to return this
+ public Object clone() {
+ // immutable - OK to return this
return this;
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java Tue Nov 18 16:06:06 2008
@@ -19,7 +19,7 @@
import java.util.Arrays;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.util.StringUtil;
/**
@@ -33,9 +33,10 @@
*
* @author Andrew C. Oliver (acoliver at apache dot org)
*/
-public final class WriteAccessRecord extends Record {
- private static final byte PAD_CHAR = (byte) ' ';
+public final class WriteAccessRecord extends StandardRecord {
public final static short sid = 0x005C;
+
+ private static final byte PAD_CHAR = (byte) ' ';
private static final int DATA_SIZE = 112;
private String field_1_username;
/** this record is always padded to a constant length */
@@ -113,24 +114,18 @@
return buffer.toString();
}
- public int serialize(int offset, byte[] data) {
+ public void serialize(LittleEndianOutput out) {
String username = getUsername();
boolean is16bit = StringUtil.hasMultibyte(username);
- LittleEndian.putUShort(data, 0 + offset, sid);
- LittleEndian.putUShort(data, 2 + offset, DATA_SIZE);
- LittleEndian.putUShort(data, 4 + offset, username.length());
- LittleEndian.putByte(data, 6 + offset, is16bit ? 0x01 : 0x00);
- int pos = offset + 7;
+ out.writeShort(username.length());
+ out.writeByte(is16bit ? 0x01 : 0x00);
if (is16bit) {
- StringUtil.putUnicodeLE(username, data, pos);
- pos += username.length() * 2;
+ StringUtil.putUnicodeLE(username, out);
} else {
- StringUtil.putCompressedUnicode(username, data, pos);
- pos += username.length();
+ StringUtil.putCompressedUnicode(username, out);
}
- System.arraycopy(padding, 0, data, pos, padding.length);
- return 4 + DATA_SIZE;
+ out.write(padding);
}
protected int getDataSize() {
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java Tue Nov 18 16:06:06 2008
@@ -51,8 +51,8 @@
// (The whole PageSettingsBlock may not be present)
private PageBreakRecord _rowBreaksRecord;
private PageBreakRecord _columnBreaksRecord;
- private HeaderRecord header;
- private FooterRecord footer;
+ private HeaderRecord _header;
+ private FooterRecord _footer;
private HCenterRecord _hCenter;
private VCenterRecord _vCenter;
private LeftMarginRecord _leftMargin;
@@ -77,8 +77,8 @@
public PageSettingsBlock() {
_rowBreaksRecord = new HorizontalPageBreakRecord();
_columnBreaksRecord = new VerticalPageBreakRecord();
- header = createHeader();
- footer = createFooter();
+ _header = new HeaderRecord("");
+ _footer = new FooterRecord("");
_hCenter = createHCenter();
_vCenter = createVCenter();
printSetup = createPrintSetup();
@@ -117,10 +117,10 @@
_columnBreaksRecord = (PageBreakRecord) rs.getNext();
break;
case HeaderRecord.sid:
- header = (HeaderRecord) rs.getNext();
+ _header = (HeaderRecord) rs.getNext();
break;
case FooterRecord.sid:
- footer = (FooterRecord) rs.getNext();
+ _footer = (FooterRecord) rs.getNext();
break;
case HCenterRecord.sid:
_hCenter = (HCenterRecord) rs.getNext();
@@ -193,8 +193,8 @@
public void visitContainedRecords(RecordVisitor rv) {
visitIfPresent(_rowBreaksRecord, rv);
visitIfPresent(_columnBreaksRecord, rv);
- visitIfPresent(header, rv);
- visitIfPresent(footer, rv);
+ visitIfPresent(_header, rv);
+ visitIfPresent(_footer, rv);
visitIfPresent(_hCenter, rv);
visitIfPresent(_vCenter, rv);
visitIfPresent(_leftMargin, rv);
@@ -221,28 +221,6 @@
}
/**
- * creates the Header Record and sets it to nothing/0 length
- */
- private static HeaderRecord createHeader() {
- HeaderRecord retval = new HeaderRecord();
-
- retval.setHeaderLength(( byte ) 0);
- retval.setHeader(null);
- return retval;
- }
-
- /**
- * creates the Footer Record and sets it to nothing/0 length
- */
- private static FooterRecord createFooter() {
- FooterRecord retval = new FooterRecord();
-
- retval.setFooterLength(( byte ) 0);
- retval.setFooter(null);
- return retval;
- }
-
- /**
* creates the HCenter Record and sets it to false (don't horizontally center)
*/
private static HCenterRecord createHCenter() {
@@ -292,7 +270,7 @@
*/
public HeaderRecord getHeader ()
{
- return header;
+ return _header;
}
/**
@@ -301,7 +279,7 @@
*/
public void setHeader (HeaderRecord newHeader)
{
- header = newHeader;
+ _header = newHeader;
}
/**
@@ -310,7 +288,7 @@
*/
public FooterRecord getFooter ()
{
- return footer;
+ return _footer;
}
/**
@@ -319,7 +297,7 @@
*/
public void setFooter (FooterRecord newFooter)
{
- footer = newFooter;
+ _footer = newFooter;
}
/**
@@ -419,11 +397,11 @@
*/
private static void shiftBreaks(PageBreakRecord breaks, int start, int stop, int count) {
- Iterator iterator = breaks.getBreaksIterator();
- List shiftedBreak = new ArrayList();
+ Iterator<PageBreakRecord.Break> iterator = breaks.getBreaksIterator();
+ List<PageBreakRecord.Break> shiftedBreak = new ArrayList<PageBreakRecord.Break>();
while(iterator.hasNext())
{
- PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
+ PageBreakRecord.Break breakItem = iterator.next();
int breakLocation = breakItem.main;
boolean inStart = (breakLocation >= start);
boolean inEnd = (breakLocation <= stop);
@@ -433,7 +411,7 @@
iterator = shiftedBreak.iterator();
while (iterator.hasNext()) {
- PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
+ PageBreakRecord.Break breakItem = iterator.next();
breaks.removeBreak(breakItem.main);
breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo);
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java Tue Nov 18 16:06:06 2008
@@ -250,7 +250,7 @@
// Serialize a block of cells for those rows
final int startRowNumber = getStartRowNumberForBlock(blockIndex);
final int endRowNumber = getEndRowNumberForBlock(blockIndex);
- DBCellRecord cellRecord = new DBCellRecord();
+ DBCellRecord.Builder dbcrBuilder = new DBCellRecord.Builder();
// Note: Cell references start from the second row...
int cellRefOffset = (rowBlockSize - RowRecord.ENCODED_SIZE);
for (int row = startRowNumber; row <= endRowNumber; row++) {
@@ -261,13 +261,12 @@
pos += rowCellSize;
// Add the offset to the first cell for the row into the
// DBCellRecord.
- cellRecord.addCellOffset((short) cellRefOffset);
+ dbcrBuilder.addCellOffset(cellRefOffset);
cellRefOffset = rowCellSize;
}
}
// Calculate Offset from the start of a DBCellRecord to the first Row
- cellRecord.setRowOffset(pos);
- rv.visitRecord(cellRecord);
+ rv.visitRecord(dbcrBuilder.build(pos));
}
for (int i=0; i< _unknownRecords.size(); i++) {
// Potentially breaking the file here since we don't know exactly where to write these records
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Tue Nov 18 16:06:06 2008
@@ -1015,9 +1015,7 @@
if(workbook != source.workbook) {
// Then we need to clone the format string,
// and update the format record for this
- short fmt = workbook.createFormat(
- source.getDataFormatString()
- );
+ short fmt = (short)workbook.createFormat(source.getDataFormatString() );
setDataFormat(fmt);
// Finally we need to clone the font,
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java Tue Nov 18 16:06:06 2008
@@ -15,12 +15,6 @@
limitations under the License.
==================================================================== */
-
-/*
- * HSSFFont.java
- *
- * Created on December 9, 2001, 10:34 AM
- */
package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.record.FontRecord;
@@ -29,16 +23,13 @@
/**
* Represents a Font used in a workbook.
*
- * @version 1.0-pre
+ *
* @author Andrew C. Oliver
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createFont()
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
* @see org.apache.poi.hssf.usermodel.HSSFCellStyle#setFont(HSSFFont)
*/
-
-public class HSSFFont implements Font
-{
-
+public final class HSSFFont implements Font {
private FontRecord font;
private short index;
@@ -60,7 +51,6 @@
public void setFontName(String name)
{
font.setFontName(name);
- font.setFontNameLength(( byte ) name.length());
}
/**
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFooter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFooter.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFooter.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFooter.java Tue Nov 18 16:06:06 2008
@@ -86,7 +86,6 @@
"&C" + (center == null ? "" : center) +
"&L" + (left == null ? "" : left) +
"&R" + (right == null ? "" : right));
- footerRecord.setFooterLength((byte)footerRecord.getFooter().length());
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFHeader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFHeader.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFHeader.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFHeader.java Tue Nov 18 16:06:06 2008
@@ -92,7 +92,6 @@
headerRecord.setHeader( "&C" + ( center == null ? "" : center ) +
"&L" + ( left == null ? "" : left ) +
"&R" + ( right == null ? "" : right ) );
- headerRecord.setHeaderLength( (byte) headerRecord.getHeader().length() );
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java Tue Nov 18 16:06:06 2008
@@ -47,12 +47,12 @@
import org.apache.poi.hssf.record.HeaderRecord;
import org.apache.poi.hssf.record.LegendRecord;
import org.apache.poi.hssf.record.LineFormatRecord;
-import org.apache.poi.hssf.record.LinkedDataFormulaField;
import org.apache.poi.hssf.record.LinkedDataRecord;
import org.apache.poi.hssf.record.PlotAreaRecord;
import org.apache.poi.hssf.record.PlotGrowthRecord;
import org.apache.poi.hssf.record.PrintSetupRecord;
import org.apache.poi.hssf.record.ProtectRecord;
+import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.SCLRecord;
import org.apache.poi.hssf.record.SeriesIndexRecord;
@@ -96,12 +96,12 @@
public void createBarChart( HSSFWorkbook workbook, HSSFSheet sheet )
{
- List records = new ArrayList();
+ List<Record> records = new ArrayList<Record>();
records.add( createMSDrawingObjectRecord() );
records.add( createOBJRecord() );
records.add( createBOFRecord() );
- records.add( createHeaderRecord() );
- records.add( createFooterRecord() );
+ records.add(new HeaderRecord(""));
+ records.add(new FooterRecord(""));
records.add( createHCenterRecord() );
records.add( createVCenterRecord() );
records.add( createPrintSetupRecord() );
@@ -340,20 +340,6 @@
return r;
}
- private FooterRecord createFooterRecord()
- {
- FooterRecord r = new FooterRecord();
- r.setFooter(null);
- return r;
- }
-
- private HeaderRecord createHeaderRecord()
- {
- HeaderRecord r = new HeaderRecord();
- r.setHeader(null);
- return r;
- }
-
private BOFRecord createBOFRecord()
{
BOFRecord r = new BOFRecord();
@@ -447,7 +433,7 @@
r.setReferenceType(LinkedDataRecord.REFERENCE_TYPE_DIRECT);
r.setCustomNumberFormat(false);
r.setIndexNumberFmtRecord((short)0);
- r.setFormulaOfLink( new LinkedDataFormulaField() );
+ r.setFormulaOfLink(null);
return r;
}
@@ -647,7 +633,7 @@
r.setReferenceType( LinkedDataRecord.REFERENCE_TYPE_DIRECT );
r.setCustomNumberFormat( false );
r.setIndexNumberFmtRecord( (short) 0 );
- r.setFormulaOfLink( new LinkedDataFormulaField() );
+ r.setFormulaOfLink(null);
return r;
}
@@ -758,11 +744,9 @@
r.setReferenceType( LinkedDataRecord.REFERENCE_TYPE_WORKSHEET );
r.setCustomNumberFormat( false );
r.setIndexNumberFmtRecord( (short) 0 );
- LinkedDataFormulaField formula = new LinkedDataFormulaField();
Area3DPtg p = new Area3DPtg(0, 31, 1, 1,
false, false, false, false, 0);
- formula.setFormulaTokens(new Ptg[] { p, });
- r.setFormulaOfLink( formula );
+ r.setFormulaOfLink(new Ptg[] { p, });
return r;
}
@@ -773,11 +757,9 @@
r.setReferenceType( LinkedDataRecord.REFERENCE_TYPE_WORKSHEET );
r.setCustomNumberFormat( false );
r.setIndexNumberFmtRecord( (short) 0 );
- LinkedDataFormulaField formula = new LinkedDataFormulaField();
Area3DPtg p = new Area3DPtg(0, 31, 0, 0,
false, false, false, false, 0);
- formula.setFormulaTokens(new Ptg[] { p, });
- r.setFormulaOfLink( formula );
+ r.setFormulaOfLink(new Ptg[] { p, });
return r;
}
@@ -788,7 +770,7 @@
r.setReferenceType( LinkedDataRecord.REFERENCE_TYPE_DIRECT );
r.setCustomNumberFormat( false );
r.setIndexNumberFmtRecord( (short) 0 );
- r.setFormulaOfLink( new LinkedDataFormulaField() );
+ r.setFormulaOfLink(null);
return r;
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java Tue Nov 18 16:06:06 2008
@@ -14,58 +14,52 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.record;
import junit.framework.TestCase;
/**
- * Tests the serialization and deserialization of the FontRecord
- * class works correctly. Test data taken directly from a real
- * Excel file.
+ * Tests the serialization and deserialization of the {@link FontRecord}
+ * class works correctly. Test data taken directly from a real Excel file.
*/
public final class TestFontRecord extends TestCase {
- byte[] header = new byte[] {
- 0x31, 00, 0x1a, 00, // sid=31, 26 bytes long
- };
- byte[] data = new byte[] {
- 0xC8-256, 00, // font height = xc8
- 00, 00, // attrs = 0
- 0xFF-256, 0x7F, // colour palette = x7fff
- 0x90-256, 0x01, // bold weight = x190
- 00, 00, // supersubscript
- 00, 00, // underline, family
- 00, 00, // charset, padding
- 05, 01, // name length, unicode flag
- 0x41, 0x00, 0x72, 0x00, 0x69, // Arial, as unicode
- 0x00, 0x61, 0x00, 0x6C, 0x00
+
+ private static final byte[] data = {
+ 0xC8-256, 00, // font height = xc8
+ 00, 00, // attrs = 0
+ 0xFF-256, 0x7F, // colour palette = x7fff
+ 0x90-256, 0x01, // bold weight = x190
+ 00, 00, // supersubscript
+ 00, 00, // underline, family
+ 00, 00, // charset, padding
+ 05, 00, // name length, unicode flag
+ 0x41, 0x72, 0x69, 0x61, 0x6C, // Arial, as unicode
+
};
public void testLoad() {
FontRecord record = new FontRecord(TestcaseRecordInputStream.create(0x31, data));
- assertEquals( 0xc8, record.getFontHeight());
- assertEquals( 0x00, record.getAttributes());
- assertFalse( record.isItalic());
- assertFalse( record.isStruckout());
- assertFalse( record.isMacoutlined());
- assertFalse( record.isMacshadowed());
- assertEquals( 0x7fff, record.getColorPaletteIndex());
- assertEquals( 0x190, record.getBoldWeight());
- assertEquals( 0x00, record.getSuperSubScript());
- assertEquals( 0x00, record.getUnderline());
- assertEquals( 0x00, record.getFamily());
- assertEquals( 0x00, record.getCharset());
- assertEquals( 0x05, record.getFontNameLength());
- assertEquals( "Arial", record.getFontName());
+ assertEquals(0xc8, record.getFontHeight());
+ assertEquals(0x00, record.getAttributes());
+ assertFalse(record.isItalic());
+ assertFalse(record.isStruckout());
+ assertFalse(record.isMacoutlined());
+ assertFalse(record.isMacshadowed());
+ assertEquals(0x7fff, record.getColorPaletteIndex());
+ assertEquals(0x190, record.getBoldWeight());
+ assertEquals(0x00, record.getSuperSubScript());
+ assertEquals(0x00, record.getUnderline());
+ assertEquals(0x00, record.getFamily());
+ assertEquals(0x00, record.getCharset());
+ assertEquals("Arial", record.getFontName());
-
- assertEquals( 26 + 4, record.getRecordSize() );
+ assertEquals(21 + 4, record.getRecordSize());
}
- public void testStore()
- {
+ public void testStore() {
// .fontheight = c8
// .attributes = 0
// .italic = false
@@ -90,7 +84,6 @@
record.setUnderline((byte)0);
record.setFamily((byte)0);
record.setCharset((byte)0);
- record.setFontNameLength((byte)5);
record.setFontName("Arial");
byte [] recordBytes = record.serialize();
@@ -98,10 +91,10 @@
for (int i = 0; i < data.length; i++)
assertEquals("At offset " + i, data[i], recordBytes[i+4]);
}
-
- public void testCloneOnto() throws Exception {
+
+ public void testCloneOnto() {
FontRecord base = new FontRecord(TestcaseRecordInputStream.create(0x31, data));
-
+
FontRecord other = new FontRecord();
other.cloneStyleFrom(base);
@@ -110,18 +103,18 @@
for (int i = 0; i < data.length; i++)
assertEquals("At offset " + i, data[i], recordBytes[i+4]);
}
-
+
public void testSameProperties() throws Exception {
FontRecord f1 = new FontRecord(TestcaseRecordInputStream.create(0x31, data));
FontRecord f2 = new FontRecord(TestcaseRecordInputStream.create(0x31, data));
-
+
assertTrue(f1.sameProperties(f2));
-
+
f2.setFontName("Arial2");
assertFalse(f1.sameProperties(f2));
f2.setFontName("Arial");
assertTrue(f1.sameProperties(f2));
-
+
f2.setFontHeight((short)11);
assertFalse(f1.sameProperties(f2));
f2.setFontHeight((short)0xc8);
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestLinkedDataRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestLinkedDataRecord.java?rev=718810&r1=718809&r2=718810&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestLinkedDataRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestLinkedDataRecord.java Tue Nov 18 16:06:06 2008
@@ -167,7 +167,7 @@
Area3DPtg ptgExpected = new Area3DPtg(0, 7936, 0, 0,
false, false, false, false, 0);
- Object ptgActual = record.getFormulaOfLink().getFormulaTokens()[0];
+ Ptg ptgActual = record.getFormulaOfLink()[0];
assertEquals(ptgExpected.toString(), ptgActual.toString());
assertEquals( data.length + 4, record.getRecordSize() );
@@ -182,9 +182,7 @@
record.setIndexNumberFmtRecord( (short)0 );
Area3DPtg ptg = new Area3DPtg(0, 7936, 0, 0,
false, false, false, false, 0);
- LinkedDataFormulaField formulaOfLink = new LinkedDataFormulaField();
- formulaOfLink.setFormulaTokens(new Ptg[] { ptg, });
- record.setFormulaOfLink(formulaOfLink );
+ record.setFormulaOfLink(new Ptg[] { ptg, } );
byte [] recordBytes = record.serialize();
assertEquals(recordBytes.length - 4, data.length);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org