Fixed generics compiler warnings in Workbook. Other minor code clean-up.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@721602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-11-29 00:46:33 +00:00
parent 45287875d7
commit 2b6a9c351e
2 changed files with 281 additions and 409 deletions

View File

@ -17,13 +17,66 @@
package org.apache.poi.hssf.model; package org.apache.poi.hssf.model;
import java.security.AccessControlException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.hssf.record.*; import org.apache.poi.ddf.EscherBoolProperty;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.ddf.EscherDggRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRGBProperty;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.ddf.EscherSplitMenuColorsRecord;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.BackupRecord;
import org.apache.poi.hssf.record.BookBoolRecord;
import org.apache.poi.hssf.record.BoundSheetRecord;
import org.apache.poi.hssf.record.CodepageRecord;
import org.apache.poi.hssf.record.CountryRecord;
import org.apache.poi.hssf.record.DSFRecord;
import org.apache.poi.hssf.record.DateWindow1904Record;
import org.apache.poi.hssf.record.DrawingGroupRecord;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.EscherAggregate;
import org.apache.poi.hssf.record.ExtSSTRecord;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.ExternSheetRecord;
import org.apache.poi.hssf.record.FileSharingRecord;
import org.apache.poi.hssf.record.FnGroupCountRecord;
import org.apache.poi.hssf.record.FontRecord;
import org.apache.poi.hssf.record.FormatRecord;
import org.apache.poi.hssf.record.HideObjRecord;
import org.apache.poi.hssf.record.HyperlinkRecord;
import org.apache.poi.hssf.record.InterfaceEndRecord;
import org.apache.poi.hssf.record.InterfaceHdrRecord;
import org.apache.poi.hssf.record.MMSRecord;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.PaletteRecord;
import org.apache.poi.hssf.record.PasswordRecord;
import org.apache.poi.hssf.record.PasswordRev4Record;
import org.apache.poi.hssf.record.PrecisionRecord;
import org.apache.poi.hssf.record.ProtectRecord;
import org.apache.poi.hssf.record.ProtectionRev4Record;
import org.apache.poi.hssf.record.RecalcIdRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RefreshAllRecord;
import org.apache.poi.hssf.record.SSTRecord;
import org.apache.poi.hssf.record.StyleRecord;
import org.apache.poi.hssf.record.SupBookRecord;
import org.apache.poi.hssf.record.TabIdRecord;
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.record.UseSelFSRecord;
import org.apache.poi.hssf.record.WindowOneRecord;
import org.apache.poi.hssf.record.WindowProtectRecord;
import org.apache.poi.hssf.record.WriteAccessRecord;
import org.apache.poi.hssf.record.WriteProtectRecord;
import org.apache.poi.hssf.record.formula.NameXPtg; import org.apache.poi.hssf.record.formula.NameXPtg;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheet; import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheet;
@ -52,7 +105,6 @@ import org.apache.poi.util.POILogger;
* @author Dan Sherman (dsherman at isisph.com) * @author Dan Sherman (dsherman at isisph.com)
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook * @see org.apache.poi.hssf.usermodel.HSSFWorkbook
* @version 1.0-pre
*/ */
public final class Workbook implements Model { public final class Workbook implements Model {
/** /**
@ -61,18 +113,20 @@ public final class Workbook implements Model {
*/ */
private static final int MAX_SENSITIVE_SHEET_NAME_LEN = 31; private static final int MAX_SENSITIVE_SHEET_NAME_LEN = 31;
private static final int DEBUG = POILogger.DEBUG;
private static final POILogger log = POILogFactory.getLogger(Workbook.class);
private static final int DEBUG = POILogger.DEBUG;
/** /**
* constant used to set the "codepage" wherever "codepage" is set in records * constant used to set the "codepage" wherever "codepage" is set in records
* (which is duplicated in more than one record) * (which is duplicated in more than one record)
*/ */
private final static short CODEPAGE = ( short ) 0x4b0; private final static short CODEPAGE = 0x04B0;
/** /**
* this contains the Worksheet record objects * this contains the Worksheet record objects
*/ */
protected WorkbookRecordList records = new WorkbookRecordList(); private final WorkbookRecordList records = new WorkbookRecordList();
/** /**
* this contains a reference to the SSTRecord so that new stings can be added * this contains a reference to the SSTRecord so that new stings can be added
@ -87,25 +141,21 @@ public final class Workbook implements Model {
* holds the "boundsheet" records (aka bundlesheet) so that they can have their * holds the "boundsheet" records (aka bundlesheet) so that they can have their
* reference to their "BOF" marker * reference to their "BOF" marker
*/ */
protected ArrayList boundsheets = new ArrayList(); private final List<BoundSheetRecord> boundsheets = new ArrayList<BoundSheetRecord>();
private final List<FormatRecord> formats = new ArrayList<FormatRecord>();
protected ArrayList formats = new ArrayList(); private final List<HyperlinkRecord> hyperlinks = new ArrayList<HyperlinkRecord>();
protected ArrayList hyperlinks = new ArrayList();
protected int numxfs = 0; // hold the number of extended format records protected int numxfs = 0; // hold the number of extended format records
protected int numfonts = 0; // hold the number of font records protected int numfonts = 0; // hold the number of font records
private int maxformatid = -1; // holds the max format id private int maxformatid = -1; // holds the max format id
private boolean uses1904datewindowing = false; // whether 1904 date windowing is being used private boolean uses1904datewindowing = false; // whether 1904 date windowing is being used
private DrawingManager2 drawingManager; private DrawingManager2 drawingManager;
private List escherBSERecords = new ArrayList(); // EscherBSERecord private List<EscherBSERecord> escherBSERecords = new ArrayList<EscherBSERecord>();
private WindowOneRecord windowOne; private WindowOneRecord windowOne;
private FileSharingRecord fileShare; private FileSharingRecord fileShare;
private WriteAccessRecord writeAccess; private WriteAccessRecord writeAccess;
private WriteProtectRecord writeProtect; private WriteProtectRecord writeProtect;
private static POILogger log = POILogFactory.getLogger(Workbook.class);
/** /**
* Creates new Workbook with no intitialization --useless right now * Creates new Workbook with no intitialization --useless right now
* @see #createWorkbook(List) * @see #createWorkbook(List)
@ -125,17 +175,17 @@ public final class Workbook implements Model {
* @param recs an array of Record objects * @param recs an array of Record objects
* @return Workbook object * @return Workbook object
*/ */
public static Workbook createWorkbook(List recs) { public static Workbook createWorkbook(List<Record> recs) {
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "Workbook (readfile) created with reclen=", log.log(DEBUG, "Workbook (readfile) created with reclen=",
new Integer(recs.size())); new Integer(recs.size()));
Workbook retval = new Workbook(); Workbook retval = new Workbook();
ArrayList records = new ArrayList(recs.size() / 3); List<Record> records = new ArrayList<Record>(recs.size() / 3);
retval.records.setRecords(records); retval.records.setRecords(records);
int k; int k;
for (k = 0; k < recs.size(); k++) { for (k = 0; k < recs.size(); k++) {
Record rec = ( Record ) recs.get(k); Record rec = recs.get(k);
if (rec.getSid() == EOFRecord.sid) { if (rec.getSid() == EOFRecord.sid) {
records.add(rec); records.add(rec);
@ -148,7 +198,7 @@ public final class Workbook implements Model {
case BoundSheetRecord.sid : case BoundSheetRecord.sid :
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found boundsheet record at " + k); log.log(DEBUG, "found boundsheet record at " + k);
retval.boundsheets.add(rec); retval.boundsheets.add((BoundSheetRecord) rec);
retval.records.setBspos( k ); retval.records.setBspos( k );
break; break;
@ -202,7 +252,7 @@ public final class Workbook implements Model {
case FormatRecord.sid : case FormatRecord.sid :
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found format record at " + k); log.log(DEBUG, "found format record at " + k);
retval.formats.add(rec); retval.formats.add((FormatRecord) rec);
retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).getIndexCode() ? retval.maxformatid : ((FormatRecord)rec).getIndexCode(); retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).getIndexCode() ? retval.maxformatid : ((FormatRecord)rec).getIndexCode();
break; break;
case DateWindow1904Record.sid : case DateWindow1904Record.sid :
@ -247,16 +297,16 @@ public final class Workbook implements Model {
// Look for other interesting values that // Look for other interesting values that
// follow the EOFRecord // follow the EOFRecord
for ( ; k < recs.size(); k++) { for ( ; k < recs.size(); k++) {
Record rec = ( Record ) recs.get(k); Record rec = recs.get(k);
switch (rec.getSid()) { switch (rec.getSid()) {
case HyperlinkRecord.sid: case HyperlinkRecord.sid:
retval.hyperlinks.add(rec); retval.hyperlinks.add((HyperlinkRecord)rec);
break; break;
} }
} }
if (retval.windowOne == null) { if (retval.windowOne == null) {
retval.windowOne = (WindowOneRecord) retval.createWindowOne(); retval.windowOne = createWindowOne();
} }
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "exit create workbook from existing file function"); log.log(DEBUG, "exit create workbook from existing file function");
@ -272,82 +322,75 @@ public final class Workbook implements Model {
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log( DEBUG, "creating new workbook from scratch" ); log.log( DEBUG, "creating new workbook from scratch" );
Workbook retval = new Workbook(); Workbook retval = new Workbook();
ArrayList records = new ArrayList( 30 ); List<Record> records = new ArrayList<Record>( 30 );
retval.records.setRecords(records); retval.records.setRecords(records);
ArrayList formats = new ArrayList( 8 ); List<FormatRecord> formats = retval.formats;
records.add( retval.createBOF() ); records.add(retval.createBOF());
records.add( retval.createInterfaceHdr() ); records.add(retval.createInterfaceHdr());
records.add( retval.createMMS() ); records.add(retval.createMMS());
records.add( retval.createInterfaceEnd() ); records.add(retval.createInterfaceEnd());
records.add( retval.createWriteAccess() ); records.add(retval.createWriteAccess());
records.add( retval.createCodepage() ); records.add(retval.createCodepage());
records.add( retval.createDSF() ); records.add(retval.createDSF());
records.add( retval.createTabId() ); records.add(retval.createTabId());
retval.records.setTabpos( records.size() - 1 ); retval.records.setTabpos(records.size() - 1);
records.add( retval.createFnGroupCount() ); records.add(retval.createFnGroupCount());
records.add( retval.createWindowProtect() ); records.add(createWindowProtect());
records.add( retval.createProtect() ); records.add(createProtect());
retval.records.setProtpos( records.size() - 1 ); retval.records.setProtpos(records.size() - 1);
records.add( retval.createPassword() ); records.add(createPassword());
records.add( retval.createProtectionRev4() ); records.add(createProtectionRev4());
records.add( retval.createPasswordRev4() ); records.add(retval.createPasswordRev4());
retval.windowOne = (WindowOneRecord) retval.createWindowOne(); retval.windowOne = createWindowOne();
records.add( retval.windowOne ); records.add(retval.windowOne);
records.add( retval.createBackup() ); records.add(retval.createBackup());
retval.records.setBackuppos( records.size() - 1 ); retval.records.setBackuppos(records.size() - 1);
records.add( retval.createHideObj() ); records.add(retval.createHideObj());
records.add( retval.createDateWindow1904() ); records.add(retval.createDateWindow1904());
records.add( retval.createPrecision() ); records.add(retval.createPrecision());
records.add( retval.createRefreshAll() ); records.add(createRefreshAll());
records.add( retval.createBookBool() ); records.add(retval.createBookBool());
records.add( retval.createFont() ); records.add(retval.createFont());
records.add( retval.createFont() ); records.add(retval.createFont());
records.add( retval.createFont() ); records.add(retval.createFont());
records.add( retval.createFont() ); records.add(retval.createFont());
retval.records.setFontpos( records.size() - 1 ); // last font record postion retval.records.setFontpos( records.size() - 1 ); // last font record position
retval.numfonts = 4; retval.numfonts = 4;
// set up format records // set up format records
for ( int i = 0; i <= 7; i++ ) for (int i = 0; i <= 7; i++) {
{ FormatRecord rec = createFormat(i);
Record rec; retval.maxformatid = retval.maxformatid >= rec.getIndexCode() ? retval.maxformatid : rec.getIndexCode();
rec = retval.createFormat( i ); formats.add(rec);
retval.maxformatid = retval.maxformatid >= ( (FormatRecord) rec ).getIndexCode() ? retval.maxformatid : ( (FormatRecord) rec ).getIndexCode(); records.add(rec);
formats.add( rec );
records.add( rec );
} }
retval.formats = formats;
for ( int k = 0; k < 21; k++ ) for (int k = 0; k < 21; k++) {
{ records.add(retval.createExtendedFormat(k));
records.add( retval.createExtendedFormat( k ) );
retval.numxfs++; retval.numxfs++;
} }
retval.records.setXfpos( records.size() - 1 ); retval.records.setXfpos( records.size() - 1 );
for ( int k = 0; k < 6; k++ ) for (int k = 0; k < 6; k++) {
{ records.add(retval.createStyle(k));
records.add( retval.createStyle( k ) );
} }
records.add( retval.createUseSelFS() ); records.add(retval.createUseSelFS());
int nBoundSheets = 1; // now just do 1 int nBoundSheets = 1; // now just do 1
for ( int k = 0; k < nBoundSheets; k++ ) { for (int k = 0; k < nBoundSheets; k++) {
BoundSheetRecord bsr = retval.createBoundSheet(k); BoundSheetRecord bsr = createBoundSheet(k);
records.add(bsr); records.add(bsr);
retval.boundsheets.add(bsr); retval.boundsheets.add(bsr);
retval.records.setBspos(records.size() - 1); retval.records.setBspos(records.size() - 1);
} }
// retval.records.supbookpos = retval.records.bspos + 1;
// retval.records.namepos = retval.records.supbookpos + 2;
records.add( retval.createCountry() ); records.add( retval.createCountry() );
for ( int k = 0; k < nBoundSheets; k++ ) { for ( int k = 0; k < nBoundSheets; k++ ) {
retval.getOrCreateLinkTable().checkExternSheet(k); retval.getOrCreateLinkTable().checkExternSheet(k);
} }
retval.sst = (SSTRecord) retval.createSST(); retval.sst = new SSTRecord();
records.add( retval.sst ); records.add(retval.sst);
records.add( retval.createExtendedSST() ); records.add(retval.createExtendedSST());
records.add(EOFRecord.instance); records.add(EOFRecord.instance);
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
@ -434,7 +477,7 @@ public final class Workbook implements Model {
*/ */
public FontRecord createNewFont() { public FontRecord createNewFont() {
FontRecord rec = ( FontRecord ) createFont(); FontRecord rec = createFont();
records.add(records.getFontpos()+1, rec); records.add(records.getFontpos()+1, rec);
records.setFontpos( records.getFontpos() + 1 ); records.setFontpos( records.getFontpos() + 1 );
@ -480,7 +523,7 @@ public final class Workbook implements Model {
} }
private BoundSheetRecord getBoundSheetRec(int sheetIndex) { private BoundSheetRecord getBoundSheetRec(int sheetIndex) {
return ((BoundSheetRecord) boundsheets.get(sheetIndex)); return boundsheets.get(sheetIndex);
} }
/** /**
@ -502,7 +545,7 @@ public final class Workbook implements Model {
*/ */
public void setSheetName(int sheetnum, String sheetname) { public void setSheetName(int sheetnum, String sheetname) {
checkSheets(sheetnum); checkSheets(sheetnum);
BoundSheetRecord sheet = (BoundSheetRecord)boundsheets.get( sheetnum ); BoundSheetRecord sheet = boundsheets.get(sheetnum);
sheet.setSheetname(sheetname); sheet.setSheetname(sheetname);
} }
@ -874,7 +917,7 @@ public final class Workbook implements Model {
public void insertSST() { public void insertSST() {
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "creating new SST via insertSST!"); log.log(DEBUG, "creating new SST via insertSST!");
sst = ( SSTRecord ) createSST(); sst = new SSTRecord();
records.add(records.size() - 1, createExtendedSST()); records.add(records.size() - 1, createExtendedSST());
records.add(records.size() - 2, sst); records.add(records.size() - 2, sst);
} }
@ -986,49 +1029,26 @@ public final class Workbook implements Model {
return retval; return retval;
} }
/** private static BOFRecord createBOF() {
* creates the BOF record
* @see org.apache.poi.hssf.record.BOFRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a BOFRecord
*/
protected Record createBOF() {
BOFRecord retval = new BOFRecord(); BOFRecord retval = new BOFRecord();
retval.setVersion(( short ) 0x600); retval.setVersion(( short ) 0x600);
retval.setType(( short ) 5); retval.setType(BOFRecord.TYPE_WORKBOOK);
retval.setBuild(( short ) 0x10d3); retval.setBuild(( short ) 0x10d3);
// retval.setBuild((short)0x0dbb);
retval.setBuildYear(( short ) 1996); retval.setBuildYear(( short ) 1996);
retval.setHistoryBitMask(0x41); // was c1 before verify retval.setHistoryBitMask(0x41); // was c1 before verify
retval.setRequiredVersion(0x6); retval.setRequiredVersion(0x6);
return retval; return retval;
} }
/** private static InterfaceHdrRecord createInterfaceHdr() {
* creates the InterfaceHdr record
* @see org.apache.poi.hssf.record.InterfaceHdrRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a InterfaceHdrRecord
*/
protected Record createInterfaceHdr() {
InterfaceHdrRecord retval = new InterfaceHdrRecord(); InterfaceHdrRecord retval = new InterfaceHdrRecord();
retval.setCodepage(CODEPAGE); retval.setCodepage(CODEPAGE);
return retval; return retval;
} }
/** private static MMSRecord createMMS() {
* creates an MMS record
* @see org.apache.poi.hssf.record.MMSRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a MMSRecord
*/
protected Record createMMS() {
MMSRecord retval = new MMSRecord(); MMSRecord retval = new MMSRecord();
retval.setAddMenuCount(( byte ) 0); retval.setAddMenuCount(( byte ) 0);
@ -1036,33 +1056,19 @@ public final class Workbook implements Model {
return retval; return retval;
} }
/** private static InterfaceEndRecord createInterfaceEnd() {
* creates the InterfaceEnd record
* @see org.apache.poi.hssf.record.InterfaceEndRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a InterfaceEndRecord
*/
protected Record createInterfaceEnd() {
return new InterfaceEndRecord(); return new InterfaceEndRecord();
} }
/** /**
* creates the WriteAccess record containing the logged in user's name * creates the WriteAccess record containing the logged in user's name
* @see org.apache.poi.hssf.record.WriteAccessRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a WriteAccessRecord
*/ */
private static WriteAccessRecord createWriteAccess() {
protected Record createWriteAccess() {
WriteAccessRecord retval = new WriteAccessRecord(); WriteAccessRecord retval = new WriteAccessRecord();
try try {
{
retval.setUsername(System.getProperty("user.name")); retval.setUsername(System.getProperty("user.name"));
} } catch (AccessControlException e) {
catch (java.security.AccessControlException e)
{
// AccessControlException can occur in a restricted context // AccessControlException can occur in a restricted context
// (client applet/jws application or restricted security server) // (client applet/jws application or restricted security server)
retval.setUsername("POI"); retval.setUsername("POI");
@ -1070,37 +1076,19 @@ public final class Workbook implements Model {
return retval; return retval;
} }
/** private static CodepageRecord createCodepage() {
* creates the Codepage record containing the constant stored in CODEPAGE
* @see org.apache.poi.hssf.record.CodepageRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a CodepageRecord
*/
protected Record createCodepage() {
CodepageRecord retval = new CodepageRecord(); CodepageRecord retval = new CodepageRecord();
retval.setCodepage(CODEPAGE); retval.setCodepage(CODEPAGE);
return retval; return retval;
} }
/** private static DSFRecord createDSF() {
* creates the DSF record containing a 0 since HSSF can't even create Dual Stream Files
* @see org.apache.poi.hssf.record.DSFRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a DSFRecord
*/
protected Record createDSF() {
return new DSFRecord(false); // we don't even support double stream files return new DSFRecord(false); // we don't even support double stream files
} }
/** /**
* creates the TabId record containing an array of 0,1,2. This release of HSSF * creates the TabId record containing an array
* always has the default three sheets, no less, no more.
* @see org.apache.poi.hssf.record.TabIdRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a TabIdRecord
*/ */
private static TabIdRecord createTabId() { private static TabIdRecord createTabId() {
return new TabIdRecord(); return new TabIdRecord();
@ -1108,12 +1096,8 @@ public final class Workbook implements Model {
/** /**
* creates the FnGroupCount record containing the Magic number constant of 14. * creates the FnGroupCount record containing the Magic number constant of 14.
* @see org.apache.poi.hssf.record.FnGroupCountRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a FnGroupCountRecord
*/ */
private static FnGroupCountRecord createFnGroupCount() {
protected Record createFnGroupCount() {
FnGroupCountRecord retval = new FnGroupCountRecord(); FnGroupCountRecord retval = new FnGroupCountRecord();
retval.setCount(( short ) 14); retval.setCount(( short ) 14);
@ -1133,8 +1117,8 @@ public final class Workbook implements Model {
* @return a new Protect record with protect set to false. * @return a new Protect record with protect set to false.
*/ */
private static ProtectRecord createProtect() { private static ProtectRecord createProtect() {
// by default even when we support it we won't // by default even when we support it we won't
// want it to be protected // want it to be protected
return new ProtectRecord(false); return new ProtectRecord(false);
} }
@ -1170,12 +1154,8 @@ public final class Workbook implements Model {
* displayed tab - 0 <P> * displayed tab - 0 <P>
* num selected tab- 0 <P> * num selected tab- 0 <P>
* tab width ratio - 0x258 <P> * tab width ratio - 0x258 <P>
* @see org.apache.poi.hssf.record.WindowOneRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a WindowOneRecord
*/ */
private static WindowOneRecord createWindowOne() {
protected Record createWindowOne() {
WindowOneRecord retval = new WindowOneRecord(); WindowOneRecord retval = new WindowOneRecord();
retval.setHorizontalHold(( short ) 0x168); retval.setHorizontalHold(( short ) 0x168);
@ -1192,60 +1172,39 @@ public final class Workbook implements Model {
/** /**
* creates the Backup record with backup set to 0. (loose the data, who cares) * creates the Backup record with backup set to 0. (loose the data, who cares)
* @see org.apache.poi.hssf.record.BackupRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a BackupRecord
*/ */
private static BackupRecord createBackup() {
protected Record createBackup() {
BackupRecord retval = new BackupRecord(); BackupRecord retval = new BackupRecord();
retval.setBackup( retval.setBackup(( short ) 0); // by default DONT save backups of files...just loose data
( short ) 0); // by default DONT save backups of files...just loose data
return retval; return retval;
} }
/** /**
* creates the HideObj record with hide object set to 0. (don't hide) * creates the HideObj record with hide object set to 0. (don't hide)
* @see org.apache.poi.hssf.record.HideObjRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a HideObjRecord
*/ */
private static HideObjRecord createHideObj() {
protected Record createHideObj() {
HideObjRecord retval = new HideObjRecord(); HideObjRecord retval = new HideObjRecord();
retval.setHideObj(( short ) 0); // by default set hide object off retval.setHideObj(( short ) 0); // by default set hide object off
return retval; return retval;
} }
/** /**
* creates the DateWindow1904 record with windowing set to 0. (don't window) * creates the DateWindow1904 record with windowing set to 0. (don't window)
* @see org.apache.poi.hssf.record.DateWindow1904Record
* @see org.apache.poi.hssf.record.Record
* @return record containing a DateWindow1904Record
*/ */
private static DateWindow1904Record createDateWindow1904() {
protected Record createDateWindow1904() {
DateWindow1904Record retval = new DateWindow1904Record(); DateWindow1904Record retval = new DateWindow1904Record();
retval.setWindowing( retval.setWindowing(( short ) 0); // don't EVER use 1904 date windowing...tick tock..
( short ) 0); // don't EVER use 1904 date windowing...tick tock..
return retval; return retval;
} }
/** /**
* creates the Precision record with precision set to true. (full precision) * creates the Precision record with precision set to true. (full precision)
* @see org.apache.poi.hssf.record.PrecisionRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a PrecisionRecord
*/ */
private static PrecisionRecord createPrecision() {
protected Record createPrecision() {
PrecisionRecord retval = new PrecisionRecord(); PrecisionRecord retval = new PrecisionRecord();
retval.setFullPrecision(true); // always use real numbers in calculations!
retval.setFullPrecision(
true); // always use real numbers in calculations!
return retval; return retval;
} }
@ -1258,14 +1217,9 @@ public final class Workbook implements Model {
/** /**
* creates the BookBool record with saveLinkValues set to 0. (don't save link values) * creates the BookBool record with saveLinkValues set to 0. (don't save link values)
* @see org.apache.poi.hssf.record.BookBoolRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a BookBoolRecord
*/ */
private static BookBoolRecord createBookBool() {
protected Record createBookBool() {
BookBoolRecord retval = new BookBoolRecord(); BookBoolRecord retval = new BookBoolRecord();
retval.setSaveLinkValues(( short ) 0); retval.setSaveLinkValues(( short ) 0);
return retval; return retval;
} }
@ -1278,12 +1232,8 @@ public final class Workbook implements Model {
* bold weight = 0x190<P> * bold weight = 0x190<P>
* Font Name Length = 5 <P> * Font Name Length = 5 <P>
* Font Name = Arial <P> * Font Name = Arial <P>
*
* @see org.apache.poi.hssf.record.FontRecord
* @see org.apache.poi.hssf.record.Record
* @return record containing a FontRecord
*/ */
protected Record createFont() { private static FontRecord createFont() {
FontRecord retval = new FontRecord(); FontRecord retval = new FontRecord();
retval.setFontHeight(( short ) 0xc8); retval.setFontHeight(( short ) 0xc8);
@ -1298,12 +1248,9 @@ public final class Workbook implements Model {
* Creates a FormatRecord object * Creates a FormatRecord object
* @param id the number of the format record to create (meaning its position in * @param id the number of the format record to create (meaning its position in
* a file as M$ Excel would create it.) * a file as M$ Excel would create it.)
* @return record containing a FormatRecord
* @see org.apache.poi.hssf.record.FormatRecord
* @see org.apache.poi.hssf.record.Record
*/ */
private static FormatRecord createFormat(int id) { private static FormatRecord createFormat(int id) {
// we'll need multiple editions for // we'll need multiple editions for
// the different formats // the different formats
switch (id) { switch (id) {
@ -1323,13 +1270,8 @@ public final class Workbook implements Model {
* Creates an ExtendedFormatRecord object * Creates an ExtendedFormatRecord object
* @param id the number of the extended format record to create (meaning its position in * @param id the number of the extended format record to create (meaning its position in
* a file as MS Excel would create it.) * a file as MS Excel would create it.)
*
* @return record containing an ExtendedFormatRecord
* @see org.apache.poi.hssf.record.ExtendedFormatRecord
* @see org.apache.poi.hssf.record.Record
*/ */
private static ExtendedFormatRecord createExtendedFormat(int id) { // we'll need multiple editions
protected Record createExtendedFormat(int id) { // we'll need multiple editions
ExtendedFormatRecord retval = new ExtendedFormatRecord(); ExtendedFormatRecord retval = new ExtendedFormatRecord();
switch (id) { switch (id) {
@ -1656,8 +1598,7 @@ public final class Workbook implements Model {
* creates an default cell type ExtendedFormatRecord object. * creates an default cell type ExtendedFormatRecord object.
* @return ExtendedFormatRecord with intial defaults (cell-type) * @return ExtendedFormatRecord with intial defaults (cell-type)
*/ */
private static ExtendedFormatRecord createExtendedFormat() {
protected ExtendedFormatRecord createExtendedFormat() {
ExtendedFormatRecord retval = new ExtendedFormatRecord(); ExtendedFormatRecord retval = new ExtendedFormatRecord();
retval.setFontIndex(( short ) 0); retval.setFontIndex(( short ) 0);
@ -1680,11 +1621,8 @@ public final class Workbook implements Model {
* Creates a StyleRecord object * Creates a StyleRecord object
* @param id the number of the style record to create (meaning its position in * @param id the number of the style record to create (meaning its position in
* a file as MS Excel would create it. * a file as MS Excel would create it.
* @return record containing a StyleRecord
* @see org.apache.poi.hssf.record.StyleRecord
* @see org.apache.poi.hssf.record.Record
*/ */
protected Record createStyle(int id) { // we'll need multiple editions private static StyleRecord createStyle(int id) { // we'll need multiple editions
StyleRecord retval = new StyleRecord(); StyleRecord retval = new StyleRecord();
switch (id) { switch (id) {
@ -1730,11 +1668,8 @@ public final class Workbook implements Model {
/** /**
* Creates a palette record initialized to the default palette * Creates a palette record initialized to the default palette
* @return a PaletteRecord instance populated with the default colors
* @see org.apache.poi.hssf.record.PaletteRecord
*/ */
protected PaletteRecord createPalette() private static PaletteRecord createPalette() {
{
return new PaletteRecord(); return new PaletteRecord();
} }
@ -1760,12 +1695,8 @@ public final class Workbook implements Model {
/** /**
* Creates the Country record with the default country set to 1 * Creates the Country record with the default country set to 1
* and current country set to 7 in case of russian locale ("ru_RU") and 1 otherwise * and current country set to 7 in case of russian locale ("ru_RU") and 1 otherwise
* @return record containing a CountryRecord
* @see org.apache.poi.hssf.record.CountryRecord
* @see org.apache.poi.hssf.record.Record
*/ */
private static CountryRecord createCountry() {
protected Record createCountry() { // what a novel idea, create your own!
CountryRecord retval = new CountryRecord(); CountryRecord retval = new CountryRecord();
retval.setDefaultCountry(( short ) 1); retval.setDefaultCountry(( short ) 1);
@ -1781,30 +1712,13 @@ public final class Workbook implements Model {
return retval; return retval;
} }
/**
* Creates the SST record with no strings and the unique/num string set to 0
* @return record containing a SSTRecord
* @see org.apache.poi.hssf.record.SSTRecord
* @see org.apache.poi.hssf.record.Record
*/
protected Record createSST() {
return new SSTRecord();
}
/** /**
* Creates the ExtendedSST record with numstrings per bucket set to 0x8. HSSF * Creates the ExtendedSST record with numstrings per bucket set to 0x8. HSSF
* doesn't yet know what to do with this thing, but we create it with nothing in * doesn't yet know what to do with this thing, but we create it with nothing in
* it hardly just to make Excel happy and our sheets look like Excel's * it hardly just to make Excel happy and our sheets look like Excel's
*
* @return record containing an ExtSSTRecord
* @see org.apache.poi.hssf.record.ExtSSTRecord
* @see org.apache.poi.hssf.record.Record
*/ */
private static ExtSSTRecord createExtendedSST() {
protected Record createExtendedSST() {
ExtSSTRecord retval = new ExtSSTRecord(); ExtSSTRecord retval = new ExtSSTRecord();
retval.setNumStringsPerBucket(( short ) 0x8); retval.setNumStringsPerBucket(( short ) 0x8);
return retval; return retval;
} }
@ -1971,7 +1885,7 @@ public final class Workbook implements Model {
* Returns the list of FormatRecords in the workbook. * Returns the list of FormatRecords in the workbook.
* @return ArrayList of FormatRecords in the notebook * @return ArrayList of FormatRecords in the notebook
*/ */
public ArrayList getFormats() { public List getFormats() {
return formats; return formats;
} }
@ -2051,22 +1965,10 @@ public final class Workbook implements Model {
return hyperlinks; return hyperlinks;
} }
public List getRecords() public List<Record> getRecords() {
{
return records.getRecords(); return records.getRecords();
} }
// public void insertChartRecords( List chartRecords )
// {
// backuppos += chartRecords.size();
// fontpos += chartRecords.size();
// palettepos += chartRecords.size();
// bspos += chartRecords.size();
// xfpos += chartRecords.size();
//
// records.addAll(protpos, chartRecords);
// }
/** /**
* Whether date windowing is based on 1/2/1904 or 1/1/1900. * Whether date windowing is based on 1/2/1904 or 1/1/1900.
* Some versions of Excel (Mac) can save workbooks using 1904 date windowing. * Some versions of Excel (Mac) can save workbooks using 1904 date windowing.
@ -2107,11 +2009,11 @@ public final class Workbook implements Model {
public void findDrawingGroup() { public void findDrawingGroup() {
// Need to find a DrawingGroupRecord that // Need to find a DrawingGroupRecord that
// contains a EscherDggRecord // contains a EscherDggRecord
for(Iterator rit = records.iterator(); rit.hasNext();) { for(Iterator<Record> rit = records.iterator(); rit.hasNext();) {
Record r = (Record)rit.next(); Record r = rit.next();
if(r instanceof DrawingGroupRecord) { if(r instanceof DrawingGroupRecord) {
DrawingGroupRecord dg = (DrawingGroupRecord)r; DrawingGroupRecord dg = (DrawingGroupRecord)r;
dg.processChildRecords(); dg.processChildRecords();
EscherContainerRecord cr = EscherContainerRecord cr =
@ -2140,8 +2042,7 @@ public final class Workbook implements Model {
// If there is one, does it have a EscherDggRecord? // If there is one, does it have a EscherDggRecord?
if(dgLoc != -1) { if(dgLoc != -1) {
DrawingGroupRecord dg = DrawingGroupRecord dg = (DrawingGroupRecord)records.get(dgLoc);
(DrawingGroupRecord)records.get(dgLoc);
EscherDggRecord dgg = null; EscherDggRecord dgg = null;
for(Iterator it = dg.getEscherRecords().iterator(); it.hasNext();) { for(Iterator it = dg.getEscherRecords().iterator(); it.hasNext();) {
Object er = it.next(); Object er = it.next();
@ -2160,10 +2061,8 @@ public final class Workbook implements Model {
* Creates a primary drawing group record. If it already * Creates a primary drawing group record. If it already
* exists then it's modified. * exists then it's modified.
*/ */
public void createDrawingGroup() public void createDrawingGroup() {
{ if (drawingManager == null) {
if (drawingManager == null)
{
EscherContainerRecord dggContainer = new EscherContainerRecord(); EscherContainerRecord dggContainer = new EscherContainerRecord();
EscherDggRecord dgg = new EscherDggRecord(); EscherDggRecord dgg = new EscherDggRecord();
EscherOptRecord opt = new EscherOptRecord(); EscherOptRecord opt = new EscherOptRecord();
@ -2209,16 +2108,13 @@ public final class Workbook implements Model {
dggContainer.addChildRecord(splitMenuColors); dggContainer.addChildRecord(splitMenuColors);
int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid); int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
if (dgLoc == -1) if (dgLoc == -1) {
{
DrawingGroupRecord drawingGroup = new DrawingGroupRecord(); DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
drawingGroup.addEscherRecord(dggContainer); drawingGroup.addEscherRecord(dggContainer);
int loc = findFirstRecordLocBySid(CountryRecord.sid); int loc = findFirstRecordLocBySid(CountryRecord.sid);
getRecords().add(loc+1, drawingGroup); getRecords().add(loc+1, drawingGroup);
} } else {
else
{
DrawingGroupRecord drawingGroup = new DrawingGroupRecord(); DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
drawingGroup.addEscherRecord(dggContainer); drawingGroup.addEscherRecord(dggContainer);
getRecords().set(dgLoc, drawingGroup); getRecords().set(dgLoc, drawingGroup);
@ -2231,13 +2127,11 @@ public final class Workbook implements Model {
return windowOne; return windowOne;
} }
public EscherBSERecord getBSERecord(int pictureIndex) public EscherBSERecord getBSERecord(int pictureIndex) {
{ return escherBSERecords.get(pictureIndex-1);
return (EscherBSERecord)escherBSERecords.get(pictureIndex-1);
} }
public int addBSERecord(EscherBSERecord e) public int addBSERecord(EscherBSERecord e) {
{
createDrawingGroup(); createDrawingGroup();
// maybe we don't need that as an instance variable anymore // maybe we don't need that as an instance variable anymore
@ -2271,53 +2165,53 @@ public final class Workbook implements Model {
} }
public WriteProtectRecord getWriteProtect() { public WriteProtectRecord getWriteProtect() {
if (this.writeProtect == null) { if (writeProtect == null) {
this.writeProtect = new WriteProtectRecord(); writeProtect = new WriteProtectRecord();
int i = 0; int i = 0;
for (i = 0; for (i = 0;
i < records.size() && !(records.get(i) instanceof BOFRecord); i < records.size() && !(records.get(i) instanceof BOFRecord);
i++) { i++) {
} }
records.add(i+1,this.writeProtect); records.add(i+1, writeProtect);
} }
return this.writeProtect; return this.writeProtect;
} }
public WriteAccessRecord getWriteAccess() { public WriteAccessRecord getWriteAccess() {
if (this.writeAccess == null) { if (writeAccess == null) {
this.writeAccess = (WriteAccessRecord)createWriteAccess(); writeAccess = createWriteAccess();
int i = 0; int i = 0;
for (i = 0; for (i = 0;
i < records.size() && !(records.get(i) instanceof InterfaceEndRecord); i < records.size() && !(records.get(i) instanceof InterfaceEndRecord);
i++) { i++) {
} }
records.add(i+1,this.writeAccess); records.add(i+1, writeAccess);
} }
return this.writeAccess; return writeAccess;
} }
public FileSharingRecord getFileSharing() { public FileSharingRecord getFileSharing() {
if (this.fileShare == null) { if (fileShare == null) {
this.fileShare = new FileSharingRecord(); fileShare = new FileSharingRecord();
int i = 0; int i = 0;
for (i = 0; for (i = 0;
i < records.size() && !(records.get(i) instanceof WriteAccessRecord); i < records.size() && !(records.get(i) instanceof WriteAccessRecord);
i++) { i++) {
} }
records.add(i+1,this.fileShare); records.add(i+1, fileShare);
} }
return this.fileShare; return fileShare;
} }
/** /**
* is the workbook protected with a password (not encrypted)? * is the workbook protected with a password (not encrypted)?
*/ */
public boolean isWriteProtected() { public boolean isWriteProtected() {
if (this.fileShare == null) { if (fileShare == null) {
return false; return false;
} }
FileSharingRecord frec = getFileSharing(); FileSharingRecord frec = getFileSharing();
return (frec.getReadOnly() == 1); return frec.getReadOnly() == 1;
} }
/** /**

View File

@ -23,151 +23,130 @@ import java.util.List;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
public class WorkbookRecordList public final class WorkbookRecordList {
{ private List<Record> records = new ArrayList<Record>();
private List records = new ArrayList();
private int protpos = 0; // holds the position of the protect record. private int protpos = 0; // holds the position of the protect record.
private int bspos = 0; // holds the position of the last bound sheet. private int bspos = 0; // holds the position of the last bound sheet.
private int tabpos = 0; // holds the position of the tabid record private int tabpos = 0; // holds the position of the tabid record
private int fontpos = 0; // hold the position of the last font record private int fontpos = 0; // hold the position of the last font record
private int xfpos = 0; // hold the position of the last extended font record private int xfpos = 0; // hold the position of the last extended font record
private int backuppos = 0; // holds the position of the backup record. private int backuppos = 0; // holds the position of the backup record.
private int namepos = 0; // holds the position of last name record private int namepos = 0; // holds the position of last name record
private int supbookpos = 0; // holds the position of sup book private int supbookpos = 0; // holds the position of sup book
private int externsheetPos = 0;// holds the position of the extern sheet private int externsheetPos = 0;// holds the position of the extern sheet
private int palettepos = -1; // hold the position of the palette, if applicable private int palettepos = -1; // hold the position of the palette, if applicable
public void setRecords( List records ) public void setRecords(List<Record> records) {
{ this.records = records;
this.records = records; }
}
public int size() public int size() {
{ return records.size();
return records.size(); }
}
public Record get( int i ) public Record get(int i) {
{ return records.get(i);
return (Record) records.get(i); }
}
public void add( int pos, Record r ) public void add(int pos, Record r) {
{ records.add(pos, r);
records.add(pos, r); if (getProtpos() >= pos) setProtpos( protpos + 1 );
if (getProtpos() >= pos) setProtpos( protpos + 1 ); if (getBspos() >= pos) setBspos( bspos + 1 );
if (getBspos() >= pos) setBspos( bspos + 1 ); if (getTabpos() >= pos) setTabpos( tabpos + 1 );
if (getTabpos() >= pos) setTabpos( tabpos + 1 ); if (getFontpos() >= pos) setFontpos( fontpos + 1 );
if (getFontpos() >= pos) setFontpos( fontpos + 1 ); if (getXfpos() >= pos) setXfpos( xfpos + 1 );
if (getXfpos() >= pos) setXfpos( xfpos + 1 ); if (getBackuppos() >= pos) setBackuppos( backuppos + 1 );
if (getBackuppos() >= pos) setBackuppos( backuppos + 1 ); if (getNamepos() >= pos) setNamepos(namepos+1);
if (getNamepos() >= pos) setNamepos(namepos+1); if (getSupbookpos() >= pos) setSupbookpos(supbookpos+1);
if (getSupbookpos() >= pos) setSupbookpos(supbookpos+1); if ((getPalettepos() != -1) && (getPalettepos() >= pos)) setPalettepos( palettepos + 1 );
if ((getPalettepos() != -1) && (getPalettepos() >= pos)) setPalettepos( palettepos + 1 ); if (getExternsheetPos() >= pos) setExternsheetPos(getExternsheetPos() + 1);
if (getExternsheetPos() >= pos) setExternsheetPos(getExternsheetPos() + 1); }
}
public List getRecords() public List<Record> getRecords() {
{ return records;
return records; }
}
public Iterator iterator() public Iterator<Record> iterator() {
{ return records.iterator();
return records.iterator(); }
}
public void remove( Object record ) { public void remove( Object record ) {
int i = records.indexOf(record); int i = records.indexOf(record);
this.remove(i); this.remove(i);
} }
public void remove( int pos ) public void remove( int pos )
{ {
records.remove(pos); records.remove(pos);
if (getProtpos() >= pos) setProtpos( protpos - 1 ); if (getProtpos() >= pos) setProtpos( protpos - 1 );
if (getBspos() >= pos) setBspos( bspos - 1 ); if (getBspos() >= pos) setBspos( bspos - 1 );
if (getTabpos() >= pos) setTabpos( tabpos - 1 ); if (getTabpos() >= pos) setTabpos( tabpos - 1 );
if (getFontpos() >= pos) setFontpos( fontpos - 1 ); if (getFontpos() >= pos) setFontpos( fontpos - 1 );
if (getXfpos() >= pos) setXfpos( xfpos - 1 ); if (getXfpos() >= pos) setXfpos( xfpos - 1 );
if (getBackuppos() >= pos) setBackuppos( backuppos - 1 ); if (getBackuppos() >= pos) setBackuppos( backuppos - 1 );
if (getNamepos() >= pos) setNamepos(getNamepos()-1); if (getNamepos() >= pos) setNamepos(getNamepos()-1);
if (getSupbookpos() >= pos) setSupbookpos(getSupbookpos()-1); if (getSupbookpos() >= pos) setSupbookpos(getSupbookpos()-1);
if ((getPalettepos() != -1) && (getPalettepos() >= pos)) setPalettepos( palettepos - 1 ); if ((getPalettepos() != -1) && (getPalettepos() >= pos)) setPalettepos( palettepos - 1 );
if (getExternsheetPos() >= pos) setExternsheetPos( getExternsheetPos() -1); if (getExternsheetPos() >= pos) setExternsheetPos( getExternsheetPos() -1);
} }
public int getProtpos() public int getProtpos() {
{ return protpos;
return protpos; }
}
public void setProtpos( int protpos ) public void setProtpos(int protpos) {
{ this.protpos = protpos;
this.protpos = protpos; }
}
public int getBspos() public int getBspos() {
{ return bspos;
return bspos; }
}
public void setBspos( int bspos ) public void setBspos(int bspos) {
{ this.bspos = bspos;
this.bspos = bspos; }
}
public int getTabpos() public int getTabpos() {
{ return tabpos;
return tabpos; }
}
public void setTabpos( int tabpos ) public void setTabpos(int tabpos) {
{ this.tabpos = tabpos;
this.tabpos = tabpos; }
}
public int getFontpos() public int getFontpos() {
{ return fontpos;
return fontpos; }
}
public void setFontpos( int fontpos ) public void setFontpos(int fontpos) {
{ this.fontpos = fontpos;
this.fontpos = fontpos; }
}
public int getXfpos() public int getXfpos() {
{ return xfpos;
return xfpos; }
}
public void setXfpos( int xfpos ) public void setXfpos(int xfpos) {
{ this.xfpos = xfpos;
this.xfpos = xfpos; }
}
public int getBackuppos() public int getBackuppos() {
{ return backuppos;
return backuppos; }
}
public void setBackuppos( int backuppos ) public void setBackuppos(int backuppos) {
{ this.backuppos = backuppos;
this.backuppos = backuppos; }
}
public int getPalettepos() public int getPalettepos() {
{ return palettepos;
return palettepos; }
}
public void setPalettepos( int palettepos ) public void setPalettepos(int palettepos) {
{ this.palettepos = palettepos;
this.palettepos = palettepos; }
}
/** /**
@ -217,5 +196,4 @@ public class WorkbookRecordList
public void setExternsheetPos(int externsheetPos) { public void setExternsheetPos(int externsheetPos) {
this.externsheetPos = externsheetPos; this.externsheetPos = externsheetPos;
} }
} }