mirror of https://github.com/apache/poi.git
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:
parent
7b61feb5f6
commit
8bb747bc62
|
@ -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,82 +14,60 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import org.apache.poi.util.HexDump;
|
||||
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
|
||||
* records that have a particular pupose or subject.
|
||||
* records that have a particular purpose or subject.
|
||||
* Used in sheets and workbooks.<P>
|
||||
* REFERENCE: PG 289 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
|
||||
* @author Andrew C. Oliver
|
||||
* @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
|
||||
*/
|
||||
|
||||
public final static short sid = 0x809;
|
||||
private short field_1_version;
|
||||
private short field_2_type;
|
||||
private short field_3_build;
|
||||
private short field_4_year;
|
||||
private int field_5_history;
|
||||
private int field_6_rversion;
|
||||
|
||||
/**
|
||||
* suggested default (0x06 - BIFF8)
|
||||
*/
|
||||
/** suggested default (0x06 - BIFF8) */
|
||||
public final static int VERSION = 0x06;
|
||||
/** 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 short VERSION = 0x06;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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_6_rversion;
|
||||
|
||||
/**
|
||||
* 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_2_type = in.readShort();
|
||||
|
||||
|
||||
// Some external tools don't generate all of
|
||||
// the remaining fields
|
||||
if (in.remaining() >= 2) {
|
||||
|
@ -112,9 +89,7 @@ public final class BOFRecord
|
|||
* @see #VERSION
|
||||
* @param version version to be set
|
||||
*/
|
||||
|
||||
public void setVersion(short version)
|
||||
{
|
||||
public void setVersion(int version) {
|
||||
field_1_version = version;
|
||||
}
|
||||
|
||||
|
@ -128,9 +103,7 @@ public final class BOFRecord
|
|||
* @see #TYPE_WORKSPACE_FILE
|
||||
* @param type type to be set
|
||||
*/
|
||||
|
||||
public void setType(short type)
|
||||
{
|
||||
public void setType(int type) {
|
||||
field_2_type = type;
|
||||
}
|
||||
|
||||
|
@ -139,9 +112,7 @@ public final class BOFRecord
|
|||
* @see #BUILD
|
||||
* @param build build number to set
|
||||
*/
|
||||
|
||||
public void setBuild(short build)
|
||||
{
|
||||
public void setBuild(int build) {
|
||||
field_3_build = build;
|
||||
}
|
||||
|
||||
|
@ -150,9 +121,7 @@ public final class BOFRecord
|
|||
* @see #BUILD_YEAR
|
||||
* @param year build year to set
|
||||
*/
|
||||
|
||||
public void setBuildYear(short year)
|
||||
{
|
||||
public void setBuildYear(int year) {
|
||||
field_4_year = year;
|
||||
}
|
||||
|
||||
|
@ -161,9 +130,7 @@ public final class BOFRecord
|
|||
* @see #HISTORY_MASK
|
||||
* @param bitmask bitmask to set for the history
|
||||
*/
|
||||
|
||||
public void setHistoryBitMask(int bitmask)
|
||||
{
|
||||
public void setHistoryBitMask(int bitmask) {
|
||||
field_5_history = bitmask;
|
||||
}
|
||||
|
||||
|
@ -173,20 +140,16 @@ public final class BOFRecord
|
|||
* @see #VERSION
|
||||
* @param version version to set
|
||||
*/
|
||||
|
||||
public void setRequiredVersion(int version)
|
||||
{
|
||||
public void setRequiredVersion(int version) {
|
||||
field_6_rversion = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Version number - for BIFF8 should be 0x06
|
||||
* @see #VERSION
|
||||
* @return short version number of the generator of this file
|
||||
* @return version number of the generator of this file
|
||||
*/
|
||||
|
||||
public short getVersion()
|
||||
{
|
||||
public int getVersion() {
|
||||
return field_1_version;
|
||||
}
|
||||
|
||||
|
@ -198,11 +161,9 @@ public final class BOFRecord
|
|||
* @see #TYPE_CHART
|
||||
* @see #TYPE_EXCEL_4_MACRO
|
||||
* @see #TYPE_WORKSPACE_FILE
|
||||
* @return short type of object
|
||||
* @return type of object
|
||||
*/
|
||||
|
||||
public short getType()
|
||||
{
|
||||
public int getType() {
|
||||
return field_2_type;
|
||||
}
|
||||
|
||||
|
@ -211,9 +172,7 @@ public final class BOFRecord
|
|||
* @see #BUILD
|
||||
* @return short build number of the generator of this file
|
||||
*/
|
||||
|
||||
public short getBuild()
|
||||
{
|
||||
public int getBuild() {
|
||||
return field_3_build;
|
||||
}
|
||||
|
||||
|
@ -222,9 +181,7 @@ public final class BOFRecord
|
|||
* @see #BUILD_YEAR
|
||||
* @return short build year of the generator of this file
|
||||
*/
|
||||
|
||||
public short getBuildYear()
|
||||
{
|
||||
public int getBuildYear() {
|
||||
return field_4_year;
|
||||
}
|
||||
|
||||
|
@ -233,9 +190,7 @@ public final class BOFRecord
|
|||
* @see #HISTORY_MASK
|
||||
* @return int bitmask showing the history of the file (who cares!)
|
||||
*/
|
||||
|
||||
public int getHistoryBitMask()
|
||||
{
|
||||
public int getHistoryBitMask() {
|
||||
return field_5_history;
|
||||
}
|
||||
|
||||
|
@ -245,33 +200,37 @@ public final class BOFRecord
|
|||
* @see #VERSION
|
||||
* @return int least version that can read the file
|
||||
*/
|
||||
|
||||
public int getRequiredVersion()
|
||||
{
|
||||
public int getRequiredVersion() {
|
||||
return field_6_rversion;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
buffer.append("[BOF RECORD]\n");
|
||||
buffer.append(" .version = ")
|
||||
.append(Integer.toHexString(getVersion())).append("\n");
|
||||
buffer.append(" .type = ")
|
||||
.append(Integer.toHexString(getType())).append("\n");
|
||||
buffer.append(" .build = ")
|
||||
.append(Integer.toHexString(getBuild())).append("\n");
|
||||
buffer.append(" .buildyear = ").append(getBuildYear())
|
||||
.append("\n");
|
||||
buffer.append(" .history = ")
|
||||
.append(Integer.toHexString(getHistoryBitMask())).append("\n");
|
||||
buffer.append(" .requiredversion = ")
|
||||
.append(Integer.toHexString(getRequiredVersion())).append("\n");
|
||||
buffer.append(" .version = ").append(HexDump.shortToHex(getVersion())).append("\n");
|
||||
buffer.append(" .type = ").append(HexDump.shortToHex(getType()));
|
||||
buffer.append(" (").append(getTypeName()).append(")").append("\n");
|
||||
buffer.append(" .build = ").append(HexDump.shortToHex(getBuild())).append("\n");
|
||||
buffer.append(" .buildyear= ").append(getBuildYear()).append("\n");
|
||||
buffer.append(" .history = ").append(HexDump.intToHex(getHistoryBitMask())).append("\n");
|
||||
buffer.append(" .reqver = ").append(HexDump.intToHex(getRequiredVersion())).append("\n");
|
||||
buffer.append("[/BOF RECORD]\n");
|
||||
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) {
|
||||
out.writeShort(getVersion());
|
||||
out.writeShort(getType());
|
||||
|
@ -285,8 +244,7 @@ public final class BOFRecord
|
|||
return 16;
|
||||
}
|
||||
|
||||
public short getSid()
|
||||
{
|
||||
public short getSid(){
|
||||
return sid;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,14 +28,14 @@ import org.apache.poi.util.LittleEndianOutput;
|
|||
|
||||
/**
|
||||
* 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 StandardRecord {
|
||||
public final static short sid = 0x1051;
|
||||
|
||||
private static final BitField customNumberFormat= BitFieldFactory.getInstance(0x1);
|
||||
|
||||
|
||||
private byte field_1_linkType;
|
||||
public final static byte LINK_TYPE_TITLE_OR_TEXT = 0;
|
||||
public final static byte LINK_TYPE_VALUES = 1;
|
||||
|
@ -63,44 +63,34 @@ public final class LinkedDataRecord extends StandardRecord {
|
|||
field_3_options = in.readShort();
|
||||
field_4_indexNumberFmtRecord = in.readShort();
|
||||
int encodedTokenLen = in.readUShort();
|
||||
field_5_formulaOfLink = Formula.read(encodedTokenLen, in);
|
||||
field_5_formulaOfLink = Formula.read(encodedTokenLen, in);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
buffer.append("[AI]\n");
|
||||
buffer.append(" .linkType = ")
|
||||
.append("0x").append(HexDump.toHex( getLinkType ()))
|
||||
.append(" (").append( getLinkType() ).append(" )");
|
||||
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(" .indexNumberFmtRecord = ")
|
||||
.append("0x").append(HexDump.toHex( getIndexNumberFmtRecord ()))
|
||||
.append(" (").append( getIndexNumberFmtRecord() ).append(" )");
|
||||
buffer.append(System.getProperty("line.separator"));
|
||||
buffer.append(" .formulaOfLink = ")
|
||||
.append(" (").append( getFormulaOfLink() ).append(" )");
|
||||
buffer.append(System.getProperty("line.separator"));
|
||||
buffer.append(" .linkType = ").append(HexDump.byteToHex(getLinkType())).append('\n');
|
||||
buffer.append(" .referenceType = ").append(HexDump.byteToHex(getReferenceType())).append('\n');
|
||||
buffer.append(" .options = ").append(HexDump.shortToHex(getOptions())).append('\n');
|
||||
buffer.append(" .customNumberFormat = ").append(isCustomNumberFormat()).append('\n');
|
||||
buffer.append(" .indexNumberFmtRecord = ").append(HexDump.shortToHex(getIndexNumberFmtRecord())).append('\n');
|
||||
buffer.append(" .formulaOfLink = ").append('\n');
|
||||
Ptg[] ptgs = field_5_formulaOfLink.getTokens();
|
||||
for (int i = 0; i < ptgs.length; i++) {
|
||||
Ptg ptg = ptgs[i];
|
||||
buffer.append(ptg.toString()).append(ptg.getRVAType()).append('\n');
|
||||
}
|
||||
|
||||
buffer.append("[/AI]\n");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -114,7 +104,7 @@ public final class LinkedDataRecord extends StandardRecord {
|
|||
|
||||
public Object clone() {
|
||||
LinkedDataRecord rec = new LinkedDataRecord();
|
||||
|
||||
|
||||
rec.field_1_linkType = field_1_linkType;
|
||||
rec.field_2_referenceType = field_2_referenceType;
|
||||
rec.field_3_options = field_3_options;
|
||||
|
@ -129,7 +119,7 @@ public final class LinkedDataRecord extends StandardRecord {
|
|||
/**
|
||||
* Get the link type field for the LinkedData record.
|
||||
*
|
||||
* @return One of
|
||||
* @return One of
|
||||
* LINK_TYPE_TITLE_OR_TEXT
|
||||
* LINK_TYPE_VALUES
|
||||
* LINK_TYPE_CATEGORIES
|
||||
|
@ -143,7 +133,7 @@ public final class LinkedDataRecord extends StandardRecord {
|
|||
* Set the link type field for the LinkedData record.
|
||||
*
|
||||
* @param field_1_linkType
|
||||
* One of
|
||||
* One of
|
||||
* LINK_TYPE_TITLE_OR_TEXT
|
||||
* LINK_TYPE_VALUES
|
||||
* LINK_TYPE_CATEGORIES
|
||||
|
@ -156,7 +146,7 @@ public final class LinkedDataRecord extends StandardRecord {
|
|||
/**
|
||||
* Get the reference type field for the LinkedData record.
|
||||
*
|
||||
* @return One of
|
||||
* @return One of
|
||||
* REFERENCE_TYPE_DEFAULT_CATEGORIES
|
||||
* REFERENCE_TYPE_DIRECT
|
||||
* REFERENCE_TYPE_WORKSHEET
|
||||
|
@ -172,7 +162,7 @@ public final class LinkedDataRecord extends StandardRecord {
|
|||
* Set the reference type field for the LinkedData record.
|
||||
*
|
||||
* @param field_2_referenceType
|
||||
* One of
|
||||
* One of
|
||||
* REFERENCE_TYPE_DEFAULT_CATEGORIES
|
||||
* REFERENCE_TYPE_DIRECT
|
||||
* REFERENCE_TYPE_WORKSHEET
|
||||
|
|
Loading…
Reference in New Issue