PageRenderTime 78ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/org/apache/poi/hwpf/dev/HWPFLister.java

https://github.com/minstrelsy/SimpleAndroidDocView
Java | 763 lines | 633 code | 107 blank | 23 comment | 106 complexity | a5fd3aeec9338ae1535ca742a1539e0e 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.dev;
  16. import java.io.ByteArrayInputStream;
  17. import java.io.ByteArrayOutputStream;
  18. import java.io.File;
  19. import java.io.FileInputStream;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.lang.reflect.Method;
  23. import java.util.ArrayList;
  24. import java.util.Arrays;
  25. import java.util.Collections;
  26. import java.util.Iterator;
  27. import java.util.LinkedHashMap;
  28. import java.util.List;
  29. import java.util.Map;
  30. import org.apache.poi.POIDocument;
  31. import org.apache.poi.hwpf.HWPFDocument;
  32. import org.apache.poi.hwpf.HWPFDocumentCore;
  33. import org.apache.poi.hwpf.HWPFOldDocument;
  34. import org.apache.poi.hwpf.OldWordFileFormatException;
  35. import org.apache.poi.hwpf.model.CHPX;
  36. import org.apache.poi.hwpf.model.FieldsDocumentPart;
  37. import org.apache.poi.hwpf.model.FileInformationBlock;
  38. import org.apache.poi.hwpf.model.GenericPropertyNode;
  39. import org.apache.poi.hwpf.model.LFO;
  40. import org.apache.poi.hwpf.model.LFOData;
  41. import org.apache.poi.hwpf.model.ListLevel;
  42. import org.apache.poi.hwpf.model.ListTables;
  43. import org.apache.poi.hwpf.model.PAPFormattedDiskPage;
  44. import org.apache.poi.hwpf.model.PAPX;
  45. import org.apache.poi.hwpf.model.PlexOfCps;
  46. import org.apache.poi.hwpf.model.StyleDescription;
  47. import org.apache.poi.hwpf.model.StyleSheet;
  48. import org.apache.poi.hwpf.model.TextPiece;
  49. import org.apache.poi.hwpf.sprm.SprmIterator;
  50. import org.apache.poi.hwpf.sprm.SprmOperation;
  51. import org.apache.poi.hwpf.usermodel.Bookmark;
  52. import org.apache.poi.hwpf.usermodel.Bookmarks;
  53. import org.apache.poi.hwpf.usermodel.Field;
  54. import org.apache.poi.hwpf.usermodel.OfficeDrawing;
  55. import org.apache.poi.hwpf.usermodel.Paragraph;
  56. import org.apache.poi.hwpf.usermodel.ParagraphProperties;
  57. import org.apache.poi.hwpf.usermodel.Picture;
  58. import org.apache.poi.hwpf.usermodel.Range;
  59. import org.apache.poi.poifs.common.POIFSConstants;
  60. import org.apache.poi.poifs.filesystem.DirectoryEntry;
  61. import org.apache.poi.poifs.filesystem.DirectoryNode;
  62. import org.apache.poi.poifs.filesystem.Entry;
  63. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  64. import org.apache.poi.util.Beta;
  65. import org.apache.poi.util.IOUtils;
  66. import org.apache.poi.util.LittleEndian;
  67. /**
  68. * Used by developers to list out key information on a HWPF file. End users will
  69. * probably never need to use this program.
  70. *
  71. * @author Nick Burch (nick at torchbox dot com)
  72. * @author Sergey Vladimirov (vlsergey at gmail dot com)
  73. */
  74. @Beta
  75. public final class HWPFLister
  76. {
  77. private static HWPFDocumentCore loadDoc( File docFile ) throws IOException
  78. {
  79. final FileInputStream istream = new FileInputStream( docFile );
  80. try
  81. {
  82. return loadDoc( istream );
  83. }
  84. finally
  85. {
  86. IOUtils.closeQuietly( istream );
  87. }
  88. }
  89. private static HWPFDocumentCore loadDoc( InputStream inputStream )
  90. throws IOException
  91. {
  92. final POIFSFileSystem poifsFileSystem = HWPFDocumentCore
  93. .verifyAndBuildPOIFS( inputStream );
  94. try
  95. {
  96. return new HWPFDocument( poifsFileSystem );
  97. }
  98. catch ( OldWordFileFormatException exc )
  99. {
  100. return new HWPFOldDocument( poifsFileSystem );
  101. }
  102. }
  103. public static void main( String[] args ) throws Exception
  104. {
  105. if ( args.length == 0 )
  106. {
  107. System.err.println( "Use:" );
  108. System.err.println( "\tHWPFLister <filename>\n" + "\t\t[--dop]\n"
  109. + "\t\t[--textPieces] [--textPiecesText]\n"
  110. + "\t\t[--chpx] [--chpxProperties] [--chpxSprms]\n"
  111. + "\t\t[--papx] [--papxProperties] [--papxSprms]\n"
  112. + "\t\t[--paragraphs] [--paragraphsText]\n"
  113. + "\t\t[--bookmarks]\n" + "\t\t[--escher]\n"
  114. + "\t\t[--fields]\n" + "\t\t[--pictures]\n"
  115. + "\t\t[--officeDrawings]\n" + "\t\t[--styles]\n"
  116. + "\t\t[--writereadback]\n" );
  117. System.exit( 1 );
  118. }
  119. boolean outputDop = false;
  120. boolean outputTextPieces = false;
  121. boolean outputTextPiecesText = false;
  122. boolean outputChpx = false;
  123. boolean outputChpxProperties = false;
  124. boolean outputChpxSprms = false;
  125. boolean outputParagraphs = false;
  126. boolean outputParagraphsText = false;
  127. boolean outputPapx = false;
  128. boolean outputPapxSprms = false;
  129. boolean outputPapxProperties = false;
  130. boolean outputBookmarks = false;
  131. boolean outputEscher = false;
  132. boolean outputFields = false;
  133. boolean outputPictures = false;
  134. boolean outputOfficeDrawings = false;
  135. boolean outputStyles = false;
  136. boolean writereadback = false;
  137. for ( String arg : Arrays.asList( args ).subList( 1, args.length ) )
  138. {
  139. if ( "--dop".equals( arg ) )
  140. outputDop = true;
  141. if ( "--textPieces".equals( arg ) )
  142. outputTextPieces = true;
  143. if ( "--textPiecesText".equals( arg ) )
  144. outputTextPiecesText = true;
  145. if ( "--chpx".equals( arg ) )
  146. outputChpx = true;
  147. if ( "--chpxProperties".equals( arg ) )
  148. outputChpxProperties = true;
  149. if ( "--chpxSprms".equals( arg ) )
  150. outputChpxSprms = true;
  151. if ( "--paragraphs".equals( arg ) )
  152. outputParagraphs = true;
  153. if ( "--paragraphsText".equals( arg ) )
  154. outputParagraphsText = true;
  155. if ( "--papx".equals( arg ) )
  156. outputPapx = true;
  157. if ( "--papxProperties".equals( arg ) )
  158. outputPapxProperties = true;
  159. if ( "--papxSprms".equals( arg ) )
  160. outputPapxSprms = true;
  161. if ( "--bookmarks".equals( arg ) )
  162. outputBookmarks = true;
  163. if ( "--escher".equals( arg ) )
  164. outputEscher = true;
  165. if ( "--fields".equals( arg ) )
  166. outputFields = true;
  167. if ( "--pictures".equals( arg ) )
  168. outputPictures = true;
  169. if ( "--officeDrawings".equals( arg ) )
  170. outputOfficeDrawings = true;
  171. if ( "--styles".equals( arg ) )
  172. outputStyles = true;
  173. if ( "--writereadback".equals( arg ) )
  174. writereadback = true;
  175. }
  176. HWPFDocumentCore doc = loadDoc( new File( args[0] ) );
  177. if ( writereadback )
  178. doc = writeOutAndReadBack( doc );
  179. HWPFDocumentCore original;
  180. {
  181. System.setProperty( "org.apache.poi.hwpf.preserveBinTables",
  182. Boolean.TRUE.toString() );
  183. System.setProperty( "org.apache.poi.hwpf.preserveTextTable",
  184. Boolean.TRUE.toString() );
  185. original = loadDoc( new File( args[0] ) );
  186. if ( writereadback )
  187. original = writeOutAndReadBack( original );
  188. }
  189. HWPFLister listerOriginal = new HWPFLister( original );
  190. HWPFLister listerRebuilded = new HWPFLister( doc );
  191. System.out.println( "== OLE streams ==" );
  192. listerOriginal.dumpFileSystem();
  193. System.out.println( "== FIB (original) ==" );
  194. listerOriginal.dumpFIB();
  195. if ( outputDop )
  196. {
  197. System.out.println( "== Document properties ==" );
  198. listerOriginal.dumpDop();
  199. }
  200. if ( outputTextPieces )
  201. {
  202. System.out.println( "== Text pieces (original) ==" );
  203. listerOriginal.dumpTextPieces( outputTextPiecesText );
  204. }
  205. if ( outputChpx )
  206. {
  207. System.out.println( "== CHPX (original) ==" );
  208. listerOriginal.dumpChpx( outputChpxProperties, outputChpxSprms );
  209. System.out.println( "== CHPX (rebuilded) ==" );
  210. listerRebuilded.dumpChpx( outputChpxProperties, outputChpxSprms );
  211. }
  212. if ( outputPapx )
  213. {
  214. System.out.println( "== PAPX (original) ==" );
  215. listerOriginal.dumpPapx( outputPapxProperties, outputPapxSprms );
  216. System.out.println( "== PAPX (rebuilded) ==" );
  217. listerRebuilded.dumpPapx( outputPapxProperties, outputPapxSprms );
  218. }
  219. if ( outputParagraphs )
  220. {
  221. System.out.println( "== Text paragraphs (original) ==" );
  222. listerRebuilded.dumpParagraphs( true );
  223. System.out.println( "== DOM paragraphs (rebuilded) ==" );
  224. listerRebuilded.dumpParagraphsDom( outputParagraphsText );
  225. }
  226. if ( outputBookmarks )
  227. {
  228. System.out.println( "== BOOKMARKS (rebuilded) ==" );
  229. listerRebuilded.dumpBookmarks();
  230. }
  231. if ( outputEscher )
  232. {
  233. System.out.println( "== ESCHER PROPERTIES (rebuilded) ==" );
  234. listerRebuilded.dumpEscher();
  235. }
  236. if ( outputFields )
  237. {
  238. System.out.println( "== FIELDS (rebuilded) ==" );
  239. listerRebuilded.dumpFields();
  240. }
  241. if ( outputOfficeDrawings )
  242. {
  243. System.out.println( "== OFFICE DRAWINGS (rebuilded) ==" );
  244. listerRebuilded.dumpOfficeDrawings();
  245. }
  246. if ( outputPictures )
  247. {
  248. System.out.println( "== PICTURES (rebuilded) ==" );
  249. listerRebuilded.dumpPictures();
  250. }
  251. if ( outputStyles )
  252. {
  253. System.out.println( "== STYLES (rebuilded) ==" );
  254. listerRebuilded.dumpStyles();
  255. }
  256. }
  257. private static HWPFDocumentCore writeOutAndReadBack(
  258. HWPFDocumentCore original )
  259. {
  260. try
  261. {
  262. ByteArrayOutputStream baos = new ByteArrayOutputStream( 4096 );
  263. original.write( baos );
  264. ByteArrayInputStream bais = new ByteArrayInputStream(
  265. baos.toByteArray() );
  266. return loadDoc( bais );
  267. }
  268. catch ( IOException e )
  269. {
  270. throw new RuntimeException( e );
  271. }
  272. }
  273. private final HWPFDocumentCore _doc;
  274. private LinkedHashMap<Integer, String> paragraphs;
  275. public HWPFLister( HWPFDocumentCore doc )
  276. {
  277. _doc = doc;
  278. buildParagraphs();
  279. }
  280. private void buildParagraphs()
  281. {
  282. paragraphs = new LinkedHashMap<Integer, String>();
  283. StringBuilder part = new StringBuilder();
  284. String text = _doc.getDocumentText();
  285. for ( int charIndex = 0; charIndex < text.length(); charIndex++ )
  286. {
  287. char c = text.charAt( charIndex );
  288. part.append( c );
  289. if ( c == 13 || c == 7 || c == 12 )
  290. {
  291. paragraphs.put( Integer.valueOf( charIndex ), part.toString() );
  292. part.setLength( 0 );
  293. }
  294. }
  295. }
  296. private void dumpBookmarks()
  297. {
  298. if ( !( _doc instanceof HWPFDocument ) )
  299. {
  300. System.out.println( "Word 95 not supported so far" );
  301. return;
  302. }
  303. HWPFDocument document = (HWPFDocument) _doc;
  304. Bookmarks bookmarks = document.getBookmarks();
  305. for ( int b = 0; b < bookmarks.getBookmarksCount(); b++ )
  306. {
  307. Bookmark bookmark = bookmarks.getBookmark( b );
  308. System.out.println( "[" + bookmark.getStart() + "; "
  309. + bookmark.getEnd() + "): " + bookmark.getName() );
  310. }
  311. }
  312. public void dumpChpx( boolean withProperties, boolean withSprms )
  313. {
  314. for ( CHPX chpx : _doc.getCharacterTable().getTextRuns() )
  315. {
  316. System.out.println( chpx );
  317. if ( withProperties )
  318. {
  319. System.out.println( chpx.getCharacterProperties(
  320. _doc.getStyleSheet(), (short) StyleSheet.NIL_STYLE ) );
  321. }
  322. if ( withSprms )
  323. {
  324. SprmIterator sprmIt = new SprmIterator( chpx.getGrpprl(), 0 );
  325. while ( sprmIt.hasNext() )
  326. {
  327. SprmOperation sprm = sprmIt.next();
  328. System.out.println( "\t" + sprm.toString() );
  329. }
  330. }
  331. if ( true )
  332. {
  333. String text = new Range( chpx.getStart(), chpx.getEnd(),
  334. _doc.getOverallRange() )
  335. {
  336. public String toString()
  337. {
  338. return "CHPX range (" + super.toString() + ")";
  339. }
  340. }.text();
  341. StringBuilder stringBuilder = new StringBuilder();
  342. for ( char c : text.toCharArray() )
  343. {
  344. if ( c < 30 )
  345. stringBuilder
  346. .append( "\\0x" + Integer.toHexString( c ) );
  347. else
  348. stringBuilder.append( c );
  349. }
  350. System.out.println( stringBuilder );
  351. }
  352. }
  353. }
  354. private void dumpDop()
  355. {
  356. if ( !( _doc instanceof HWPFDocument ) )
  357. {
  358. System.out.println( "Word 95 not supported so far" );
  359. return;
  360. }
  361. System.out.println( ( (HWPFDocument) _doc ).getDocProperties() );
  362. }
  363. private void dumpEscher()
  364. {
  365. if ( _doc instanceof HWPFOldDocument )
  366. {
  367. System.out.println( "Word 95 not supported so far" );
  368. return;
  369. }
  370. System.out.println( ( (HWPFDocument) _doc ).getEscherRecordHolder() );
  371. }
  372. public void dumpFIB()
  373. {
  374. FileInformationBlock fib = _doc.getFileInformationBlock();
  375. System.out.println( fib );
  376. }
  377. private void dumpFields()
  378. {
  379. if ( !( _doc instanceof HWPFDocument ) )
  380. {
  381. System.out.println( "Word 95 not supported so far" );
  382. return;
  383. }
  384. HWPFDocument document = (HWPFDocument) _doc;
  385. for ( FieldsDocumentPart part : FieldsDocumentPart.values() )
  386. {
  387. System.out.println( "=== Document part: " + part + " ===" );
  388. for ( Field field : document.getFields().getFields( part ) )
  389. {
  390. System.out.println( field );
  391. }
  392. }
  393. }
  394. public void dumpFileSystem() throws Exception
  395. {
  396. java.lang.reflect.Field field = POIDocument.class
  397. .getDeclaredField( "directory" );
  398. field.setAccessible( true );
  399. DirectoryNode directoryNode = (DirectoryNode) field.get( _doc );
  400. System.out.println( dumpFileSystem( directoryNode ) );
  401. }
  402. private String dumpFileSystem( DirectoryEntry directory )
  403. {
  404. StringBuilder result = new StringBuilder();
  405. result.append( "+ " );
  406. result.append( directory.getName() );
  407. for ( Iterator<Entry> iterator = directory.getEntries(); iterator
  408. .hasNext(); )
  409. {
  410. Entry entry = iterator.next();
  411. String entryToString = "\n" + dumpFileSystem( entry );
  412. entryToString = entryToString.replaceAll( "\n", "\n+---" );
  413. result.append( entryToString );
  414. }
  415. result.append( "\n" );
  416. return result.toString();
  417. }
  418. private String dumpFileSystem( Entry entry )
  419. {
  420. if ( entry instanceof DirectoryEntry )
  421. return dumpFileSystem( (DirectoryEntry) entry );
  422. return entry.getName();
  423. }
  424. private void dumpOfficeDrawings()
  425. {
  426. if ( !( _doc instanceof HWPFDocument ) )
  427. {
  428. System.out.println( "Word 95 not supported so far" );
  429. return;
  430. }
  431. HWPFDocument document = (HWPFDocument) _doc;
  432. if ( document.getOfficeDrawingsHeaders() != null )
  433. {
  434. System.out.println( "=== Document part: HEADER ===" );
  435. for ( OfficeDrawing officeDrawing : document
  436. .getOfficeDrawingsHeaders().getOfficeDrawings() )
  437. {
  438. System.out.println( officeDrawing );
  439. }
  440. }
  441. if ( document.getOfficeDrawingsHeaders() != null )
  442. {
  443. System.out.println( "=== Document part: MAIN ===" );
  444. for ( OfficeDrawing officeDrawing : document
  445. .getOfficeDrawingsMain().getOfficeDrawings() )
  446. {
  447. System.out.println( officeDrawing );
  448. }
  449. }
  450. }
  451. public void dumpPapx( boolean withProperties, boolean withSprms )
  452. throws Exception
  453. {
  454. if ( _doc instanceof HWPFDocument )
  455. {
  456. System.out.println( "binary PAP pages " );
  457. HWPFDocument doc = (HWPFDocument) _doc;
  458. java.lang.reflect.Field fMainStream = HWPFDocumentCore.class
  459. .getDeclaredField( "_mainStream" );
  460. fMainStream.setAccessible( true );
  461. byte[] mainStream = (byte[]) fMainStream.get( _doc );
  462. PlexOfCps binTable = new PlexOfCps( doc.getTableStream(), doc
  463. .getFileInformationBlock().getFcPlcfbtePapx(), doc
  464. .getFileInformationBlock().getLcbPlcfbtePapx(), 4 );
  465. List<PAPX> papxs = new ArrayList<PAPX>();
  466. int length = binTable.length();
  467. for ( int x = 0; x < length; x++ )
  468. {
  469. GenericPropertyNode node = binTable.getProperty( x );
  470. int pageNum = LittleEndian.getInt( node.getBytes() );
  471. int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE
  472. * pageNum;
  473. PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(
  474. mainStream, doc.getDataStream(), pageOffset,
  475. doc.getTextTable() );
  476. System.out.println( "* PFKP: " + pfkp );
  477. for ( PAPX papx : pfkp.getPAPXs() )
  478. {
  479. System.out.println( "** " + papx );
  480. papxs.add( papx );
  481. if ( papx != null && withSprms )
  482. {
  483. SprmIterator sprmIt = new SprmIterator(
  484. papx.getGrpprl(), 2 );
  485. dumpSprms( sprmIt, "*** " );
  486. }
  487. }
  488. }
  489. Collections.sort( papxs );
  490. System.out.println( "* Sorted by END" );
  491. for ( PAPX papx : papxs )
  492. {
  493. System.out.println( "** " + papx );
  494. if ( papx != null && withSprms )
  495. {
  496. SprmIterator sprmIt = new SprmIterator( papx.getGrpprl(), 2 );
  497. dumpSprms( sprmIt, "*** " );
  498. }
  499. }
  500. }
  501. Method newParagraph = Paragraph.class.getDeclaredMethod(
  502. "newParagraph", Range.class, PAPX.class );
  503. newParagraph.setAccessible( true );
  504. java.lang.reflect.Field _props = Paragraph.class
  505. .getDeclaredField( "_props" );
  506. _props.setAccessible( true );
  507. for ( PAPX papx : _doc.getParagraphTable().getParagraphs() )
  508. {
  509. System.out.println( papx );
  510. if ( withProperties )
  511. {
  512. Paragraph paragraph = (Paragraph) newParagraph.invoke( null,
  513. _doc.getOverallRange(), papx );
  514. System.out.println( _props.get( paragraph ) );
  515. }
  516. if ( true )
  517. {
  518. SprmIterator sprmIt = new SprmIterator( papx.getGrpprl(), 2 );
  519. dumpSprms( sprmIt, "\t" );
  520. }
  521. }
  522. }
  523. public void dumpParagraphs( boolean dumpAssotiatedPapx )
  524. {
  525. for ( Map.Entry<Integer, String> entry : paragraphs.entrySet() )
  526. {
  527. Integer endOfParagraphCharOffset = entry.getKey();
  528. System.out.println( "[...; " + ( endOfParagraphCharOffset + 1 )
  529. + "): " + entry.getValue() );
  530. if ( dumpAssotiatedPapx )
  531. {
  532. boolean hasAssotiatedPapx = false;
  533. for ( PAPX papx : _doc.getParagraphTable().getParagraphs() )
  534. {
  535. if ( papx.getStart() <= endOfParagraphCharOffset.intValue()
  536. && endOfParagraphCharOffset.intValue() < papx
  537. .getEnd() )
  538. {
  539. hasAssotiatedPapx = true;
  540. System.out.println( "* " + papx );
  541. SprmIterator sprmIt = new SprmIterator(
  542. papx.getGrpprl(), 2 );
  543. dumpSprms( sprmIt, "** " );
  544. }
  545. }
  546. if ( !hasAssotiatedPapx )
  547. {
  548. System.out.println( "* "
  549. + "NO PAPX ASSOTIATED WITH PARAGRAPH!" );
  550. }
  551. }
  552. }
  553. }
  554. protected void dumpSprms( SprmIterator sprmIt, String linePrefix )
  555. {
  556. while ( sprmIt.hasNext() )
  557. {
  558. SprmOperation sprm = sprmIt.next();
  559. System.out.println( linePrefix + sprm.toString() );
  560. }
  561. }
  562. public void dumpParagraphsDom( boolean withText )
  563. {
  564. Range range = _doc.getOverallRange();
  565. for ( int p = 0; p < range.numParagraphs(); p++ )
  566. {
  567. Paragraph paragraph = range.getParagraph( p );
  568. System.out.println( p + ":\t" + paragraph.toString() );
  569. if ( withText )
  570. System.out.println( paragraph.text() );
  571. }
  572. }
  573. private void dumpPictures()
  574. {
  575. if ( _doc instanceof HWPFOldDocument )
  576. {
  577. System.out.println( "Word 95 not supported so far" );
  578. return;
  579. }
  580. List<Picture> allPictures = ( (HWPFDocument) _doc ).getPicturesTable()
  581. .getAllPictures();
  582. for ( Picture picture : allPictures )
  583. {
  584. System.out.println( picture.toString() );
  585. }
  586. }
  587. private void dumpStyles()
  588. {
  589. if ( _doc instanceof HWPFOldDocument )
  590. {
  591. System.out.println( "Word 95 not supported so far" );
  592. return;
  593. }
  594. HWPFDocument hwpfDocument = (HWPFDocument) _doc;
  595. for ( int s = 0; s < hwpfDocument.getStyleSheet().numStyles(); s++ )
  596. {
  597. StyleDescription styleDescription = hwpfDocument.getStyleSheet()
  598. .getStyleDescription( s );
  599. if ( styleDescription == null )
  600. continue;
  601. System.out.println( "=== Style #" + s + " '"
  602. + styleDescription.getName() + "' ===" );
  603. System.out.println( styleDescription );
  604. if ( styleDescription.getPAPX() != null )
  605. dumpSprms( new SprmIterator( styleDescription.getPAPX(), 2 ),
  606. "Style's PAP SPRM: " );
  607. if ( styleDescription.getCHPX() != null )
  608. dumpSprms( new SprmIterator( styleDescription.getCHPX(), 0 ),
  609. "Style's CHP SPRM: " );
  610. }
  611. }
  612. protected void dumpParagraphLevels( ListTables listTables,
  613. ParagraphProperties paragraph )
  614. {
  615. if ( paragraph.getIlfo() != 0 )
  616. {
  617. final LFO lfo = listTables.getLfo( paragraph.getIlfo() );
  618. System.out.println( "PAP's LFO: " + lfo );
  619. final LFOData lfoData = listTables.getLfoData( paragraph.getIlfo() );
  620. System.out.println( "PAP's LFOData: " + lfoData );
  621. if ( lfo != null )
  622. {
  623. final ListLevel listLevel = listTables.getLevel( lfo.getLsid(),
  624. paragraph.getIlvl() );
  625. System.out.println( "PAP's ListLevel: " + listLevel );
  626. if ( listLevel.getGrpprlPapx() != null )
  627. {
  628. System.out.println( "PAP's ListLevel PAPX:" );
  629. dumpSprms(
  630. new SprmIterator( listLevel.getGrpprlPapx(), 0 ),
  631. "* " );
  632. }
  633. if ( listLevel.getGrpprlPapx() != null )
  634. {
  635. System.out.println( "PAP's ListLevel CHPX:" );
  636. dumpSprms(
  637. new SprmIterator( listLevel.getGrpprlChpx(), 0 ),
  638. "* " );
  639. }
  640. }
  641. }
  642. }
  643. public void dumpTextPieces( boolean withText )
  644. {
  645. for ( TextPiece textPiece : _doc.getTextTable().getTextPieces() )
  646. {
  647. System.out.println( textPiece );
  648. if ( withText )
  649. {
  650. System.out.println( "\t" + textPiece.getStringBuilder() );
  651. }
  652. }
  653. }
  654. }