org.apache.poi.hssf.record
Class SSTRecord

java.lang.Object
  extended by org.apache.poi.hssf.record.Record
      extended by org.apache.poi.hssf.record.SSTRecord

public class SSTRecord
extends Record

Title: Static String Table Record

Description: This holds all the strings for LabelSSTRecords.

REFERENCE: PG 389 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)

Author:
Andrew C. Oliver (acoliver at apache dot org), Marc Johnson (mjohnson at apache dot org), Glen Stampoultzis (glens at apache.org)
See Also:
LabelSSTRecord, ContinueRecord

Field Summary
static short sid
           
 
Constructor Summary
SSTRecord()
          default constructor
SSTRecord(RecordInputStream in)
          Constructs an SST record and sets its fields appropriately.
 
Method Summary
 int addString(UnicodeString string)
          Add a string.
 int calcExtSSTRecordSize()
          Calculates the size in bytes of the EXTSST record as it would be if the record was serialized.
 ExtSSTRecord createExtSSTRecord(int sstOffset)
          Creates an extended string record based on the current contents of the current SST record.
 boolean equals(java.lang.Object o)
           
protected  void fillFields(RecordInputStream in)
          Fill the fields from the data
 int getNumStrings()
           
 int getNumUniqueStrings()
           
 int getRecordSize()
          gives the current serialized size of the record.
 short getSid()
          return the non static version of the id for this record.
 UnicodeString getString(int id)
          Get a particular string by its index
 int hashCode()
           
 boolean isString16bit(int id)
           
 int serialize(int offset, byte[] data)
          called by the class that is responsible for writing this sucker.
 void setNumStrings(int count)
          USE THIS METHOD AT YOUR OWN PERIL: THE addString METHODS MANIPULATE THE NUMBER OF STRINGS AS A SIDE EFFECT; YOUR ATTEMPTS AT MANIPULATING THE STRING COUNT IS LIKELY TO BE VERY WRONG AND WILL RESULT IN BAD BEHAVIOR WHEN THIS RECORD IS WRITTEN OUT AND ANOTHER PROCESS ATTEMPTS TO READ THE RECORD
 void setNumUniqueStrings(int count)
          USE THIS METHOD AT YOUR OWN PERIL: THE addString METHODS MANIPULATE THE NUMBER OF UNIQUE STRINGS AS A SIDE EFFECT; YOUR ATTEMPTS AT MANIPULATING THE UNIQUE STRING COUNT IS LIKELY TO BE VERY WRONG AND WILL RESULT IN BAD BEHAVIOR WHEN THIS RECORD IS WRITTEN OUT AND ANOTHER PROCESS ATTEMPTS TO READ THE RECORD
 java.lang.String toString()
          Return a debugging string representation
protected  void validateSid(short id)
          validate SID
 
Methods inherited from class org.apache.poi.hssf.record.Record
clone, cloneViaReserialise, isInValueSection, isValue, serialize
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

sid

public static final short sid
See Also:
Constant Field Values
Constructor Detail

SSTRecord

public SSTRecord()
default constructor


SSTRecord

public SSTRecord(RecordInputStream in)
Constructs an SST record and sets its fields appropriately.

Parameters:
in - the RecordInputstream to read the record from
Method Detail

addString

public int addString(UnicodeString string)
Add a string.

Parameters:
string - string to be added
Returns:
the index of that string in the table

getNumStrings

public int getNumStrings()
Returns:
number of strings

getNumUniqueStrings

public int getNumUniqueStrings()
Returns:
number of unique strings

setNumStrings

public void setNumStrings(int count)
USE THIS METHOD AT YOUR OWN PERIL: THE addString METHODS MANIPULATE THE NUMBER OF STRINGS AS A SIDE EFFECT; YOUR ATTEMPTS AT MANIPULATING THE STRING COUNT IS LIKELY TO BE VERY WRONG AND WILL RESULT IN BAD BEHAVIOR WHEN THIS RECORD IS WRITTEN OUT AND ANOTHER PROCESS ATTEMPTS TO READ THE RECORD

Parameters:
count - number of strings

setNumUniqueStrings

public void setNumUniqueStrings(int count)
USE THIS METHOD AT YOUR OWN PERIL: THE addString METHODS MANIPULATE THE NUMBER OF UNIQUE STRINGS AS A SIDE EFFECT; YOUR ATTEMPTS AT MANIPULATING THE UNIQUE STRING COUNT IS LIKELY TO BE VERY WRONG AND WILL RESULT IN BAD BEHAVIOR WHEN THIS RECORD IS WRITTEN OUT AND ANOTHER PROCESS ATTEMPTS TO READ THE RECORD

Parameters:
count - number of strings

getString

public UnicodeString getString(int id)
Get a particular string by its index

Parameters:
id - index into the array of strings
Returns:
the desired string

isString16bit

public boolean isString16bit(int id)

toString

public java.lang.String toString()
Return a debugging string representation

Overrides:
toString in class Record
Returns:
string representation

getSid

public short getSid()
Description copied from class: Record
return the non static version of the id for this record.

Specified by:
getSid in class Record
Returns:
sid

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
hashcode

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

validateSid

protected void validateSid(short id)
                    throws RecordFormatException
validate SID

Specified by:
validateSid in class Record
Parameters:
id - the alleged SID
Throws:
RecordFormatException - if validation fails

fillFields

protected void fillFields(RecordInputStream in)
Fill the fields from the data

The data consists of sets of string data. This string data is arranged as follows:

 short  string_length;   // length of string data
 byte   string_flag;     // flag specifying special string
                         // handling
 short  run_count;       // optional count of formatting runs
 int    extend_length;   // optional extension length
 char[] string_data;     // string data, can be byte[] or
                         // short[] (length of array is
                         // string_length)
 int[]  formatting_runs; // optional formatting runs (length of
                         // array is run_count)
 byte[] extension;       // optional extension (length of array
                         // is extend_length)
 

The string_flag is bit mapped as follows:

Bit number Meaning if 0 Meaning if 1
0 string_data is byte[] string_data is short[]
1 Should always be 0 string_flag is defective
2 extension is not included extension is included
3 formatting run data is not included formatting run data is included
4 Should always be 0 string_flag is defective
5 Should always be 0 string_flag is defective
6 Should always be 0 string_flag is defective
7 Should always be 0 string_flag is defective

We can handle eating the overhead associated with bits 2 or 3 (or both) being set, but we have no idea what to do with the associated data. The UnicodeString class can handle the byte[] vs short[] nature of the actual string data

Specified by:
fillFields in class Record
Parameters:
in - the RecordInputstream to read the record from

serialize

public int serialize(int offset,
                     byte[] data)
called by the class that is responsible for writing this sucker. Subclasses should implement this so that their data is passed back in a byte array.

Specified by:
serialize in class Record
Parameters:
offset - to begin writing at
data - byte array containing instance data
Returns:
size

getRecordSize

public int getRecordSize()
Description copied from class: Record
gives the current serialized size of the record. Should include the sid and reclength (4 bytes).

Overrides:
getRecordSize in class Record

createExtSSTRecord

public ExtSSTRecord createExtSSTRecord(int sstOffset)
Creates an extended string record based on the current contents of the current SST record. The offset within the stream to the SST record is required because the extended string record points directly to the strings in the SST record.

NOTE: THIS FUNCTION MUST ONLY BE CALLED AFTER THE SST RECORD HAS BEEN SERIALIZED.

Parameters:
sstOffset - The offset in the stream to the start of the SST record.
Returns:
The new SST record.

calcExtSSTRecordSize

public int calcExtSSTRecordSize()
Calculates the size in bytes of the EXTSST record as it would be if the record was serialized.

Returns:
The size of the ExtSST record in bytes.


Copyright 2008 The Apache Software Foundation or its licensors, as applicable.