You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by ni...@apache.org on 2006/04/04 19:02:15 UTC

svn commit: r391365 - in /jakarta/poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/HWPFDocument.java testcases/org/apache/poi/TestPOIDocument.java

Author: nick
Date: Tue Apr  4 10:02:14 2006
New Revision: 391365

URL: http://svn.apache.org/viewcvs?rev=391365&view=rev
Log:
Convert HWPFDocument to having POIDocument as its parent

Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocument.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=391365&r1=391364&r2=391365&view=diff
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Tue Apr  4 10:02:14 2006
@@ -22,18 +22,13 @@
 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 @@
  *
  * @author Ryan Ackley
  */
-public class HWPFDocument
+public class HWPFDocument extends POIDocument
 //  implements Cloneable
 {
   /** The FIB*/
@@ -110,12 +105,16 @@
   /**
    * 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");

Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocument.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocument.java?rev=391365&r1=391364&r2=391365&view=diff
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocument.java (original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocument.java Tue Apr  4 10:02:14 2006
@@ -24,6 +24,7 @@
 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 @@
  * @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 {
@@ -57,6 +68,16 @@
     	// Check they are as expected for the test doc
     	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 {



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/