poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1081291 - in /poi/trunk: src/documentation/content/xdocs/ src/scratchpad/src/org/apache/poi/hwpf/ src/scratchpad/src/org/apache/poi/hwpf/model/ src/scratchpad/testcases/org/apache/poi/hwpf/ src/scratchpad/testcases/org/apache/poi/hwpf/mode...
Date Mon, 14 Mar 2011 09:10:13 GMT
Author: yegor
Date: Mon Mar 14 09:10:12 2011
New Revision: 1081291

URL: http://svn.apache.org/viewvc?rev=1081291&view=rev
Log:
 support for getting HWPFDocument fields, see Bugzilla 50313

Added:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestFieldsTables.java
    poi/trunk/test-data/document/test-fields.doc   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Mar 14 09:10:12 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta2" date="2011-??-??">
+           <action dev="poi-developers" type="fix">50313 - support for getting HWPFDocument
fields</action>
            <action dev="poi-developers" type="fix">50912 - fixed setting named styles
to HSSFCells</action>
            <action dev="poi-developers" type="fix">50779 - fixed RecordFormatException
when reading unicode strings with photenic data</action>
            <action dev="poi-developers" type="fix">50718 - More helpful error message
when you try to create a CellReference with #REF!</action>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Mon Mar 14 09:10:12
2011
@@ -32,12 +32,11 @@ import org.apache.poi.hwpf.model.Complex
 import org.apache.poi.hwpf.model.DocumentProperties;
 import org.apache.poi.hwpf.model.EscherRecordHolder;
 import org.apache.poi.hwpf.model.FSPATable;
+import org.apache.poi.hwpf.model.FieldsTables;
 import org.apache.poi.hwpf.model.FontTable;
-import org.apache.poi.hwpf.model.GenericPropertyNode;
 import org.apache.poi.hwpf.model.ListTables;
 import org.apache.poi.hwpf.model.PAPBinTable;
 import org.apache.poi.hwpf.model.PicturesTable;
-import org.apache.poi.hwpf.model.PlexOfCps;
 import org.apache.poi.hwpf.model.PropertyNode;
 import org.apache.poi.hwpf.model.RevisionMarkAuthorTable;
 import org.apache.poi.hwpf.model.SavedByTable;
@@ -100,6 +99,9 @@ public final class HWPFDocument extends 
 
   /** Holds Office Art objects */
   protected ShapesTable _officeArts;
+  
+  /** Holds the fields PLCFs */
+  protected FieldsTables _fieldsTables;
 
   protected HWPFDocument()
   {
@@ -264,13 +266,7 @@ public final class HWPFDocument extends 
       _rmat = new RevisionMarkAuthorTable(_tableStream, rmarkOffset, rmarkLength);
     }
     
-    PlexOfCps plc = new PlexOfCps(_tableStream, _fib.getFcPlcffldMom(), _fib.getLcbPlcffldMom(),
2);
-    for (int x = 0; x < plc.length(); x++)
-    {
-      GenericPropertyNode node = plc.getProperty(x);
-      byte[] fld = node.getBytes();
-      int breakpoint = 0;
-    }
+    _fieldsTables = new FieldsTables(_tableStream, _fib);
   }
 
   public TextPieceTable getTextTable()
@@ -416,6 +412,13 @@ public final class HWPFDocument extends 
   }
 
   /**
+   * @return FieldsTables object, that is able to extract fields descriptors from this document
+   */
+  public FieldsTables getFieldsTables() {
+      return _fieldsTables;
+  }
+  
+  /**
    * Writes out the word file that is represented by an instance of this class.
    *
    * @param out The OutputStream to write to.

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java Mon Mar 14
09:10:12 2011
@@ -17,23 +17,146 @@
 
 package org.apache.poi.hwpf.model;
 
-import org.apache.poi.util.BitField;
-import org.apache.poi.util.BitFieldFactory;
+import java.text.MessageFormat;
 
+import org.apache.poi.util.HexDump;
+
+/**
+ * Class for the FLD structure.
+ * 
+ * @author Cedric Bosdonnat <cbosdonnat@novell.com>
+ *
+ */
 public final class FieldDescriptor
 {
+  public static final int FIELD_BEGIN_MARK = 0x13;
+  public static final int FIELD_SEPARATOR_MARK = 0x14;
+  public static final int FIELD_END_MARK = 0x15;
+
+  private static final short BOUNDARY_MASK = 0x1F;
+  private static final short TYPE_MASK = 0xFF;
+  private static final short ZOMBIE_EMBED_MASK = 0x02;
+  private static final short RESULT_DIRTY_MASK = 0x04;
+  private static final short RESULT_EDITED_MASK = 0x08;
+  private static final short LOCKED_MASK = 0x10;
+  private static final short PRIVATE_RESULT_MASK = 0x20;
+  private static final short NESTED_MASK = 0x40;
+  private static final short HAS_SEP_MASK = 0x80;
+
   byte _fieldBoundaryType;
   byte _info;
-    private final static BitField fZombieEmbed = BitFieldFactory.getInstance(0x02);
-    private final static BitField fResultDiry = BitFieldFactory.getInstance(0x04);
-    private final static BitField fResultEdited = BitFieldFactory.getInstance(0x08);
-    private final static BitField fLocked = BitFieldFactory.getInstance(0x10);
-    private final static BitField fPrivateResult = BitFieldFactory.getInstance(0x20);
-    private final static BitField fNested = BitFieldFactory.getInstance(0x40);
-    private final static BitField fHasSep = BitFieldFactory.getInstance(0x80);
 
+  private int fieldType;
+  private boolean zombieEmbed;
+  private boolean resultDirty;
+  private boolean resultEdited;
+  private boolean locked;
+  private boolean privateResult;
+  private boolean nested;
+  private boolean hasSep;
+
+  public FieldDescriptor(byte[] data)
+  {
+    _fieldBoundaryType = (byte) (data[0] & BOUNDARY_MASK);
+    _info = data[1];
+
+    if (_fieldBoundaryType == FIELD_BEGIN_MARK)
+    {
+      fieldType = _info & TYPE_MASK;
+    } else if (_fieldBoundaryType == FIELD_END_MARK)
+    {
+      zombieEmbed = ((_info & ZOMBIE_EMBED_MASK) == 1);
+      resultDirty = ((_info & RESULT_DIRTY_MASK) == 1);
+      resultEdited = ((_info & RESULT_EDITED_MASK) == 1);
+      locked = ((_info & LOCKED_MASK) == 1);
+      privateResult = ((_info & PRIVATE_RESULT_MASK) == 1);
+      nested = ((_info & NESTED_MASK) == 1);
+      hasSep = ((_info & HAS_SEP_MASK) == 1);
+    }
+  }
+
+  public int getBoundaryType()
+  {
+    return _fieldBoundaryType;
+  }
+
+  public int getFieldType()
+  {
+    if (_fieldBoundaryType != FIELD_BEGIN_MARK)
+      throw new UnsupportedOperationException(
+          "This field is only defined for begin marks.");
+    return fieldType;
+  }
 
-  public FieldDescriptor()
+  public boolean isZombieEmbed()
   {
+    if (_fieldBoundaryType != FIELD_END_MARK)
+      throw new UnsupportedOperationException(
+          "This field is only defined for end marks.");
+    return zombieEmbed;
+  }
+
+  public boolean isResultDirty()
+  {
+    if (_fieldBoundaryType != FIELD_END_MARK)
+      throw new UnsupportedOperationException(
+          "This field is only defined for end marks.");
+    return resultDirty;
+  }
+
+  public boolean isResultEdited()
+  {
+    if (_fieldBoundaryType != FIELD_END_MARK)
+      throw new UnsupportedOperationException(
+          "This field is only defined for end marks.");
+    return resultEdited;
+  }
+
+  public boolean isLocked()
+  {
+    if (_fieldBoundaryType != FIELD_END_MARK)
+      throw new UnsupportedOperationException(
+          "This field is only defined for end marks.");
+    return locked;
+  }
+
+  public boolean isPrivateResult()
+  {
+    if (_fieldBoundaryType != FIELD_END_MARK)
+      throw new UnsupportedOperationException(
+          "This field is only defined for end marks.");
+    return privateResult;
+  }
+
+  public boolean isNested()
+  {
+    if (_fieldBoundaryType != FIELD_END_MARK)
+      throw new UnsupportedOperationException(
+          "This field is only defined for end marks.");
+    return nested;
+  }
+
+  public boolean isHasSep()
+  {
+    if (_fieldBoundaryType != FIELD_END_MARK)
+      throw new UnsupportedOperationException(
+          "This field is only defined for end marks.");
+    return hasSep;
+  }
+
+  public String toString()
+  {
+    String details = new String();
+    if (_fieldBoundaryType == FIELD_BEGIN_MARK)
+    {
+      details = " type: " + fieldType;
+    }
+    else if (_fieldBoundaryType == FIELD_END_MARK)
+    {
+      details = " flags: 0x" + HexDump.toHex(_info);
+    }
+
+    return MessageFormat.format("FLD - 0x{0}{1}", HexDump
+        .toHex((byte) _fieldBoundaryType), details);
   }
 }

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java?rev=1081291&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java Mon Mar 14 09:10:12
2011
@@ -0,0 +1,116 @@
+/*
+ *  ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.hwpf.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+
+/**
+ * This class provides access to all the fields Plex.
+ * 
+ * @author Cedric Bosdonnat <cbosdonnat@novell.com>
+ *
+ */
+public class FieldsTables
+{
+  public static final int PLCFFLDATN = 0;
+  public static final int PLCFFLDEDN = 1;
+  public static final int PLCFFLDFTN = 2;
+  public static final int PLCFFLDHDR = 3;
+  public static final int PLCFFLDHDRTXBX = 4;
+  public static final int PLCFFLDMOM = 5;
+  public static final int PLCFFLDTXBX = 6;
+
+  // The size in bytes of the FLD data structure
+  private static final int FLD_SIZE = 2;
+
+  private HashMap<Integer, ArrayList<PlexOfField>> _tables;
+
+  public FieldsTables(byte[] tableStream, FileInformationBlock fib)
+  {
+    _tables = new HashMap<Integer, ArrayList<PlexOfField>>();
+
+    for (int i = PLCFFLDATN; i <= PLCFFLDTXBX; i++ )
+    {
+      _tables.put(i, readPLCF(tableStream, fib, i));
+    }
+  }
+  
+  public ArrayList<PlexOfField> getFieldsPLCF( int type )
+  {
+    return _tables.get(type);
+  }
+
+  private ArrayList<PlexOfField> readPLCF(byte[] tableStream, FileInformationBlock
fib, int type)
+  {
+    int start = 0;
+    int length = 0;
+
+    switch (type)
+    {
+    case PLCFFLDATN:
+      start = fib.getFcPlcffldAtn();
+      length = fib.getLcbPlcffldAtn();
+      break;
+    case PLCFFLDEDN:
+      start = fib.getFcPlcffldEdn();
+      length = fib.getLcbPlcffldEdn();
+      break;
+    case PLCFFLDFTN:
+      start = fib.getFcPlcffldFtn();
+      length = fib.getLcbPlcffldFtn();
+      break;
+    case PLCFFLDHDR:
+      start = fib.getFcPlcffldHdr();
+      length = fib.getLcbPlcffldHdr();
+      break;
+    case PLCFFLDHDRTXBX:
+      start = fib.getFcPlcffldHdrtxbx();
+      length = fib.getLcbPlcffldHdrtxbx();
+      break;
+    case PLCFFLDMOM:
+      start = fib.getFcPlcffldMom();
+      length = fib.getLcbPlcffldMom();
+      break;
+    case PLCFFLDTXBX:
+      start = fib.getFcPlcffldTxbx();
+      length = fib.getLcbPlcffldTxbx();
+    default:
+      break;
+    }
+
+    ArrayList<PlexOfField> fields = new ArrayList<PlexOfField>();
+
+    if (start > 0 && length > 0)
+    {
+      PlexOfCps plcf = new PlexOfCps(tableStream, start, length, FLD_SIZE);
+      fields.ensureCapacity(plcf.length());
+
+      for ( int i = 0; i < plcf.length(); i ++ ) {
+        GenericPropertyNode propNode = plcf.getProperty( i );
+        PlexOfField plex = new PlexOfField( propNode.getStart(), propNode.getEnd(), propNode.getBytes()
);
+        fields.add( plex );
+      }
+    }
+
+    return fields;
+  }
+}

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java Mon Mar
14 09:10:12 2011
@@ -66,7 +66,13 @@ public final class FileInformationBlock 
       fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFSED));
       fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFLST));
       fieldSet.add(Integer.valueOf(FIBFieldHandler.PLFLFO));
+      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDATN));
+      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDEDN));
+      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDFTN));
+      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDHDR));
+      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDHDRTXBX));
       fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDMOM));
+      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDTXBX));
       fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBFFFN));
       fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBFRMARK));
       fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBSAVEDBY));
@@ -456,6 +462,56 @@ public final class FileInformationBlock 
       _fieldHandler.clearFields();
     }
 
+    public int getFcPlcffldAtn()
+    {
+      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDATN);
+    }
+
+    public int getLcbPlcffldAtn()
+    {
+      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDATN);
+    }
+
+    public int getFcPlcffldEdn()
+    {
+      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDEDN);
+    }
+
+    public int getLcbPlcffldEdn()
+    {
+      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDEDN);
+    }
+
+    public int getFcPlcffldFtn()
+    {
+      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDFTN);
+    }
+
+    public int getLcbPlcffldFtn()
+    {
+      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDFTN);
+    }
+
+    public int getFcPlcffldHdr()
+    {
+      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDHDR);
+    }
+
+    public int getLcbPlcffldHdr()
+    {
+      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDHDR);
+    }
+
+    public int getFcPlcffldHdrtxbx()
+    {
+      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDHDRTXBX);
+    }
+
+    public int getLcbPlcffldHdrtxbx()
+    {
+      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDHDRTXBX);
+    }
+    
     public int getFcPlcffldMom()
     {
       return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDMOM);
@@ -465,6 +521,16 @@ public final class FileInformationBlock 
     {
       return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDMOM);
     }
+    
+    public int getFcPlcffldTxbx()
+    {
+      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDTXBX);
+    }
+
+    public int getLcbPlcffldTxbx()
+    {
+      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDTXBX);
+    }
 
     public int getFcPlcspaMom()
     {

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java?rev=1081291&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java Mon Mar 14 09:10:12
2011
@@ -0,0 +1,60 @@
+/*
+ *  ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.hwpf.model;
+
+import java.text.MessageFormat;
+
+/**
+ * Structure describing the Plex for fields (contained plclfd* in the spec).
+ * 
+ * @author Cedric Bosdonnat <cbosdonnat@novell.com>
+ *
+ */
+public class PlexOfField 
+{
+  private int fcStart;
+  private int fcEnd;
+  private FieldDescriptor fld;
+  
+  public PlexOfField( int fcStart, int fcEnd, byte[] data ) {
+      this.fcStart = fcStart;
+      this.fcEnd = fcEnd;
+      
+      fld = new FieldDescriptor( data );
+  }
+  
+  public int getFcStart() {
+      return fcStart;
+  }
+
+  public int getFcEnd() {
+      return fcEnd;
+  }
+
+  public FieldDescriptor getFld() {
+      return fld;
+  }
+  
+  public String toString() {
+      return MessageFormat.format( "[{0}, {1}) - {2}", 
+              fcStart, fcEnd, fld.toString() );
+      
+  }
+}

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java Mon Mar 14 09:10:12
2011
@@ -69,6 +69,7 @@ public final class AllHWPFTests {
 		suite.addTestSuite(TestSectionTable.class);
 		suite.addTestSuite(TestStyleSheet.class);
 		suite.addTestSuite(TestTextPieceTable.class);
+		suite.addTestSuite(TestFieldsTables.class);
 
 		suite.addTestSuite(TestBug46610.class);
 		suite.addTestSuite(TestHeaderStories.class);

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java Mon Mar 14
09:10:12 2011
@@ -25,13 +25,16 @@ import org.apache.poi.POIDataSamples;
 
 public final class HWPFDocFixture
 {
+  public static final String DEFAULT_TEST_FILE = "test.doc";
+  
   public byte[] _tableStream;
   public byte[] _mainStream;
   public FileInformationBlock _fib;
+  private String _testFile;
 
-  public HWPFDocFixture(Object obj)
+  public HWPFDocFixture(Object obj, String testFile)
   {
-
+    _testFile = testFile;
   }
 
   public void setUp()
@@ -39,7 +42,7 @@ public final class HWPFDocFixture
     try
     {
       POIFSFileSystem filesystem = new POIFSFileSystem(
-              POIDataSamples.getDocumentInstance().openResourceAsStream("test.doc"));
+              POIDataSamples.getDocumentInstance().openResourceAsStream(_testFile));
 
       DocumentEntry documentProps =
         (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java Mon Mar 14 09:10:12
2011
@@ -32,11 +32,16 @@ public abstract class HWPFTestCase exten
 	protected void setUp() throws Exception {
 		super.setUp();
 		/** @todo verify the constructors */
-		_hWPFDocFixture = new HWPFDocFixture(this);
+		_hWPFDocFixture = new HWPFDocFixture(this, getTestFile());
 
 		_hWPFDocFixture.setUp();
 	}
 
+	protected String getTestFile()
+	{
+	  return HWPFDocFixture.DEFAULT_TEST_FILE;
+	}
+
 	protected void tearDown() throws Exception {
 		if (_hWPFDocFixture != null) {
 			_hWPFDocFixture.tearDown();

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestFieldsTables.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestFieldsTables.java?rev=1081291&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestFieldsTables.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestFieldsTables.java Mon Mar 14
09:10:12 2011
@@ -0,0 +1,91 @@
+/*
+ *  ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.hwpf;
+
+import java.util.ArrayList;
+
+import org.apache.poi.hwpf.model.FieldsTables;
+import org.apache.poi.hwpf.model.FileInformationBlock;
+import org.apache.poi.hwpf.model.PlexOfField;
+
+/**
+ * Test case for the fields tables, this test is based on the test-fields.doc file
+ * instead of the usual test.doc.
+ * 
+ * @author Cedric Bosdonnat <cbosdonnat@novell.com>
+ *
+ */
+public class TestFieldsTables extends HWPFTestCase
+{
+  private static final int ALL_TYPES[] = {
+      FieldsTables.PLCFFLDATN,
+      FieldsTables.PLCFFLDEDN,
+      FieldsTables.PLCFFLDFTN,
+      FieldsTables.PLCFFLDHDR,
+      FieldsTables.PLCFFLDHDRTXBX,
+      FieldsTables.PLCFFLDMOM,
+      FieldsTables.PLCFFLDTXBX
+  };
+  
+  private static final String EXPECTED[] = {
+      "[19, 43) - FLD - 0x13 type: 31\n[43, 54) - FLD - 0x14\n[54, 59) - FLD - 0x15 flags:
0x81\n",
+      "[31, 59) - FLD - 0x13 type: 69\n[59, 61) - FLD - 0x14\n[61, 66) - FLD - 0x15 flags:
0x80\n",
+      "[23, 49) - FLD - 0x13 type: 17\n[49, 64) - FLD - 0x14\n[64, 69) - FLD - 0x15 flags:
0x80\n",
+      "[18, 42) - FLD - 0x13 type: 33\n[42, 44) - FLD - 0x14\n[44, 47) - FLD - 0x15 flags:
0x81\n" +
+        "[47, 75) - FLD - 0x13 type: 29\n[75, 85) - FLD - 0x14\n[85, 91) - FLD - 0x15 flags:
0x81\n",
+      "[30, 54) - FLD - 0x13 type: 32\n[54, 62) - FLD - 0x14\n[62, 68) - FLD - 0x15 flags:
0x81\n",
+      "[1, 31) - FLD - 0x13 type: 21\n[31, 51) - FLD - 0x14\n[51, 541) - FLD - 0x15 flags:
0x81\n",
+      "[19, 47) - FLD - 0x13 type: 25\n[47, 49) - FLD - 0x14\n[49, 55) - FLD - 0x15 flags:
0x81\n"
+  };
+  
+  public TestFieldsTables()
+  {
+  }
+  
+  protected String getTestFile()
+  {
+    return "test-fields.doc";
+  }
+  
+  public void testReadFields()
+  {
+    FileInformationBlock fib = _hWPFDocFixture._fib;
+    byte[] tableStream = _hWPFDocFixture._tableStream;
+    
+    FieldsTables fieldsTables = new FieldsTables(tableStream, fib);
+    
+    for (int i = 0; i < ALL_TYPES.length; i++)
+    {
+      ArrayList<PlexOfField> fieldsPlexes = fieldsTables.getFieldsPLCF( ALL_TYPES[i]
);
+      String result = dumpPlexes(fieldsPlexes);
+      assertEquals(EXPECTED[i], result);
+    }
+  }
+
+  private String dumpPlexes(ArrayList<PlexOfField> fieldsPlexes)
+  {
+    String dump = new String();
+    for ( int i=0; i<fieldsPlexes.size(); i++)
+    {
+      dump += fieldsPlexes.get(i).toString() + "\n";
+    }
+    return dump;
+  }
+}

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java Mon
Mar 14 09:10:12 2011
@@ -77,7 +77,7 @@ public final class TestCHPBinTable
     throws Exception
   {
     super.setUp();
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
 
     _hWPFDocFixture.setUp();
   }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
Mon Mar 14 09:10:12 2011
@@ -66,7 +66,7 @@ public final class TestDocumentPropertie
     super.setUp();
     /**@todo verify the constructors*/
 
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
 
     _hWPFDocFixture.setUp();
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java
Mon Mar 14 09:10:12 2011
@@ -53,7 +53,7 @@ public final class TestFileInformationBl
   {
     super.setUp();
     /**@todo verify the constructors*/
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
 
     _hWPFDocFixture.setUp();
     _fileInformationBlock = _hWPFDocFixture._fib;

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java Mon Mar
14 09:10:12 2011
@@ -58,7 +58,7 @@ public final class TestFontTable
   {
     super.setUp();
     /**@todo verify the constructors*/
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
 
     _hWPFDocFixture.setUp();
   }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java Mon
Mar 14 09:10:12 2011
@@ -77,7 +77,7 @@ public final class TestPAPBinTable
   {
     super.setUp();
     /**@todo verify the constructors*/
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
 
     _hWPFDocFixture.setUp();
   }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java Mon Mar
14 09:10:12 2011
@@ -61,7 +61,7 @@ public final class TestPlexOfCps
   {
     super.setUp();
     /**@todo verify the constructors*/
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
 
     _hWPFDocFixture.setUp();
   }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java Mon
Mar 14 09:10:12 2011
@@ -92,7 +92,7 @@ public final class TestSectionTable
   {
     super.setUp();
     /**@todo verify the constructors*/
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
 
     _hWPFDocFixture.setUp();
   }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java Mon Mar
14 09:10:12 2011
@@ -66,7 +66,7 @@ public final class TestStyleSheet
   {
     super.setUp();
     /**@todo verify the constructors*/
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
     _hWPFDocFixture.setUp();
     FileInformationBlock fib = _hWPFDocFixture._fib;
     byte[] mainStream = _hWPFDocFixture._mainStream;

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java?rev=1081291&r1=1081290&r2=1081291&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java Mon
Mar 14 09:10:12 2011
@@ -170,7 +170,7 @@ public final class TestTextPieceTable ex
   {
     super.setUp();
 
-    _hWPFDocFixture = new HWPFDocFixture(this);
+    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
     _hWPFDocFixture.setUp();
   }
 

Added: poi/trunk/test-data/document/test-fields.doc
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/test-fields.doc?rev=1081291&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/test-fields.doc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message