poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1156662 [1/3] - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/ src/org/apache/poi/hwpf/dev/ src/org/apache/poi/hwpf/model/ src/org/apache/poi/hwpf/model/types/ testcases/org/apache/poi/hwpf/model/ testcases/org/apache/poi/hwpf/user...
Date Thu, 11 Aug 2011 16:37:32 GMT
Author: sergey
Date: Thu Aug 11 16:37:31 2011
New Revision: 1156662

URL: http://svn.apache.org/viewvc?rev=1156662&view=rev
Log:
fix issues related to document properties loading and saving

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java

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=1156662&r1=1156661&r2=1156662&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 Thu Aug 11 16:37:31
2011
@@ -264,7 +264,7 @@ public final class HWPFDocument extends 
     //fcMin = _fib.getFcMin()
 
     // Start to load up our standard structures.
-    _dop = new DocumentProperties(_tableStream, _fib.getFcDop());
+    _dop = new DocumentProperties(_tableStream, _fib.getFcDop(), _fib.getLcbDop() );
     _cft = new ComplexFileTable(_mainStream, _tableStream, _fib.getFcClx(), fcMin);
     TextPieceTable _tpt = _cft.getTextPieceTable();
 
@@ -683,6 +683,21 @@ public final class HWPFDocument extends 
     int fcMac = mainStream.getOffset();
 
         /*
+         * dop (document properties record) Written immediately after the end of
+         * the previously recorded structure. This is recorded in all Word
+         * documents
+         * 
+         * Microsoft Office Word 97-2007 Binary File Format (.doc)
+         * Specification; Page 23 of 210
+         */
+
+    // write out the DocumentProperties.
+    _fib.setFcDop(tableOffset);
+    _dop.writeTo(tableStream);
+    _fib.setLcbDop(tableStream.getOffset() - tableOffset);
+    tableOffset = tableStream.getOffset();
+
+        /*
          * plcfBkmkf (table recording beginning CPs of bookmarks) Written
          * immediately after the sttbfBkmk, if the document contains bookmarks.
          * 
@@ -881,13 +896,6 @@ public final class HWPFDocument extends 
     _fib.setLcbSttbfffn(tableStream.getOffset() - tableOffset);
     tableOffset = tableStream.getOffset();
 
-    // write out the DocumentProperties.
-    _fib.setFcDop(tableOffset);
-    byte[] buf = new byte[_dop.getSize()];
-    _fib.setLcbDop(_dop.getSize());
-    _dop.serialize(buf, 0);
-    tableStream.write(buf);
-
     // set some variables in the FileInformationBlock.
     _fib.setFcMin(fcMin);
     _fib.setFcMac(fcMac);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java?rev=1156662&r1=1156661&r2=1156662&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java Thu Aug 11 16:37:31
2011
@@ -101,7 +101,7 @@ public final class HWPFLister
         if ( args.length == 0 )
         {
             System.err.println( "Use:" );
-            System.err.println( "\tHWPFLister <filename>\n"
+            System.err.println( "\tHWPFLister <filename>\n" + "\t\t[--dop]\n"
                     + "\t\t[--textPieces] [--textPiecesText]\n"
                     + "\t\t[--chpx] [--chpxProperties] [--chpxSprms]\n"
                     + "\t\t[--papx] [--papxProperties] [--papxSprms]\n"
@@ -112,6 +112,8 @@ public final class HWPFLister
             System.exit( 1 );
         }
 
+        boolean outputDop = false;
+
         boolean outputTextPieces = false;
         boolean outputTextPiecesText = false;
 
@@ -136,6 +138,9 @@ public final class HWPFLister
 
         for ( String arg : Arrays.asList( args ).subList( 1, args.length ) )
         {
+            if ( "--dop".equals( arg ) )
+                outputDop = true;
+
             if ( "--textPieces".equals( arg ) )
                 outputTextPieces = true;
             if ( "--textPiecesText".equals( arg ) )
@@ -197,6 +202,12 @@ public final class HWPFLister
         System.out.println( "== FIB (original) ==" );
         listerOriginal.dumpFIB();
 
+        if ( outputDop )
+        {
+            System.out.println( "== Document properties ==" );
+            listerOriginal.dumpDop();
+        }
+
         if ( outputTextPieces )
         {
             System.out.println( "== Text pieces (original) ==" );
@@ -371,6 +382,17 @@ public final class HWPFLister
         }
     }
 
+    private void dumpDop()
+    {
+        if ( !( _doc instanceof HWPFDocument ) )
+        {
+            System.out.println( "Word 95 not supported so far" );
+            return;
+        }
+
+        System.out.println( ( (HWPFDocument) _doc ).getDocProperties() );
+    }
+
     private void dumpEscher()
     {
         if ( _doc instanceof HWPFOldDocument )

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java?rev=1156662&r1=1156661&r2=1156662&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java Thu Aug
11 16:37:31 2011
@@ -17,19 +17,60 @@
 
 package org.apache.poi.hwpf.model;
 
+import java.io.IOException;
+
+import org.apache.poi.hwpf.model.io.HWPFOutputStream;
 import org.apache.poi.hwpf.model.types.DOPAbstractType;
 import org.apache.poi.util.Internal;
+import org.apache.poi.util.LittleEndian;
 
 /**
  * Comment me
- *
+ * 
  * @author Ryan Ackley
  */
 @Internal
-public final class DocumentProperties extends DOPAbstractType {
+public final class DocumentProperties extends DOPAbstractType
+{
+
+    private byte[] _preserved;
+
+    /**
+     * @deprecated Use {@link #DocumentProperties(byte[],int,int)} instead
+     */
+    public DocumentProperties( byte[] tableStream, int offset )
+    {
+        this( tableStream, offset, DOPAbstractType.getSize() );
+    }
+
+    public DocumentProperties( byte[] tableStream, int offset, int length )
+    {
+        super.fillFields( tableStream, offset );
+
+        final int supportedSize = DOPAbstractType.getSize();
+        if ( length != supportedSize )
+        {
+            this._preserved = LittleEndian.getByteArray( tableStream, offset
+                    + supportedSize, length - supportedSize );
+        }
+        else
+        {
+            _preserved = new byte[0];
+        }
+    }
+
+    @Override
+    public void serialize( byte[] data, int offset )
+    {
+        super.serialize( data, offset );
+    }
 
+    public void writeTo( HWPFOutputStream tableStream ) throws IOException
+    {
+        byte[] supported = new byte[getSize()];
+        serialize( supported, 0 );
 
-	public DocumentProperties(byte[] tableStream, int offset) {
-		super.fillFields(tableStream, offset);
-	}
+        tableStream.write( supported );
+        tableStream.write( _preserved );
+    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java?rev=1156662&r1=1156661&r2=1156662&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java Thu Aug 11
16:37:31 2011
@@ -71,6 +71,7 @@ public final class FIBFieldHandler
   public static final int PRENVPORT = 28;
   public static final int PRENVLAND = 29;
   public static final int WSS = 30;
+  // 402 == 0x0192; 406 == 0x0196
   public static final int DOP = 31;
   public static final int STTBFASSOC = 32;
   public static final int CLX = 33;

Modified: 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=1156662&r1=1156661&r2=1156662&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java Thu Aug 11 16:37:31
2011
@@ -135,7 +135,11 @@ public class FieldsTables
             throws IOException
     {
         if ( plexOfCps == null || plexOfCps.length() == 0 )
+        {
+            fib.setFieldsPlcfOffset( part, outputStream.getOffset() );
+            fib.setFieldsPlcfLength( part, 0 );
             return 0;
+        }
 
         byte[] data = plexOfCps.toByteArray();
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java?rev=1156662&r1=1156661&r2=1156662&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java Thu Aug 11 16:37:31
2011
@@ -87,7 +87,7 @@ public class NotesTables
     {
         if ( descriptors == null || descriptors.length() == 0 )
         {
-            fib.setNotesDescriptorsOffset( noteType, 0 );
+            fib.setNotesDescriptorsOffset( noteType, tableStream.getOffset() );
             fib.setNotesDescriptorsSize( noteType, 0 );
             return;
         }
@@ -105,7 +105,7 @@ public class NotesTables
     {
         if ( textPositions == null || textPositions.length() == 0 )
         {
-            fib.setNotesTextPositionsOffset( noteType, 0 );
+            fib.setNotesTextPositionsOffset( noteType, tableStream.getOffset() );
             fib.setNotesTextPositionsSize( noteType, 0 );
             return;
         }



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


Mime
View raw message