import java.io.IOException;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
-import java.io.FileOutputStream;
import java.util.Iterator;
+import org.apache.poi.POIDocument;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.common.POIFSConstants;
-import org.apache.poi.hwpf.usermodel.CharacterRun;
-import org.apache.poi.hwpf.usermodel.Paragraph;
-import org.apache.poi.hwpf.usermodel.TableProperties;
-import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
-import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
import org.apache.poi.hwpf.model.*;
import org.apache.poi.hwpf.model.io.*;
*
* @author Ryan Ackley
*/
-public class HWPFDocument
+public class HWPFDocument extends POIDocument
// implements Cloneable
{
/** The FIB*/
/**
* This constructor loads a Word document from a POIFSFileSystem
*
- * @param filesystem The POIFSFileSystem that contains the Word document.
+ * @param pfilesystem The POIFSFileSystem that contains the Word document.
* @throws IOException If there is an unexpected IOException from the passed
* in POIFSFileSystem.
*/
- public HWPFDocument(POIFSFileSystem filesystem) throws IOException
+ public HWPFDocument(POIFSFileSystem pfilesystem) throws IOException
{
+ // Sort out the hpsf properties
+ filesystem = pfilesystem;
+ readProperties();
+
// read in the main stream.
DocumentEntry documentProps =
(DocumentEntry)filesystem.getRoot().getEntry("WordDocument");
import java.io.*;
import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.poifs.filesystem.*;
/**
* @author Nick Burch (nick at torchbox dot com)
*/
public class TestPOIDocument extends TestCase {
- // The POI Document to work on
+ // The POI Documents to work on
private POIDocument doc;
- // POIFS primed on the test (powerpoint) data
+ private POIDocument doc2;
+ // POIFS primed on the test (powerpoint and word) data
private POIFSFileSystem pfs;
+ private POIFSFileSystem pfs2;
/**
- * Set things up, using a PowerPoint document for our testing
+ * Set things up, using a PowerPoint document and
+ * a Word Document for our testing
*/
public void setUp() throws Exception {
- String dirname = System.getProperty("HSLF.testdata.path");
- String filename = dirname + "/basic_test_ppt_file.ppt";
- FileInputStream fis = new FileInputStream(filename);
- pfs = new POIFSFileSystem(fis);
+ String dirnameHSLF = System.getProperty("HSLF.testdata.path");
+ String filenameHSLF = dirnameHSLF + "/basic_test_ppt_file.ppt";
+ String dirnameHWPF = System.getProperty("HWPF.testdata.path");
+ String filenameHWPF = dirnameHWPF + "/test2.doc";
+
+ FileInputStream fisHSLF = new FileInputStream(filenameHSLF);
+ pfs = new POIFSFileSystem(fisHSLF);
doc = new HSLFSlideShow(pfs);
+
+ FileInputStream fisHWPF = new FileInputStream(filenameHWPF);
+ pfs2 = new POIFSFileSystem(fisHWPF);
+ doc2 = new HWPFDocument(pfs2);
}
public void testReadProperties() throws Exception {
assertEquals("Hogwarts", doc.getSummaryInformation().getAuthor());
assertEquals(10598, doc.getDocumentSummaryInformation().getByteCount());
}
+
+ public void testReadProperties2() throws Exception {
+ // Check again on the word one
+ assertNotNull(doc2.getDocumentSummaryInformation());
+ assertNotNull(doc2.getSummaryInformation());
+
+ assertEquals("Hogwarts", doc2.getSummaryInformation().getAuthor());
+ assertEquals("", doc2.getSummaryInformation().getKeywords());
+ assertEquals(0, doc2.getDocumentSummaryInformation().getByteCount());
+ }
public void testWriteProperties() throws Exception {
// Just check we can write them back out into a filesystem