package org.apache.poi.hssf.eventusermodel.dummyrecord;
import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordFormatException;
/**
* A dummy record to indicate that we've now had the last
* cell record for this row.
*/
-public class LastCellOfRowDummyRecord extends Record {
+public final class LastCellOfRowDummyRecord extends Record {
private int row;
private int lastColumnNumber;
return -1;
}
public int serialize(int offset, byte[] data) {
- return -1;
+ throw new RecordFormatException("Cannot serialize a dummy record");
+ }
+ public int getRecordSize() {
+ throw new RecordFormatException("Cannot serialize a dummy record");
}
}
package org.apache.poi.hssf.eventusermodel.dummyrecord;
import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordFormatException;
/**
* A dummy record for when we're missing a cell in a row,
* but still want to trigger something
*/
-public class MissingCellDummyRecord extends Record {
+public final class MissingCellDummyRecord extends Record {
private int row;
private int column;
return -1;
}
public int serialize(int offset, byte[] data) {
- return -1;
+ throw new RecordFormatException("Cannot serialize a dummy record");
+ }
+ public int getRecordSize() {
+ throw new RecordFormatException("Cannot serialize a dummy record");
}
public int getRow() { return row; }
package org.apache.poi.hssf.eventusermodel.dummyrecord;
import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.record.RecordFormatException;
/**
* A dummy record for when we're missing a row, but still
* want to trigger something
*/
-public class MissingRowDummyRecord extends Record {
+public final class MissingRowDummyRecord extends Record {
private int rowNumber;
public MissingRowDummyRecord(int rowNumber) {
return -1;
}
public int serialize(int offset, byte[] data) {
- return -1;
+ throw new RecordFormatException("Cannot serialize a dummy record");
+ }
+ public int getRecordSize() {
+ throw new RecordFormatException("Cannot serialize a dummy record");
}
public int getRowNumber() {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.record;
*/
public final class ContinueRecord extends Record {
public final static short sid = 0x003C;
- private byte[] _data;
+ private byte[] _data;
public ContinueRecord(byte[] data) {
_data = data;
}
- /**
- * USE ONLY within "processContinue"
- */
- public byte [] serialize()
- {
- byte[] retval = new byte[ _data.length + 4 ];
- serialize(0, retval);
- return retval;
+ public int getRecordSize() {
+ return 4 + _data.length;
}
public int serialize(int offset, byte[] data) {
/**
* THROWS A RUNTIME EXCEPTION.. USE LABELSSTRecords. YOU HAVE NO REASON to use LABELRecord!!
*/
- public int serialize(int offset, byte [] data)
- {
- throw new RecordFormatException(
- "Label Records are supported READ ONLY...convert to LabelSST");
+ public int serialize(int offset, byte [] data) {
+ throw new RecordFormatException("Label Records are supported READ ONLY...convert to LabelSST");
+ }
+ public int getRecordSize() {
+ throw new RecordFormatException("Label Records are supported READ ONLY...convert to LabelSST");
}
public short getSid()
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-/*
- * MulBlankRecord.java
- *
- * Created on December 10, 2001, 12:49 PM
- */
package org.apache.poi.hssf.record;
/**
- * Title: Mulitple Blank cell record <P>
+ * Title: Multiple Blank cell record(0x00BE) <P/>
* Description: Represents a set of columns in a row with no value but with styling.
* In this release we have read-only support for this record type.
- * The RecordFactory converts this to a set of BlankRecord objects.<P>
- * REFERENCE: PG 329 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
+ * The RecordFactory converts this to a set of BlankRecord objects.<P/>
+ * REFERENCE: PG 329 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P/>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Glen Stampoultzis (glens at apache.org)
- * @version 2.0-pre
- * @see org.apache.poi.hssf.record.BlankRecord
+ * @see BlankRecord
*/
-
-public class MulBlankRecord
- extends Record
-{
- public final static short sid = 0xbe;
- //private short field_1_row;
- private int field_1_row;
+public final class MulBlankRecord extends Record {
+ public final static short sid = 0x00BE;
+
+ private int field_1_row;
private short field_2_first_col;
private short[] field_3_xfs;
private short field_4_last_col;
- /** Creates new MulBlankRecord */
-
- public MulBlankRecord()
- {
- }
/**
* get the row number of the cells this represents
*
* @return row number
*/
-
- //public short getRow()
public int getRow()
{
return field_1_row;
* starting column (first cell this holds in the row)
* @return first column number
*/
-
public short getFirstColumn()
{
return field_2_first_col;
* ending column (last cell this holds in the row)
* @return first column number
*/
-
public short getLastColumn()
{
return field_4_last_col;
* get the number of columns this contains (last-first +1)
* @return number of columns (last - first +1)
*/
-
public int getNumColumns()
{
return field_4_last_col - field_2_first_col + 1;
* @param coffset the column (coffset = column - field_2_first_col)
* @return the XF index for the column
*/
-
public short getXFAt(int coffset)
{
return field_3_xfs[ coffset ];
/**
* @param in the RecordInputstream to read the record from
*/
- public MulBlankRecord(RecordInputStream in)
- {
- //field_1_row = LittleEndian.getShort(data, 0 + offset);
+ public MulBlankRecord(RecordInputStream in) {
field_1_row = in.readUShort();
field_2_first_col = in.readShort();
field_3_xfs = parseXFs(in);
field_4_last_col = in.readShort();
}
- private short [] parseXFs(RecordInputStream in)
+ private static short [] parseXFs(RecordInputStream in)
{
short[] retval = new short[ (in.remaining() - 2) / 2 ];
return retval;
}
- public String toString()
- {
+ public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[MULBLANK]\n");
- buffer.append("row = ")
- .append(Integer.toHexString(getRow())).append("\n");
- buffer.append("firstcol = ")
- .append(Integer.toHexString(getFirstColumn())).append("\n");
- buffer.append(" lastcol = ")
- .append(Integer.toHexString(getLastColumn())).append("\n");
- for (int k = 0; k < getNumColumns(); k++)
- {
- buffer.append("xf").append(k).append(" = ")
- .append(Integer.toHexString(getXFAt(k))).append("\n");
+ buffer.append("row = ").append(Integer.toHexString(getRow())).append("\n");
+ buffer.append("firstcol = ").append(Integer.toHexString(getFirstColumn())).append("\n");
+ buffer.append(" lastcol = ").append(Integer.toHexString(getLastColumn())).append("\n");
+ for (int k = 0; k < getNumColumns(); k++) {
+ buffer.append("xf").append(k).append(" = ").append(
+ Integer.toHexString(getXFAt(k))).append("\n");
}
buffer.append("[/MULBLANK]\n");
return buffer.toString();
return sid;
}
- public int serialize(int offset, byte [] data)
- {
- throw new RecordFormatException(
- "Sorry, you can't serialize a MulBlank in this release");
+ public int serialize(int offset, byte [] data) {
+ throw new RecordFormatException( "Sorry, you can't serialize MulBlank in this release");
+ }
+ public int getRecordSize() {
+ throw new RecordFormatException( "Sorry, you can't serialize MulBlank in this release");
}
}
return sid;
}
- public int serialize(int offset, byte [] data)
- {
- throw new RecordFormatException(
- "Sorry, you can't serialize a MulRK in this release");
+ public int serialize(int offset, byte [] data) {
+ throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release");
+ }
+ public int getRecordSize() {
+ throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release");
}
private static final class RkRec {
return sb.toString();
}
-// temporarily just constructs a new number record and returns its value
- public int serialize(int offset, byte [] data)
- {
- NumberRecord rec = new NumberRecord();
-
- rec.setColumn(getColumn());
- rec.setRow(getRow());
- rec.setValue(getRKNumber());
- rec.setXFIndex(getXFIndex());
- return rec.serialize(offset, data);
- }
-
- /**
- * Debugging main()
- * <P>
- * Normally I'd do this in a junit test, but let's face it -- once
- * this algorithm has been tested and it works, we are never ever
- * going to change it. This is driven by the Faceless Enemy's
- * minions, who dare not change the algorithm out from under us.
- *
- * @param ignored_args command line arguments, which we blithely
- * ignore
- */
-
- public static void main(String ignored_args[])
- {
- int[] values =
- {
- 0x3FF00000, 0x405EC001, 0x02F1853A, 0x02F1853B, 0xFCDD699A
- };
- double[] rvalues =
- {
- 1, 1.23, 12345678, 123456.78, -13149594
- };
-
- for (int j = 0; j < values.length; j++)
- {
- System.out.println("input = " + Integer.toHexString(values[ j ])
- + " -> " + rvalues[ j ] + ": "
- + RKUtil.decodeNumber(values[ j ]));
- }
- }
+ public int serialize(int offset, byte [] data) {
+ throw new RecordFormatException( "Sorry, you can't serialize RK in this release");
+ }
+ public int getRecordSize() {
+ throw new RecordFormatException( "Sorry, you can't serialize RK in this release");
+ }
public short getSid()
{
* @author Andrew C. Oliver
* @author Marc Johnson (mjohnson at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au)
- * @version 2.0-pre
*/
public abstract class Record extends RecordBase {
* @return byte array containing instance data
*/
- public byte [] serialize()
- {
+ public final byte[] serialize() {
byte[] retval = new byte[ getRecordSize() ];
serialize(0, retval);
return retval;
}
-
- /**
- * gives the current serialized size of the record. Should include the sid and reclength (4 bytes).
- */
-
- public int getRecordSize()
- {
-
- // this is kind od a stupid way to do it but for now we just serialize
- // the record and return the size of the byte array
- return serialize().length;
- }
-
/**
* get a string representation of the record (for biffview/debugging)
*/
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.util;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
/**
- * Tests the RKUtil class.
+ * Tests the {@link RKUtil} class.
*/
-public class TestRKUtil
- extends TestCase
-{
- public TestRKUtil(String s)
- {
- super(s);
- }
-
- /**
- * Check we can decode correctly.
- */
- public void testDecode()
- throws Exception
- {
- assertEquals(3.0, RKUtil.decodeNumber(1074266112), 0.0000001);
- assertEquals(3.3, RKUtil.decodeNumber(1081384961), 0.0000001);
- assertEquals(3.33, RKUtil.decodeNumber(1081397249), 0.0000001);
- }
+public final class TestRKUtil extends TestCase {
+
+ /**
+ * Check we can decode correctly.
+ */
+ public void testDecode() {
+
+ int[] values = { 1074266112, 1081384961, 1081397249,
+ 0x3FF00000, 0x405EC001, 0x02F1853A, 0x02F1853B, 0xFCDD699A,
+ };
+ double[] rvalues = { 3.0, 3.3, 3.33,
+ 1, 1.23, 12345678, 123456.78, -13149594,
+ };
+
+ for (int j = 0; j < values.length; j++) {
+
+ int intBits = values[j];
+ double expectedValue = rvalues[j];
+ double actualValue = RKUtil.decodeNumber(intBits);
+ if (expectedValue != actualValue) {
+ throw new AssertionFailedError("0x" + Integer.toHexString(intBits)
+ + " should decode to " + expectedValue + " but got " + actualValue);
+ }
+ }
+ }
}