PageRenderTime 244ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/minstrelsy/SimpleAndroidDocView
Java | 1108 lines | 824 code | 173 blank | 111 comment | 35 complexity | d1e2f02dc9ef99107ca7326905a58d39 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 java.io.IOException;
  17. import java.lang.reflect.Method;
  18. import java.lang.reflect.Modifier;
  19. import java.util.HashSet;
  20. import org.apache.poi.EncryptedDocumentException;
  21. import org.apache.poi.hwpf.model.io.HWPFOutputStream;
  22. import org.apache.poi.util.Internal;
  23. import org.apache.poi.util.LittleEndian;
  24. import org.apache.poi.util.POILogFactory;
  25. import org.apache.poi.util.POILogger;
  26. /**
  27. * The File Information Block (FIB). Holds pointers
  28. * to various bits of the file, and lots of flags which
  29. * specify properties of the document.
  30. *
  31. * The {@link FibBase} class, holds the
  32. * first 32 bytes.
  33. * The next part, the fibRgW / FibRgW97, is handled
  34. * by {@link FibRgW97}.
  35. * The next part, the fibRgLw / The FibRgLw97, is
  36. * handled by the {@link FibRgLw}.
  37. * Finally, the rest of the fields are handled by
  38. * the {@link FIBFieldHandler}.
  39. *
  40. * @author andy
  41. */
  42. @Internal
  43. public final class FileInformationBlock implements Cloneable
  44. {
  45. public static final POILogger logger = POILogFactory
  46. .getLogger( FileInformationBlock.class );
  47. private FibBase _fibBase;
  48. private int _csw;
  49. private FibRgW97 _fibRgW;
  50. private int _cslw;
  51. private FibRgLw _fibRgLw;
  52. private int _cbRgFcLcb;
  53. private FIBFieldHandler _fieldHandler;
  54. private int _cswNew;
  55. private int _nFibNew;
  56. private byte[] _fibRgCswNew;
  57. /** Creates a new instance of FileInformationBlock */
  58. public FileInformationBlock( byte[] mainDocument )
  59. {
  60. int offset = 0;
  61. _fibBase = new FibBase( mainDocument, offset );
  62. offset = FibBase.getSize();
  63. assert offset == 32;
  64. if ( _fibBase.isFEncrypted() )
  65. {
  66. throw new EncryptedDocumentException(
  67. "Cannot process encrypted word file" );
  68. }
  69. _csw = LittleEndian.getUShort( mainDocument, offset );
  70. offset += LittleEndian.SHORT_SIZE;
  71. assert offset == 34;
  72. _fibRgW = new FibRgW97( mainDocument, offset );
  73. offset += FibRgW97.getSize();
  74. assert offset == 62;
  75. _cslw = LittleEndian.getUShort( mainDocument, offset );
  76. offset += LittleEndian.SHORT_SIZE;
  77. assert offset == 64;
  78. if ( _fibBase.getNFib() < 105 )
  79. {
  80. _fibRgLw = new FibRgLw95( mainDocument, offset );
  81. offset += FibRgLw97.getSize();
  82. // magic number, run tests after changes
  83. _cbRgFcLcb = 74;
  84. // skip fibRgFcLcbBlob (read later at fillVariableFields)
  85. offset += _cbRgFcLcb * LittleEndian.INT_SIZE * 2;
  86. _cswNew = LittleEndian.getUShort( mainDocument, offset );
  87. offset += LittleEndian.SHORT_SIZE;
  88. _cswNew = 0;
  89. _nFibNew = -1;
  90. _fibRgCswNew = new byte[0];
  91. return;
  92. }
  93. _fibRgLw = new FibRgLw97( mainDocument, offset );
  94. offset += FibRgLw97.getSize();
  95. assert offset == 152;
  96. _cbRgFcLcb = LittleEndian.getUShort( mainDocument, offset );
  97. offset += LittleEndian.SHORT_SIZE;
  98. assert offset == 154;
  99. // skip fibRgFcLcbBlob (read later at fillVariableFields)
  100. offset += _cbRgFcLcb * LittleEndian.INT_SIZE * 2;
  101. _cswNew = LittleEndian.getUShort( mainDocument, offset );
  102. offset += LittleEndian.SHORT_SIZE;
  103. if ( _cswNew != 0 )
  104. {
  105. _nFibNew = LittleEndian.getUShort( mainDocument, offset );
  106. offset += LittleEndian.SHORT_SIZE;
  107. // first short is already read as _nFibNew
  108. final int fibRgCswNewLength = ( _cswNew - 1 )
  109. * LittleEndian.SHORT_SIZE;
  110. _fibRgCswNew = new byte[fibRgCswNewLength];
  111. LittleEndian.getByteArray( mainDocument, offset, fibRgCswNewLength );
  112. offset += fibRgCswNewLength;
  113. }
  114. else
  115. {
  116. _nFibNew = -1;
  117. _fibRgCswNew = new byte[0];
  118. }
  119. assertCbRgFcLcb();
  120. assertCswNew();
  121. }
  122. private void assertCbRgFcLcb()
  123. {
  124. switch ( getNFib() )
  125. {
  126. case 0x00C1:
  127. assertCbRgFcLcb( "0x00C1", 0x005D, "0x005D", _cbRgFcLcb );
  128. break;
  129. case 0x00D9:
  130. assertCbRgFcLcb( "0x00D9", 0x006C, "0x006C", _cbRgFcLcb );
  131. break;
  132. case 0x0101:
  133. assertCbRgFcLcb( "0x0101", 0x0088, "0x0088", _cbRgFcLcb );
  134. break;
  135. case 0x010C:
  136. assertCbRgFcLcb( "0x010C", 0x00A4, "0x00A4", _cbRgFcLcb );
  137. break;
  138. case 0x0112:
  139. assertCbRgFcLcb( "0x0112", 0x00B7, "0x00B7", _cbRgFcLcb );
  140. break;
  141. }
  142. }
  143. private static void assertCbRgFcLcb( final String strNFib,
  144. final int expectedCbRgFcLcb, final String strCbRgFcLcb,
  145. final int cbRgFcLcb )
  146. {
  147. if ( cbRgFcLcb == expectedCbRgFcLcb )
  148. return;
  149. logger.log( POILogger.WARN, "Since FIB.nFib == ", strNFib,
  150. " value of FIB.cbRgFcLcb MUST be ", strCbRgFcLcb + ", not 0x",
  151. Integer.toHexString( cbRgFcLcb ) );
  152. }
  153. private void assertCswNew()
  154. {
  155. switch ( getNFib() )
  156. {
  157. case 0x00C1:
  158. assertCswNew( "0x00C1", 0x0000, "0x0000", _cswNew );
  159. break;
  160. case 0x00D9:
  161. assertCswNew( "0x00D9", 0x0002, "0x0002", _cswNew );
  162. break;
  163. case 0x0101:
  164. assertCswNew( "0x0101", 0x0002, "0x0002", _cswNew );
  165. break;
  166. case 0x010C:
  167. assertCswNew( "0x010C", 0x0002, "0x0002", _cswNew );
  168. break;
  169. case 0x0112:
  170. assertCswNew( "0x0112", 0x0005, "0x0005", _cswNew );
  171. break;
  172. }
  173. }
  174. private static void assertCswNew( final String strNFib,
  175. final int expectedCswNew, final String strExpectedCswNew,
  176. final int cswNew )
  177. {
  178. if ( cswNew == expectedCswNew )
  179. return;
  180. logger.log( POILogger.WARN, "Since FIB.nFib == ", strNFib,
  181. " value of FIB.cswNew MUST be ",
  182. strExpectedCswNew + ", not 0x", Integer.toHexString( cswNew ) );
  183. }
  184. public void fillVariableFields( byte[] mainDocument, byte[] tableStream )
  185. {
  186. /*
  187. * Listed fields won't be treat as UnhandledDataStructure. For all other
  188. * fields FIBFieldHandler will load it content into
  189. * UnhandledDataStructure and save them on save.
  190. */
  191. HashSet<Integer> knownFieldSet = new HashSet<Integer>();
  192. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STSHF ) );
  193. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.CLX ) );
  194. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.DOP ) );
  195. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLCFBTECHPX ) );
  196. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLCFBTEPAPX ) );
  197. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLCFSED ) );
  198. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLFLST ) );
  199. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLFLFO ) );
  200. // field info
  201. for ( FieldsDocumentPart part : FieldsDocumentPart.values() )
  202. knownFieldSet.add( Integer.valueOf( part.getFibFieldsField() ) );
  203. // bookmarks
  204. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLCFBKF ) );
  205. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLCFBKL ) );
  206. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBFBKMK ) );
  207. // notes
  208. for ( NoteType noteType : NoteType.values() )
  209. {
  210. knownFieldSet.add( Integer.valueOf( noteType
  211. .getFibDescriptorsFieldIndex() ) );
  212. knownFieldSet.add( Integer.valueOf( noteType
  213. .getFibTextPositionsFieldIndex() ) );
  214. }
  215. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBFFFN ) );
  216. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBFRMARK ) );
  217. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBSAVEDBY ) );
  218. knownFieldSet.add( Integer.valueOf( FIBFieldHandler.MODIFIED ) );
  219. _fieldHandler = new FIBFieldHandler( mainDocument, 154, _cbRgFcLcb,
  220. tableStream, knownFieldSet, true );
  221. }
  222. @Override
  223. public String toString()
  224. {
  225. StringBuilder stringBuilder = new StringBuilder( );
  226. stringBuilder.append( _fibBase );
  227. stringBuilder.append( "[FIB2]\n" );
  228. stringBuilder.append( "\tSubdocuments info:\n" );
  229. for ( SubdocumentType type : SubdocumentType.values() )
  230. {
  231. stringBuilder.append( "\t\t" );
  232. stringBuilder.append( type );
  233. stringBuilder.append( " has length of " );
  234. stringBuilder.append( getSubdocumentTextStreamLength( type ) );
  235. stringBuilder.append( " char(s)\n" );
  236. }
  237. stringBuilder.append( "\tFields PLCF info:\n" );
  238. for ( FieldsDocumentPart part : FieldsDocumentPart.values() )
  239. {
  240. stringBuilder.append( "\t\t" );
  241. stringBuilder.append( part );
  242. stringBuilder.append( ": PLCF starts at " );
  243. stringBuilder.append( getFieldsPlcfOffset( part ) );
  244. stringBuilder.append( " and have length of " );
  245. stringBuilder.append( getFieldsPlcfLength( part ) );
  246. stringBuilder.append( "\n" );
  247. }
  248. stringBuilder.append( "\tNotes PLCF info:\n" );
  249. for ( NoteType noteType : NoteType.values() )
  250. {
  251. stringBuilder.append( "\t\t" );
  252. stringBuilder.append( noteType );
  253. stringBuilder.append( ": descriptions starts " );
  254. stringBuilder.append( getNotesDescriptorsOffset( noteType ) );
  255. stringBuilder.append( " and have length of " );
  256. stringBuilder.append( getNotesDescriptorsSize( noteType ) );
  257. stringBuilder.append( " bytes\n" );
  258. stringBuilder.append( "\t\t" );
  259. stringBuilder.append( noteType );
  260. stringBuilder.append( ": text positions starts " );
  261. stringBuilder.append( getNotesTextPositionsOffset( noteType ) );
  262. stringBuilder.append( " and have length of " );
  263. stringBuilder.append( getNotesTextPositionsSize( noteType ) );
  264. stringBuilder.append( " bytes\n" );
  265. }
  266. stringBuilder.append( _fieldHandler );
  267. try
  268. {
  269. stringBuilder.append( "\tJava reflection info:\n" );
  270. for ( Method method : FileInformationBlock.class.getMethods() )
  271. {
  272. if ( !method.getName().startsWith( "get" )
  273. || !Modifier.isPublic( method.getModifiers() )
  274. || Modifier.isStatic( method.getModifiers() )
  275. || method.getParameterTypes().length > 0 )
  276. continue;
  277. stringBuilder.append( "\t\t" );
  278. stringBuilder.append( method.getName() );
  279. stringBuilder.append( " => " );
  280. stringBuilder.append( method.invoke( this ) );
  281. stringBuilder.append( "\n" );
  282. }
  283. }
  284. catch ( Exception exc )
  285. {
  286. stringBuilder.append( "(exc: " + exc.getMessage() + ")" );
  287. }
  288. stringBuilder.append( "[/FIB2]\n" );
  289. return stringBuilder.toString();
  290. }
  291. public int getNFib()
  292. {
  293. if ( _cswNew == 0 )
  294. return _fibBase.getNFib();
  295. return _nFibNew;
  296. }
  297. public int getFcDop()
  298. {
  299. return _fieldHandler.getFieldOffset(FIBFieldHandler.DOP);
  300. }
  301. public void setFcDop(int fcDop)
  302. {
  303. _fieldHandler.setFieldOffset(FIBFieldHandler.DOP, fcDop);
  304. }
  305. public int getLcbDop()
  306. {
  307. return _fieldHandler.getFieldSize(FIBFieldHandler.DOP);
  308. }
  309. public void setLcbDop(int lcbDop)
  310. {
  311. _fieldHandler.setFieldSize(FIBFieldHandler.DOP, lcbDop);
  312. }
  313. public int getFcStshf()
  314. {
  315. return _fieldHandler.getFieldOffset(FIBFieldHandler.STSHF);
  316. }
  317. public int getLcbStshf()
  318. {
  319. return _fieldHandler.getFieldSize(FIBFieldHandler.STSHF);
  320. }
  321. public void setFcStshf(int fcStshf)
  322. {
  323. _fieldHandler.setFieldOffset(FIBFieldHandler.STSHF, fcStshf);
  324. }
  325. public void setLcbStshf(int lcbStshf)
  326. {
  327. _fieldHandler.setFieldSize(FIBFieldHandler.STSHF, lcbStshf);
  328. }
  329. public int getFcClx()
  330. {
  331. return _fieldHandler.getFieldOffset(FIBFieldHandler.CLX);
  332. }
  333. public int getLcbClx()
  334. {
  335. return _fieldHandler.getFieldSize(FIBFieldHandler.CLX);
  336. }
  337. public void setFcClx(int fcClx)
  338. {
  339. _fieldHandler.setFieldOffset(FIBFieldHandler.CLX, fcClx);
  340. }
  341. public void setLcbClx(int lcbClx)
  342. {
  343. _fieldHandler.setFieldSize(FIBFieldHandler.CLX, lcbClx);
  344. }
  345. public int getFcPlcfbteChpx()
  346. {
  347. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFBTECHPX);
  348. }
  349. public int getLcbPlcfbteChpx()
  350. {
  351. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFBTECHPX);
  352. }
  353. public void setFcPlcfbteChpx(int fcPlcfBteChpx)
  354. {
  355. _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFBTECHPX, fcPlcfBteChpx);
  356. }
  357. public void setLcbPlcfbteChpx(int lcbPlcfBteChpx)
  358. {
  359. _fieldHandler.setFieldSize(FIBFieldHandler.PLCFBTECHPX, lcbPlcfBteChpx);
  360. }
  361. public int getFcPlcfbtePapx()
  362. {
  363. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFBTEPAPX);
  364. }
  365. public int getLcbPlcfbtePapx()
  366. {
  367. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFBTEPAPX);
  368. }
  369. public void setFcPlcfbtePapx(int fcPlcfBtePapx)
  370. {
  371. _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFBTEPAPX, fcPlcfBtePapx);
  372. }
  373. public void setLcbPlcfbtePapx(int lcbPlcfBtePapx)
  374. {
  375. _fieldHandler.setFieldSize(FIBFieldHandler.PLCFBTEPAPX, lcbPlcfBtePapx);
  376. }
  377. public int getFcPlcfsed()
  378. {
  379. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFSED);
  380. }
  381. public int getLcbPlcfsed()
  382. {
  383. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFSED);
  384. }
  385. public void setFcPlcfsed(int fcPlcfSed)
  386. {
  387. _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFSED, fcPlcfSed);
  388. }
  389. public void setLcbPlcfsed(int lcbPlcfSed)
  390. {
  391. _fieldHandler.setFieldSize(FIBFieldHandler.PLCFSED, lcbPlcfSed);
  392. }
  393. @Deprecated
  394. public int getFcPlcfLst()
  395. {
  396. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFLST);
  397. }
  398. /**
  399. * An unsigned integer that specifies an offset in the Table Stream. A
  400. * PlfLst that contains list formatting information begins at this offset.
  401. * An array of LVLs is appended to the PlfLst. lcbPlfLst does not account
  402. * for the array of LVLs. The size of the array of LVLs is specified by the
  403. * LSTFs in PlfLst. For each LSTF whose fSimpleList is set to 0x1, there is
  404. * one LVL in the array of LVLs that specifies the level formatting of the
  405. * single level in the list which corresponds to the LSTF. And, for each
  406. * LSTF whose fSimpleList is set to 0x0, there are 9 LVLs in the array of
  407. * LVLs that specify the level formatting of the respective levels in the
  408. * list which corresponds to the LSTF. This array of LVLs is in the same
  409. * respective order as the LSTFs in PlfLst. If lcbPlfLst is 0, fcPlfLst is
  410. * undefined and MUST be ignored.
  411. * <p>
  412. * Quote from
  413. * "[MS-DOC] -- v20110315, Word (.doc) Binary File Format; page 76 / 621"
  414. */
  415. public int getFcPlfLst()
  416. {
  417. return _fieldHandler.getFieldOffset( FIBFieldHandler.PLFLST );
  418. }
  419. @Deprecated
  420. public int getLcbPlcfLst()
  421. {
  422. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFLST);
  423. }
  424. public int getLcbPlfLst()
  425. {
  426. return _fieldHandler.getFieldSize( FIBFieldHandler.PLFLST );
  427. }
  428. @Deprecated
  429. public void setFcPlcfLst( int fcPlcfLst )
  430. {
  431. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFLST, fcPlcfLst );
  432. }
  433. public void setFcPlfLst( int fcPlfLst )
  434. {
  435. _fieldHandler.setFieldOffset( FIBFieldHandler.PLFLST, fcPlfLst );
  436. }
  437. @Deprecated
  438. public void setLcbPlcfLst( int lcbPlcfLst )
  439. {
  440. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFLST, lcbPlcfLst );
  441. }
  442. public void setLcbPlfLst( int lcbPlfLst )
  443. {
  444. _fieldHandler.setFieldSize( FIBFieldHandler.PLFLST, lcbPlfLst );
  445. }
  446. /**
  447. * An unsigned integer that specifies an offset in the Table Stream. A
  448. * PlfLfo that contains list formatting override information begins at this
  449. * offset. If lcbPlfLfo is zero, fcPlfLfo is undefined and MUST be ignored.
  450. * <p>
  451. * Quote from
  452. * "[MS-DOC] -- v20110315, Word (.doc) Binary File Format; page 76 / 621"
  453. */
  454. public int getFcPlfLfo()
  455. {
  456. return _fieldHandler.getFieldOffset( FIBFieldHandler.PLFLFO );
  457. }
  458. public int getLcbPlfLfo()
  459. {
  460. return _fieldHandler.getFieldSize(FIBFieldHandler.PLFLFO);
  461. }
  462. /**
  463. * @return Offset in table stream of the STTBF that records bookmark names
  464. * in the main document
  465. */
  466. public int getFcSttbfbkmk()
  467. {
  468. return _fieldHandler.getFieldOffset( FIBFieldHandler.STTBFBKMK );
  469. }
  470. public void setFcSttbfbkmk( int offset )
  471. {
  472. _fieldHandler.setFieldOffset( FIBFieldHandler.STTBFBKMK, offset );
  473. }
  474. /**
  475. * @return Count of bytes in Sttbfbkmk
  476. */
  477. public int getLcbSttbfbkmk()
  478. {
  479. return _fieldHandler.getFieldSize( FIBFieldHandler.STTBFBKMK );
  480. }
  481. public void setLcbSttbfbkmk( int length )
  482. {
  483. _fieldHandler.setFieldSize( FIBFieldHandler.STTBFBKMK, length );
  484. }
  485. /**
  486. * @return Offset in table stream of the PLCF that records the beginning CP
  487. * offsets of bookmarks in the main document. See BKF structure
  488. * definition.
  489. */
  490. public int getFcPlcfbkf()
  491. {
  492. return _fieldHandler.getFieldOffset( FIBFieldHandler.PLCFBKF );
  493. }
  494. public void setFcPlcfbkf( int offset )
  495. {
  496. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFBKF, offset );
  497. }
  498. /**
  499. * @return Count of bytes in Plcfbkf
  500. */
  501. public int getLcbPlcfbkf()
  502. {
  503. return _fieldHandler.getFieldSize( FIBFieldHandler.PLCFBKF );
  504. }
  505. public void setLcbPlcfbkf( int length )
  506. {
  507. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFBKF, length );
  508. }
  509. /**
  510. * @return Offset in table stream of the PLCF that records the ending CP
  511. * offsets of bookmarks recorded in the main document. No structure
  512. * is stored in this PLCF.
  513. */
  514. public int getFcPlcfbkl()
  515. {
  516. return _fieldHandler.getFieldOffset( FIBFieldHandler.PLCFBKL );
  517. }
  518. public void setFcPlcfbkl( int offset )
  519. {
  520. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFBKL, offset );
  521. }
  522. /**
  523. * @return Count of bytes in Plcfbkl
  524. */
  525. public int getLcbPlcfbkl()
  526. {
  527. return _fieldHandler.getFieldSize( FIBFieldHandler.PLCFBKL );
  528. }
  529. public void setLcbPlcfbkl( int length )
  530. {
  531. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFBKL, length );
  532. }
  533. public void setFcPlfLfo(int fcPlfLfo)
  534. {
  535. _fieldHandler.setFieldOffset(FIBFieldHandler.PLFLFO, fcPlfLfo);
  536. }
  537. public void setLcbPlfLfo(int lcbPlfLfo)
  538. {
  539. _fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, lcbPlfLfo);
  540. }
  541. public int getFcSttbfffn()
  542. {
  543. return _fieldHandler.getFieldOffset(FIBFieldHandler.STTBFFFN);
  544. }
  545. public int getLcbSttbfffn()
  546. {
  547. return _fieldHandler.getFieldSize(FIBFieldHandler.STTBFFFN);
  548. }
  549. public void setFcSttbfffn(int fcSttbFffn)
  550. {
  551. _fieldHandler.setFieldOffset(FIBFieldHandler.STTBFFFN, fcSttbFffn);
  552. }
  553. public void setLcbSttbfffn(int lcbSttbFffn)
  554. {
  555. _fieldHandler.setFieldSize(FIBFieldHandler.STTBFFFN, lcbSttbFffn);
  556. }
  557. public int getFcSttbfRMark()
  558. {
  559. return _fieldHandler.getFieldOffset(FIBFieldHandler.STTBFRMARK);
  560. }
  561. public int getLcbSttbfRMark()
  562. {
  563. return _fieldHandler.getFieldSize(FIBFieldHandler.STTBFRMARK);
  564. }
  565. public void setFcSttbfRMark(int fcSttbfRMark)
  566. {
  567. _fieldHandler.setFieldOffset(FIBFieldHandler.STTBFRMARK, fcSttbfRMark);
  568. }
  569. public void setLcbSttbfRMark(int lcbSttbfRMark)
  570. {
  571. _fieldHandler.setFieldSize(FIBFieldHandler.STTBFRMARK, lcbSttbfRMark);
  572. }
  573. /**
  574. * Return the offset to the PlcfHdd, in the table stream,
  575. * i.e. fcPlcfHdd
  576. */
  577. public int getPlcfHddOffset() {
  578. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFHDD);
  579. }
  580. /**
  581. * Return the size of the PlcfHdd, in the table stream,
  582. * i.e. lcbPlcfHdd
  583. */
  584. public int getPlcfHddSize() {
  585. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFHDD);
  586. }
  587. public void setPlcfHddOffset(int fcPlcfHdd) {
  588. _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFHDD, fcPlcfHdd);
  589. }
  590. public void setPlcfHddSize(int lcbPlcfHdd) {
  591. _fieldHandler.setFieldSize(FIBFieldHandler.PLCFHDD, lcbPlcfHdd);
  592. }
  593. public int getFcSttbSavedBy()
  594. {
  595. return _fieldHandler.getFieldOffset(FIBFieldHandler.STTBSAVEDBY);
  596. }
  597. public int getLcbSttbSavedBy()
  598. {
  599. return _fieldHandler.getFieldSize(FIBFieldHandler.STTBSAVEDBY);
  600. }
  601. public void setFcSttbSavedBy(int fcSttbSavedBy)
  602. {
  603. _fieldHandler.setFieldOffset(FIBFieldHandler.STTBSAVEDBY, fcSttbSavedBy);
  604. }
  605. public void setLcbSttbSavedBy(int fcSttbSavedBy)
  606. {
  607. _fieldHandler.setFieldSize(FIBFieldHandler.STTBSAVEDBY, fcSttbSavedBy);
  608. }
  609. public int getModifiedLow()
  610. {
  611. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
  612. }
  613. public int getModifiedHigh()
  614. {
  615. return _fieldHandler.getFieldSize(FIBFieldHandler.PLFLFO);
  616. }
  617. public void setModifiedLow(int modifiedLow)
  618. {
  619. _fieldHandler.setFieldOffset(FIBFieldHandler.PLFLFO, modifiedLow);
  620. }
  621. public void setModifiedHigh(int modifiedHigh)
  622. {
  623. _fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, modifiedHigh);
  624. }
  625. /**
  626. * How many bytes of the main stream contain real data.
  627. */
  628. public int getCbMac()
  629. {
  630. return _fibRgLw.getCbMac();
  631. }
  632. /**
  633. * Updates the count of the number of bytes in the
  634. * main stream which contain real data
  635. */
  636. public void setCbMac( int cbMac )
  637. {
  638. _fibRgLw.setCbMac( cbMac );
  639. }
  640. /**
  641. * @return length of specified subdocument text stream in characters
  642. */
  643. public int getSubdocumentTextStreamLength( SubdocumentType type )
  644. {
  645. if ( type == null )
  646. throw new IllegalArgumentException( "argument 'type' is null" );
  647. return _fibRgLw.getSubdocumentTextStreamLength( type );
  648. }
  649. public void setSubdocumentTextStreamLength( SubdocumentType type, int length )
  650. {
  651. if ( type == null )
  652. throw new IllegalArgumentException( "argument 'type' is null" );
  653. if ( length < 0 )
  654. throw new IllegalArgumentException(
  655. "Subdocument length can't be less than 0 (passed value is "
  656. + length + "). " + "If there is no subdocument "
  657. + "length must be set to zero." );
  658. _fibRgLw.setSubdocumentTextStreamLength( type, length );
  659. }
  660. public void clearOffsetsSizes()
  661. {
  662. _fieldHandler.clearFields();
  663. }
  664. public int getFieldsPlcfOffset( FieldsDocumentPart part )
  665. {
  666. return _fieldHandler.getFieldOffset( part.getFibFieldsField() );
  667. }
  668. public int getFieldsPlcfLength( FieldsDocumentPart part )
  669. {
  670. return _fieldHandler.getFieldSize( part.getFibFieldsField() );
  671. }
  672. public void setFieldsPlcfOffset( FieldsDocumentPart part, int offset )
  673. {
  674. _fieldHandler.setFieldOffset( part.getFibFieldsField(), offset );
  675. }
  676. public void setFieldsPlcfLength( FieldsDocumentPart part, int length )
  677. {
  678. _fieldHandler.setFieldSize( part.getFibFieldsField(), length );
  679. }
  680. @Deprecated
  681. public int getFcPlcffldAtn()
  682. {
  683. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDATN);
  684. }
  685. @Deprecated
  686. public int getLcbPlcffldAtn()
  687. {
  688. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDATN);
  689. }
  690. @Deprecated
  691. public void setFcPlcffldAtn( int offset )
  692. {
  693. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFFLDATN, offset );
  694. }
  695. @Deprecated
  696. public void setLcbPlcffldAtn( int size )
  697. {
  698. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFFLDATN, size );
  699. }
  700. @Deprecated
  701. public int getFcPlcffldEdn()
  702. {
  703. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDEDN);
  704. }
  705. @Deprecated
  706. public int getLcbPlcffldEdn()
  707. {
  708. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDEDN);
  709. }
  710. @Deprecated
  711. public void setFcPlcffldEdn( int offset )
  712. {
  713. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFFLDEDN, offset );
  714. }
  715. @Deprecated
  716. public void setLcbPlcffldEdn( int size )
  717. {
  718. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFFLDEDN, size );
  719. }
  720. @Deprecated
  721. public int getFcPlcffldFtn()
  722. {
  723. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDFTN);
  724. }
  725. @Deprecated
  726. public int getLcbPlcffldFtn()
  727. {
  728. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDFTN);
  729. }
  730. @Deprecated
  731. public void setFcPlcffldFtn( int offset )
  732. {
  733. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFFLDFTN, offset );
  734. }
  735. @Deprecated
  736. public void setLcbPlcffldFtn( int size )
  737. {
  738. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFFLDFTN, size );
  739. }
  740. @Deprecated
  741. public int getFcPlcffldHdr()
  742. {
  743. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDHDR);
  744. }
  745. @Deprecated
  746. public int getLcbPlcffldHdr()
  747. {
  748. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDHDR);
  749. }
  750. @Deprecated
  751. public void setFcPlcffldHdr( int offset )
  752. {
  753. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFFLDHDR, offset );
  754. }
  755. @Deprecated
  756. public void setLcbPlcffldHdr( int size )
  757. {
  758. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFFLDHDR, size );
  759. }
  760. @Deprecated
  761. public int getFcPlcffldHdrtxbx()
  762. {
  763. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDHDRTXBX);
  764. }
  765. @Deprecated
  766. public int getLcbPlcffldHdrtxbx()
  767. {
  768. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDHDRTXBX);
  769. }
  770. @Deprecated
  771. public void setFcPlcffldHdrtxbx( int offset )
  772. {
  773. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFFLDHDRTXBX, offset );
  774. }
  775. @Deprecated
  776. public void setLcbPlcffldHdrtxbx( int size )
  777. {
  778. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFFLDHDRTXBX, size );
  779. }
  780. @Deprecated
  781. public int getFcPlcffldMom()
  782. {
  783. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDMOM);
  784. }
  785. @Deprecated
  786. public int getLcbPlcffldMom()
  787. {
  788. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDMOM);
  789. }
  790. @Deprecated
  791. public void setFcPlcffldMom( int offset )
  792. {
  793. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFFLDMOM, offset );
  794. }
  795. @Deprecated
  796. public void setLcbPlcffldMom( int size )
  797. {
  798. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFFLDMOM, size );
  799. }
  800. @Deprecated
  801. public int getFcPlcffldTxbx()
  802. {
  803. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDTXBX);
  804. }
  805. @Deprecated
  806. public int getLcbPlcffldTxbx()
  807. {
  808. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDTXBX);
  809. }
  810. @Deprecated
  811. public void setFcPlcffldTxbx( int offset )
  812. {
  813. _fieldHandler.setFieldOffset( FIBFieldHandler.PLCFFLDTXBX, offset );
  814. }
  815. @Deprecated
  816. public void setLcbPlcffldTxbx( int size )
  817. {
  818. _fieldHandler.setFieldSize( FIBFieldHandler.PLCFFLDTXBX, size );
  819. }
  820. public int getFSPAPlcfOffset( FSPADocumentPart part )
  821. {
  822. return _fieldHandler.getFieldOffset( part.getFibFieldsField() );
  823. }
  824. public int getFSPAPlcfLength( FSPADocumentPart part )
  825. {
  826. return _fieldHandler.getFieldSize( part.getFibFieldsField() );
  827. }
  828. public void setFSPAPlcfOffset( FSPADocumentPart part, int offset )
  829. {
  830. _fieldHandler.setFieldOffset( part.getFibFieldsField(), offset );
  831. }
  832. public void setFSPAPlcfLength( FSPADocumentPart part, int length )
  833. {
  834. _fieldHandler.setFieldSize( part.getFibFieldsField(), length );
  835. }
  836. @Deprecated
  837. public int getFcPlcspaMom()
  838. {
  839. return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCSPAMOM);
  840. }
  841. @Deprecated
  842. public int getLcbPlcspaMom()
  843. {
  844. return _fieldHandler.getFieldSize(FIBFieldHandler.PLCSPAMOM);
  845. }
  846. public int getFcDggInfo()
  847. {
  848. return _fieldHandler.getFieldOffset(FIBFieldHandler.DGGINFO);
  849. }
  850. public int getLcbDggInfo()
  851. {
  852. return _fieldHandler.getFieldSize(FIBFieldHandler.DGGINFO);
  853. }
  854. public int getNotesDescriptorsOffset( NoteType noteType )
  855. {
  856. return _fieldHandler.getFieldOffset( noteType
  857. .getFibDescriptorsFieldIndex() );
  858. }
  859. public void setNotesDescriptorsOffset( NoteType noteType, int offset )
  860. {
  861. _fieldHandler.setFieldOffset( noteType.getFibDescriptorsFieldIndex(),
  862. offset );
  863. }
  864. public int getNotesDescriptorsSize( NoteType noteType )
  865. {
  866. return _fieldHandler.getFieldSize( noteType
  867. .getFibDescriptorsFieldIndex() );
  868. }
  869. public void setNotesDescriptorsSize( NoteType noteType, int offset )
  870. {
  871. _fieldHandler.setFieldSize( noteType.getFibDescriptorsFieldIndex(),
  872. offset );
  873. }
  874. public int getNotesTextPositionsOffset( NoteType noteType )
  875. {
  876. return _fieldHandler.getFieldOffset( noteType
  877. .getFibTextPositionsFieldIndex() );
  878. }
  879. public void setNotesTextPositionsOffset( NoteType noteType, int offset )
  880. {
  881. _fieldHandler.setFieldOffset( noteType.getFibTextPositionsFieldIndex(),
  882. offset );
  883. }
  884. public int getNotesTextPositionsSize( NoteType noteType )
  885. {
  886. return _fieldHandler.getFieldSize( noteType
  887. .getFibTextPositionsFieldIndex() );
  888. }
  889. public void setNotesTextPositionsSize( NoteType noteType, int offset )
  890. {
  891. _fieldHandler.setFieldSize( noteType.getFibTextPositionsFieldIndex(),
  892. offset );
  893. }
  894. public void writeTo( byte[] mainStream, HWPFOutputStream tableStream )
  895. throws IOException
  896. {
  897. _cbRgFcLcb = _fieldHandler.getFieldsCount();
  898. _fibBase.serialize( mainStream, 0 );
  899. int offset = FibBase.getSize();
  900. LittleEndian.putUShort( mainStream, offset, _csw );
  901. offset += LittleEndian.SHORT_SIZE;
  902. _fibRgW.serialize( mainStream, offset );
  903. offset += FibRgW97.getSize();
  904. LittleEndian.putUShort( mainStream, offset, _cslw );
  905. offset += LittleEndian.SHORT_SIZE;
  906. ( (FibRgLw97) _fibRgLw ).serialize( mainStream, offset );
  907. offset += FibRgLw97.getSize();
  908. LittleEndian.putUShort( mainStream, offset, _cbRgFcLcb );
  909. offset += LittleEndian.SHORT_SIZE;
  910. _fieldHandler.writeTo( mainStream, offset, tableStream );
  911. offset += _cbRgFcLcb * LittleEndian.INT_SIZE * 2;
  912. LittleEndian.putUShort( mainStream, offset, _cswNew );
  913. offset += LittleEndian.SHORT_SIZE;
  914. if ( _cswNew != 0 )
  915. {
  916. LittleEndian.putUShort( mainStream, offset, _nFibNew );
  917. offset += LittleEndian.SHORT_SIZE;
  918. System.arraycopy( _fibRgCswNew, 0, mainStream, offset,
  919. _fibRgCswNew.length );
  920. offset += _fibRgCswNew.length;
  921. }
  922. }
  923. public int getSize()
  924. {
  925. return FibBase.getSize() + LittleEndian.SHORT_SIZE + FibRgW97.getSize()
  926. + LittleEndian.SHORT_SIZE + FibRgLw97.getSize()
  927. + LittleEndian.SHORT_SIZE + _fieldHandler.sizeInBytes();
  928. }
  929. public FibBase getFibBase()
  930. {
  931. return _fibBase;
  932. }
  933. }