mirror of https://github.com/apache/poi.git
add dump fields feature
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148270 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
67710377a8
commit
962c8ce606
|
@ -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 )
|
||||
|
|
|
@ -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 <T> int binarySearch( GenericPropertyNode[] array,
|
||||
private static <T> 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<Field> getFields( int documentPart )
|
||||
{
|
||||
Map<Integer, Field> map = _fieldsByOffset.get( Integer
|
||||
.valueOf( documentPart ) );
|
||||
if ( map == null || map.isEmpty() )
|
||||
return Collections.emptySet();
|
||||
|
||||
return Collections.unmodifiableCollection( map.values() );
|
||||
}
|
||||
|
||||
public ArrayList<PlexOfField> getFieldsPLCF( int type )
|
||||
{
|
||||
return toArrayList( _tables.get( Integer.valueOf( type ) ) );
|
||||
|
|
Loading…
Reference in New Issue