javadocs fixes (jdk8)

eclipse source clean-ups (final members, override annotations, for-each loops)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1752037 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-07-09 18:52:26 +00:00
parent aac75f3f3c
commit 848f056369
25 changed files with 410 additions and 170 deletions

View File

@ -46,8 +46,12 @@ public final class ExtSSTRecord extends ContinuableRecord {
/** 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;
@ -155,7 +159,13 @@ public final class ExtSSTRecord extends ContinuableRecord {
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;
}

View File

@ -29,13 +29,13 @@ import org.apache.poi.util.LittleEndianOutput;
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)
@ -196,6 +196,8 @@ public class ExternSheetRecord extends StandardRecord {
}
/**
* @param extBookIndex external sheet reference index
*
* @return -1 if not found
*/
public int findRefIndexFromExtBookIndex(int extBookIndex) {
@ -212,6 +214,12 @@ public class ExternSheetRecord extends StandardRecord {
* 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();
@ -223,6 +231,12 @@ public class ExternSheetRecord extends StandardRecord {
* 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();
@ -235,25 +249,24 @@ public class ExternSheetRecord extends StandardRecord {
* 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>&gt;=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
@ -280,8 +293,7 @@ public class ExternSheetRecord extends StandardRecord {
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));

View File

@ -421,6 +421,8 @@ public final class FontRecord extends StandardRecord {
* 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;
@ -462,6 +464,10 @@ public final class FontRecord extends StandardRecord {
* 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

View File

@ -100,8 +100,8 @@ public final class FtPioGrbitSubRecord extends SubRecord implements Cloneable {
/**
* 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) {

View File

@ -80,7 +80,9 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
@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;
@ -265,10 +267,12 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
}
/**
* 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);
}
/**
@ -279,10 +283,12 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
}
/**
* 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);
}
/**
@ -293,10 +299,12 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
}
/**
* 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);
}
/**
@ -307,10 +315,12 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
}
/**
* 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);
}
/**
@ -372,12 +382,13 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
* @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);
}
}
/**
@ -386,12 +397,13 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
* @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() {
@ -413,20 +425,22 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
/**
* 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;
@ -536,6 +550,7 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
}
}
@Override
public void serialize(LittleEndianOutput out) {
_range.serialize(out);
@ -590,6 +605,7 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
}
}
@Override
protected int getDataSize() {
int size = 0;
size += 2 + 2 + 2 + 2; //rwFirst, rwLast, colFirst, colLast
@ -654,11 +670,13 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
out.write(tail);
}
@Override
public short getSid() {
return HyperlinkRecord.sid;
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
@ -683,6 +701,8 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
/**
* 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
@ -690,6 +710,8 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
}
/**
* 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
@ -697,6 +719,8 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
}
/**
* 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;

View File

@ -103,6 +103,7 @@ public final class IndexRecord extends StandardRecord implements Cloneable {
return field_5_dbcells.get(cellnum);
}
@Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
@ -120,6 +121,7 @@ public final class IndexRecord extends StandardRecord implements Cloneable {
return buffer.toString();
}
@Override
public void serialize(LittleEndianOutput out) {
out.writeInt(0);
@ -131,18 +133,21 @@ public final class IndexRecord extends StandardRecord implements Cloneable {
}
}
@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;
}

View File

@ -22,9 +22,9 @@ import org.apache.poi.util.POILogFactory;
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
*/
@ -76,16 +76,19 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/*
* 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;
@ -123,18 +126,22 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/**
* 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();
@ -152,6 +159,7 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/**
* NO-OP!
*/
@Override
public void setColumn(short col)
{
}
@ -159,6 +167,7 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/**
* NO-OP!
*/
@Override
public void setRow(int row)
{
}
@ -166,6 +175,7 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/**
* no op!
*/
@Override
public void setXFIndex(short xf)
{
}

View File

@ -22,9 +22,8 @@ import org.apache.poi.util.LittleEndianOutput;
/**
* 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;
@ -80,6 +79,7 @@ public final class LabelSSTRecord extends CellRecord implements Cloneable {
return 4;
}
@Override
public short getSid() {
return sid;
}

View File

@ -270,12 +270,16 @@ public class LbsDataSubRecord extends SubRecord {
sb.append("[ftLbsData]\n");
sb.append(" .unknownShort1 =").append(HexDump.shortToHex(_cbFContinued)).append("\n");
sb.append(" .formula = ").append('\n');
if(_linkPtg != null) sb.append(_linkPtg.toString()).append(_linkPtg.getRVAType()).append('\n');
if(_linkPtg != null) {
sb.append(_linkPtg.toString()).append(_linkPtg.getRVAType()).append('\n');
}
sb.append(" .nEntryCount =").append(HexDump.shortToHex(_cLines)).append("\n");
sb.append(" .selEntryIx =").append(HexDump.shortToHex(_iSel)).append("\n");
sb.append(" .style =").append(HexDump.shortToHex(_flags)).append("\n");
sb.append(" .unknownShort10=").append(HexDump.shortToHex(_idEdit)).append("\n");
if(_dropData != null) sb.append('\n').append(_dropData.toString());
if(_dropData != null) {
sb.append('\n').append(_dropData.toString());
}
sb.append("[/ftLbsData]\n");
return sb.toString();
}
@ -354,14 +358,16 @@ public class LbsDataSubRecord extends SubRecord {
}
/**
* Set the style of this dropdown.
* Set the style of this dropdown.<p>
*
* Possible values:
* <p>
* 0 Combo dropdown control
* 1 Combo Edit dropdown control
* 2 Simple dropdown control (just the dropdown button)
* <ul>
* <li>0: Combo dropdown control</li>
* <li>1: Combo Edit dropdown control</li>
* <li>2: Simple dropdown control (just the dropdown button)</li>
* </ul>
*
* @param style the style - see possible values
*/
public void setStyle(int style){
_wStyle = style;
@ -369,6 +375,8 @@ public class LbsDataSubRecord extends SubRecord {
/**
* Set the number of lines to be displayed in the dropdown.
*
* @param num the number of lines to be displayed in the dropdown
*/
public void setNumLines(int num){
_cLine = num;
@ -379,13 +387,17 @@ public class LbsDataSubRecord extends SubRecord {
out.writeShort(_cLine);
out.writeShort(_dxMin);
StringUtil.writeUnicodeString(out, _str);
if(_unused != null) out.writeByte(_unused);
if(_unused != null) {
out.writeByte(_unused);
}
}
public int getDataSize() {
int size = 6;
size += StringUtil.getEncodedSize(_str);
if(_unused != null) size++;
if(_unused != null) {
size++;
}
return size;
}
@ -397,7 +409,9 @@ public class LbsDataSubRecord extends SubRecord {
sb.append(" ._cLine: ").append(_cLine).append('\n');
sb.append(" ._dxMin: ").append(_dxMin).append('\n');
sb.append(" ._str: ").append(_str).append('\n');
if(_unused != null) sb.append(" ._unused: ").append(_unused).append('\n');
if(_unused != null) {
sb.append(" ._unused: ").append(_unused).append('\n');
}
sb.append("[/LbsDropData]\n");
return sb.toString();

View File

@ -29,7 +29,7 @@ import org.apache.poi.util.LittleEndianOutput;
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;
@ -62,20 +62,25 @@ public final class MergeCellsRecord extends StandardRecord implements Cloneable
}
/**
* @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);
@ -84,6 +89,7 @@ public final class MergeCellsRecord extends StandardRecord implements Cloneable
}
}
@Override
public String toString() {
StringBuffer retval = new StringBuffer();

View File

@ -33,10 +33,10 @@ import org.apache.poi.util.LittleEndianOutput;
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;
@ -68,6 +68,9 @@ public final class MulRKRecord extends StandardRecord {
/**
* 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) {
@ -76,6 +79,9 @@ public final class MulRKRecord extends StandardRecord {
/**
* 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) {
@ -93,7 +99,8 @@ public final class MulRKRecord extends StandardRecord {
}
public String toString() {
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[MULRK]\n");
@ -109,15 +116,18 @@ public final class MulRKRecord extends StandardRecord {
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");
}

View File

@ -138,6 +138,8 @@ public final class NameCommentRecord extends StandardRecord {
/**
* 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;

View File

@ -101,13 +101,15 @@ public final class NameRecord extends ContinuableRecord {
/**
* 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
@ -272,7 +274,10 @@ public final class NameRecord extends ContinuableRecord {
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()
{
@ -341,7 +346,8 @@ public final class NameRecord extends ContinuableRecord {
*
* @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();
@ -473,7 +479,8 @@ public final class NameRecord extends ContinuableRecord {
/**
* return the non static version of the id for this record.
*/
public short getSid() {
@Override
public short getSid() {
return sid;
}
/*
@ -527,7 +534,8 @@ public final class NameRecord extends ContinuableRecord {
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");
@ -544,8 +552,7 @@ public final class NameRecord extends ContinuableRecord {
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");
}

View File

@ -73,6 +73,8 @@ public final class NoteRecord extends StandardRecord implements Cloneable {
/**
* 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();
@ -195,6 +197,8 @@ public final class NoteRecord extends StandardRecord implements Cloneable {
/**
* For unit testing only!
*
* @return true, if author element uses multi byte
*/
protected boolean authorIsMultibyte() {
return field_5_hasMultibyte;
@ -202,6 +206,8 @@ public final class NoteRecord extends StandardRecord implements Cloneable {
/**
* 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;
@ -209,6 +215,8 @@ public final class NoteRecord extends StandardRecord implements Cloneable {
/**
* 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;

View File

@ -45,6 +45,9 @@ public final class NoteStructureSubRecord extends SubRecord implements Cloneable
/**
* 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) {
@ -60,6 +63,7 @@ public final class NoteStructureSubRecord extends SubRecord implements Cloneable
* Convert this record to string.
* Used by BiffViewer and other utilities.
*/
@Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
@ -76,13 +80,15 @@ public final class NoteStructureSubRecord extends SubRecord implements Cloneable
*
* @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;
}

View File

@ -25,10 +25,10 @@ import org.apache.poi.util.HexDump;
* 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+
@ -63,6 +63,7 @@ public abstract class OldCellRecord {
public final short getXFIndex() {
return field_3_xf_index;
}
public int getCellAttrs()
{
return field_3_cell_attrs;
@ -70,10 +71,13 @@ public abstract class OldCellRecord {
/**
* 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;
}
@ -101,11 +105,15 @@ public abstract class OldCellRecord {
* 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();
}

View File

@ -33,7 +33,7 @@ public final class OldLabelRecord extends OldCellRecord {
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;
/**
@ -76,6 +76,8 @@ public final class OldLabelRecord extends OldCellRecord {
/**
* Get the String of the cell
*
* @return the String of the cell
*/
public String getValue()
{
@ -84,19 +86,26 @@ public final class OldLabelRecord extends OldCellRecord {
/**
* 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";
}

View File

@ -40,8 +40,8 @@ public final class PaletteRecord extends StandardRecord {
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);
}
}
@ -53,6 +53,7 @@ public final class PaletteRecord extends StandardRecord {
}
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
@ -68,6 +69,7 @@ public final class PaletteRecord extends StandardRecord {
return buffer.toString();
}
@Override
public void serialize(LittleEndianOutput out) {
out.writeShort(_colors.size());
for (int i = 0; i < _colors.size(); i++) {
@ -75,10 +77,12 @@ public final class PaletteRecord extends StandardRecord {
}
}
@Override
protected int getDataSize() {
return 2 + _colors.size() * PColor.ENCODED_SIZE;
}
@Override
public short getSid() {
return sid;
}
@ -86,6 +90,8 @@ public final class PaletteRecord extends StandardRecord {
/**
* Returns the color value at a given index
*
* @param byteIndex palette index, must be &gt;= 0x8
*
* @return the RGB triplet for the color, or <code>null</code> if the specified index
* does not exist
*/
@ -105,6 +111,9 @@ public final class PaletteRecord extends StandardRecord {
*
* @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)
{
@ -195,9 +204,9 @@ public final class PaletteRecord extends StandardRecord {
*/
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;
@ -223,6 +232,7 @@ public final class PaletteRecord extends StandardRecord {
out.writeByte(0);
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(" red = ").append(_red & 0xff).append('\n');

View File

@ -51,6 +51,7 @@ public final class PaneRecord extends StandardRecord {
field_5_activePane = in.readShort();
}
@Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
@ -81,6 +82,7 @@ public final class PaneRecord extends StandardRecord {
return buffer.toString();
}
@Override
public void serialize(LittleEndianOutput out) {
out.writeShort(field_1_x);
out.writeShort(field_2_y);
@ -89,15 +91,18 @@ public final class PaneRecord extends StandardRecord {
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();
@ -109,11 +114,10 @@ public final class PaneRecord extends StandardRecord {
return rec;
}
/**
* Get the x field for the Pane record.
*
* @param the x value
*/
public short getX()
{
@ -122,6 +126,8 @@ public final class PaneRecord extends StandardRecord {
/**
* Set the x field for the Pane record.
*
* @param field_1_x the x value
*/
public void setX(short field_1_x)
{
@ -130,6 +136,8 @@ public final class PaneRecord extends StandardRecord {
/**
* Get the y field for the Pane record.
*
* @return the y value
*/
public short getY()
{
@ -138,6 +146,8 @@ public final class PaneRecord extends StandardRecord {
/**
* Set the y field for the Pane record.
*
* @param field_2_y the y value
*/
public void setY(short field_2_y)
{
@ -146,6 +156,8 @@ public final class PaneRecord extends StandardRecord {
/**
* Get the top row field for the Pane record.
*
* @return the top row
*/
public short getTopRow()
{
@ -154,6 +166,8 @@ public final class PaneRecord extends StandardRecord {
/**
* Set the top row field for the Pane record.
*
* @param field_3_topRow the top row
*/
public void setTopRow(short field_3_topRow)
{
@ -162,6 +176,8 @@ public final class PaneRecord extends StandardRecord {
/**
* Get the left column field for the Pane record.
*
* @return the left column
*/
public short getLeftColumn()
{
@ -170,6 +186,8 @@ public final class PaneRecord extends StandardRecord {
/**
* Set the left column field for the Pane record.
*
* @param field_4_leftColumn the left column
*/
public void setLeftColumn(short field_4_leftColumn)
{

View File

@ -26,7 +26,6 @@ import java.util.ArrayList;
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;
@ -78,6 +77,7 @@ public final class RecordFactory {
public ReflectionConstructorRecordCreator(Constructor<? extends Record> c) {
_c = c;
}
@Override
public Record create(RecordInputStream in) {
Object[] args = { in, };
try {
@ -99,6 +99,7 @@ public final class RecordFactory {
}
}
}
@Override
public Class<? extends Record> getRecordClass() {
return _c.getDeclaringClass();
}
@ -112,6 +113,7 @@ public final class RecordFactory {
public ReflectionMethodRecordCreator(Method m) {
_m = m;
}
@Override
public Record create(RecordInputStream in) {
Object[] args = { in, };
try {
@ -124,6 +126,7 @@ public final class RecordFactory {
throw new RecordFormatException("Unable to construct record instance" , e.getTargetException());
}
}
@Override
@SuppressWarnings("unchecked")
public Class<? extends Record> getRecordClass() {
return (Class<? extends Record>) _m.getDeclaringClass();
@ -292,9 +295,13 @@ public final class RecordFactory {
/**
* 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.
*/
@ -305,9 +312,13 @@ public final class RecordFactory {
}
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);
@ -337,6 +348,9 @@ public final class RecordFactory {
/**
* 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();
@ -349,7 +363,10 @@ public final class RecordFactory {
}
/**
* 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()];
@ -366,7 +383,10 @@ public final class RecordFactory {
}
/**
* 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()];
@ -389,9 +409,7 @@ public final class RecordFactory {
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);
@ -410,9 +428,7 @@ public final class RecordFactory {
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() + ")");
}

View File

@ -193,6 +193,8 @@ public final class RecordFactoryInputStream {
/**
* @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).
@ -238,8 +240,7 @@ public final class RecordFactoryInputStream {
}
/**
* 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;

View File

@ -25,6 +25,7 @@ import org.apache.poi.hssf.dev.BiffViewer;
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;
@ -98,13 +99,16 @@ public final class RecordInputStream implements LittleEndianInput {
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();
}
}
@ -138,7 +142,8 @@ public final class RecordInputStream implements LittleEndianInput {
* @return the number of bytes available in the current BIFF record
* @see #remaining()
*/
public int available() {
@Override
public int available() {
return remaining();
}
@ -158,6 +163,9 @@ public final class RecordInputStream implements LittleEndianInput {
/**
* 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.
*/
@ -230,56 +238,63 @@ public final class RecordInputStream implements LittleEndianInput {
/**
* 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)) {
@ -290,11 +305,13 @@ public final class RecordInputStream implements LittleEndianInput {
}
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();
@ -355,7 +372,7 @@ public final class RecordInputStream implements LittleEndianInput {
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) {
@ -412,27 +429,30 @@ public final class RecordInputStream implements LittleEndianInput {
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);
/**
* 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();
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.
*

View File

@ -41,6 +41,7 @@ public final class SCLRecord extends StandardRecord {
field_2_denominator = in.readShort();
}
@Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
@ -59,20 +60,24 @@ public final class SCLRecord extends StandardRecord {
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();
@ -81,11 +86,10 @@ public final class SCLRecord extends StandardRecord {
return rec;
}
/**
* Get the numerator field for the SCL record.
*
* @return the numerator
*/
public short getNumerator()
{
@ -94,6 +98,8 @@ public final class SCLRecord extends StandardRecord {
/**
* Set the numerator field for the SCL record.
*
* @param field_1_numerator the numerator
*/
public void setNumerator(short field_1_numerator)
{
@ -102,6 +108,8 @@ public final class SCLRecord extends StandardRecord {
/**
* Get the denominator field for the SCL record.
*
* @return the denominator
*/
public short getDenominator()
{
@ -110,6 +118,8 @@ public final class SCLRecord extends StandardRecord {
/**
* Set the denominator field for the SCL record.
*
* @param field_2_denominator the denominator
*/
public void setDenominator(short field_2_denominator)
{

View File

@ -26,10 +26,7 @@ import org.apache.poi.util.LittleEndianOutput;
* 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;
@ -41,6 +38,9 @@ public final class SelectionRecord extends StandardRecord {
/**
* 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'
@ -67,6 +67,7 @@ public final class SelectionRecord extends StandardRecord {
/**
* set which window pane this is for
* @param pane the window pane
*/
public void setPane(byte pane) {
field_1_pane = pane;
@ -127,6 +128,7 @@ public final class SelectionRecord extends StandardRecord {
return field_4_active_cell_ref_index;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
@ -139,10 +141,12 @@ public final class SelectionRecord extends StandardRecord {
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());
@ -150,15 +154,17 @@ public final class SelectionRecord extends StandardRecord {
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;

View File

@ -66,8 +66,8 @@ public final class PageSettingsBlock extends RecordAggregate {
@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);
}
}
}
@ -93,7 +93,7 @@ public final class PageSettingsBlock extends RecordAggregate {
* 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) {
@ -120,6 +120,8 @@ public final class PageSettingsBlock extends RecordAggregate {
}
/**
* @param sid the record sid
*
* @return <code>true</code> if the specified Record sid is one belonging to the
* 'Page Settings Block'.
*/
@ -205,8 +207,9 @@ public final class PageSettingsBlock extends RecordAggregate {
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;
@ -242,6 +245,9 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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);
@ -250,6 +256,7 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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);
@ -258,6 +265,7 @@ public final class PageSettingsBlock extends RecordAggregate {
@Override
public void visitContainedRecords(RecordVisitor rv) {
// Replicates record order from Excel 2007, though this is not critical
@ -481,8 +489,9 @@ public final class PageSettingsBlock extends RecordAggregate {
int breakLocation = breakItem.main;
boolean inStart = (breakLocation >= start);
boolean inEnd = (breakLocation <= stop);
if(inStart && inEnd)
if(inStart && inEnd) {
shiftedBreak.add(breakItem);
}
}
iterator = shiftedBreak.iterator();
@ -496,7 +505,9 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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);
@ -504,17 +515,20 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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) {
@ -525,6 +539,8 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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
*/
public boolean isColumnBroken(int column) {
@ -533,9 +549,9 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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);
@ -543,9 +559,9 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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);
@ -590,6 +606,8 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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) {
@ -604,10 +622,11 @@ public final class PageSettingsBlock extends RecordAggregate {
/**
* 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
@ -616,16 +635,18 @@ public final class PageSettingsBlock extends RecordAggregate {
* 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
*/
@ -665,6 +686,7 @@ public final class PageSettingsBlock extends RecordAggregate {
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());