record sid clean-up

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@719031 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-11-19 19:09:05 +00:00
parent 2a7fa85dd9
commit 3673b6a984
16 changed files with 294 additions and 516 deletions

View File

@ -801,20 +801,14 @@ public final class Sheet implements Model {
* creates the Iteration record and sets it to false (don't iteratively calculate formulas)
*/
private static IterationRecord createIteration() {
IterationRecord retval = new IterationRecord();
retval.setIteration(false);
return retval;
return new IterationRecord(false);
}
/**
* creates the Delta record and sets it to 0.0010 (default accuracy)
*/
private static DeltaRecord createDelta() {
DeltaRecord retval = new DeltaRecord();
retval.setMaxChange(0.0010);
return retval;
return new DeltaRecord(DeltaRecord.DEFAULT_VALUE);
}
/**
@ -1412,18 +1406,6 @@ public final class Sheet implements Model {
this.selection = selection;
}
/**
* creates a Protect record with protect set to false.
*/
private static ProtectRecord createProtect() {
if (log.check( POILogger.DEBUG )) {
log.log(POILogger.DEBUG, "create protect record with protection disabled");
}
ProtectRecord retval = new ProtectRecord();
retval.setProtect(false); // TODO - supply param to constructor
return retval;
}
/**
* creates an ObjectProtect record with protect set to false.
*/
@ -1454,7 +1436,7 @@ public final class Sheet implements Model {
public ProtectRecord getProtect()
{
if (protect == null) {
protect = createProtect();
protect = new ProtectRecord(false);
// Insert the newly created protect record just before DefaultColWidthRecord
int loc = findFirstRecordLocBySid(DefaultColWidthRecord.sid);
records.add(loc, protect);
@ -1477,16 +1459,10 @@ public final class Sheet implements Model {
}
/**
* creates a Password record with password set to 00.
* creates a Password record with password set to 0x0000.
*/
private static PasswordRecord createPassword() {
if (log.check( POILogger.DEBUG )) {
log.log(POILogger.DEBUG, "create password record with 00 password");
}
PasswordRecord retval = new PasswordRecord();
retval.setPassword((short)00);
return retval;
return new PasswordRecord(0x0000);
}
/**

View File

@ -1092,11 +1092,7 @@ public final class Workbook implements Model {
*/
protected Record createDSF() {
DSFRecord retval = new DSFRecord();
retval.setDsf(
( short ) 0); // we don't even support double stream files
return retval;
return new DSFRecord(false); // we don't even support double stream files
}
/**
@ -1125,75 +1121,42 @@ public final class Workbook implements Model {
}
/**
* creates the WindowProtect record with protect set to false.
* @see org.apache.poi.hssf.record.WindowProtectRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a WindowProtectRecord
* @return a new WindowProtect record with protect set to false.
*/
protected Record createWindowProtect() {
WindowProtectRecord retval = new WindowProtectRecord();
retval.setProtect(
false); // by default even when we support it we won't
return retval; // want it to be protected
private static WindowProtectRecord createWindowProtect() {
// by default even when we support it we won't
// want it to be protected
return new WindowProtectRecord(false);
}
/**
* creates the Protect record with protect set to false.
* @see org.apache.poi.hssf.record.ProtectRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a ProtectRecord
* @return a new Protect record with protect set to false.
*/
protected Record createProtect() {
ProtectRecord retval = new ProtectRecord();
retval.setProtect(
false); // by default even when we support it we won't
return retval; // want it to be protected
private static ProtectRecord createProtect() {
// by default even when we support it we won't
// want it to be protected
return new ProtectRecord(false);
}
/**
* creates the Password record with password set to 0.
* @see org.apache.poi.hssf.record.PasswordRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a PasswordRecord
* @return a new Password record with password set to 0x0000 (no password).
*/
protected Record createPassword() {
PasswordRecord retval = new PasswordRecord();
retval.setPassword(( short ) 0); // no password by default!
return retval;
private static PasswordRecord createPassword() {
return new PasswordRecord(0x0000); // no password by default!
}
/**
* creates the ProtectionRev4 record with protect set to false.
* @see org.apache.poi.hssf.record.ProtectionRev4Record
* @see org.apache.poi.hssf.record.Record
* @return record containing a ProtectionRev4Record
* @return a new ProtectionRev4 record with protect set to false.
*/
protected Record createProtectionRev4() {
ProtectionRev4Record retval = new ProtectionRev4Record();
retval.setProtect(false);
return retval;
private static ProtectionRev4Record createProtectionRev4() {
return new ProtectionRev4Record(false);
}
/**
* creates the PasswordRev4 record with password set to 0.
* @see org.apache.poi.hssf.record.PasswordRev4Record
* @see org.apache.poi.hssf.record.Record
* @return record containing a PasswordRev4Record
* @return a new PasswordRev4 record with password set to 0.
*/
protected Record createPasswordRev4() {
PasswordRev4Record retval = new PasswordRev4Record();
retval.setPassword(( short ) 0); // no password by default!
return retval;
private static PasswordRev4Record createPasswordRev4() {
return new PasswordRev4Record(0x0000);
}
/**
@ -1287,17 +1250,10 @@ public final class Workbook implements Model {
}
/**
* creates the RefreshAll record with refreshAll set to true. (refresh all calcs)
* @see org.apache.poi.hssf.record.RefreshAllRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a RefreshAllRecord
* @return a new RefreshAll record with refreshAll set to false. (do not refresh all calcs)
*/
protected Record createRefreshAll() {
RefreshAllRecord retval = new RefreshAllRecord();
retval.setRefreshAll(false);
return retval;
private static RefreshAllRecord createRefreshAll() {
return new RefreshAllRecord(false);
}
/**
@ -1783,17 +1739,10 @@ public final class Workbook implements Model {
}
/**
* Creates the UseSelFS object with the use natural language flag set to 0 (false)
* @return record containing a UseSelFSRecord
* @see org.apache.poi.hssf.record.UseSelFSRecord
* @see org.apache.poi.hssf.record.Record
* @return a new UseSelFS object with the use natural language flag set to 0 (false)
*/
protected Record createUseSelFS() {
UseSelFSRecord retval = new UseSelFSRecord();
retval.setFlag(( short ) 0);
return retval;
private static UseSelFSRecord createUseSelFS() {
return new UseSelFSRecord(false);
}
/**

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,77 +14,62 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Double Stream Flag Record<P>
* Description: tells if this is a double stream file. (always no for HSSF generated files)<P>
* Double Stream files contain both BIFF8 and BIFF7 workbooks.<P>
* REFERENCE: PG 305 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* Title: Double Stream Flag Record (0x0161)<p/>
* Description: tells if this is a double stream file. (always no for HSSF generated files)<p/>
* Double Stream files contain both BIFF8 and BIFF7 workbooks.<p/>
* REFERENCE: PG 305 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*/
public final class DSFRecord extends StandardRecord {
public final static short sid = 0x0161;
public final class DSFRecord
extends StandardRecord
{
public final static short sid = 0x161;
private short field_1_dsf;
private static final BitField biff5BookStreamFlag = BitFieldFactory.getInstance(0x0001);
public DSFRecord()
{
private int _options;
private DSFRecord(int options) {
_options = options;
}
public DSFRecord(boolean isBiff5BookStreamPresent) {
this(0);
_options = biff5BookStreamFlag.setBoolean(0, isBiff5BookStreamPresent);
}
public DSFRecord(RecordInputStream in)
{
field_1_dsf = in.readShort();
public DSFRecord(RecordInputStream in) {
this(in.readShort());
}
/**
* set the DSF flag
* @param dsfflag (0-off,1-on)
*/
public void setDsf(short dsfflag)
{
field_1_dsf = dsfflag;
public boolean isBiff5BookStreamPresent() {
return biff5BookStreamFlag.isSet(_options);
}
/**
* get the DSF flag
* @return dsfflag (0-off,1-on)
*/
public short getDsf()
{
return field_1_dsf;
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[DSF]\n");
buffer.append(" .isDSF = ")
.append(Integer.toHexString(getDsf())).append("\n");
buffer.append(" .options = ").append(HexDump.shortToHex(_options)).append("\n");
buffer.append("[/DSF]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(getDsf());
out.writeShort(_options);
}
protected int getDataSize() {
return 2;
}
public short getSid()
{
public short getSid() {
return sid;
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,67 +14,47 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Delta Record<P>
* Description: controls the accuracy of the calculations<P>
* REFERENCE: PG 303 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* Title: Delta Record (0x0010)<p/>
* Description: controls the accuracy of the calculations<p/>
* REFERENCE: PG 303 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)
* @version 2.0-pre
*/
public final class DeltaRecord
extends StandardRecord
{
public final static short sid = 0x10;
public final class DeltaRecord extends StandardRecord {
public final static short sid = 0x0010;
public final static double DEFAULT_VALUE = 0.0010; // should be .001
// a double is an IEEE 8-byte float...damn IEEE and their goofy standards an
// ambiguous numeric identifiers
private double field_1_max_change;
private double field_1_max_change;
public DeltaRecord()
{
}
public DeltaRecord(RecordInputStream in)
{
field_1_max_change = in.readDouble();
}
/**
* set the maximum change
* @param maxChange - maximum rounding error
*/
public void setMaxChange(double maxChange)
{
public DeltaRecord(double maxChange) {
field_1_max_change = maxChange;
}
public DeltaRecord(RecordInputStream in) {
field_1_max_change = in.readDouble();
}
/**
* get the maximum change
* @return maxChange - maximum rounding error
*/
public double getMaxChange()
{
public double getMaxChange() {
return field_1_max_change;
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[DELTA]\n");
buffer.append(" .maxchange = ").append(getMaxChange())
.append("\n");
buffer.append(" .maxchange = ").append(getMaxChange()).append("\n");
buffer.append("[/DELTA]\n");
return buffer.toString();
}
@ -88,14 +67,12 @@ public final class DeltaRecord
return 8;
}
public short getSid()
{
public short getSid() {
return sid;
}
public Object clone() {
DeltaRecord rec = new DeltaRecord();
rec.field_1_max_change = field_1_max_change;
return rec;
// immutable
return this;
}
}

View File

@ -24,14 +24,16 @@ import org.apache.poi.util.StringUtil;
import org.apache.poi.util.HexDump;
/**
* The <code>HyperlinkRecord</code> wraps an HLINK-record
* The <code>HyperlinkRecord</code> (0x01B8) wraps an HLINK-record
* from the Excel-97 format.
* Supports only external links for now (eg http://)
* Supports only external links for now (eg http://)
*
* @author Mark Hissink Muller <a href="mailto:mark@hissinkmuller.nl >mark&064;hissinkmuller.nl</a>
* @author Yegor Kozlov (yegor at apache dot org)
*/
public final class HyperlinkRecord extends Record {
public final static short sid = 0x01B8;
/**
* Link flags
*/
@ -60,7 +62,6 @@ public final class HyperlinkRecord extends Record {
protected final static byte[] FILE_TAIL = {(byte)0xFF, (byte)0xFF, (byte)0xAD, (byte)0xDE, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
public final static short sid = 0x1b8;
/**
* First row of the hyperlink
@ -238,8 +239,8 @@ public final class HyperlinkRecord extends Record {
*/
public String getLabel()
{
if(label == null) return null;
if(label == null) return null;
int idx = label.indexOf('\u0000');
return idx == -1 ? label : label.substring(0, idx);
}
@ -261,8 +262,8 @@ public final class HyperlinkRecord extends Record {
*/
public String getAddress()
{
if(address == null) return null;
if(address == null) return null;
int idx = address.indexOf('\u0000');
return idx == -1 ? address : address.substring(0, idx);
}
@ -402,7 +403,7 @@ public final class HyperlinkRecord extends Record {
LittleEndian.putInt(data, pos, address.length()); pos += 4;
StringUtil.putUnicodeLE(address, data, pos); pos += address.length()*2;
}
return getRecordSize();
return getRecordSize();
}
protected int getDataSize() {

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,54 +14,46 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Iteration Record<P>
* Title: Iteration Record (0x0011) <p/>
* Description: Tells whether to iterate over forumla calculations or not
* (if a formula is dependant upon another formula's result)
* (odd feature for something that can only have 32 elements in
* a formula!)<P>
* REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* REFERENCE: PG 325 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)
* @version 2.0-pre
*/
public final class IterationRecord extends StandardRecord {
public final static short sid = 0x0011;
public final class IterationRecord
extends StandardRecord
{
public final static short sid = 0x11;
private short field_1_iteration;
private static final BitField iterationOn = BitFieldFactory.getInstance(0x0001);
public IterationRecord()
{
private int _flags;
public IterationRecord(boolean iterateOn) {
_flags = iterationOn.setBoolean(0, iterateOn);
}
public IterationRecord(RecordInputStream in)
{
field_1_iteration = in.readShort();
_flags = in.readShort();
}
/**
* set whether or not to iterate for calculations
* @param iterate or not
*/
public void setIteration(boolean iterate)
{
if (iterate)
{
field_1_iteration = 1;
}
else
{
field_1_iteration = 0;
}
public void setIteration(boolean iterate) {
_flags = iterationOn.setBoolean(_flags, iterate);
}
/**
@ -70,39 +61,32 @@ public final class IterationRecord
*
* @return whether iterative calculations are turned off or on
*/
public boolean getIteration()
{
return (field_1_iteration == 1);
public boolean getIteration() {
return iterationOn.isSet(_flags);
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[ITERATION]\n");
buffer.append(" .iteration = ").append(getIteration())
.append("\n");
buffer.append(" .flags = ").append(HexDump.shortToHex(_flags)).append("\n");
buffer.append("[/ITERATION]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(field_1_iteration);
out.writeShort(_flags);
}
protected int getDataSize() {
return 2;
}
public short getSid()
{
public short getSid() {
return sid;
}
public Object clone() {
IterationRecord rec = new IterationRecord();
rec.field_1_iteration = field_1_iteration;
return rec;
return new IterationRecord(getIteration());
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,25 +14,25 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Password Record<P>
* Title: Password Record (0x0013)<p/>
* Description: stores the encrypted password for a sheet or workbook (HSSF doesn't support encryption)
* REFERENCE: PG 371 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* REFERENCE: PG 371 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*
*/
public final class PasswordRecord extends StandardRecord {
public final static short sid = 0x13;
private short field_1_password; // not sure why this is only 2 bytes, but it is... go figure
public final static short sid = 0x0013;
private int field_1_password; // not sure why this is only 2 bytes, but it is... go figure
public PasswordRecord() {
public PasswordRecord(int password) {
field_1_password = password;
}
public PasswordRecord(RecordInputStream in) {
@ -57,7 +56,7 @@ public final class PasswordRecord extends StandardRecord {
hash ^= (0x8000 | ('N' << 8) | 'K');
}
return (short)hash;
}
}
/**
* set the password
@ -65,7 +64,7 @@ public final class PasswordRecord extends StandardRecord {
* @param password representing the password
*/
public void setPassword(short password) {
public void setPassword(int password) {
field_1_password = password;
}
@ -74,7 +73,7 @@ public final class PasswordRecord extends StandardRecord {
*
* @return short representing the password
*/
public short getPassword() {
public int getPassword() {
return field_1_password;
}
@ -82,14 +81,13 @@ public final class PasswordRecord extends StandardRecord {
StringBuffer buffer = new StringBuffer();
buffer.append("[PASSWORD]\n");
buffer.append(" .password = ")
.append(Integer.toHexString(getPassword())).append("\n");
buffer.append(" .password = ").append(HexDump.shortToHex(field_1_password)).append("\n");
buffer.append("[/PASSWORD]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(getPassword());
out.writeShort(field_1_password);
}
protected int getDataSize() {
@ -104,9 +102,6 @@ public final class PasswordRecord extends StandardRecord {
* Clone this record.
*/
public Object clone() {
PasswordRecord clone = new PasswordRecord();
clone.setPassword(field_1_password);
return clone;
return new PasswordRecord(field_1_password);
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,33 +14,27 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Protection Revision 4 password Record<P>
* Description: Stores the (2 byte??!!) encrypted password for a shared
* workbook<P>
* REFERENCE: PG 374 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* Title: Protection Revision 4 password Record (0x01BC) <p/>
* Description: Stores the (2 byte??!!) encrypted password for a shared workbook<p/>
* REFERENCE: PG 374 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*/
public final class PasswordRev4Record extends StandardRecord {
public final static short sid = 0x01BC;
private int field_1_password;
public final class PasswordRev4Record
extends StandardRecord
{
public final static short sid = 0x1BC;
private short field_1_password;
public PasswordRev4Record()
{
public PasswordRev4Record(int pw) {
field_1_password = pw;
}
public PasswordRev4Record(RecordInputStream in)
{
public PasswordRev4Record(RecordInputStream in) {
field_1_password = in.readShort();
}
@ -50,44 +43,28 @@ public final class PasswordRev4Record
*
* @param pw representing the password
*/
public void setPassword(short pw)
{
public void setPassword(short pw) {
field_1_password = pw;
}
/**
* get the password
*
* @return short representing the password
*/
public short getPassword()
{
return field_1_password;
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[PROT4REVPASSWORD]\n");
buffer.append(" .password = ")
.append(Integer.toHexString(getPassword())).append("\n");
buffer.append(" .password = ").append(HexDump.shortToHex(field_1_password)).append("\n");
buffer.append("[/PROT4REVPASSWORD]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(getPassword());
out.writeShort(field_1_password);
}
protected int getDataSize() {
return 2;
}
public short getSid()
{
public short getSid() {
return sid;
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,92 +14,80 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Protect Record<P>
* Description: defines whether a sheet or workbook is protected (HSSF DOES NOT SUPPORT ENCRYPTION)<P>
* (kindly ask the US government to stop having arcane stupid encryption laws and we'll support it) <P>
* (after all terrorists will all use US-legal encrypton right??)<P>
* Title: Protect Record (0x0012) <p/>
* Description: defines whether a sheet or workbook is protected (HSSF DOES NOT SUPPORT ENCRYPTION)<p/>
* HSSF now supports the simple "protected" sheets (where they are not encrypted and open office et al
* ignore the password record entirely).
* REFERENCE: PG 373 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* REFERENCE: PG 373 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
*/
public final class ProtectRecord extends StandardRecord {
public final static short sid = 0x0012;
public final class ProtectRecord
extends StandardRecord
{
public final static short sid = 0x12;
private short field_1_protect;
private static final BitField protectFlag = BitFieldFactory.getInstance(0x0001);
public ProtectRecord()
{
private int _options;
private ProtectRecord(int options) {
_options = options;
}
public ProtectRecord(RecordInputStream in)
{
field_1_protect = in.readShort();
public ProtectRecord(boolean isProtected) {
this(0);
setProtect(isProtected);
}
public ProtectRecord(RecordInputStream in) {
this(in.readShort());
}
/**
* set whether the sheet is protected or not
* @param protect whether to protect the sheet or not
*/
public void setProtect(boolean protect)
{
if (protect)
{
field_1_protect = 1;
}
else
{
field_1_protect = 0;
}
public void setProtect(boolean protect) {
_options = protectFlag.setBoolean(_options, protect);
}
/**
* get whether the sheet is protected or not
* @return whether to protect the sheet or not
*/
public boolean getProtect()
{
return (field_1_protect == 1);
public boolean getProtect() {
return protectFlag.isSet(_options);
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[PROTECT]\n");
buffer.append(" .protect = ").append(getProtect())
.append("\n");
buffer.append(" .options = ").append(HexDump.shortToHex(_options)).append("\n");
buffer.append("[/PROTECT]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(field_1_protect);
out.writeShort(_options);
}
protected int getDataSize() {
return 2;
}
public short getSid()
{
public short getSid() {
return sid;
}
public Object clone() {
ProtectRecord rec = new ProtectRecord();
rec.field_1_protect = field_1_protect;
return rec;
return new ProtectRecord(_options);
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,84 +14,74 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Protection Revision 4 Record<P>
* Description: describes whether this is a protected shared/tracked workbook<P>
* ( HSSF does not support encryption because we don't feel like going to jail ) <P>
* REFERENCE: PG 373 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* Title: Protection Revision 4 Record (0x01AF) <p/>
* Description: describes whether this is a protected shared/tracked workbook<p/>
* REFERENCE: PG 373 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*/
public final class ProtectionRev4Record extends StandardRecord {
public final static short sid = 0x01AF;
public final class ProtectionRev4Record
extends StandardRecord
{
public final static short sid = 0x1af;
private short field_1_protect;
private static final BitField protectedFlag = BitFieldFactory.getInstance(0x0001);
public ProtectionRev4Record()
{
private int _options;
private ProtectionRev4Record(int options) {
_options = options;
}
public ProtectionRev4Record(RecordInputStream in)
{
field_1_protect = in.readShort();
public ProtectionRev4Record(boolean protect) {
this(0);
setProtect(protect);
}
public ProtectionRev4Record(RecordInputStream in) {
this(in.readUShort());
}
/**
* set whether the this is protected shared/tracked workbook or not
* @param protect whether to protect the workbook or not
*/
public void setProtect(boolean protect)
{
if (protect)
{
field_1_protect = 1;
}
else
{
field_1_protect = 0;
}
public void setProtect(boolean protect) {
_options = protectedFlag.setBoolean(_options, protect);
}
/**
* get whether the this is protected shared/tracked workbook or not
* @return whether to protect the workbook or not
*/
public boolean getProtect() {
return protectedFlag.isSet(_options);
}
public boolean getProtect()
{
return (field_1_protect == 1);
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[PROT4REV]\n");
buffer.append(" .protect = ").append(getProtect())
.append("\n");
buffer.append(" .options = ").append(HexDump.shortToHex(_options)).append("\n");
buffer.append("[/PROT4REV]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(field_1_protect);
out.writeShort(_options);
}
protected int getDataSize() {
return 2;
}
public short getSid()
{
public short getSid() {
return sid;
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,84 +14,79 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Refresh All Record <P>
* Title: Refresh All Record (0x01B7) <p/>
* Description: Flag whether to refresh all external data when loading a sheet.
* (which hssf doesn't support anyhow so who really cares?)<P>
* REFERENCE: PG 376 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*/
public final class RefreshAllRecord extends StandardRecord {
public final static short sid = 0x01B7;
public final class RefreshAllRecord
extends StandardRecord
{
public final static short sid = 0x1B7;
private short field_1_refreshall;
private static final BitField refreshFlag = BitFieldFactory.getInstance(0x0001);
public RefreshAllRecord()
{
private int _options;
private RefreshAllRecord(int options) {
_options = options;
}
public RefreshAllRecord(RecordInputStream in)
{
field_1_refreshall = in.readShort();
public RefreshAllRecord(RecordInputStream in) {
this(in.readUShort());
}
public RefreshAllRecord(boolean refreshAll) {
this(0);
setRefreshAll(refreshAll);
}
/**
* set whether to refresh all external data when loading a sheet
* @param refreshall or not
* @param refreshAll or not
*/
public void setRefreshAll(boolean refreshall)
{
if (refreshall)
{
field_1_refreshall = 1;
}
else
{
field_1_refreshall = 0;
}
public void setRefreshAll(boolean refreshAll) {
_options = refreshFlag.setBoolean(_options, refreshAll);
}
/**
* get whether to refresh all external data when loading a sheet
* @return refreshall or not
*/
public boolean getRefreshAll()
{
return (field_1_refreshall == 1);
public boolean getRefreshAll() {
return refreshFlag.isSet(_options);
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[REFRESHALL]\n");
buffer.append(" .refreshall = ").append(getRefreshAll())
.append("\n");
buffer.append(" .options = ").append(HexDump.shortToHex(_options)).append("\n");
buffer.append("[/REFRESHALL]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(field_1_refreshall);
out.writeShort(_options);
}
protected int getDataSize() {
return 2;
}
public short getSid()
{
public short getSid() {
return sid;
}
@Override
public Object clone() {
return new RefreshAllRecord(_options);
}
}

View File

@ -28,20 +28,20 @@ import org.apache.poi.util.LittleEndianOutput;
*
*/
public final class TabIdRecord extends StandardRecord {
public final static short sid = 0x13d;
private static final short[] EMPTY_SHORT_ARRAY = { };
public final static short sid = 0x013D;
private static final short[] EMPTY_SHORT_ARRAY = { };
public short[] _tabids;
public TabIdRecord() {
_tabids = EMPTY_SHORT_ARRAY;
_tabids = EMPTY_SHORT_ARRAY;
}
public TabIdRecord(RecordInputStream in) {
int nTabs = in.remaining() / 2;
int nTabs = in.remaining() / 2;
_tabids = new short[nTabs];
for (int k = 0; k < _tabids.length; k++) {
_tabids[ k ] = in.readShort();
for (int i = 0; i < _tabids.length; i++) {
_tabids[i] = in.readShort();
}
}
@ -58,9 +58,8 @@ public final class TabIdRecord extends StandardRecord {
buffer.append("[TABID]\n");
buffer.append(" .elements = ").append(_tabids.length).append("\n");
for (int k = 0; k < _tabids.length; k++)
{
buffer.append(" .element_").append(k).append(" = ").append(_tabids[ k ]).append("\n");
for (int i = 0; i < _tabids.length; i++) {
buffer.append(" .element_").append(i).append(" = ").append(_tabids[i]).append("\n");
}
buffer.append("[/TABID]\n");
return buffer.toString();
@ -69,8 +68,8 @@ public final class TabIdRecord extends StandardRecord {
public void serialize(LittleEndianOutput out) {
short[] tabids = _tabids;
for (int k = 0; k < tabids.length; k++) {
out.writeShort(tabids[ k ]);
for (int i = 0; i < tabids.length; i++) {
out.writeShort(tabids[i]);
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,85 +14,64 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Use Natural Language Formulas Flag<P>
* Title: USESELFS (0x0160) - Use Natural Language Formulas Flag <p/>
* Description: Tells the GUI if this was written by something that can use
* "natural language" formulas. HSSF can't.<P>
* REFERENCE: PG 420 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* "natural language" formulas. HSSF can't.<p/>
* REFERENCE: PG 420 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*/
public final class UseSelFSRecord extends StandardRecord {
public final static short sid = 0x0160;
public final class UseSelFSRecord
extends StandardRecord
{
public final static short sid = 0x160;
public final static short TRUE = 1;
public final static short FALSE = 0;
private short field_1_flag;
private static final BitField useNaturalLanguageFormulasFlag = BitFieldFactory.getInstance(0x0001);
public UseSelFSRecord()
{
private int _options;
private UseSelFSRecord(int options) {
_options = options;
}
public UseSelFSRecord(RecordInputStream in)
{
field_1_flag = in.readShort();
public UseSelFSRecord(RecordInputStream in) {
this(in.readUShort());
}
/**
* turn the flag on or off
*
* @param flag whether to use natural language formulas or not
* @see #TRUE
* @see #FALSE
*/
public void setFlag(short flag)
{
field_1_flag = flag;
public UseSelFSRecord(boolean b) {
this(0);
_options = useNaturalLanguageFormulasFlag.setBoolean(_options, b);
}
/**
* returns whether we use natural language formulas or not
*
* @return whether to use natural language formulas or not
* @see #TRUE
* @see #FALSE
*/
public short getFlag()
{
return field_1_flag;
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[USESELFS]\n");
buffer.append(" .flag = ")
.append(Integer.toHexString(getFlag())).append("\n");
buffer.append(" .options = ").append(HexDump.shortToHex(_options)).append("\n");
buffer.append("[/USESELFS]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(getFlag());
out.writeShort(_options);
}
protected int getDataSize() {
return 2;
}
public short getSid()
{
public short getSid() {
return sid;
}
@Override
public Object clone() {
return new UseSelFSRecord(_options);
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,50 +14,46 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Window Protect Record<P>
* Description: flags whether workbook windows are protected<P>
* REFERENCE: PG 424 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* Title: Window Protect Record (0x0019) <p/>
* Description: flags whether workbook windows are protected<p/>
* REFERENCE: PG 424 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*/
public final class WindowProtectRecord extends StandardRecord {
public final static short sid = 0x0019;
public final class WindowProtectRecord
extends StandardRecord
{
public final static short sid = 0x19;
private short field_1_protect;
private static final BitField settingsProtectedFlag = BitFieldFactory.getInstance(0x0001);
public WindowProtectRecord()
{
private int _options;
public WindowProtectRecord(int options) {
_options = options;
}
public WindowProtectRecord(RecordInputStream in)
{
field_1_protect = in.readShort();
public WindowProtectRecord(RecordInputStream in) {
this(in.readUShort());
}
public WindowProtectRecord(boolean protect) {
this(0);
setProtect(protect);
}
/**
* set whether this window should be protected or not
* @param protect or not
*/
public void setProtect(boolean protect)
{
if (protect == true)
{
field_1_protect = 1;
}
else
{
field_1_protect = 0;
}
public void setProtect(boolean protect) {
_options = settingsProtectedFlag.setBoolean(_options, protect);
}
/**
@ -66,25 +61,21 @@ public final class WindowProtectRecord
*
* @return protected or not
*/
public boolean getProtect()
{
return (field_1_protect == 1);
public boolean getProtect() {
return settingsProtectedFlag.isSet(_options);
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[WINDOWPROTECT]\n");
buffer.append(" .protect = ").append(getProtect())
.append("\n");
buffer.append(" .options = ").append(HexDump.shortToHex(_options)).append("\n");
buffer.append("[/WINDOWPROTECT]\n");
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeShort(field_1_protect);
out.writeShort(_options);
}
protected int getDataSize() {
@ -95,4 +86,8 @@ public final class WindowProtectRecord
{
return sid;
}
@Override
public Object clone() {
return new WindowProtectRecord(_options);
}
}

View File

@ -1004,7 +1004,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
* @return hashed password
*/
public short getPassword() {
return getSheet().getPassword().getPassword();
return (short)getSheet().getPassword().getPassword();
}
/**

View File

@ -108,7 +108,7 @@ public final class HSSFChart {
// unknown 33
records.add( createFontBasisRecord1() );
records.add( createFontBasisRecord2() );
records.add( createProtectRecord() );
records.add(new ProtectRecord(false));
records.add( createUnitsRecord() );
records.add( createChartRecord( 0, 0, 30434904, 19031616 ) );
records.add( createBeginRecord() );
@ -333,13 +333,6 @@ public final class HSSFChart {
return r;
}
private ProtectRecord createProtectRecord()
{
ProtectRecord r = new ProtectRecord();
r.setProtect(false);
return r;
}
private BOFRecord createBOFRecord()
{
BOFRecord r = new BOFRecord();