Example #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()));
    }
  }
  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);
    }
  }
Example #3
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();
    }
  }
    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;
    }
  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());
    }
  }
Example #6
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) + ")");
    }
  }
  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()));
    }
  }