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.

FFData.java 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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.hwpf.model;
  16. import static org.apache.poi.hwpf.model.types.FFDataBaseAbstractType.ITYPE_CHCK;
  17. import static org.apache.poi.hwpf.model.types.FFDataBaseAbstractType.ITYPE_DROP;
  18. import static org.apache.poi.hwpf.model.types.FFDataBaseAbstractType.ITYPE_TEXT;
  19. import org.apache.poi.hwpf.model.types.FFDataBaseAbstractType;
  20. import org.apache.poi.util.Internal;
  21. import org.apache.poi.util.LittleEndian;
  22. import org.apache.poi.util.LittleEndianConsts;
  23. /**
  24. * The FFData structure specifies form field data for a text box, check box, or
  25. * drop-down list box.
  26. * <p>
  27. * Class and fields descriptions are quoted from [MS-DOC] -- v20121003 Word
  28. * (.doc) Binary File Format; Copyright (c) 2012 Microsoft Corporation; Release:
  29. * October 8, 2012
  30. * <p>
  31. * This class is internal. It content or properties may change without notice
  32. * due to changes in our knowledge of internal Microsoft Word binary structures.
  33. *
  34. * @author Sergey Vladimirov; according to [MS-DOC] -- v20121003 Word (.doc)
  35. * Binary File Format; Copyright (c) 2012 Microsoft Corporation;
  36. * Release: October 8, 2012
  37. */
  38. @Internal
  39. public class FFData
  40. {
  41. private FFDataBase _base;
  42. /**
  43. * An optional STTB that specifies the entries in the dropdown list box.
  44. * This MUST exist if and only if bits.iType is iTypeDrop (2). The entries
  45. * are Unicode strings and do not have extra data. This MUST NOT exceed 25
  46. * elements.
  47. */
  48. private Sttb _hsttbDropList;
  49. /**
  50. * An optional unsigned integer that specifies the default state of the
  51. * checkbox or dropdown list box. This value MUST exist if and only if
  52. * bits.iType is iTypeChck (1) or iTypeDrop (2). If bits.iType is iTypeChck
  53. * (1), wDef MUST be 0 or 1 and specify the default state of the checkbox as
  54. * unchecked or checked, respectively. If bits.iType is iTypeDrop (2), wDef
  55. * MUST be less than the number of items in the dropdown list box and
  56. * specify the default item selected (zero-based index).
  57. */
  58. private Integer _wDef;
  59. private Xstz _xstzEntryMcr;
  60. private Xstz _xstzExitMcr;
  61. private Xstz _xstzHelpText;
  62. /**
  63. * An Xstz that specifies the name of this form field. xstzName.cch MUST NOT
  64. * exceed 20.
  65. */
  66. private Xstz _xstzName;
  67. private Xstz _xstzStatText;
  68. /**
  69. * An optional Xstz that specifies the default text of this textbox. This
  70. * structure MUST exist if and only if bits.iType is iTypeTxt (0).
  71. * xstzTextDef.cch MUST NOT exceed 255. If bits.iTypeTxt is either
  72. * iTypeTxtCurDate (3) or iTypeTxtCurTime (4), xstzTextDef MUST be an empty
  73. * string. If bits.iTypeTxt is iTypeTxtCalc (5), xstzTextDef specifies an
  74. * expression to calculate.
  75. */
  76. private Xstz _xstzTextDef;
  77. private Xstz _xstzTextFormat;
  78. public FFData( byte[] std, int offset )
  79. {
  80. fillFields( std, offset );
  81. }
  82. public void fillFields( final byte[] std, final int startOffset ) // NOSONAR
  83. {
  84. int offset = startOffset;
  85. this._base = new FFDataBase( std, offset );
  86. offset += FFDataBaseAbstractType.getSize();
  87. this._xstzName = new Xstz( std, offset );
  88. offset += this._xstzName.getSize();
  89. if ( _base.getIType() == ITYPE_TEXT )
  90. {
  91. _xstzTextDef = new Xstz( std, offset );
  92. offset += this._xstzTextDef.getSize();
  93. }
  94. else
  95. {
  96. this._xstzTextDef = null;
  97. }
  98. if ( _base.getIType() == ITYPE_CHCK
  99. || _base.getIType() == ITYPE_DROP )
  100. {
  101. this._wDef = LittleEndian.getUShort(std, offset);
  102. offset += LittleEndianConsts.SHORT_SIZE;
  103. }
  104. else
  105. {
  106. this._wDef = null;
  107. }
  108. _xstzTextFormat = new Xstz( std, offset );
  109. offset += this._xstzTextFormat.getSize();
  110. _xstzHelpText = new Xstz( std, offset );
  111. offset += this._xstzHelpText.getSize();
  112. _xstzStatText = new Xstz( std, offset );
  113. offset += this._xstzStatText.getSize();
  114. _xstzEntryMcr = new Xstz( std, offset );
  115. offset += this._xstzEntryMcr.getSize();
  116. _xstzExitMcr = new Xstz( std, offset );
  117. offset += this._xstzExitMcr.getSize();
  118. if ( _base.getIType() == ITYPE_DROP ) {
  119. _hsttbDropList = new Sttb( std, offset );
  120. }
  121. }
  122. /**
  123. * specify the default item selected (zero-based index).
  124. */
  125. public int getDefaultDropDownItemIndex()
  126. {
  127. return _wDef;
  128. }
  129. public String[] getDropList()
  130. {
  131. return _hsttbDropList.getData();
  132. }
  133. public int getSize()
  134. {
  135. int size = FFDataBaseAbstractType.getSize();
  136. size += _xstzName.getSize();
  137. if ( _base.getIType() == ITYPE_TEXT )
  138. {
  139. size += _xstzTextDef.getSize();
  140. }
  141. if ( _base.getIType() == ITYPE_CHCK
  142. || _base.getIType() == ITYPE_DROP )
  143. {
  144. size += LittleEndianConsts.SHORT_SIZE;
  145. }
  146. size += _xstzTextFormat.getSize();
  147. size += _xstzHelpText.getSize();
  148. size += _xstzStatText.getSize();
  149. size += _xstzEntryMcr.getSize();
  150. size += _xstzExitMcr.getSize();
  151. if ( _base.getIType() == ITYPE_DROP )
  152. {
  153. size += _hsttbDropList.getSize();
  154. }
  155. return size;
  156. }
  157. public String getTextDef()
  158. {
  159. return _xstzTextDef.getAsJavaString();
  160. }
  161. public byte[] serialize()
  162. {
  163. byte[] buffer = new byte[getSize()];
  164. int offset = 0;
  165. _base.serialize( buffer, offset );
  166. offset += FFDataBaseAbstractType.getSize();
  167. offset += _xstzName.serialize( buffer, offset );
  168. if ( _base.getIType() == ITYPE_TEXT )
  169. {
  170. offset += _xstzTextDef.serialize( buffer, offset );
  171. }
  172. if ( _base.getIType() == ITYPE_CHCK
  173. || _base.getIType() == ITYPE_DROP )
  174. {
  175. LittleEndian.putUShort( buffer, offset, _wDef );
  176. offset += LittleEndianConsts.SHORT_SIZE;
  177. }
  178. offset += _xstzTextFormat.serialize( buffer, offset );
  179. offset += _xstzHelpText.serialize( buffer, offset );
  180. offset += _xstzStatText.serialize( buffer, offset );
  181. offset += _xstzEntryMcr.serialize( buffer, offset );
  182. offset += _xstzExitMcr.serialize( buffer, offset );
  183. if ( _base.getIType() == ITYPE_DROP ) {
  184. _hsttbDropList.serialize( buffer, offset );
  185. }
  186. return buffer;
  187. }
  188. }