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;
/**
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(); )
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 ) )
{
}
else
{
- copyNodeRecursively( entry, pfs.getRoot() );
+ POIUtils.copyNodeRecursively( entry, pfs.getRoot() );
}
}
if ( !dataWritten )
pfs.createDocument( new ByteArrayInputStream( dataBuf ),
STREAM_DATA );
+ if ( !objectPoolWritten )
+ _objectPool.writeTo( pfs.getRoot() );
pfs.writeFilesystem( out );
this.directory = pfs.getRoot();
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);
}
/**
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
return null;
}
}
+
+ @Internal
+ public void writeTo( DirectoryEntry directoryEntry ) throws IOException
+ {
+ if ( _objectPool != null )
+ POIUtils.copyNodeRecursively( _objectPool, directoryEntry );
+ }
}
* [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" );