/** unused - supposed to be zero */
private short field_3_zero;
- /** Creates new ExtSSTInfoSubRecord */
-
+ /**
+ * Creates new ExtSSTInfoSubRecord
+ *
+ * @param streamPos stream pointer to the SST record
+ * @param bucketSstOffset ... don't really understand this yet
+ */
public InfoSubRecord(int streamPos, int bucketSstOffset) {
field_1_stream_pos = streamPos;
field_2_bucket_sst_offset = bucketSstOffset;
return infoRecs;
}
- /** Given a number of strings (in the sst), returns the size of the extsst record*/
+ /**
+ * Given a number of strings (in the sst), returns the size of the extsst record
+ *
+ * @param numStrings the number of strings
+ *
+ * @return the size of the extsst record
+ */
public static final int getRecordSizeForStrings(int numStrings) {
return 4 + 2 + getNumberOfInfoRecsForStrings(numStrings) * 8;
}
public class ExternSheetRecord extends StandardRecord {
public final static short sid = 0x0017;
- private List<RefSubRecord> _list;
+ private final List<RefSubRecord> _list;
private static final class RefSubRecord {
public static final int ENCODED_SIZE = 6;
/** index to External Book Block (which starts with a EXTERNALBOOK record) */
- private int _extBookIndex;
+ private final int _extBookIndex;
private int _firstSheetIndex; // may be -1 (0xFFFF)
private int _lastSheetIndex; // may be -1 (0xFFFF)
}
/**
+ * @param extBookIndex external sheet reference index
+ *
* @return -1 if not found
*/
public int findRefIndexFromExtBookIndex(int extBookIndex) {
* Returns the first sheet that the reference applies to, or
* -1 if the referenced sheet can't be found, or -2 if the
* reference is workbook scoped.
+ *
+ * @param extRefIndex external sheet reference index
+ *
+ * @return the first sheet that the reference applies to, or
+ * -1 if the referenced sheet can't be found, or -2 if the
+ * reference is workbook scoped
*/
public int getFirstSheetIndexFromRefIndex(int extRefIndex) {
return getRef(extRefIndex).getFirstSheetIndex();
* reference is workbook scoped.
* For a single sheet reference, the first and last should be
* the same.
+ *
+ * @param extRefIndex external sheet reference index
+ *
+ * @return the last sheet that the reference applies to, or
+ * -1 if the referenced sheet can't be found, or -2 if the
+ * reference is workbook scoped.
*/
public int getLastSheetIndexFromRefIndex(int extRefIndex) {
return getRef(extRefIndex).getLastSheetIndex();
* DDE data source referencing, or OLE data source referencing,
* then no scope is specified and this value <em>MUST</em> be -2. Otherwise,
* the scope must be set as follows:
- * <ol>
+ * <ol>
* <li><code>-2</code> Workbook-level reference that applies to the entire workbook.</li>
* <li><code>-1</code> Sheet-level reference. </li>
* <li><code>>=0</code> Sheet-level reference. This specifies the first sheet in the reference.
- * <p>
- * If the SupBook type is unused or external workbook referencing,
+ * <p>If the SupBook type is unused or external workbook referencing,
* then this value specifies the zero-based index of an external sheet name,
* see {@link org.apache.poi.hssf.record.SupBookRecord#getSheetNames()}.
* This referenced string specifies the name of the first sheet within the external workbook that is in scope.
- * This sheet MUST be a worksheet or macro sheet.
- * <p>
- * <p>
- * If the supporting link type is self-referencing, then this value specifies the zero-based index of a
+ * This sheet MUST be a worksheet or macro sheet.</p>
+ *
+ * <p>If the supporting link type is self-referencing, then this value specifies the zero-based index of a
* {@link org.apache.poi.hssf.record.BoundSheetRecord} record in the workbook stream that specifies
* the first sheet within the scope of this reference. This sheet MUST be a worksheet or a macro sheet.
* </p>
* </li>
* </ol>
*
+ * @param extBookIndex the external book block index
* @param firstSheetIndex the scope, must be -2 for add-in references
* @param lastSheetIndex the scope, must be -2 for add-in references
* @return index of newly added ref
public static ExternSheetRecord combine(ExternSheetRecord[] esrs) {
ExternSheetRecord result = new ExternSheetRecord();
- for (int i = 0; i < esrs.length; i++) {
- ExternSheetRecord esr = esrs[i];
+ for (ExternSheetRecord esr : esrs) {
int nRefs = esr.getNumOfREFRecords();
for (int j=0; j<nRefs; j++) {
result.addREFRecord(esr.getRef(j));
* Clones all the font style information from another
* FontRecord, onto this one. This
* will then hold all the same font style options.
+ *
+ * @param source the record to clone the properties from
*/
public void cloneStyleFrom(FontRecord source) {
field_1_font_height = source.field_1_font_height;
* for exact contents, because normally the
* font record's position makes a big
* difference too.
+ *
+ * @param other the record to compare with
+ *
+ * @return true, if the properties match
*/
public boolean sameProperties(FontRecord other) {
return
/**
* Use one of the bitmasks MANUAL_ADVANCE_BIT ... CURSOR_VISIBLE_BIT
- * @param bitmask
- * @param enabled
+ * @param bitmask the bitmask to apply
+ * @param enabled if true, the bitmask will be or-ed, otherwise the bits set in the mask will be removed from the flags
*/
public void setFlagByBit(int bitmask, boolean enabled) {
if (enabled) {
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof GUID)) return false;
+ if (!(obj instanceof GUID)) {
+ return false;
+ }
GUID other = (GUID) obj;
return _d1 == other._d1 && _d2 == other._d2
&& _d3 == other._d3 && _d4 == other._d4;
}
/**
- * Set the first column (zero-based)of the range that contains this hyperlink
+ * Set the first column (zero-based) of the range that contains this hyperlink
+ *
+ * @param firstCol the first column (zero-based)
*/
- public void setFirstColumn(int col) {
- _range.setFirstColumn(col);
+ public void setFirstColumn(int firstCol) {
+ _range.setFirstColumn(firstCol);
}
/**
}
/**
- * Set the last column (zero-based)of the range that contains this hyperlink
+ * Set the last column (zero-based) of the range that contains this hyperlink
+ *
+ * @param lastCol the last column (zero-based)
*/
- public void setLastColumn(int col) {
- _range.setLastColumn(col);
+ public void setLastColumn(int lastCol) {
+ _range.setLastColumn(lastCol);
}
/**
}
/**
- * Set the first row (zero-based)of the range that contains this hyperlink
+ * Set the first row (zero-based) of the range that contains this hyperlink
+ *
+ * @param firstRow the first row (zero-based)
*/
- public void setFirstRow(int col) {
- _range.setFirstRow(col);
+ public void setFirstRow(int firstRow) {
+ _range.setFirstRow(firstRow);
}
/**
}
/**
- * Set the last row (zero-based)of the range that contains this hyperlink
+ * Set the last row (zero-based) of the range that contains this hyperlink
+ *
+ * @param lastRow the last row (zero-based)
*/
- public void setLastRow(int col) {
- _range.setLastRow(col);
+ public void setLastRow(int lastRow) {
+ _range.setLastRow(lastRow);
}
/**
* @return the address of this hyperlink
*/
public String getAddress() {
- if ((_linkOpts & HLINK_URL) != 0 && FILE_MONIKER.equals(_moniker))
+ if ((_linkOpts & HLINK_URL) != 0 && FILE_MONIKER.equals(_moniker)) {
return cleanString(_address != null ? _address : _shortFilename);
- else if((_linkOpts & HLINK_PLACE) != 0)
+ } else if((_linkOpts & HLINK_PLACE) != 0) {
return cleanString(_textMark);
- else
+ } else {
return cleanString(_address);
+ }
}
/**
* @param address the address of this hyperlink
*/
public void setAddress(String address) {
- if ((_linkOpts & HLINK_URL) != 0 && FILE_MONIKER.equals(_moniker))
+ if ((_linkOpts & HLINK_URL) != 0 && FILE_MONIKER.equals(_moniker)) {
_shortFilename = appendNullTerm(address);
- else if((_linkOpts & HLINK_PLACE) != 0)
+ } else if((_linkOpts & HLINK_PLACE) != 0) {
_textMark = appendNullTerm(address);
- else
+ } else {
_address = appendNullTerm(address);
+ }
}
public String getShortFilename() {
/**
* Link options. Must be a combination of HLINK_* constants.
* For testing only
+ *
+ * @return Link options
*/
int getLinkOptions(){
return _linkOpts;
}
/**
- * Label options
+ * @return Label options
*/
public int getLabelOptions(){
return 2; // always 2
}
/**
- * Options for a file link
+ * @return Options for a file link
*/
public int getFileOptions(){
return _fileOpts;
}
}
+ @Override
public void serialize(LittleEndianOutput out) {
_range.serialize(out);
}
}
+ @Override
protected int getDataSize() {
int size = 0;
size += 2 + 2 + 2 + 2; //rwFirst, rwLast, colFirst, colLast
out.write(tail);
}
+ @Override
public short getSid() {
return HyperlinkRecord.sid;
}
+ @Override
public String toString() {
StringBuffer buffer = new StringBuffer();
/**
* Based on the link options, is this a url?
+ *
+ * @return true, if this is a url link
*/
public boolean isUrlLink() {
return (_linkOpts & HLINK_URL) > 0
}
/**
* Based on the link options, is this a file?
+ *
+ * @return true, if this is a file link
*/
public boolean isFileLink() {
return (_linkOpts & HLINK_URL) > 0
}
/**
* Based on the link options, is this a document?
+ *
+ * @return true, if this is a docment link
*/
public boolean isDocumentLink() {
return (_linkOpts & HLINK_PLACE) > 0;
return field_5_dbcells.get(cellnum);
}
+ @Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
return buffer.toString();
}
+ @Override
public void serialize(LittleEndianOutput out) {
out.writeInt(0);
}
}
+ @Override
protected int getDataSize() {
return 16 // 4 ints
+ getNumDbcells() * 4;
}
/**
- * @return the size of an INdexRecord when it needs to index the specified number of blocks
+ * @param blockCount the number of blocks to be indexed
+ * @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;
}
+ @Override
public short getSid() {
return sid;
}
import org.apache.poi.util.POILogger;
/**
- * Label Record (0x0204) - read only support for strings stored directly in the cell.. Don't
- * use this (except to read), use LabelSST instead <P>
- * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
+ * Label Record (0x0204) - read only support for strings stored directly in the cell...
+ * Don't use this (except to read), use LabelSST instead <P>
+ * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
*
* @see org.apache.poi.hssf.record.LabelSSTRecord
*/
/*
* READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST! public
*/
+ @Override
public int getRow()
{
return field_1_row;
}
+ @Override
public short getColumn()
{
return field_2_column;
}
+ @Override
public short getXFIndex()
{
return field_3_xf_index;
/**
* THROWS A RUNTIME EXCEPTION.. USE LABELSSTRecords. YOU HAVE NO REASON to use LABELRecord!!
*/
+ @Override
public int serialize(int offset, byte [] data) {
throw new RecordFormatException("Label Records are supported READ ONLY...convert to LabelSST");
}
+ @Override
public int getRecordSize() {
throw new RecordFormatException("Label Records are supported READ ONLY...convert to LabelSST");
}
+ @Override
public short getSid()
{
return sid;
}
+ @Override
public String toString()
{
StringBuffer sb = new StringBuffer();
/**
* NO-OP!
*/
+ @Override
public void setColumn(short col)
{
}
/**
* NO-OP!
*/
+ @Override
public void setRow(int row)
{
}
/**
* no op!
*/
+ @Override
public void setXFIndex(short xf)
{
}
/**
* Title: Label SST Record<P>
- * Description: Refers to a string in the shared string table and is a column
- * value. <P>
- * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
+ * Description: Refers to a string in the shared string table and is a column value.<P>
+ * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
*/
public final class LabelSSTRecord extends CellRecord implements Cloneable {
public final static short sid = 0xfd;
return 4;
}
+ @Override
public short getSid() {
return sid;
}
sb.append("[ftLbsData]\n");\r
sb.append(" .unknownShort1 =").append(HexDump.shortToHex(_cbFContinued)).append("\n");\r
sb.append(" .formula = ").append('\n');\r
- if(_linkPtg != null) sb.append(_linkPtg.toString()).append(_linkPtg.getRVAType()).append('\n');\r
+ if(_linkPtg != null) {\r
+ sb.append(_linkPtg.toString()).append(_linkPtg.getRVAType()).append('\n');\r
+ }\r
sb.append(" .nEntryCount =").append(HexDump.shortToHex(_cLines)).append("\n");\r
sb.append(" .selEntryIx =").append(HexDump.shortToHex(_iSel)).append("\n");\r
sb.append(" .style =").append(HexDump.shortToHex(_flags)).append("\n");\r
sb.append(" .unknownShort10=").append(HexDump.shortToHex(_idEdit)).append("\n");\r
- if(_dropData != null) sb.append('\n').append(_dropData.toString());\r
+ if(_dropData != null) {\r
+ sb.append('\n').append(_dropData.toString());\r
+ }\r
sb.append("[/ftLbsData]\n");\r
return sb.toString();\r
}\r
}\r
\r
/**\r
- * Set the style of this dropdown.\r
+ * Set the style of this dropdown.<p>\r
*\r
* Possible values:\r
- * <p>\r
- * 0 Combo dropdown control\r
- * 1 Combo Edit dropdown control\r
- * 2 Simple dropdown control (just the dropdown button)\r
- *\r
+ * <ul>\r
+ * <li>0: Combo dropdown control</li>\r
+ * <li>1: Combo Edit dropdown control</li>\r
+ * <li>2: Simple dropdown control (just the dropdown button)</li>\r
+ * </ul>\r
+ * \r
+ * @param style the style - see possible values\r
*/\r
public void setStyle(int style){\r
_wStyle = style;\r
\r
/**\r
* Set the number of lines to be displayed in the dropdown.\r
+ * \r
+ * @param num the number of lines to be displayed in the dropdown\r
*/\r
public void setNumLines(int num){\r
_cLine = num;\r
out.writeShort(_cLine);\r
out.writeShort(_dxMin);\r
StringUtil.writeUnicodeString(out, _str);\r
- if(_unused != null) out.writeByte(_unused);\r
+ if(_unused != null) {\r
+ out.writeByte(_unused);\r
+ }\r
}\r
\r
public int getDataSize() {\r
int size = 6;\r
size += StringUtil.getEncodedSize(_str);\r
- if(_unused != null) size++;\r
+ if(_unused != null) {\r
+ size++;\r
+ }\r
return size;\r
}\r
\r
sb.append(" ._cLine: ").append(_cLine).append('\n');\r
sb.append(" ._dxMin: ").append(_dxMin).append('\n');\r
sb.append(" ._str: ").append(_str).append('\n');\r
- if(_unused != null) sb.append(" ._unused: ").append(_unused).append('\n');\r
+ if(_unused != null) {\r
+ sb.append(" ._unused: ").append(_unused).append('\n');\r
+ }\r
sb.append("[/LbsDropData]\n");\r
\r
return sb.toString();\r
public final class MergeCellsRecord extends StandardRecord implements Cloneable {
public final static short sid = 0x00E5;
/** sometimes the regions array is shared with other MergedCellsRecords */
- private CellRangeAddress[] _regions;
+ private final CellRangeAddress[] _regions;
private final int _startIndex;
private final int _numberOfRegions;
}
/**
+ * @param index the n-th MergedRegion
+ *
* @return MergedRegion at the given index representing the area that is Merged (r1,c1 - r2,c2)
*/
public CellRangeAddress getAreaAt(int index) {
return _regions[_startIndex + index];
}
+ @Override
protected int getDataSize() {
return CellRangeAddressList.getEncodedSize(_numberOfRegions);
}
+ @Override
public short getSid() {
return sid;
}
+ @Override
public void serialize(LittleEndianOutput out) {
int nItems = _numberOfRegions;
out.writeShort(nItems);
}
}
+ @Override
public String toString() {
StringBuffer retval = new StringBuffer();
public final class MulRKRecord extends StandardRecord {
public final static short sid = 0x00BD;
- private int field_1_row;
- private short field_2_first_col;
- private RkRec[] field_3_rks;
- private short field_4_last_col;
+ private final int field_1_row;
+ private final short field_2_first_col;
+ private final RkRec[] field_3_rks;
+ private final short field_4_last_col;
public int getRow() {
return field_1_row;
/**
* returns the xf index for column (coffset = column - field_2_first_col)
+ *
+ * @param coffset the coffset = column - field_2_first_col
+ *
* @return the XF index for the column
*/
public short getXFAt(int coffset) {
/**
* returns the rk number for column (coffset = column - field_2_first_col)
+ *
+ * @param coffset the coffset = column - field_2_first_col
+ *
* @return the value (decoded into a double)
*/
public double getRKNumberAt(int coffset) {
}
- public String toString() {
+ @Override
+ public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[MULRK]\n");
return buffer.toString();
}
- public short getSid()
+ @Override
+ public short getSid()
{
return sid;
}
- public void serialize(LittleEndianOutput out) {
+ @Override
+ public void serialize(LittleEndianOutput out) {
throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release");
}
- protected int getDataSize() {
+ @Override
+ protected int getDataSize() {
throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release");
}
/**
* Updates the name we're associated with, normally used
* when renaming that Name
+ *
+ * @param newName the new name
*/
public void setNameText(String newName) {
field_6_name_text = newName;
/**
* Constructor to create a built-in named region
* @param builtin Built-in byte representation for the name record, use the public constants
+ * @param sheetNumber the sheet which the name applies to
*/
public NameRecord(byte builtin, int sheetNumber)
{
this();
field_12_built_in_code = builtin;
setOptionFlag((short)(field_1_option_flag | Option.OPT_BUILTIN));
- field_6_sheetNumber = sheetNumber; //the extern sheets are set through references
+ // the extern sheets are set through references
+ field_6_sheetNumber = sheetNumber;
}
/** sets the option flag for the named range
return (field_1_option_flag & Option.OPT_COMPLEX) != 0;
}
- /**Convenience Function to determine if the name is a built-in name
+ /**
+ * Convenience Function to determine if the name is a built-in name
+ *
+ * @return true, if the name is a built-in name
*/
public boolean isBuiltInName()
{
*
* @param out a data output stream
*/
- public void serialize(ContinuableRecordOutput out) {
+ @Override
+ public void serialize(ContinuableRecordOutput out) {
int field_7_length_custom_menu = field_14_custom_menu_text.length();
int field_8_length_description_text = field_15_description_text.length();
/**
* return the non static version of the id for this record.
*/
- public short getSid() {
+ @Override
+ public short getSid() {
return sid;
}
/*
3B 00 00 07 00 07 00 00 00 FF 00 ]
*/
- public String toString() {
+ @Override
+ public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("[NAME]\n");
sb.append(" .Name (Unicode text) = ").append( getNameText() ).append("\n");
Ptg[] ptgs = field_13_name_definition.getTokens();
sb.append(" .Formula (nTokens=").append(ptgs.length).append("):") .append("\n");
- for (int i = 0; i < ptgs.length; i++) {
- Ptg ptg = ptgs[i];
+ for (Ptg ptg : ptgs) {
sb.append(" " + ptg.toString()).append(ptg.getRVAType()).append("\n");
}
/**
* Read the record data from the supplied <code>RecordInputStream</code>
+ *
+ * @param in the RecordInputStream to read from
*/
public NoteRecord(RecordInputStream in) {
field_1_row = in.readUShort();
/**
* For unit testing only!
+ *
+ * @return true, if author element uses multi byte
*/
protected boolean authorIsMultibyte() {
return field_5_hasMultibyte;
/**
* Object id for OBJ record that contains the comment
+ *
+ * @return the Object id for OBJ record that contains the comment
*/
public int getShapeId() {
return field_4_shapeid;
/**
* Object id for OBJ record that contains the comment
+ *
+ * @param id the Object id for OBJ record that contains the comment
*/
public void setShapeId(int id) {
field_4_shapeid = id;
/**
* Read the record data from the supplied <code>RecordInputStream</code>
+ *
+ * @param in the input to read from
+ * @param size the provided size - must be 22
*/
public NoteStructureSubRecord(LittleEndianInput in, int size) {
if (size != ENCODED_SIZE) {
* Convert this record to string.
* Used by BiffViewer and other utilities.
*/
+ @Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
*
* @param out the stream to serialize into
*/
+ @Override
public void serialize(LittleEndianOutput out) {
out.writeShort(sid);
out.writeShort(reserved.length);
out.write(reserved);
}
- protected int getDataSize() {
+ @Override
+ protected int getDataSize() {
return reserved.length;
}
* Subclasses are expected to manage the cell data values (of various types).
*/
public abstract class OldCellRecord {
- private short sid;
- private boolean isBiff2;
- private int field_1_row;
- private short field_2_column;
+ private final short sid;
+ private final boolean isBiff2;
+ private final int field_1_row;
+ private final short field_2_column;
private int field_3_cell_attrs; // Biff 2
private short field_3_xf_index; // Biff 3+
public final short getXFIndex() {
return field_3_xf_index;
}
+
public int getCellAttrs()
{
return field_3_cell_attrs;
/**
* Is this a Biff2 record, or newer?
+ *
+ * @return true, if this is a Biff2 record or newer
*/
public boolean isBiff2() {
return isBiff2;
}
+
public short getSid() {
return sid;
}
* Append specific debug info (used by {@link #toString()} for the value
* contained in this record. Trailing new-line should not be appended
* (superclass does that).
+ *
+ * @param sb the StringBuilder to append to
*/
protected abstract void appendValueText(StringBuilder sb);
/**
* Gets the debug info BIFF record type name (used by {@link #toString()}.
+ *
+ * @return the debug info BIFF record type name
*/
protected abstract String getRecordName();
}
public final static short biff345_sid = 0x0204;
private short field_4_string_len;
- private byte[] field_5_bytes;
+ private final byte[] field_5_bytes;
private CodepageRecord codepage;
/**
/**
* Get the String of the cell
+ *
+ * @return the String of the cell
*/
public String getValue()
{
/**
* Not supported
+ *
+ * @param offset not supported
+ * @param data not supported
+ * @return not supported
*/
public int serialize(int offset, byte [] data) {
throw new RecordFormatException("Old Label Records are supported READ ONLY");
}
+
public int getRecordSize() {
throw new RecordFormatException("Old Label Records are supported READ ONLY");
}
+ @Override
protected void appendValueText(StringBuilder sb) {
sb.append(" .string_len= ").append(HexDump.shortToHex(field_4_string_len)).append("\n");
sb.append(" .value = ").append(getValue()).append("\n");
}
+ @Override
protected String getRecordName() {
return "OLD LABEL";
}
public PaletteRecord() {
PColor[] defaultPalette = createDefaultPalette();
_colors = new ArrayList<PColor>(defaultPalette.length);
- for (int i = 0; i < defaultPalette.length; i++) {
- _colors.add(defaultPalette[i]);
+ for (PColor element : defaultPalette) {
+ _colors.add(element);
}
}
}
}
+ @Override
public String toString() {
StringBuffer buffer = new StringBuffer();
return buffer.toString();
}
+ @Override
public void serialize(LittleEndianOutput out) {
out.writeShort(_colors.size());
for (int i = 0; i < _colors.size(); i++) {
}
}
+ @Override
protected int getDataSize() {
return 2 + _colors.size() * PColor.ENCODED_SIZE;
}
+ @Override
public short getSid() {
return sid;
}
/**
* Returns the color value at a given index
+ *
+ * @param byteIndex palette index, must be >= 0x8
*
* @return the RGB triplet for the color, or <code>null</code> if the specified index
* does not exist
*
* @param byteIndex the index to set; if this index is less than 0x8 or greater than
* 0x40, then no modification is made
+ * @param red the red color part
+ * @param green the green color part
+ * @param blue the blue color part
*/
public void setColor(short byteIndex, byte red, byte green, byte blue)
{
*/
private static final class PColor {
public static final short ENCODED_SIZE = 4;
- private int _red;
- private int _green;
- private int _blue;
+ private final int _red;
+ private final int _green;
+ private final int _blue;
public PColor(int red, int green, int blue) {
_red = red;
out.writeByte(0);
}
+ @Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(" red = ").append(_red & 0xff).append('\n');
field_5_activePane = in.readShort();
}
+ @Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
return buffer.toString();
}
+ @Override
public void serialize(LittleEndianOutput out) {
out.writeShort(field_1_x);
out.writeShort(field_2_y);
out.writeShort(field_5_activePane);
}
+ @Override
protected int getDataSize() {
return 2 + 2 + 2 + 2 + 2;
}
+ @Override
public short getSid()
{
return sid;
}
+ @Override
public Object clone() {
PaneRecord rec = new PaneRecord();
return rec;
}
-
-
-
/**
* Get the x field for the Pane record.
+ *
+ * @param the x value
*/
public short getX()
{
/**
* Set the x field for the Pane record.
+ *
+ * @param field_1_x the x value
*/
public void setX(short field_1_x)
{
/**
* Get the y field for the Pane record.
+ *
+ * @return the y value
*/
public short getY()
{
/**
* Set the y field for the Pane record.
+ *
+ * @param field_2_y the y value
*/
public void setY(short field_2_y)
{
/**
* Get the top row field for the Pane record.
+ *
+ * @return the top row
*/
public short getTopRow()
{
/**
* Set the top row field for the Pane record.
+ *
+ * @param field_3_topRow the top row
*/
public void setTopRow(short field_3_topRow)
{
/**
* Get the left column field for the Pane record.
+ *
+ * @return the left column
*/
public short getLeftColumn()
{
/**
* Set the left column field for the Pane record.
+ *
+ * @param field_4_leftColumn the left column
*/
public void setLeftColumn(short field_4_leftColumn)
{
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public ReflectionConstructorRecordCreator(Constructor<? extends Record> c) {
_c = c;
}
+ @Override
public Record create(RecordInputStream in) {
Object[] args = { in, };
try {
}
}
}
+ @Override
public Class<? extends Record> getRecordClass() {
return _c.getDeclaringClass();
}
public ReflectionMethodRecordCreator(Method m) {
_m = m;
}
+ @Override
public Record create(RecordInputStream in) {
Object[] args = { in, };
try {
throw new RecordFormatException("Unable to construct record instance" , e.getTargetException());
}
}
+ @Override
@SuppressWarnings("unchecked")
public Class<? extends Record> getRecordClass() {
return (Class<? extends Record>) _m.getDeclaringClass();
/**
* Debug / diagnosis method<p>
- * Gets the POI implementation class for a given {@code sid}. Only a subset of the any BIFF
+ *
+ * Gets the POI implementation class for a given {@code sid}. Only a subset of the BIFF
* records are actually interpreted by POI. A few others are known but not interpreted
* (see {@link UnknownRecord#getBiffName(int)}).
+ *
+ * @param sid the record sid
+ *
* @return the POI implementation class for the specified record {@code sid}.
* {@code null} if the specified record is not interpreted by POI.
*/
}
return rc.getRecordClass();
}
+
/**
* create a record, if there are MUL records than multiple records
* are returned digested into the non-mul form.
+ *
+ * @param in the RecordInputStream to read from
+ * @return the extracted records
*/
public static Record [] createRecord(RecordInputStream in) {
Record record = createSingleRecord(in);
/**
* RK record is a slightly smaller alternative to NumberRecord
* POI likes NumberRecord better
+ *
+ * @param the RK record to convert
+ * @return the NumberRecord
*/
public static NumberRecord convertToNumberRecord(RKRecord rk) {
NumberRecord num = new NumberRecord();
}
/**
- * Converts a {@link MulRKRecord} into an equivalent array of {@link NumberRecord}s
+ * Converts a {@link MulRKRecord} into an equivalent array of {@link NumberRecord NumberRecords}
+ *
+ * @param mrk the MulRKRecord to convert
+ * @return the equivalent array of {@link NumberRecord NumberRecords}
*/
public static NumberRecord[] convertRKRecords(MulRKRecord mrk) {
NumberRecord[] mulRecs = new NumberRecord[mrk.getNumColumns()];
}
/**
- * Converts a {@link MulBlankRecord} into an equivalent array of {@link BlankRecord}s
+ * Converts a {@link MulBlankRecord} into an equivalent array of {@link BlankRecord BlankRecords}
+ *
+ * @param mbk the MulBlankRecord to convert
+ * @return the equivalent array of {@link BlankRecord BlankRecords}
*/
public static BlankRecord[] convertBlankRecords(MulBlankRecord mbk) {
BlankRecord[] mulRecs = new BlankRecord[mbk.getNumColumns()];
short[] results = new short[ _recordCreatorsById.size() ];
int i = 0;
- for (Iterator<Integer> iterator = _recordCreatorsById.keySet().iterator(); iterator.hasNext(); ) {
- Integer sid = iterator.next();
-
+ for (Integer sid : _recordCreatorsById.keySet()) {
results[i++] = sid.shortValue();
}
Arrays.sort(results);
Map<Integer, I_RecordCreator> result = new HashMap<Integer, I_RecordCreator>();
Set<Class<?>> uniqueRecClasses = new HashSet<Class<?>>(records.length * 3 / 2);
- for (int i = 0; i < records.length; i++) {
-
- Class<? extends Record> recClass = records[ i ];
+ for (Class<? extends Record> recClass : records) {
if(!Record.class.isAssignableFrom(recClass)) {
throw new RuntimeException("Invalid record sub-class (" + recClass.getName() + ")");
}
Integer key = Integer.valueOf(sid);
if (result.containsKey(key)) {
Class<?> prevClass = result.get(key).getRecordClass();
- throw new RuntimeException("duplicate record sid 0x" +
+ throw new RuntimeException("duplicate record sid 0x" +
Integer.toHexString(sid).toUpperCase(Locale.ROOT)
+ " for classes (" + recClass.getName() + ") and ("
+ prevClass.getName() + ")");
/**
+ * @param in the InputStream to read from
+ *
* @param shouldIncludeContinueRecords caller can pass <code>false</code> if loose
* {@link ContinueRecord}s should be skipped (this is sometimes useful in event based
* processing).
}
/**
- * Returns the next (complete) record from the
- * stream, or null if there are no more.
+ * @return the next (complete) record from the stream, or null if there are no more.
*/
public Record nextRecord() {
Record r;
import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianInputStream;
public SimpleHeaderInput(InputStream in) {
_lei = getLEI(in);
}
- public int available() {
+ @Override
+ public int available() {
return _lei.available();
}
- public int readDataSize() {
+ @Override
+ public int readDataSize() {
return _lei.readUShort();
}
- public int readRecordSID() {
+ @Override
+ public int readRecordSID() {
return _lei.readUShort();
}
}
* @return the number of bytes available in the current BIFF record
* @see #remaining()
*/
- public int available() {
+ @Override
+ public int available() {
return remaining();
}
/**
* Note - this method is expected to be called only when completed reading the current BIFF
* record.
+ *
+ * @return true, if there's another record in the stream
+ *
* @throws LeftoverDataException if this method is called before reaching the end of the
* current record.
*/
/**
* Reads an 8 bit, signed value
*/
- public byte readByte() {
- checkRecordPosition(LittleEndian.BYTE_SIZE);
- _currentDataOffset += LittleEndian.BYTE_SIZE;
+ @Override
+ public byte readByte() {
+ checkRecordPosition(LittleEndianConsts.BYTE_SIZE);
+ _currentDataOffset += LittleEndianConsts.BYTE_SIZE;
return _dataInput.readByte();
}
/**
* Reads a 16 bit, signed value
*/
- public short readShort() {
- checkRecordPosition(LittleEndian.SHORT_SIZE);
- _currentDataOffset += LittleEndian.SHORT_SIZE;
+ @Override
+ public short readShort() {
+ checkRecordPosition(LittleEndianConsts.SHORT_SIZE);
+ _currentDataOffset += LittleEndianConsts.SHORT_SIZE;
return _dataInput.readShort();
}
/**
* Reads a 32 bit, signed value
*/
- public int readInt() {
- checkRecordPosition(LittleEndian.INT_SIZE);
- _currentDataOffset += LittleEndian.INT_SIZE;
+ @Override
+ public int readInt() {
+ checkRecordPosition(LittleEndianConsts.INT_SIZE);
+ _currentDataOffset += LittleEndianConsts.INT_SIZE;
return _dataInput.readInt();
}
/**
* Reads a 64 bit, signed value
*/
- public long readLong() {
- checkRecordPosition(LittleEndian.LONG_SIZE);
- _currentDataOffset += LittleEndian.LONG_SIZE;
+ @Override
+ public long readLong() {
+ checkRecordPosition(LittleEndianConsts.LONG_SIZE);
+ _currentDataOffset += LittleEndianConsts.LONG_SIZE;
return _dataInput.readLong();
}
/**
* Reads an 8 bit, unsigned value
*/
- public int readUByte() {
+ @Override
+ public int readUByte() {
return readByte() & 0x00FF;
}
/**
* Reads a 16 bit, unsigned value.
*/
- public int readUShort() {
- checkRecordPosition(LittleEndian.SHORT_SIZE);
- _currentDataOffset += LittleEndian.SHORT_SIZE;
+ @Override
+ public int readUShort() {
+ checkRecordPosition(LittleEndianConsts.SHORT_SIZE);
+ _currentDataOffset += LittleEndianConsts.SHORT_SIZE;
return _dataInput.readUShort();
}
- public double readDouble() {
+ @Override
+ public double readDouble() {
long valueLongBits = readLong();
double result = Double.longBitsToDouble(valueLongBits);
if (Double.isNaN(result)) {
}
return result;
}
- public void readFully(byte[] buf) {
+ @Override
+ public void readFully(byte[] buf) {
readFully(buf, 0, buf.length);
}
- public void readFully(byte[] buf, int off, int len) {
+ @Override
+ public void readFully(byte[] buf, int off, int len) {
int origLen = len;
if (buf == null) {
throw new NullPointerException();
boolean isCompressedEncoding = pIsCompressedEncoding;
int curLen = 0;
while(true) {
- int availableChars =isCompressedEncoding ? remaining() : remaining() / LittleEndian.SHORT_SIZE;
+ int availableChars =isCompressedEncoding ? remaining() : remaining() / LittleEndianConsts.SHORT_SIZE;
if (requestedLength - curLen <= availableChars) {
// enough space in current record, so just read it out
while(curLen < requestedLength) {
return result;
}
- /** Reads all byte data for the current record, including any
- * that overlaps into any following continue records.
- *
- * @deprecated POI 2.0 Best to write a input stream that wraps this one where there is
- * special sub record that may overlap continue records.
- */
- public byte[] readAllContinuedRemainder() {
- //Using a ByteArrayOutputStream is just an easy way to get a
- //growable array of the data.
- ByteArrayOutputStream out = new ByteArrayOutputStream(2*MAX_RECORD_DATA_SIZE);
-
- while (true) {
- byte[] b = readRemainder();
- out.write(b, 0, b.length);
- if (!isContinueNext()) {
- break;
- }
- nextRecord();
+ /**
+ * Reads all byte data for the current record, including any that overlaps
+ * into any following continue records.
+ *
+ * @return all byte data for the current record
+ *
+ * @deprecated POI 2.0 Best to write a input stream that wraps this one
+ * where there is special sub record that may overlap continue
+ * records.
+ */
+ @Deprecated
+ public byte[] readAllContinuedRemainder() {
+ ByteArrayOutputStream out = new ByteArrayOutputStream(2 * MAX_RECORD_DATA_SIZE);
+
+ while (true) {
+ byte[] b = readRemainder();
+ out.write(b, 0, b.length);
+ if (!isContinueNext()) {
+ break;
+ }
+ nextRecord();
+ }
+ return out.toByteArray();
}
- return out.toByteArray();
- }
/** The remaining number of bytes in the <i>current</i> record.
*
field_2_denominator = in.readShort();
}
+ @Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
return buffer.toString();
}
+ @Override
public void serialize(LittleEndianOutput out) {
out.writeShort(field_1_numerator);
out.writeShort(field_2_denominator);
}
+ @Override
protected int getDataSize() {
return 2 + 2;
}
+ @Override
public short getSid()
{
return sid;
}
+ @Override
public Object clone() {
SCLRecord rec = new SCLRecord();
return rec;
}
-
-
-
/**
* Get the numerator field for the SCL record.
+ *
+ * @return the numerator
*/
public short getNumerator()
{
/**
* Set the numerator field for the SCL record.
+ *
+ * @param field_1_numerator the numerator
*/
public void setNumerator(short field_1_numerator)
{
/**
* Get the denominator field for the SCL record.
+ *
+ * @return the denominator
*/
public short getDenominator()
{
/**
* Set the denominator field for the SCL record.
+ *
+ * @param field_2_denominator the denominator
*/
public void setDenominator(short field_2_denominator)
{
* Description: shows the user's selection on the sheet
* for write set num refs to 0<P>
*
- * REFERENCE: PG 291 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)
- * @author Glen Stampoultzis (glens at apache.org)
+ * REFERENCE: PG 291 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
*/
public final class SelectionRecord extends StandardRecord {
public final static short sid = 0x001D;
/**
* Creates a default selection record (cell A1, in pane ID 3)
+ *
+ * @param activeCellRow the active cells row index
+ * @param activeCellCol the active cells column index
*/
public SelectionRecord(int activeCellRow, int activeCellCol) {
field_1_pane = 3; // pane id 3 is always present. see OOO sec 5.75 'PANE'
/**
* set which window pane this is for
+ * @param pane the window pane
*/
public void setPane(byte pane) {
field_1_pane = pane;
return field_4_active_cell_ref_index;
}
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("[/SELECTION]\n");
return sb.toString();
}
+ @Override
protected int getDataSize() {
return 9 // 1 byte + 4 shorts
+ CellRangeAddress8Bit.getEncodedSize(field_6_refs.length);
}
+ @Override
public void serialize(LittleEndianOutput out) {
out.writeByte(getPane());
out.writeShort(getActiveCellRow());
out.writeShort(getActiveCellRef());
int nRefs = field_6_refs.length;
out.writeShort(nRefs);
- for (int i = 0; i < field_6_refs.length; i++) {
- field_6_refs[i].serialize(out);
+ for (CellRangeAddress8Bit field_6_ref : field_6_refs) {
+ field_6_ref.serialize(out);
}
}
+ @Override
public short getSid() {
return sid;
}
+ @Override
public Object clone() {
SelectionRecord rec = new SelectionRecord(field_2_row_active_cell, field_3_col_active_cell);
rec.field_1_pane = field_1_pane;
@Override
public void visitContainedRecords(RecordVisitor rv) {
rv.visitRecord(_pls);
- for (int i = 0; i < _plsContinues.length; i++) {
- rv.visitRecord(_plsContinues[i]);
+ for (ContinueRecord _plsContinue : _plsContinues) {
+ rv.visitRecord(_plsContinue);
}
}
}
* The indicator of such records is a non-zero GUID,
* see {@link org.apache.poi.hssf.record.HeaderFooterRecord#getGuid()}
*/
- private List<HeaderFooterRecord> _sviewHeaderFooters = new ArrayList<HeaderFooterRecord>();
+ private final List<HeaderFooterRecord> _sviewHeaderFooters = new ArrayList<HeaderFooterRecord>();
private Record _printSize;
public PageSettingsBlock(RecordStream rs) {
}
/**
+ * @param sid the record sid
+ *
* @return <code>true</code> if the specified Record sid is one belonging to the
* 'Page Settings Block'.
*/
case HeaderFooterRecord.sid:
//there can be multiple HeaderFooterRecord records belonging to different sheet views
HeaderFooterRecord hf = (HeaderFooterRecord)rs.getNext();
- if(hf.isCurrentSheet()) _headerFooter = hf;
- else {
+ if(hf.isCurrentSheet()) {
+ _headerFooter = hf;
+ } else {
_sviewHeaderFooters.add(hf);
}
break;
/**
* Sets a page break at the indicated column
*
+ * @param column the column to add page breaks to
+ * @param fromRow the starting row
+ * @param toRow the ending row
*/
public void setColumnBreak(short column, short fromRow, short toRow) {
getColumnBreaksRecord().addBreak(column, fromRow, toRow);
/**
* Removes a page break at the indicated column
*
+ * @param column the column to check for page breaks
*/
public void removeColumnBreak(int column) {
getColumnBreaksRecord().removeBreak(column);
+ @Override
public void visitContainedRecords(RecordVisitor rv) {
// Replicates record order from Excel 2007, though this is not critical
int breakLocation = breakItem.main;
boolean inStart = (breakLocation >= start);
boolean inEnd = (breakLocation <= stop);
- if(inStart && inEnd)
+ if(inStart && inEnd) {
shiftedBreak.add(breakItem);
+ }
}
iterator = shiftedBreak.iterator();
/**
* Sets a page break at the indicated row
- * @param row
+ * @param row the row
+ * @param fromCol the starting column
+ * @param toCol the ending column
*/
public void setRowBreak(int row, short fromCol, short toCol) {
getRowBreaksRecord().addBreak((short)row, fromCol, toCol);
/**
* Removes a page break at the indicated row
- * @param row
+ * @param row the row
*/
public void removeRowBreak(int row) {
- if (getRowBreaksRecord().getBreaks().length < 1)
+ if (getRowBreaksRecord().getBreaks().length < 1) {
throw new IllegalArgumentException("Sheet does not define any row breaks");
+ }
getRowBreaksRecord().removeBreak((short)row);
}
/**
* Queries if the specified row has a page break
- * @param row
+ *
+ * @param row the row to check for
+ *
* @return true if the specified row has a page break
*/
public boolean isRowBroken(int row) {
/**
* Queries if the specified column has a page break
+ *
+ * @param column the column to check for
*
* @return <code>true</code> if the specified column has a page break
*/
/**
* Shifts the horizontal page breaks for the indicated count
- * @param startingRow
- * @param endingRow
- * @param count
+ * @param startingRow the starting row
+ * @param endingRow the ending row
+ * @param count the number of rows to shift by
*/
public void shiftRowBreaks(int startingRow, int endingRow, int count) {
shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count);
/**
* Shifts the vertical page breaks for the indicated count
- * @param startingCol
- * @param endingCol
- * @param count
+ * @param startingCol the starting column
+ * @param endingCol the ending column
+ * @param count the number of columns to shift by
*/
public void shiftColumnBreaks(short startingCol, short endingCol, short count) {
shiftBreaks(getColumnBreaksRecord(), startingCol, endingCol, count);
/**
* HEADERFOOTER is new in 2007. Some apps seem to have scattered this record long after
* the {@link PageSettingsBlock} where it belongs.
+ *
+ * @param rec the HeaderFooterRecord to set
*/
public void addLateHeaderFooter(HeaderFooterRecord rec) {
if (_headerFooter != null) {
/**
* This method reads PageSettingsBlock records from the supplied RecordStream until the first
* non-PageSettingsBlock record is encountered. As each record is read, it is incorporated
- * into this PageSettingsBlock.
- * <p/>
+ * into this PageSettingsBlock.<p>
+ *
* The latest Excel version seems to write the PageSettingsBlock uninterrupted. However there
* are several examples (that Excel reads OK) where these records are not written together:
+ *
* <ul>
* <li><b>HEADER_FOOTER(0x089C) after WINDOW2</b> - This record is new in 2007. Some apps
* seem to have scattered this record long after the PageSettingsBlock where it belongs
* This happens in the test sample file "NoGutsRecords.xls" and "WORKBOOK_in_capitals.xls"</li>
* <li><b>Margins after DIMENSION</b> - All of PSB should be before DIMENSION. (Bug-47199)</li>
* </ul>
+ *
* These were probably written by other applications (or earlier versions of Excel). It was
* decided to not write specific code for detecting each of these cases. POI now tolerates
* PageSettingsBlock records scattered all over the sheet record stream, and in any order, but
- * does not allow duplicates of any of those records.
+ * does not allow duplicates of any of those records.<p>
*
- * <p/>
* <b>Note</b> - when POI writes out this PageSettingsBlock, the records will always be written
* in one consolidated block (in the standard ordering) regardless of how scattered the records
* were when they were originally read.
*
+ * @param rs the RecordStream to read from
+ *
* @throws RecordFormatException if any PSB record encountered has the same type (sid) as
* a record that is already part of this PageSettingsBlock
*/
if (rb instanceof CustomViewSettingsRecordAggregate) {
final CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate) rb;
cv.visitContainedRecords(new RecordVisitor() {
+ @Override
public void visitRecord(Record r) {
if (r.getSid() == UserSViewBegin.sid) {
String guid = HexDump.toHex(((UserSViewBegin) r).getGuid());