You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FeatHdrRecord.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.record;
  16. import java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.poi.hssf.record.common.FtrHeader;
  19. import org.apache.poi.util.GenericRecordUtil;
  20. import org.apache.poi.util.LittleEndianOutput;
  21. /**
  22. * Title: FeatHdr (Feature Header) Record
  23. * <P>
  24. * This record specifies common information for Shared Features, and
  25. * specifies the beginning of a collection of records to define them.
  26. * The collection of data (Globals Substream ABNF, macro sheet substream
  27. * ABNF or worksheet substream ABNF) specifies Shared Feature data.
  28. */
  29. public final class FeatHdrRecord extends StandardRecord {
  30. /**
  31. * Specifies the enhanced protection type. Used to protect a
  32. * shared workbook by restricting access to some areas of it
  33. */
  34. public static final int SHAREDFEATURES_ISFPROTECTION = 0x02;
  35. /**
  36. * Specifies that formula errors should be ignored
  37. */
  38. public static final int SHAREDFEATURES_ISFFEC2 = 0x03;
  39. /**
  40. * Specifies the smart tag type. Recognises certain
  41. * types of entries (proper names, dates/times etc) and
  42. * flags them for action
  43. */
  44. public static final int SHAREDFEATURES_ISFFACTOID = 0x04;
  45. /**
  46. * Specifies the shared list type. Used for a table
  47. * within a sheet
  48. */
  49. public static final int SHAREDFEATURES_ISFLIST = 0x05;
  50. public static final short sid = 0x0867;
  51. private final FtrHeader futureHeader;
  52. // See SHAREDFEATURES
  53. private int isf_sharedFeatureType;
  54. // Should always be one
  55. private byte reserved;
  56. /**
  57. * 0x00000000 = rgbHdrData not present
  58. * 0xffffffff = rgbHdrData present
  59. */
  60. private long cbHdrData;
  61. /** We need a BOFRecord to make sense of this... */
  62. private byte[] rgbHdrData;
  63. public FeatHdrRecord() {
  64. futureHeader = new FtrHeader();
  65. futureHeader.setRecordType(sid);
  66. }
  67. public FeatHdrRecord(FeatHdrRecord other) {
  68. super(other);
  69. futureHeader = other.futureHeader.copy();
  70. isf_sharedFeatureType = other.isf_sharedFeatureType;
  71. reserved = other.reserved;
  72. cbHdrData = other.cbHdrData;
  73. rgbHdrData = (other.rgbHdrData == null) ? null : other.rgbHdrData.clone();
  74. }
  75. public FeatHdrRecord(RecordInputStream in) {
  76. futureHeader = new FtrHeader(in);
  77. isf_sharedFeatureType = in.readShort();
  78. reserved = in.readByte();
  79. cbHdrData = in.readInt();
  80. // Don't process this just yet, need the BOFRecord
  81. rgbHdrData = in.readRemainder();
  82. }
  83. public short getSid() {
  84. return sid;
  85. }
  86. public void serialize(LittleEndianOutput out) {
  87. futureHeader.serialize(out);
  88. out.writeShort(isf_sharedFeatureType);
  89. out.writeByte(reserved);
  90. out.writeInt((int)cbHdrData);
  91. out.write(rgbHdrData);
  92. }
  93. protected int getDataSize() {
  94. return 12 + 2+1+4+rgbHdrData.length;
  95. }
  96. @Override
  97. public FeatHdrRecord copy() {
  98. //HACK: do a "cheat" clone, see Record.java for more information
  99. return new FeatHdrRecord(this);
  100. }
  101. @Override
  102. public HSSFRecordTypes getGenericRecordType() {
  103. return HSSFRecordTypes.FEAT_HDR;
  104. }
  105. @Override
  106. public Map<String, Supplier<?>> getGenericProperties() {
  107. return GenericRecordUtil.getGenericProperties(
  108. "futureHeader", () -> futureHeader,
  109. "isf_sharedFeatureType", () -> isf_sharedFeatureType,
  110. "reserved", () -> reserved,
  111. "cbHdrData", () -> cbHdrData,
  112. "rgbHdrData", () -> rgbHdrData
  113. );
  114. }
  115. }