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.

ExControlAtom.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.hslf.record;
  16. import java.io.IOException;
  17. import java.io.OutputStream;
  18. import java.util.Map;
  19. import java.util.function.Supplier;
  20. import org.apache.poi.util.GenericRecordUtil;
  21. import org.apache.poi.util.LittleEndian;
  22. /**
  23. * An atom record that specifies an ActiveX control.
  24. *
  25. * @author Yegor Kozlov
  26. */
  27. public final class ExControlAtom extends RecordAtom {
  28. /**
  29. * Record header.
  30. */
  31. private byte[] _header;
  32. /**
  33. * slideId.
  34. */
  35. private int _id;
  36. /**
  37. * Constructs a brand new embedded object atom record.
  38. */
  39. protected ExControlAtom() {
  40. _header = new byte[8];
  41. LittleEndian.putShort(_header, 2, (short) getRecordType());
  42. LittleEndian.putInt(_header, 4, 4);
  43. }
  44. /**
  45. * Constructs the ExControlAtom record from its source data.
  46. *
  47. * @param source the source data as a byte array.
  48. * @param start the start offset into the byte array.
  49. * @param len the length of the slice in the byte array.
  50. */
  51. protected ExControlAtom(byte[] source, int start, int len) {
  52. // Get the header.
  53. _header = new byte[8];
  54. System.arraycopy(source, start, _header, 0, 8);
  55. _id = LittleEndian.getInt(source, start + 8);
  56. }
  57. /**
  58. * An integer that specifies which presentation slide is associated with the ActiveX control.
  59. * <p>
  60. * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record.
  61. * The value 0x00000000 specifies a null reference.
  62. * </p>
  63. *
  64. * @return an integer that specifies which presentation slide is associated with the ActiveX control
  65. */
  66. public int getSlideId() {
  67. return _id;
  68. }
  69. /**
  70. * Sets which presentation slide is associated with the ActiveX control.
  71. *
  72. * @param id an integer that specifies which presentation slide is associated with the ActiveX control
  73. * <p>
  74. * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record.
  75. * The value 0x00000000 specifies a null reference.
  76. * </p>
  77. */
  78. public void setSlideId(int id) {
  79. _id = id;
  80. }
  81. /**
  82. * Gets the record type.
  83. * @return the record type.
  84. */
  85. public long getRecordType() {
  86. return RecordTypes.ExControlAtom.typeID;
  87. }
  88. /**
  89. * Write the contents of the record back, so it can be written
  90. * to disk
  91. *
  92. * @param out the output stream to write to.
  93. * @throws java.io.IOException if an error occurs.
  94. */
  95. public void writeOut(OutputStream out) throws IOException {
  96. out.write(_header);
  97. byte[] data = new byte[4];
  98. LittleEndian.putInt(data, 0, _id);
  99. out.write(data);
  100. }
  101. @Override
  102. public Map<String, Supplier<?>> getGenericProperties() {
  103. return GenericRecordUtil.getGenericProperties("slideId", this::getSlideId);
  104. }
  105. }