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.

FileInformationBlock.java 33KB

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