* 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);
}
/**
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.
*/
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);
}
/**
- * 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);
}
/**
*/
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
}
/**
}
/**
- * 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);
}
/**
}
/**
- * 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);
}
/**
}
/**
- * 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);
}
/**
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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;
- public DSFRecord(RecordInputStream in)
- {
- field_1_dsf = in.readShort();
+ private DSFRecord(int options) {
+ _options = options;
}
-
- /**
- * set the DSF flag
- * @param dsfflag (0-off,1-on)
- */
-
- public void setDsf(short dsfflag)
- {
- field_1_dsf = dsfflag;
+ public DSFRecord(boolean isBiff5BookStreamPresent) {
+ this(0);
+ _options = biff5BookStreamFlag.setBoolean(0, isBiff5BookStreamPresent);
}
- /**
- * get the DSF flag
- * @return dsfflag (0-off,1-on)
- */
+ public DSFRecord(RecordInputStream in) {
+ this(in.readShort());
+ }
- public short getDsf()
- {
- return field_1_dsf;
+ public boolean isBiff5BookStreamPresent() {
+ return biff5BookStreamFlag.isSet(_options);
}
- 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;
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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(double maxChange) {
+ field_1_max_change = maxChange;
}
- public DeltaRecord(RecordInputStream in)
- {
+ public DeltaRecord(RecordInputStream in) {
field_1_max_change = in.readDouble();
}
- /**
- * set the maximum change
- * @param maxChange - maximum rounding error
- */
-
- public void setMaxChange(double maxChange)
- {
- field_1_max_change = maxChange;
- }
-
/**
* 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();
}
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;
}
}
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
*/
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
*/
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);
}
*/
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);
}
LittleEndian.putInt(data, pos, address.length()); pos += 4;
StringUtil.putUnicodeLE(address, data, pos); pos += address.length()*2;
}
- return getRecordSize();
+ return getRecordSize();
}
protected int getDataSize() {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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);
}
/**
*
* @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());
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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) {
hash ^= (0x8000 | ('N' << 8) | 'K');
}
return (short)hash;
- }
+ }
/**
* set the password
* @param password representing the password
*/
- public void setPassword(short password) {
+ public void setPassword(int password) {
field_1_password = password;
}
*
* @return short representing the password
*/
- public short getPassword() {
+ public int getPassword() {
return field_1_password;
}
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() {
* Clone this record.
*/
public Object clone() {
- PasswordRecord clone = new PasswordRecord();
- clone.setPassword(field_1_password);
- return clone;
+ return new PasswordRecord(field_1_password);
}
-
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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();
}
*
* @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;
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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;
+
+ private static final BitField protectFlag = BitFieldFactory.getInstance(0x0001);
+
+ private int _options;
-public final class ProtectRecord
- extends StandardRecord
-{
- public final static short sid = 0x12;
- private short field_1_protect;
+ private ProtectRecord(int options) {
+ _options = options;
+ }
- public ProtectRecord()
- {
+ public ProtectRecord(boolean isProtected) {
+ this(0);
+ setProtect(isProtected);
}
- public ProtectRecord(RecordInputStream in)
- {
- field_1_protect = in.readShort();
+ 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);
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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;
+
+ private static final BitField protectedFlag = BitFieldFactory.getInstance(0x0001);
-public final class ProtectionRev4Record
- extends StandardRecord
-{
- public final static short sid = 0x1af;
- private short field_1_protect;
+ private int _options;
+
+ private ProtectionRev4Record(int options) {
+ _options = options;
+ }
- public ProtectionRev4Record()
- {
+ public ProtectionRev4Record(boolean protect) {
+ this(0);
+ setProtect(protect);
}
- public ProtectionRev4Record(RecordInputStream in)
- {
- field_1_protect = in.readShort();
+ 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;
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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;
+
+ private static final BitField refreshFlag = BitFieldFactory.getInstance(0x0001);
-public final class RefreshAllRecord
- extends StandardRecord
-{
- public final static short sid = 0x1B7;
- private short field_1_refreshall;
+ private int _options;
+
+ private RefreshAllRecord(int options) {
+ _options = options;
+ }
- public RefreshAllRecord()
- {
+ public RefreshAllRecord(RecordInputStream in) {
+ this(in.readUShort());
}
- public RefreshAllRecord(RecordInputStream in)
- {
- field_1_refreshall = in.readShort();
+ 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);
+ }
}
*
*/
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();
}
}
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();
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]);
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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;
- public UseSelFSRecord(RecordInputStream in)
- {
- field_1_flag = in.readShort();
+ private UseSelFSRecord(int options) {
+ _options = options;
}
- /**
- * 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(RecordInputStream in) {
+ this(in.readUShort());
}
- /**
- * 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 UseSelFSRecord(boolean b) {
+ this(0);
+ _options = useNaturalLanguageFormulasFlag.setBoolean(_options, b);
}
- 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);
+ }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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);
}
/**
*
* @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() {
{
return sid;
}
+ @Override
+ public Object clone() {
+ return new WindowProtectRecord(_options);
+ }
}
* @return hashed password
*/
public short getPassword() {
- return getSheet().getPassword().getPassword();
+ return (short)getSheet().getPassword().getPassword();
}
/**
// 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() );
return r;
}
- private ProtectRecord createProtectRecord()
- {
- ProtectRecord r = new ProtectRecord();
- r.setProtect(false);
- return r;
- }
-
private BOFRecord createBOFRecord()
{
BOFRecord r = new BOFRecord();