From: Sergey Vladimirov Date: Tue, 19 Jul 2011 11:03:09 +0000 (+0000) Subject: add dump fields feature X-Git-Tag: REL_3_8_BETA4~136 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=962c8ce606a0ba63de3ee56e1e0ab576b91b7800;p=poi.git add dump fields feature git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148270 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java b/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java index aceb51572c..76ca6992d8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java @@ -36,6 +36,7 @@ import org.apache.poi.hwpf.HWPFDocumentCore; import org.apache.poi.hwpf.HWPFOldDocument; import org.apache.poi.hwpf.OldWordFileFormatException; import org.apache.poi.hwpf.model.CHPX; +import org.apache.poi.hwpf.model.FieldsTables; import org.apache.poi.hwpf.model.FileInformationBlock; import org.apache.poi.hwpf.model.GenericPropertyNode; import org.apache.poi.hwpf.model.PAPFormattedDiskPage; @@ -101,7 +102,8 @@ public final class HWPFLister + "\t\t[--chpx] [--chpxProperties] [--chpxSprms]\n" + "\t\t[--papx] [--papxProperties]\n" + "\t\t[--paragraphs] [--paragraphsSprms] [--paragraphsText]\n" - + "\t\t[--pictures]\n" + "\t\t[--writereadback]\n" ); + + "\t\t[--fields]\n" + "\t\t[--pictures]\n" + + "\t\t[--writereadback]\n" ); System.exit( 1 ); } @@ -119,6 +121,7 @@ public final class HWPFLister boolean outputPapx = false; boolean outputPapxProperties = false; + boolean outputFields = false; boolean outputPictures = false; boolean writereadback = false; @@ -149,6 +152,8 @@ public final class HWPFLister if ( "--papxProperties".equals( arg ) ) outputPapxProperties = true; + if ( "--fields".equals( arg ) ) + outputFields = true; if ( "--pictures".equals( arg ) ) outputPictures = true; @@ -191,6 +196,12 @@ public final class HWPFLister outputParagraphsText ); } + if ( outputFields ) + { + System.out.println( "== FIELDS ==" ); + lister.dumpFields(); + } + if ( outputPictures ) { System.out.println( "== PICTURES ==" ); @@ -306,6 +317,27 @@ public final class HWPFLister System.out.println( fib ); } + private void dumpFields() + { + if ( !( _doc instanceof HWPFDocument ) ) + { + System.out.println( "Word 95 not supported so far" ); + return; + } + + HWPFDocument document = (HWPFDocument) _doc; + + for ( int i = FieldsTables.PLCFFLDATN; i <= FieldsTables.PLCFFLDTXBX; i++ ) + { + System.out.println( "=== Document part: " + i + " ===" ); + for ( org.apache.poi.hwpf.model.Field field : document + .getFieldsTables().getFields( i ) ) + { + System.out.println( field ); + } + } + } + public void dumpPapx( boolean withProperties ) throws Exception { if ( _doc instanceof HWPFDocument ) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java index 9b156ce831..0141f49e94 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java @@ -22,6 +22,8 @@ package org.apache.poi.hwpf.model; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -234,7 +236,7 @@ public class FieldsTables * This is port and adaptation of Arrays.binarySearch from Java 6 (Apache * Harmony). */ - public static int binarySearch( GenericPropertyNode[] array, + private static int binarySearch( GenericPropertyNode[] array, int startIndex, int endIndex, int requiredStartOffset ) { checkIndexForBinarySearch( array.length, startIndex, endIndex ); @@ -342,6 +344,16 @@ public class FieldsTables return new PlexOfCps( tableStream, start, length, FLD_SIZE ); } + public Collection getFields( int documentPart ) + { + Map map = _fieldsByOffset.get( Integer + .valueOf( documentPart ) ); + if ( map == null || map.isEmpty() ) + return Collections.emptySet(); + + return Collections.unmodifiableCollection( map.values() ); + } + public ArrayList getFieldsPLCF( int type ) { return toArrayList( _tables.get( Integer.valueOf( type ) ) );