Convert HWPFDocument to having POIDocument as its parent

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@391365 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2006-04-04 17:02:14 +00:00
parent 7fa4feb4bb
commit 4850277501
2 changed files with 36 additions and 16 deletions

View File

@ -22,18 +22,13 @@ import java.io.FileInputStream;
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.*;
@ -47,7 +42,7 @@ import org.apache.poi.hwpf.usermodel.*;
*
* @author Ryan Ackley
*/
public class HWPFDocument
public class HWPFDocument extends POIDocument
// implements Cloneable
{
/** The FIB*/
@ -110,12 +105,16 @@ public class HWPFDocument
/**
* 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");

View File

@ -24,6 +24,7 @@ import junit.framework.TestCase;
import java.io.*;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.poifs.filesystem.*;
/**
@ -33,20 +34,30 @@ 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 {
@ -58,6 +69,16 @@ public class TestPOIDocument extends TestCase {
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