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.

RefreshAllRecord.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * Flag whether to refresh all external data when loading a sheet.
  24. * (which hssf doesn't support anyhow so who really cares?)
  25. */
  26. public final class RefreshAllRecord extends StandardRecord {
  27. public static final short sid = 0x01B7;
  28. private static final BitField refreshFlag = BitFieldFactory.getInstance(0x0001);
  29. private int _options;
  30. private RefreshAllRecord(int options) {
  31. _options = options;
  32. }
  33. private RefreshAllRecord(RefreshAllRecord other) {
  34. super(other);
  35. _options = other._options;
  36. }
  37. public RefreshAllRecord(RecordInputStream in) {
  38. this(in.readUShort());
  39. }
  40. public RefreshAllRecord(boolean refreshAll) {
  41. this(0);
  42. setRefreshAll(refreshAll);
  43. }
  44. /**
  45. * set whether to refresh all external data when loading a sheet
  46. * @param refreshAll or not
  47. */
  48. public void setRefreshAll(boolean refreshAll) {
  49. _options = refreshFlag.setBoolean(_options, refreshAll);
  50. }
  51. /**
  52. * get whether to refresh all external data when loading a sheet
  53. * @return refreshall or not
  54. */
  55. public boolean getRefreshAll() {
  56. return refreshFlag.isSet(_options);
  57. }
  58. public void serialize(LittleEndianOutput out) {
  59. out.writeShort(_options);
  60. }
  61. protected int getDataSize() {
  62. return 2;
  63. }
  64. public short getSid() {
  65. return sid;
  66. }
  67. @Override
  68. public RefreshAllRecord copy() {
  69. return new RefreshAllRecord(this);
  70. }
  71. @Override
  72. public HSSFRecordTypes getGenericRecordType() {
  73. return HSSFRecordTypes.REFRESH_ALL;
  74. }
  75. @Override
  76. public Map<String, Supplier<?>> getGenericProperties() {
  77. return GenericRecordUtil.getGenericProperties(
  78. "options", () -> _options,
  79. "refreshAll", this::getRefreshAll
  80. );
  81. }
  82. }