View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2006 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-Excel.
6   //
7   // MillScript-Excel is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-Excel is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-Excel; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.office.excel.records.syntax;
22  
23  import org.millscript.commons.alert.reporters.StandardWarningAlertReporter;
24  import org.millscript.office.excel.RecordSyntax;
25  import org.millscript.office.excel.RecordTokenizer;
26  import org.millscript.office.excel.alerts.BIFFAlert;
27  import org.millscript.office.excel.records.Array;
28  import org.millscript.office.excel.versions.BIFF2;
29  import org.millscript.office.excel.versions.BIFF3;
30  import org.millscript.office.excel.versions.BIFF4S;
31  import org.millscript.office.excel.versions.BIFF4W;
32  import org.millscript.office.excel.versions.BIFF5;
33  import org.millscript.office.excel.versions.BIFF7;
34  import org.millscript.office.excel.versions.BIFF8;
35  import org.millscript.office.excel.versions.BIFF8X;
36  import org.millscript.office.excel.versions.BIFFVersion;
37  
38  /**
39   * 
40   */
41  public class ArrayRecordSyntax extends RecordSyntax implements BIFF2, BIFF3, BIFF4S, BIFF4W, BIFF5, BIFF7, BIFF8, BIFF8X {
42  
43      /**
44       * @see org.millscript.office.excel.RecordSyntax#newRecord(RecordTokenizer)
45       */
46      @Override
47      public Array newRecord( final RecordTokenizer tokenizer ) {
48          final Array array = new Array();
49          // In this record the cell range address is always stored in the
50          // pre-BIFF8 layout
51          array.setCellRangeAddress(
52              tokenizer.readCellRangeAddressPreBIFF8()
53          );
54          // Set the options
55          if ( tokenizer.getBiffVersion() == BIFFVersion.BIFF2 ) {
56              final byte options = tokenizer.readByte();
57              switch ( options ) {
58                  case 0:
59                      array.setAlwaysRecalculate( false );
60                  case 1:
61                      array.setAlwaysRecalculate( true );
62                  default:
63                      // TODO - This should support an application level reporting
64                      // mechanism as soon as it is available via the Alert library
65                      StandardWarningAlertReporter.WARNING_REPORTER.report(
66                          new BIFFAlert(
67                              "Unknown option flag for ARRAY record"
68                          ).culprit( "option flag", options )
69                      );
70              }
71          } else {
72              final int options = tokenizer.readUnsigned2Byte();
73              if ( ( options & 0x0001 ) == 1 ) {
74                  array.setAlwaysRecalculate( true );
75              } else if ( ( options & 0x0002 ) == 1 ) {
76                  array.setAlwaysRecalculate( false );
77              } else {
78                  // TODO - This should support an application level reporting
79                  // mechanism as soon as it is available via the Alert library
80                  StandardWarningAlertReporter.WARNING_REPORTER.report(
81                      new BIFFAlert(
82                          "Unknown option flag for ARRAY record"
83                      ).culprit( "option flag", options )
84                  );
85              }
86          }
87          // Get the formula action
88          array.setFormulaExpr(
89              tokenizer.readFormula(
90                  tokenizer.getBytesLeftInCurrentRecordData()
91              )
92          );
93          return array;
94      }
95  
96  }