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.

FLDAbstractType.java 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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.types;
  16. import org.apache.poi.util.BitField;
  17. import org.apache.poi.util.Internal;
  18. /**
  19. * Field Descriptor (FLD).
  20. */
  21. @Internal
  22. public abstract class FLDAbstractType
  23. {
  24. protected byte field_1_chHolder;
  25. private static final BitField ch = new BitField( 0x1f );
  26. private static final BitField reserved = new BitField( 0xe0 );
  27. protected byte field_2_flt;
  28. private static final BitField fDiffer = new BitField( 0x01 );
  29. private static final BitField fZombieEmbed = new BitField( 0x02 );
  30. private static final BitField fResultDirty = new BitField( 0x04 );
  31. private static final BitField fResultEdited = new BitField( 0x08 );
  32. private static final BitField fLocked = new BitField( 0x10 );
  33. private static final BitField fPrivateResult = new BitField( 0x20 );
  34. private static final BitField fNested = new BitField( 0x40 );
  35. private static final BitField fHasSep = new BitField( 0x40 );
  36. public FLDAbstractType()
  37. {
  38. }
  39. protected void fillFields( byte[] data, int offset )
  40. {
  41. field_1_chHolder = data[0x0 + offset];
  42. field_2_flt = data[0x1 + offset];
  43. }
  44. public void serialize( byte[] data, int offset )
  45. {
  46. data[0x0 + offset] = field_1_chHolder;
  47. data[0x1 + offset] = field_2_flt;
  48. }
  49. public String toString() {
  50. return
  51. "[FLD]\n" +
  52. " .chHolder = (" + getChHolder() + " )\n" +
  53. " .ch = " + getCh() + "\n" +
  54. " .reserved = " + getReserved() + "\n" +
  55. " .flt = (" + getFlt() + " )\n" +
  56. " .fDiffer = " + isFDiffer() + "\n" +
  57. " .fZombieEmbed = " + isFZombieEmbed() + "\n" +
  58. " .fResultDirty = " + isFResultDirty() + "\n" +
  59. " .fResultEdited = " + isFResultEdited() + "\n" +
  60. " .fLocked = " + isFLocked() + "\n" +
  61. " .fPrivateResult = " + isFPrivateResult() + "\n" +
  62. " .fNested = " + isFNested() + "\n" +
  63. " .fHasSep = " + isFHasSep() + "\n" +
  64. "[/FLD]\n";
  65. }
  66. /**
  67. * Size of record (exluding 4 byte header)
  68. */
  69. public static int getSize()
  70. {
  71. return 4 + +1 + 1;
  72. }
  73. /**
  74. * ch field holder (along with reserved bits).
  75. */
  76. public byte getChHolder()
  77. {
  78. return field_1_chHolder;
  79. }
  80. /**
  81. * ch field holder (along with reserved bits).
  82. */
  83. public void setChHolder( byte field_1_chHolder )
  84. {
  85. this.field_1_chHolder = field_1_chHolder;
  86. }
  87. /**
  88. * Field type when ch == 19 OR field flags when ch == 21 .
  89. */
  90. public byte getFlt()
  91. {
  92. return field_2_flt;
  93. }
  94. /**
  95. * Field type when ch == 19 OR field flags when ch == 21 .
  96. */
  97. public void setFlt( byte field_2_flt )
  98. {
  99. this.field_2_flt = field_2_flt;
  100. }
  101. /**
  102. * Sets the ch field value. Type of field boundary the FLD describes: 19 --
  103. * field begin mark, 20 -- field separation mark; 21 -- field end mark
  104. */
  105. public void setCh( byte value )
  106. {
  107. field_1_chHolder = (byte) ch.setValue( field_1_chHolder, value );
  108. }
  109. /**
  110. * Type of field boundary the FLD describes: 19 -- field begin mark, 20 --
  111. * field separation mark; 21 -- field end mark
  112. *
  113. * @return the ch field value.
  114. */
  115. public byte getCh()
  116. {
  117. return (byte) ch.getValue( field_1_chHolder );
  118. }
  119. /**
  120. * Sets the reserved field value. Reserved
  121. */
  122. public void setReserved( byte value )
  123. {
  124. field_1_chHolder = (byte) reserved.setValue( field_1_chHolder, value );
  125. }
  126. /**
  127. * Reserved
  128. *
  129. * @return the reserved field value.
  130. */
  131. public byte getReserved()
  132. {
  133. return (byte) reserved.getValue( field_1_chHolder );
  134. }
  135. /**
  136. * Sets the fDiffer field value. Ignored for saved file
  137. */
  138. public void setFDiffer( boolean value )
  139. {
  140. field_2_flt = (byte) fDiffer.setBoolean( field_2_flt, value );
  141. }
  142. /**
  143. * Ignored for saved file
  144. *
  145. * @return the fDiffer field value.
  146. */
  147. public boolean isFDiffer()
  148. {
  149. return fDiffer.isSet( field_2_flt );
  150. }
  151. /**
  152. * Sets the fZombieEmbed field value. ==1 when result still believes this
  153. * field is an EMBED or LINK field
  154. */
  155. public void setFZombieEmbed( boolean value )
  156. {
  157. field_2_flt = (byte) fZombieEmbed.setBoolean( field_2_flt, value );
  158. }
  159. /**
  160. * ==1 when result still believes this field is an EMBED or LINK field
  161. *
  162. * @return the fZombieEmbed field value.
  163. */
  164. public boolean isFZombieEmbed()
  165. {
  166. return fZombieEmbed.isSet( field_2_flt );
  167. }
  168. /**
  169. * Sets the fResultDirty field value. ==1 when user has edited or formatted
  170. * the result. == 0 otherwise
  171. */
  172. public void setFResultDirty( boolean value )
  173. {
  174. field_2_flt = (byte) fResultDirty.setBoolean( field_2_flt, value );
  175. }
  176. /**
  177. * ==1 when user has edited or formatted the result. == 0 otherwise
  178. *
  179. * @return the fResultDirty field value.
  180. */
  181. public boolean isFResultDirty()
  182. {
  183. return fResultDirty.isSet( field_2_flt );
  184. }
  185. /**
  186. * Sets the fResultEdited field value. ==1 when user has inserted text into
  187. * or deleted text from the result
  188. */
  189. public void setFResultEdited( boolean value )
  190. {
  191. field_2_flt = (byte) fResultEdited.setBoolean( field_2_flt, value );
  192. }
  193. /**
  194. * ==1 when user has inserted text into or deleted text from the result
  195. *
  196. * @return the fResultEdited field value.
  197. */
  198. public boolean isFResultEdited()
  199. {
  200. return fResultEdited.isSet( field_2_flt );
  201. }
  202. /**
  203. * Sets the fLocked field value. ==1 when field is locked from recalculation
  204. */
  205. public void setFLocked( boolean value )
  206. {
  207. field_2_flt = (byte) fLocked.setBoolean( field_2_flt, value );
  208. }
  209. /**
  210. * ==1 when field is locked from recalculation
  211. *
  212. * @return the fLocked field value.
  213. */
  214. public boolean isFLocked()
  215. {
  216. return fLocked.isSet( field_2_flt );
  217. }
  218. /**
  219. * Sets the fPrivateResult field value. ==1 whenever the result of the field
  220. * is never to be shown
  221. */
  222. public void setFPrivateResult( boolean value )
  223. {
  224. field_2_flt = (byte) fPrivateResult.setBoolean( field_2_flt, value );
  225. }
  226. /**
  227. * ==1 whenever the result of the field is never to be shown
  228. *
  229. * @return the fPrivateResult field value.
  230. */
  231. public boolean isFPrivateResult()
  232. {
  233. return fPrivateResult.isSet( field_2_flt );
  234. }
  235. /**
  236. * Sets the fNested field value. ==1 when field is nested within another
  237. * field
  238. */
  239. public void setFNested( boolean value )
  240. {
  241. field_2_flt = (byte) fNested.setBoolean( field_2_flt, value );
  242. }
  243. /**
  244. * ==1 when field is nested within another field
  245. *
  246. * @return the fNested field value.
  247. */
  248. public boolean isFNested()
  249. {
  250. return fNested.isSet( field_2_flt );
  251. }
  252. /**
  253. * Sets the fHasSep field value. ==1 when field has a field separator
  254. */
  255. public void setFHasSep( boolean value )
  256. {
  257. field_2_flt = (byte) fHasSep.setBoolean( field_2_flt, value );
  258. }
  259. /**
  260. * ==1 when field has a field separator
  261. *
  262. * @return the fHasSep field value.
  263. */
  264. public boolean isFHasSep()
  265. {
  266. return fHasSep.isSet( field_2_flt );
  267. }
  268. } // END OF CLASS