Exemplo n.º 1
0
  /** @param in the RecordInputstream to read the record from */
  public LabelRecord(RecordInputStream in) {
    field_1_row = in.readUShort();
    field_2_column = in.readShort();
    field_3_xf_index = in.readShort();
    field_4_string_len = in.readShort();
    field_5_unicode_flag = in.readByte();
    if (field_4_string_len > 0) {
      if (isUnCompressedUnicode()) {
        field_6_value = in.readUnicodeLEString(field_4_string_len);
      } else {
        field_6_value = in.readCompressedUnicode(field_4_string_len);
      }
    } else {
      field_6_value = "";
    }

    if (in.remaining() > 0) {
      logger.log(
          POILogger.INFO,
          "LabelRecord data remains: "
              + in.remaining()
              + " : "
              + HexDump.toHex(in.readRemainder()));
    }
  }
Exemplo n.º 2
0
 public ArrayRecord(RecordInputStream in) {
   super(in);
   _options = in.readUShort();
   _field3notUsed = in.readInt();
   int formulaTokenLen = in.readUShort();
   int totalFormulaLen = in.available();
   _formula = Formula.read(formulaTokenLen, in, totalFormulaLen);
 }
 private static String readRawString(RecordInputStream in, int textLength) {
   byte compressByte = in.readByte();
   boolean isCompressed = (compressByte & 0x01) == 0;
   if (isCompressed) {
     return in.readCompressedUnicode(textLength);
   }
   return in.readUnicodeLEString(textLength);
 }
Exemplo n.º 4
0
 /**
  * construct an unknown record. No fields are interpreted and the record will be serialized in its
  * original form more or less
  *
  * @param in the RecordInputstream to read the record from
  */
 public UnknownRecord(RecordInputStream in) {
   _sid = in.getSid();
   _rawData = in.readRemainder();
   if (false && getBiffName(_sid) == null) {
     // unknown sids in the range 0x0004-0x0013 are probably 'sub-records' of ObjectRecord
     // those sids are in a different number space.
     // TODO - put unknown OBJ sub-records in a different class
     System.out.println("Unknown record 0x" + Integer.toHexString(_sid).toUpperCase());
   }
 }
Exemplo n.º 5
0
  /** @param in the RecordInputstream to read the record from */
  public StringRecord(RecordInputStream in) {
    int field_1_string_length = in.readUShort();
    _is16bitUnicode = in.readByte() != 0x00;

    if (_is16bitUnicode) {
      _text = in.readUnicodeLEString(field_1_string_length);
    } else {
      _text = in.readCompressedUnicode(field_1_string_length);
    }
  }
 private static void processFontRuns(
     RecordInputStream in, HSSFRichTextString str, int formattingRunDataLength) {
   if (formattingRunDataLength % FORMAT_RUN_ENCODED_SIZE != 0) {
     throw new RecordFormatException(
         "Bad format run data length " + formattingRunDataLength + ")");
   }
   int nRuns = formattingRunDataLength / FORMAT_RUN_ENCODED_SIZE;
   for (int i = 0; i < nRuns; i++) {
     short index = in.readShort();
     short iFont = in.readShort();
     in.readInt(); // skip reserved.
     str.applyFont(index, str.length(), iFont);
   }
 }
Exemplo n.º 7
0
  public static Record createSingleRecord(RecordInputStream in) {
    I_RecordCreator constructor = _recordCreatorsById.get(Integer.valueOf(in.getSid()));

    if (constructor == null) {
      return new UnknownRecord(in);
    }

    return constructor.create(in);
  }
Exemplo n.º 8
0
  public BOFRecord(RecordInputStream in) {
    field_1_version = in.readShort();
    field_2_type = in.readShort();

    // Some external tools don't generate all of
    //  the remaining fields
    if (in.remaining() >= 2) {
      field_3_build = in.readShort();
    }
    if (in.remaining() >= 2) {
      field_4_year = in.readShort();
    }
    if (in.remaining() >= 4) {
      field_5_history = in.readInt();
    }
    if (in.remaining() >= 4) {
      field_6_rversion = in.readInt();
    }
  }
Exemplo n.º 9
0
  public ExternSheetRecord(RecordInputStream in) {
    _list = new ArrayList<RefSubRecord>();

    int nItems = in.readShort();

    for (int i = 0; i < nItems; ++i) {
      RefSubRecord rec = new RefSubRecord(in);
      _list.add(rec);
    }
  }
Exemplo n.º 10
0
  /**
   * called by the constructor, should set class level fields. Should throw runtime exception for
   * bad/incomplete data.
   *
   * @param in the stream to read from
   */
  public SupBookRecord(RecordInputStream in) {
    int recLen = in.remaining();

    field_1_number_of_sheets = in.readShort();

    if (recLen > SMALL_RECORD_SIZE) {
      // 5.38.1 External References
      _isAddInFunctions = false;

      field_2_encoded_url = in.readString();
      String[] sheetNames = new String[field_1_number_of_sheets];
      for (int i = 0; i < sheetNames.length; i++) {
        sheetNames[i] = in.readString();
      }
      field_3_sheet_names = sheetNames;
      return;
    }
    // else not 'External References'
    field_2_encoded_url = null;
    field_3_sheet_names = null;

    short nextShort = in.readShort();
    if (nextShort == TAG_INTERNAL_REFERENCES) {
      // 5.38.2 'Internal References'
      _isAddInFunctions = false;
    } else if (nextShort == TAG_ADD_IN_FUNCTIONS) {
      // 5.38.3 'Add-In Functions'
      _isAddInFunctions = true;
      if (field_1_number_of_sheets != 1) {
        throw new RuntimeException(
            "Expected 0x0001 for number of sheets field in 'Add-In Functions' but got ("
                + field_1_number_of_sheets
                + ")");
      }
    } else {
      throw new RuntimeException(
          "invalid EXTERNALBOOK code (" + Integer.toHexString(nextShort) + ")");
    }
  }
Exemplo n.º 11
0
 public SeriesRecord(RecordInputStream in) {
   field_1_categoryDataType = in.readShort();
   field_2_valuesDataType = in.readShort();
   field_3_numCategories = in.readShort();
   field_4_numValues = in.readShort();
   field_5_bubbleSeriesType = in.readShort();
   field_6_numBubbleValues = in.readShort();
 }
Exemplo n.º 12
0
  /** Returns the next (complete) record from the stream, or null if there are no more. */
  public Record nextRecord() {
    Record r;
    r = getNextUnreadRecord();
    if (r != null) {
      // found an unread record
      return r;
    }
    while (true) {
      if (!_recStream.hasNextRecord()) {
        // recStream is exhausted;
        return null;
      }

      if (_lastRecordWasEOFLevelZero) {
        // Potential place for ending the workbook stream
        // Check that the next record is not BOFRecord(0x0809)
        // Normally the input stream contains only zero padding after the last EOFRecord,
        // but bug 46987 and 48068 suggests that the padding may be garbage.
        // This code relies on the padding bytes not starting with BOFRecord.sid
        if (_recStream.getNextSid() != BOFRecord.sid) {
          return null;
        }
        // else - another sheet substream starting here
      }

      // step underlying RecordInputStream to the next record
      _recStream.nextRecord();

      r = readNextRecord();
      if (r == null) {
        // some record types may get skipped (e.g. DBCellRecord and ContinueRecord)
        continue;
      }
      return r;
    }
  }
Exemplo n.º 13
0
    public StreamEncryptionInfo(RecordInputStream rs, List<Record> outputRecs) {
      Record rec;
      rs.nextRecord();
      int recSize = 4 + rs.remaining();
      rec = RecordFactory.createSingleRecord(rs);
      outputRecs.add(rec);
      FilePassRecord fpr = null;
      if (rec instanceof BOFRecord) {
        _hasBOFRecord = true;

        // Fetch the next record, and see if it indicates whether
        //  the document is encrypted or not
        if (rs.hasNextRecord()) {
          rs.nextRecord();
          rec = RecordFactory.createSingleRecord(rs);
          recSize += rec.getRecordSize();
          outputRecs.add(rec);

          // Encrypted is normally BOF then FILEPASS
          // May sometimes be BOF, WRITEPROTECT, FILEPASS
          if (rec instanceof WriteProtectRecord && rs.hasNextRecord()) {
            rs.nextRecord();
            rec = RecordFactory.createSingleRecord(rs);
            recSize += rec.getRecordSize();
            outputRecs.add(rec);
          }

          // If it's a FILEPASS, track it specifically but
          //  don't include it in the main stream
          if (rec instanceof FilePassRecord) {
            fpr = (FilePassRecord) rec;
            outputRecs.remove(outputRecs.size() - 1);
            // TODO - add fpr not added to outputRecs
            rec = outputRecs.get(0);
          } else {
            // workbook not encrypted (typical case)
            if (rec instanceof EOFRecord) {
              // A workbook stream is never empty, so crash instead
              // of trying to keep track of nesting level
              throw new IllegalStateException("Nothing between BOF and EOF");
            }
          }
        }
      } else {
        // Invalid in a normal workbook stream.
        // However, some test cases work on sub-sections of
        // the workbook stream that do not begin with BOF
        _hasBOFRecord = false;
      }
      _initialRecordsSize = recSize;
      _filePassRec = fpr;
      _lastRecord = rec;
    }
Exemplo n.º 14
0
  public IndexRecord(RecordInputStream in) {
    int field_1_zero = in.readInt();
    if (field_1_zero != 0) {
      throw new RecordFormatException("Expected zero for field 1 but got " + field_1_zero);
    }
    field_2_first_row = in.readInt();
    field_3_last_row_add1 = in.readInt();
    field_4_zero = in.readInt();

    int nCells = in.remaining() / 4;
    field_5_dbcells = new IntList(nCells);
    for (int i = 0; i < nCells; i++) {
      field_5_dbcells.add(in.readInt());
    }
  }
Exemplo n.º 15
0
  public HyperlinkRecord(RecordInputStream in) {
    _range = new CellRangeAddress(in);

    _guid = new GUID(in);

    /**
     * streamVersion (4 bytes): An unsigned integer that specifies the version number of the
     * serialization implementation used to save this structure. This value MUST equal 2.
     */
    int streamVersion = in.readInt();
    if (streamVersion != 0x00000002) {
      throw new RecordFormatException("Stream Version must be 0x2 but found " + streamVersion);
    }
    _linkOpts = in.readInt();

    if ((_linkOpts & HLINK_LABEL) != 0) {
      int label_len = in.readInt();
      _label = in.readUnicodeLEString(label_len);
    }

    if ((_linkOpts & HLINK_TARGET_FRAME) != 0) {
      int len = in.readInt();
      _targetFrame = in.readUnicodeLEString(len);
    }

    if ((_linkOpts & HLINK_URL) != 0 && (_linkOpts & HLINK_UNC_PATH) != 0) {
      _moniker = null;
      int nChars = in.readInt();
      _address = in.readUnicodeLEString(nChars);
    }

    if ((_linkOpts & HLINK_URL) != 0 && (_linkOpts & HLINK_UNC_PATH) == 0) {
      _moniker = new GUID(in);

      if (URL_MONIKER.equals(_moniker)) {
        int length = in.readInt();
        /**
         * The value of <code>length<code> be either the byte size of the url field
         * (including the terminating NULL character) or the byte size of the url field plus 24.
         * If the value of this field is set to the byte size of the url field,
         * then the tail bytes fields are not present.
         */
        int remaining = in.remaining();
        if (length == remaining) {
          int nChars = length / 2;
          _address = in.readUnicodeLEString(nChars);
        } else {
          int nChars = (length - TAIL_SIZE) / 2;
          _address = in.readUnicodeLEString(nChars);
          /**
           * TODO: make sense of the remaining bytes According to the spec they consist of: 1.
           * 16-byte GUID: This field MUST equal {0xF4815879, 0x1D3B, 0x487F, 0xAF, 0x2C, 0x82,
           * 0x5D, 0xC4, 0x85, 0x27, 0x63} 2. Serial version, this field MUST equal 0 if present. 3.
           * URI Flags
           */
          _uninterpretedTail = readTail(URL_TAIL, in);
        }
      } else if (FILE_MONIKER.equals(_moniker)) {
        _fileOpts = in.readShort();

        int len = in.readInt();
        _shortFilename = StringUtil.readCompressedUnicode(in, len);
        _uninterpretedTail = readTail(FILE_TAIL, in);
        int size = in.readInt();
        if (size > 0) {
          int charDataSize = in.readInt();

          // From the spec: An optional unsigned integer that MUST be 3 if present
          // but some files has 4
          int usKeyValue = in.readUShort();

          _address = StringUtil.readUnicodeLE(in, charDataSize / 2);
        } else {
          _address = null;
        }
      } else if (STD_MONIKER.equals(_moniker)) {
        _fileOpts = in.readShort();

        int len = in.readInt();

        byte[] path_bytes = new byte[len];
        in.readFully(path_bytes);

        _address = new String(path_bytes);
      }
    }

    if ((_linkOpts & HLINK_PLACE) != 0) {

      int len = in.readInt();
      _textMark = in.readUnicodeLEString(len);
    }

    if (in.remaining() > 0) {
      logger.log(
          POILogger.WARN,
          "Hyperlink data remains: " + in.remaining() + " : " + HexDump.toHex(in.readRemainder()));
    }
  }
  public TextObjectRecord(RecordInputStream in) {
    field_1_options = in.readUShort();
    field_2_textOrientation = in.readUShort();
    field_3_reserved4 = in.readUShort();
    field_4_reserved5 = in.readUShort();
    field_5_reserved6 = in.readUShort();
    int field_6_textLength = in.readUShort();
    int field_7_formattingDataLength = in.readUShort();
    field_8_reserved7 = in.readInt();

    if (in.remaining() > 0) {
      // Text Objects can have simple reference formulas
      // (This bit not mentioned in the MS document)
      if (in.remaining() < 11) {
        throw new RecordFormatException("Not enough remaining data for a link formula");
      }
      int formulaSize = in.readUShort();
      _unknownPreFormulaInt = in.readInt();
      Ptg[] ptgs = Ptg.readTokens(formulaSize, in);
      if (ptgs.length != 1) {
        throw new RecordFormatException("Read " + ptgs.length + " tokens but expected exactly 1");
      }
      _linkRefPtg = (OperandPtg) ptgs[0];
      if (in.remaining() > 0) {
        _unknownPostFormulaByte = Byte.valueOf(in.readByte());
      } else {
        _unknownPostFormulaByte = null;
      }
    } else {
      _linkRefPtg = null;
    }
    if (in.remaining() > 0) {
      throw new RecordFormatException("Unused " + in.remaining() + " bytes at end of record");
    }

    String text;
    if (field_6_textLength > 0) {
      text = readRawString(in, field_6_textLength);
    } else {
      text = "";
    }
    _text = new HSSFRichTextString(text);

    if (field_7_formattingDataLength > 0) {
      processFontRuns(in, _text, field_7_formattingDataLength);
    }
  }
Exemplo n.º 17
0
 public UncalcedRecord(RecordInputStream in) { // NO_UCD
   in.readShort(); // unused
 }
Exemplo n.º 18
0
 public BackupRecord(RecordInputStream in) {
   field_1_backup = in.readShort();
 }
 public DefaultColWidthRecord(RecordInputStream in) {
   field_1_col_width = in.readUShort();
 }
Exemplo n.º 20
0
 public BookBoolRecord(RecordInputStream in) {
   field_1_save_link_values = in.readShort();
 }
Exemplo n.º 21
0
 /** @param in the RecordInputstream to read the record from */
 public RefSubRecord(RecordInputStream in) {
   this(in.readShort(), in.readShort(), in.readShort());
 }