From f40455464932e4e05efd75ed1e28b89dc2d1bf79 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Wed, 19 Nov 2008 19:09:05 +0000 Subject: [PATCH] record sid clean-up git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@719031 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/model/Sheet.java | 34 +----- .../org/apache/poi/hssf/model/Workbook.java | 103 +++++------------- .../org/apache/poi/hssf/record/DSFRecord.java | 66 +++++------ .../apache/poi/hssf/record/DeltaRecord.java | 53 +++------ .../poi/hssf/record/HyperlinkRecord.java | 17 +-- .../poi/hssf/record/IterationRecord.java | 60 ++++------ .../poi/hssf/record/PasswordRecord.java | 33 +++--- .../poi/hssf/record/PasswordRev4Record.java | 53 +++------ .../apache/poi/hssf/record/ProtectRecord.java | 71 +++++------- .../poi/hssf/record/ProtectionRev4Record.java | 69 +++++------- .../poi/hssf/record/RefreshAllRecord.java | 68 ++++++------ .../apache/poi/hssf/record/TabIdRecord.java | 23 ++-- .../poi/hssf/record/UseSelFSRecord.java | 74 +++++-------- .../poi/hssf/record/WindowProtectRecord.java | 67 ++++++------ .../apache/poi/hssf/usermodel/HSSFSheet.java | 2 +- .../apache/poi/hssf/usermodel/HSSFChart.java | 9 +- 16 files changed, 290 insertions(+), 512 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 23d6ec115c..7010368b99 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -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); } /** diff --git a/src/java/org/apache/poi/hssf/model/Workbook.java b/src/java/org/apache/poi/hssf/model/Workbook.java index 84ebf99622..011d2b2f47 100644 --- a/src/java/org/apache/poi/hssf/model/Workbook.java +++ b/src/java/org/apache/poi/hssf/model/Workbook.java @@ -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); } /** diff --git a/src/java/org/apache/poi/hssf/record/DSFRecord.java b/src/java/org/apache/poi/hssf/record/DSFRecord.java index 8eba5d612c..0797039594 100644 --- a/src/java/org/apache/poi/hssf/record/DSFRecord.java +++ b/src/java/org/apache/poi/hssf/record/DSFRecord.java @@ -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

- * Description: tells if this is a double stream file. (always no for HSSF generated files)

- * Double Stream files contain both BIFF8 and BIFF7 workbooks.

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

+ * Title: Double Stream Flag Record (0x0161)

+ * Description: tells if this is a double stream file. (always no for HSSF generated files)

+ * Double Stream files contain both BIFF8 and BIFF7 workbooks.

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

* @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; } } diff --git a/src/java/org/apache/poi/hssf/record/DeltaRecord.java b/src/java/org/apache/poi/hssf/record/DeltaRecord.java index c005ff1a6a..c6d4577cf1 100644 --- a/src/java/org/apache/poi/hssf/record/DeltaRecord.java +++ b/src/java/org/apache/poi/hssf/record/DeltaRecord.java @@ -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

- * Description: controls the accuracy of the calculations

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

+ * Title: Delta Record (0x0010)

+ * Description: controls the accuracy of the calculations

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

* @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(); } @@ -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; } } diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java index d4d824f89b..04697a52d3 100644 --- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java +++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java @@ -24,14 +24,16 @@ import org.apache.poi.util.StringUtil; import org.apache.poi.util.HexDump; /** - * The HyperlinkRecord wraps an HLINK-record + * The HyperlinkRecord (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 + * Title: Password Record (0x0013)

* 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)

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

* @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); } - } diff --git a/src/java/org/apache/poi/hssf/record/PasswordRev4Record.java b/src/java/org/apache/poi/hssf/record/PasswordRev4Record.java index d05018e70c..8786bf965e 100644 --- a/src/java/org/apache/poi/hssf/record/PasswordRev4Record.java +++ b/src/java/org/apache/poi/hssf/record/PasswordRev4Record.java @@ -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

- * Description: Stores the (2 byte??!!) encrypted password for a shared - * workbook

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

+ * Title: Protection Revision 4 password Record (0x01BC)

+ * Description: Stores the (2 byte??!!) encrypted password for a shared workbook

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

* @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; } } diff --git a/src/java/org/apache/poi/hssf/record/ProtectRecord.java b/src/java/org/apache/poi/hssf/record/ProtectRecord.java index 7bbb6f2f7b..fcf68dcbbd 100644 --- a/src/java/org/apache/poi/hssf/record/ProtectRecord.java +++ b/src/java/org/apache/poi/hssf/record/ProtectRecord.java @@ -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

- * Description: defines whether a sheet or workbook is protected (HSSF DOES NOT SUPPORT ENCRYPTION)

- * (kindly ask the US government to stop having arcane stupid encryption laws and we'll support it)

- * (after all terrorists will all use US-legal encrypton right??)

+ * Title: Protect Record (0x0012)

+ * Description: defines whether a sheet or workbook is protected (HSSF DOES NOT SUPPORT ENCRYPTION)

* 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)

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

* @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); } } diff --git a/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java b/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java index 7671f4e02d..64a4460be8 100644 --- a/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java +++ b/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java @@ -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

- * Description: describes whether this is a protected shared/tracked workbook

- * ( HSSF does not support encryption because we don't feel like going to jail )

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

+ * Title: Protection Revision 4 Record (0x01AF)

+ * Description: describes whether this is a protected shared/tracked workbook

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

* @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; } } diff --git a/src/java/org/apache/poi/hssf/record/RefreshAllRecord.java b/src/java/org/apache/poi/hssf/record/RefreshAllRecord.java index 632fcab20f..055a247d68 100644 --- a/src/java/org/apache/poi/hssf/record/RefreshAllRecord.java +++ b/src/java/org/apache/poi/hssf/record/RefreshAllRecord.java @@ -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

+ * Title: Refresh All Record (0x01B7)

* Description: Flag whether to refresh all external data when loading a sheet. * (which hssf doesn't support anyhow so who really cares?)

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

* @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); + } } diff --git a/src/java/org/apache/poi/hssf/record/TabIdRecord.java b/src/java/org/apache/poi/hssf/record/TabIdRecord.java index 7c6803d4ea..843d2aa774 100644 --- a/src/java/org/apache/poi/hssf/record/TabIdRecord.java +++ b/src/java/org/apache/poi/hssf/record/TabIdRecord.java @@ -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]); } } diff --git a/src/java/org/apache/poi/hssf/record/UseSelFSRecord.java b/src/java/org/apache/poi/hssf/record/UseSelFSRecord.java index fc81167fb1..f1c1e3044a 100644 --- a/src/java/org/apache/poi/hssf/record/UseSelFSRecord.java +++ b/src/java/org/apache/poi/hssf/record/UseSelFSRecord.java @@ -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

+ * Title: USESELFS (0x0160) - Use Natural Language Formulas Flag

* Description: Tells the GUI if this was written by something that can use - * "natural language" formulas. HSSF can't.

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

+ * "natural language" formulas. HSSF can't.

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

* @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); + } } diff --git a/src/java/org/apache/poi/hssf/record/WindowProtectRecord.java b/src/java/org/apache/poi/hssf/record/WindowProtectRecord.java index 79140dfd8d..e6f0688501 100644 --- a/src/java/org/apache/poi/hssf/record/WindowProtectRecord.java +++ b/src/java/org/apache/poi/hssf/record/WindowProtectRecord.java @@ -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

- * Description: flags whether workbook windows are protected

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

+ * Title: Window Protect Record (0x0019)

+ * Description: flags whether workbook windows are protected

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

* @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); + } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 8651ff48cd..d5627b91cf 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -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(); } /** diff --git a/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java b/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java index c0a1daaeb1..10a75b375e 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java +++ b/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java @@ -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(); -- 2.39.5