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.

ProtectionRev4Record.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.util.BitField;
  19. import org.apache.poi.util.BitFieldFactory;
  20. import org.apache.poi.util.GenericRecordUtil;
  21. import org.apache.poi.util.LittleEndianOutput;
  22. /**
  23. * Describes whether this is a protected shared/tracked workbook<p>
  24. */
  25. public final class ProtectionRev4Record extends StandardRecord {
  26. public static final short sid = 0x01AF;
  27. private static final BitField protectedFlag = BitFieldFactory.getInstance(0x0001);
  28. private int _options;
  29. private ProtectionRev4Record(int options) {
  30. _options = options;
  31. }
  32. private ProtectionRev4Record(ProtectionRev4Record other) {
  33. super(other);
  34. _options = other._options;
  35. }
  36. public ProtectionRev4Record(boolean protect) {
  37. this(0);
  38. setProtect(protect);
  39. }
  40. public ProtectionRev4Record(RecordInputStream in) {
  41. this(in.readUShort());
  42. }
  43. /**
  44. * set whether the this is protected shared/tracked workbook or not
  45. * @param protect whether to protect the workbook or not
  46. */
  47. public void setProtect(boolean protect) {
  48. _options = protectedFlag.setBoolean(_options, protect);
  49. }
  50. /**
  51. * get whether the this is protected shared/tracked workbook or not
  52. * @return whether to protect the workbook or not
  53. */
  54. public boolean getProtect() {
  55. return protectedFlag.isSet(_options);
  56. }
  57. public void serialize(LittleEndianOutput out) {
  58. out.writeShort(_options);
  59. }
  60. protected int getDataSize() {
  61. return 2;
  62. }
  63. public short getSid() {
  64. return sid;
  65. }
  66. @Override
  67. public ProtectionRev4Record copy() {
  68. return new ProtectionRev4Record(this);
  69. }
  70. @Override
  71. public HSSFRecordTypes getGenericRecordType() {
  72. return HSSFRecordTypes.PROTECTION_REV_4;
  73. }
  74. @Override
  75. public Map<String, Supplier<?>> getGenericProperties() {
  76. return GenericRecordUtil.getGenericProperties(
  77. "options", () -> _options,
  78. "protect", this::getProtect
  79. );
  80. }
  81. }