poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1160152 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/ src/org/apache/poi/hwpf/usermodel/ testcases/org/apache/poi/hwpf/extractor/
Date Mon, 22 Aug 2011 08:55:22 GMT
Author: sergey
Date: Mon Aug 22 08:55:21 2011
New Revision: 1160152

URL: http://svn.apache.org/viewvc?rev=1160152&view=rev
Log:
refix 51686 - fix possible NPE, add writeTo() to ObjectPoolImpl.

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.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=1160152&r1=1160151&r2=1160152&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 Aug 22 08:55:21
2011
@@ -69,6 +69,7 @@ import org.apache.poi.poifs.filesystem.D
 import org.apache.poi.poifs.filesystem.Entry;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.Internal;
+import org.apache.poi.util.POIUtils;
 
 
 /**
@@ -947,6 +948,7 @@ public final class HWPFDocument extends 
         POIFSFileSystem pfs = new POIFSFileSystem();
         boolean docWritten = false;
         boolean dataWritten = false;
+        boolean objectPoolWritten = false;
         boolean tableWritten = false;
         boolean propertiesWritten = false;
         for ( Iterator<Entry> iter = directory.getEntries(); iter.hasNext(); )
@@ -961,6 +963,14 @@ public final class HWPFDocument extends 
                     docWritten = true;
                 }
             }
+            else if ( entry.getName().equals( STREAM_OBJECT_POOL ) )
+            {
+                if ( !objectPoolWritten )
+                {
+                    _objectPool.writeTo( pfs.getRoot() );
+                    objectPoolWritten = true;
+                }
+            }
             else if ( entry.getName().equals( STREAM_TABLE_0 )
                     || entry.getName().equals( STREAM_TABLE_1 ) )
             {
@@ -993,7 +1003,7 @@ public final class HWPFDocument extends 
             }
             else
             {
-                copyNodeRecursively( entry, pfs.getRoot() );
+                POIUtils.copyNodeRecursively( entry, pfs.getRoot() );
             }
         }
 
@@ -1008,6 +1018,8 @@ public final class HWPFDocument extends 
         if ( !dataWritten )
             pfs.createDocument( new ByteArrayInputStream( dataBuf ),
                     STREAM_DATA );
+        if ( !objectPoolWritten )
+            _objectPool.writeTo( pfs.getRoot() );
 
         pfs.writeFilesystem( out );
         this.directory = pfs.getRoot();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java?rev=1160152&r1=1160151&r2=1160152&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java Mon Aug 22 08:55:21
2011
@@ -158,12 +158,14 @@ public abstract class HWPFDocumentCore e
       throw new EncryptedDocumentException("Cannot process encrypted word files!");
     }
 
+    DirectoryEntry objectPoolEntry;
     try {
-      DirectoryEntry objectPoolEntry = (DirectoryEntry) directory
+      objectPoolEntry = (DirectoryEntry) directory
               .getEntry(STREAM_OBJECT_POOL);
-      _objectPool = new ObjectPoolImpl(objectPoolEntry);
     } catch (FileNotFoundException exc) {
+      objectPoolEntry = null;
     }
+    _objectPool = new ObjectPoolImpl(objectPoolEntry);
   }
 
   /**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java?rev=1160152&r1=1160151&r2=1160152&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java Mon Aug
22 08:55:21 2011
@@ -17,10 +17,12 @@
 package org.apache.poi.hwpf.usermodel;
 
 import java.io.FileNotFoundException;
+import java.io.IOException;
 
 import org.apache.poi.poifs.filesystem.DirectoryEntry;
 import org.apache.poi.poifs.filesystem.Entry;
 import org.apache.poi.util.Internal;
+import org.apache.poi.util.POIUtils;
 
 @Internal
 public class ObjectPoolImpl implements ObjectsPool
@@ -47,4 +49,11 @@ public class ObjectPoolImpl implements O
             return null;
         }
     }
+
+    @Internal
+    public void writeTo( DirectoryEntry directoryEntry ) throws IOException
+    {
+        if ( _objectPool != null )
+            POIUtils.copyNodeRecursively( _objectPool, directoryEntry );
+    }
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java?rev=1160152&r1=1160151&r2=1160152&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
Mon Aug 22 08:55:21 2011
@@ -362,7 +362,7 @@ public final class TestWordExtractor ext
      * [RESOLVED FIXED] Bug 51686 - Update to POI 3.8 beta 4 causes
      * ConcurrentModificationException in Tika's OfficeParser
      */
-    public void testRootEntiesNavigation() throws IOException
+    public void testBug51686() throws IOException
     {
         InputStream is = POIDataSamples.getDocumentInstance()
                 .openResourceAsStream( "Bug51686.doc" );



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


Mime
View raw message