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.

ObjectProtectRecord.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.GenericRecordUtil;
  19. import org.apache.poi.util.LittleEndianOutput;
  20. /**
  21. * Protect embedded object with the lamest "security" ever invented.
  22. * This record tells "I want to protect my objects" with lame security.
  23. * It appears in conjunction with the PASSWORD and PROTECT records as well as its scenario protect cousin.
  24. */
  25. public final class ObjectProtectRecord extends StandardRecord {
  26. public static final short sid = 0x63;
  27. private short field_1_protect;
  28. public ObjectProtectRecord() {}
  29. public ObjectProtectRecord(ObjectProtectRecord other) {
  30. super(other);
  31. field_1_protect = other.field_1_protect;
  32. }
  33. public ObjectProtectRecord(RecordInputStream in) {
  34. field_1_protect = in.readShort();
  35. }
  36. /**
  37. * set whether the sheet is protected or not
  38. * @param protect whether to protect the sheet or not
  39. */
  40. public void setProtect(boolean protect)
  41. {
  42. field_1_protect = (short) (protect ? 1 : 0);
  43. }
  44. /**
  45. * get whether the sheet is protected or not
  46. * @return whether to protect the sheet or not
  47. */
  48. public boolean getProtect()
  49. {
  50. return (field_1_protect == 1);
  51. }
  52. public void serialize(LittleEndianOutput out) {
  53. out.writeShort(field_1_protect);
  54. }
  55. protected int getDataSize() {
  56. return 2;
  57. }
  58. public short getSid()
  59. {
  60. return sid;
  61. }
  62. @Override
  63. public ObjectProtectRecord copy() {
  64. return new ObjectProtectRecord(this);
  65. }
  66. @Override
  67. public HSSFRecordTypes getGenericRecordType() {
  68. return HSSFRecordTypes.OBJECT_PROTECT;
  69. }
  70. @Override
  71. public Map<String, Supplier<?>> getGenericProperties() {
  72. return GenericRecordUtil.getGenericProperties("protect", this::getProtect);
  73. }
  74. }