PageRenderTime 315ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/apache/poi/hwpf/model/FFData.java

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