improved toString methods

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@721043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-11-27 00:17:28 +00:00
parent b780e3173a
commit c87a1fe88a
2 changed files with 86 additions and 138 deletions

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,78 +15,56 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
/** /**
* Title: Beginning Of File<P> * Title: Beginning Of File (0x0809)<P>
* Description: Somewhat of a misnomer, its used for the beginning of a set of * Description: Somewhat of a misnomer, its used for the beginning of a set of
* records that have a particular pupose or subject. * records that have a particular purpose or subject.
* Used in sheets and workbooks.<P> * Used in sheets and workbooks.<P>
* REFERENCE: PG 289 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> * REFERENCE: PG 289 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* @author Andrew C. Oliver * @author Andrew C. Oliver
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre
*/ */
public final class BOFRecord extends StandardRecord {
public final class BOFRecord
extends StandardRecord
{
/** /**
* for BIFF8 files the BOF is 0x809. For earlier versions it was 0x09 or 0x(biffversion)09 * for BIFF8 files the BOF is 0x809. For earlier versions it was 0x09 or 0x(biffversion)09
*/ */
public final static short sid = 0x809; public final static short sid = 0x809;
private short field_1_version;
private short field_2_type; /** suggested default (0x06 - BIFF8) */
private short field_3_build; public final static int VERSION = 0x06;
private short field_4_year; /** suggested default 0x10d3 */
public final static int BUILD = 0x10d3;
/** suggested default 0x07CC (1996) */
public final static int BUILD_YEAR = 0x07CC; // 1996
/** suggested default for a normal sheet (0x41) */
public final static int HISTORY_MASK = 0x41;
public final static int TYPE_WORKBOOK = 0x05;
public final static int TYPE_VB_MODULE = 0x06;
public final static int TYPE_WORKSHEET = 0x10;
public final static int TYPE_CHART = 0x20;
public final static int TYPE_EXCEL_4_MACRO = 0x40;
public final static int TYPE_WORKSPACE_FILE = 0x100;
private int field_1_version;
private int field_2_type;
private int field_3_build;
private int field_4_year;
private int field_5_history; private int field_5_history;
private int field_6_rversion; private int field_6_rversion;
/**
* suggested default (0x06 - BIFF8)
*/
public final static short VERSION = 0x06;
/**
* suggested default 0x10d3
*/
public final static short BUILD = 0x10d3;
/**
* suggested default 0x07CC (1996)
*/
public final static short BUILD_YEAR = 0x07CC; // 1996
/**
* suggested default for a normal sheet (0x41)
*/
public final static short HISTORY_MASK = 0x41;
public final static short TYPE_WORKBOOK = 0x05;
public final static short TYPE_VB_MODULE = 0x06;
public final static short TYPE_WORKSHEET = 0x10;
public final static short TYPE_CHART = 0x20;
public final static short TYPE_EXCEL_4_MACRO = 0x40;
public final static short TYPE_WORKSPACE_FILE = 0x100;
/** /**
* Constructs an empty BOFRecord with no fields set. * Constructs an empty BOFRecord with no fields set.
*/ */
public BOFRecord() {
public BOFRecord()
{
} }
public BOFRecord(RecordInputStream in) public BOFRecord(RecordInputStream in) {
{
field_1_version = in.readShort(); field_1_version = in.readShort();
field_2_type = in.readShort(); field_2_type = in.readShort();
@ -112,9 +89,7 @@ public final class BOFRecord
* @see #VERSION * @see #VERSION
* @param version version to be set * @param version version to be set
*/ */
public void setVersion(int version) {
public void setVersion(short version)
{
field_1_version = version; field_1_version = version;
} }
@ -128,9 +103,7 @@ public final class BOFRecord
* @see #TYPE_WORKSPACE_FILE * @see #TYPE_WORKSPACE_FILE
* @param type type to be set * @param type type to be set
*/ */
public void setType(int type) {
public void setType(short type)
{
field_2_type = type; field_2_type = type;
} }
@ -139,9 +112,7 @@ public final class BOFRecord
* @see #BUILD * @see #BUILD
* @param build build number to set * @param build build number to set
*/ */
public void setBuild(int build) {
public void setBuild(short build)
{
field_3_build = build; field_3_build = build;
} }
@ -150,9 +121,7 @@ public final class BOFRecord
* @see #BUILD_YEAR * @see #BUILD_YEAR
* @param year build year to set * @param year build year to set
*/ */
public void setBuildYear(int year) {
public void setBuildYear(short year)
{
field_4_year = year; field_4_year = year;
} }
@ -161,9 +130,7 @@ public final class BOFRecord
* @see #HISTORY_MASK * @see #HISTORY_MASK
* @param bitmask bitmask to set for the history * @param bitmask bitmask to set for the history
*/ */
public void setHistoryBitMask(int bitmask) {
public void setHistoryBitMask(int bitmask)
{
field_5_history = bitmask; field_5_history = bitmask;
} }
@ -173,20 +140,16 @@ public final class BOFRecord
* @see #VERSION * @see #VERSION
* @param version version to set * @param version version to set
*/ */
public void setRequiredVersion(int version) {
public void setRequiredVersion(int version)
{
field_6_rversion = version; field_6_rversion = version;
} }
/** /**
* Version number - for BIFF8 should be 0x06 * Version number - for BIFF8 should be 0x06
* @see #VERSION * @see #VERSION
* @return short version number of the generator of this file * @return version number of the generator of this file
*/ */
public int getVersion() {
public short getVersion()
{
return field_1_version; return field_1_version;
} }
@ -198,11 +161,9 @@ public final class BOFRecord
* @see #TYPE_CHART * @see #TYPE_CHART
* @see #TYPE_EXCEL_4_MACRO * @see #TYPE_EXCEL_4_MACRO
* @see #TYPE_WORKSPACE_FILE * @see #TYPE_WORKSPACE_FILE
* @return short type of object * @return type of object
*/ */
public int getType() {
public short getType()
{
return field_2_type; return field_2_type;
} }
@ -211,9 +172,7 @@ public final class BOFRecord
* @see #BUILD * @see #BUILD
* @return short build number of the generator of this file * @return short build number of the generator of this file
*/ */
public int getBuild() {
public short getBuild()
{
return field_3_build; return field_3_build;
} }
@ -222,9 +181,7 @@ public final class BOFRecord
* @see #BUILD_YEAR * @see #BUILD_YEAR
* @return short build year of the generator of this file * @return short build year of the generator of this file
*/ */
public int getBuildYear() {
public short getBuildYear()
{
return field_4_year; return field_4_year;
} }
@ -233,9 +190,7 @@ public final class BOFRecord
* @see #HISTORY_MASK * @see #HISTORY_MASK
* @return int bitmask showing the history of the file (who cares!) * @return int bitmask showing the history of the file (who cares!)
*/ */
public int getHistoryBitMask() {
public int getHistoryBitMask()
{
return field_5_history; return field_5_history;
} }
@ -245,33 +200,37 @@ public final class BOFRecord
* @see #VERSION * @see #VERSION
* @return int least version that can read the file * @return int least version that can read the file
*/ */
public int getRequiredVersion() {
public int getRequiredVersion()
{
return field_6_rversion; return field_6_rversion;
} }
public String toString() public String toString() {
{
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append("[BOF RECORD]\n"); buffer.append("[BOF RECORD]\n");
buffer.append(" .version = ") buffer.append(" .version = ").append(HexDump.shortToHex(getVersion())).append("\n");
.append(Integer.toHexString(getVersion())).append("\n"); buffer.append(" .type = ").append(HexDump.shortToHex(getType()));
buffer.append(" .type = ") buffer.append(" (").append(getTypeName()).append(")").append("\n");
.append(Integer.toHexString(getType())).append("\n"); buffer.append(" .build = ").append(HexDump.shortToHex(getBuild())).append("\n");
buffer.append(" .build = ") buffer.append(" .buildyear= ").append(getBuildYear()).append("\n");
.append(Integer.toHexString(getBuild())).append("\n"); buffer.append(" .history = ").append(HexDump.intToHex(getHistoryBitMask())).append("\n");
buffer.append(" .buildyear = ").append(getBuildYear()) buffer.append(" .reqver = ").append(HexDump.intToHex(getRequiredVersion())).append("\n");
.append("\n");
buffer.append(" .history = ")
.append(Integer.toHexString(getHistoryBitMask())).append("\n");
buffer.append(" .requiredversion = ")
.append(Integer.toHexString(getRequiredVersion())).append("\n");
buffer.append("[/BOF RECORD]\n"); buffer.append("[/BOF RECORD]\n");
return buffer.toString(); return buffer.toString();
} }
private String getTypeName() {
switch(field_2_type) {
case TYPE_CHART: return "chart";
case TYPE_EXCEL_4_MACRO: return "excel 4 macro";
case TYPE_VB_MODULE: return "vb module";
case TYPE_WORKBOOK: return "workbook";
case TYPE_WORKSHEET: return "worksheet";
case TYPE_WORKSPACE_FILE: return "workspace file";
}
return "#error unknown type#";
}
public void serialize(LittleEndianOutput out) { public void serialize(LittleEndianOutput out) {
out.writeShort(getVersion()); out.writeShort(getVersion());
out.writeShort(getType()); out.writeShort(getType());
@ -285,8 +244,7 @@ public final class BOFRecord
return 16; return 16;
} }
public short getSid() public short getSid(){
{
return sid; return sid;
} }

View File

@ -66,31 +66,21 @@ public final class LinkedDataRecord extends StandardRecord {
field_5_formulaOfLink = Formula.read(encodedTokenLen, in); field_5_formulaOfLink = Formula.read(encodedTokenLen, in);
} }
public String toString() public String toString() {
{
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append("[AI]\n"); buffer.append("[AI]\n");
buffer.append(" .linkType = ") buffer.append(" .linkType = ").append(HexDump.byteToHex(getLinkType())).append('\n');
.append("0x").append(HexDump.toHex( getLinkType ())) buffer.append(" .referenceType = ").append(HexDump.byteToHex(getReferenceType())).append('\n');
.append(" (").append( getLinkType() ).append(" )"); buffer.append(" .options = ").append(HexDump.shortToHex(getOptions())).append('\n');
buffer.append(System.getProperty("line.separator"));
buffer.append(" .referenceType = ")
.append("0x").append(HexDump.toHex( getReferenceType ()))
.append(" (").append( getReferenceType() ).append(" )");
buffer.append(System.getProperty("line.separator"));
buffer.append(" .options = ")
.append("0x").append(HexDump.toHex( getOptions ()))
.append(" (").append( getOptions() ).append(" )");
buffer.append(System.getProperty("line.separator"));
buffer.append(" .customNumberFormat = ").append(isCustomNumberFormat()).append('\n'); buffer.append(" .customNumberFormat = ").append(isCustomNumberFormat()).append('\n');
buffer.append(" .indexNumberFmtRecord = ") buffer.append(" .indexNumberFmtRecord = ").append(HexDump.shortToHex(getIndexNumberFmtRecord())).append('\n');
.append("0x").append(HexDump.toHex( getIndexNumberFmtRecord ())) buffer.append(" .formulaOfLink = ").append('\n');
.append(" (").append( getIndexNumberFmtRecord() ).append(" )"); Ptg[] ptgs = field_5_formulaOfLink.getTokens();
buffer.append(System.getProperty("line.separator")); for (int i = 0; i < ptgs.length; i++) {
buffer.append(" .formulaOfLink = ") Ptg ptg = ptgs[i];
.append(" (").append( getFormulaOfLink() ).append(" )"); buffer.append(ptg.toString()).append(ptg.getRVAType()).append('\n');
buffer.append(System.getProperty("line.separator")); }
buffer.append("[/AI]\n"); buffer.append("[/AI]\n");
return buffer.toString(); return buffer.toString();